This commit was generated by cvs2svn to track changes on a CVS vendor
[openssl.git] / util / mk1mf.pl
1 #!/usr/local/bin/perl
2 # A bit of an evil hack but it post processes the file ../MINFO which
3 # is generated by `make files` in the top directory.
4 # This script outputs one mega makefile that has no shell stuff or any
5 # funny stuff
6 #
7
8 $INSTALLTOP="/usr/local/ssl";
9
10 $infile="MINFO";
11
12 %ops=(
13         "VC-WIN32",   "Microsoft Visual C++ 4.[01] - Windows NT [34].x",
14         "VC-W31-16",  "Microsoft Visual C++ 1.52 - Windows 3.1 - 286",
15         "VC-WIN16",   "Alias for VC-W31-32",
16         "VC-W31-32",  "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+",
17         "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS",
18         "BC-NT",   "Borland C++ 4.5 - Windows NT  - PROBABLY NOT WORKING",
19         "BC-W31",  "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING",
20         "BC-MSDOS","Borland C++ 4.5 - MSDOS",
21         "FreeBSD","FreeBSD distribution",
22         "default","cc under unix",
23         );
24
25 $type="";
26 foreach (@ARGV)
27         {
28         if    (/^no-rc2$/)      { $no_rc2=1; }
29         elsif (/^no-rc4$/)      { $no_rc4=1; }
30         elsif (/^no-idea$/)     { $no_idea=1; }
31         elsif (/^no-des$/)      { $no_des=1; }
32         elsif (/^no-bf$/)       { $no_bf=1; }
33         elsif (/^no-md2$/)      { $no_md2=1; }
34         elsif (/^no-md5$/)      { $no_md5=1; }
35         elsif (/^no-sha$/)      { $no_sha=1; }
36         elsif (/^no-sha1$/)     { $no_sha1=1; }
37         elsif (/^no-mdc2$/)     { $no_mdc2=1; }
38         elsif (/^no-patents$/)  { $no_rc2=$no_rc4=$no_idea=$no_sha1=$no_rsa=1; }
39         elsif (/^no-rsa$/)      { $no_rsa=1; }
40         elsif (/^no-dsa$/)      { $no_dsa=1; }
41         elsif (/^no-dh$/)       { $no_dh=1; }
42         elsif (/^no-asm$/)      { $no_asm=1; }
43         elsif (/^no-ssl2$/)     { $no_ssl2=1; }
44         elsif (/^no-ssl3$/)     { $no_ssl3=1; }
45         elsif (/^no-err$/)      { $no_err=1; }
46         elsif (/^no-sock$/)     { $no_sock=1; }
47
48         elsif (/^rsaref$/)      { $rsaref=1; }
49         elsif (/^gcc$/)         { $gcc=1; }
50         elsif (/^debug$/)       { $debug=1; }
51         elsif (/^shlib$/)       { $shlib=1; }
52         elsif (/^dll$/)         { $shlib=1; }
53         elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
54         elsif (/^-[lL].*$/)     { $l_flags.="$_ "; }
55         elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
56                 { $c_flags.="$_ "; }
57         else
58                 {
59                 if (!defined($ops{$_}))
60                         {
61                         print STDERR "unknown option - $_\n";
62                         print STDERR "usage: perl mk1mf.pl [system] [options]\n";
63                         print STDERR "\nwhere [system] can be one of the following\n";
64                         foreach $i (sort keys %ops)
65                                 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
66                         print STDERR <<"EOF";
67 and [options] can be one of
68         no-md2 no-md5 no-sha no-sha1 no-mdc2    - Skip this digest
69         no-rc2 no-rc4 no-idea no-des no-bf      - Skip this symetriccipher
70         no-rsa no-dsa no-dh                     - Skip this public key cipher
71         no-ssl2 no-ssl3                         - Skip this version of SSL
72         just-ssl                                - remove all non-ssl keys/digest
73         no-asm                                  - No x86 asm
74         no-socks                                - No socket code
75         no-err                                  - No error strings
76         dll/shlib                               - Build shared libraries (MS)
77         debug                                   - Debug build
78         gcc                                     - Use Gcc (unix)
79         rsaref                                  - Build to require RSAref
80
81 Values that can be set
82 TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath CC=C-compiler
83
84 -L<ex_lib_path> -l<ex_lib>                      - extra library flags (unix)
85 -<ex_cc_flags>                                  - extra 'cc' flags,
86                                                   added (MS), or replace (unix)
87 EOF
88                         exit(1);
89                         }
90                 $type=$_;
91                 }
92         }
93
94 $no_mdc2=1 if ($no_des);
95
96 $no_ssl3=1 if ($no_md5 || $no_sha1);
97 $no_ssl3=1 if ($no_rsa && $no_dh);
98
99 $no_ssl2=1 if ($no_md5 || $no_rsa);
100 $no_ssl2=1 if ($no_rsa);
101
102 $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
103 $src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
104 $out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:'out';
105 $tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:'tmp';
106 $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
107
108 ($ssl,$crypto)=("ssl","crypto");
109 $RSAglue="RSAglue";
110 $ranlib="echo ranlib";
111
112 push(@INC,"util/pl","pl");
113 if ($type eq "VC-MSDOS")
114         {
115         $asmbits=16;
116         $msdos=1;
117         require 'VC-16.pl';
118         }
119 elsif ($type eq "VC-W31-16")
120         {
121         $asmbits=16;
122         $msdos=1; $win16=1;
123         require 'VC-16.pl';
124         }
125 elsif (($type eq "VC-W31-32") || ($type eq "VC-WIN16"))
126         {
127         $asmbits=32;
128         $msdos=1; $win16=1;
129         require 'VC-16.pl';
130         }
131 elsif (($type eq "VC-WIN32") || ($type eq "VC-NT"))
132         {
133         require 'VC-32.pl';
134         }
135 elsif ($type eq "BC-NT")
136         {
137         $bc=1;
138         require 'BC-32.pl';
139         }
140 elsif ($type eq "BC-W31")
141         {
142         $bc=1;
143         $msdos=1; $w16=1;
144         require 'BC-16.pl';
145         }
146 elsif ($type eq "BC-Q16")
147         {
148         $msdos=1; $w16=1; $shlib=0; $qw=1;
149         require 'BC-16.pl';
150         }
151 elsif ($type eq "BC-MSDOS")
152         {
153         $asmbits=16;
154         $msdos=1;
155         require 'BC-16.pl';
156         }
157 elsif ($type eq "FreeBSD")
158         {
159         require 'unix.pl';
160         $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
161         }
162 else
163         {
164         require "unix.pl";
165
166         $unix=1;
167         $cflags.=' -DTERMIO';
168         }
169
170 # $bin_dir.=$o causes a core dump on my sparc :-(
171 $bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
172
173 $cflags.=" -DNO_IDEA" if $no_idea;
174 $cflags.=" -DNO_RC2"  if $no_rc2;
175 $cflags.=" -DNO_RC4"  if $no_rc4;
176 $cflags.=" -DNO_MD2"  if $no_md2;
177 $cflags.=" -DNO_MD5"  if $no_md5;
178 $cflags.=" -DNO_SHA"  if $no_sha;
179 $cflags.=" -DNO_SHA1" if $no_sha1;
180 $cflags.=" -DNO_MDC2" if $no_mdc2;
181 $cflags.=" -DNO_BLOWFISH"  if $no_bf;
182 $cflags.=" -DNO_DES"  if $no_des;
183 $cflags.=" -DNO_RSA"  if $no_rsa;
184 $cflags.=" -DNO_DSA"  if $no_dsa;
185 $cflags.=" -DNO_DH"   if $no_dh;
186 $cflags.=" -DNO_SOCK" if $no_sock;
187 $cflags.=" -DNO_SSL2" if $no_ssl2;
188 $cflags.=" -DNO_SSL3" if $no_ssl3;
189 $cflags.=" -DNO_ERR"  if $no_err;
190 $cflags.=" -DRSAref"  if $rsaref ne "";
191
192 if ($unix)
193         { $cflags="$c_flags" if ($c_flags ne ""); }
194 else    { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
195
196 $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
197
198 if ($ranlib ne "")
199         {
200         $ranlib="\$(SRC_D)$o$ranlib";
201         }
202
203 if ($msdos)
204         {
205         $banner ="\t\@echo Make sure you have run 'perl Configure $type' in the\n";
206         $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
207         $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
208         $banner.="\t\@echo documentation for details.\n";
209         }
210
211 # have to do this to allow $(CC) under unix
212 $link="$bin_dir$link" if ($link !~ /^\$/);
213
214 $INSTALLTOP =~ s|/|$o|g;
215
216 $defs= <<"EOF";
217 # This makefile has been automatically generated from the SSLeay distribution.
218 # This single makefile will build the complete SSLeay distribution and
219 # by default leave the 'intertesting' output files in .${o}out and the stuff
220 # that needs deleting in .${o}tmp.
221 # The file was generated by running 'make makefile.one', which
222 # does a 'make files', which writes all the environment variables from all
223 # the makefiles to the file call MINFO.  This file is used by
224 # util${o}mk1mf.pl to generate makefile.one.
225 # The 'makefile per directory' system suites me when developing this
226 # library and also so I can 'distribute' indervidual library sections.
227 # The one monster makefile better suits building in non-unix
228 # environments.
229
230 INSTALLTOP=$INSTALLTOP
231
232 # Set your compiler options
233 CC=$bin_dir${cc}
234 CFLAG=$cflags
235 APP_CFLAG=$app_cflag
236 LIB_CFLAG=$lib_cflag
237 APP_EX_OBJ=$app_ex_obj
238 SHLIB_EX_OBJ=$shlib_ex_obj
239 # add extra libraries to this define, for solaris -lsocket -lnsl would
240 # be added
241 EX_LIBS=$ex_libs
242
243 # The SSLeay directory
244 SRC_D=$src_dir
245
246 LINK=$link
247 LFLAGS=$lflags
248
249 BN_MULW_OBJ=$bn_mulw_obj
250 BN_MULW_SRC=$bn_mulw_src
251 DES_ENC_OBJ=$des_enc_obj
252 DES_ENC_SRC=$des_enc_src
253 DES_CRYPT_OBJ=$des_crypt_obj
254 DES_CRYPT_SRC=$des_crypt_src
255 BF_ENC_OBJ=$bf_enc_obj
256 BF_ENC_SRC=$bf_enc_src
257
258 # The output directory for everything intersting
259 OUT_D=$out_dir
260 # The output directory for all the temporary muck
261 TMP_D=$tmp_dir
262
263 CP=$cp
264 RM=$rm
265 RANLIB=$ranlib
266 MKDIR=mkdir
267 MKLIB=$bin_dir$mklib
268 MLFLAGS=$mlflags
269 ASM=$bin_dir$asm
270
271 ######################################################
272 # You should not need to touch anything below this point
273 ######################################################
274
275 E_EXE=ssleay
276 SSL=$ssl
277 CRYPTO=$crypto
278 RSAGLUE=$RSAglue
279
280 # BIN_D  - Binary output directory
281 # TEST_D - Binary test file output directory
282 # LIB_D  - library output directory
283 # INC_D  - include directory
284 BIN_D=\$(OUT_D)
285 TEST_D=\$(OUT_D)
286 LIB_D=\$(OUT_D)
287 INC_D=\$(OUT_D)
288
289 # INCL_D - local library directory
290 # OBJ_D  - temp object file directory
291 OBJ_D=\$(TMP_D)
292 INCL_D=\$(TMP_D)
293
294 O_SSL=     \$(LIB_D)$o$plib\$(SSL)$shlibp
295 O_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
296 O_RSAGLUE= \$(LIB_D)$o$plib\$(RSAGLUE)$libp
297 L_SSL=     \$(LIB_D)$o$plib\$(SSL)$libp
298 L_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$libp
299
300 L_LIBS= \$(L_SSL) \$(L_CRYPTO)
301 #L_LIBS= \$(O_SSL) \$(O_RSAGLUE) -lrsaref \$(O_CRYPTO)
302
303 ######################################################
304 # Don't touch anything below this point
305 ######################################################
306
307 INC=-DFLAT_INC -I\$(INC_D) -I\$(INCL_D)
308 APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
309 LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
310 LIBS_DEP=\$(O_CRYPTO) \$(O_RSAGLUE) \$(O_SSL)
311
312 #############################################
313 EOF
314
315 $rules=<<"EOF";
316 all: banner \$(OUT_D) \$(TMP_D) headers lib exe
317
318 banner:
319 $banner
320
321 \$(OUT_D):
322         \$(MKDIR) \$(OUT_D)
323
324 \$(TMP_D):
325         \$(MKDIR) \$(TMP_D)
326
327 headers: \$(HEADER) \$(EXHEADER)
328
329 lib: \$(LIBS_DEP)
330
331 exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
332
333 install:
334         \$(MKDIR) \$(INSTALLTOP)
335         \$(MKDIR) \$(INSTALLTOP)${o}bin
336         \$(MKDIR) \$(INSTALLTOP)${o}include
337         \$(MKDIR) \$(INSTALLTOP)${o}lib
338         \$(CP) \$(INC_D)${o}*.h \$(INSTALLTOP)${o}include
339         \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin
340         \$(CP) \$(LIB_D)$o\$(O_SSL) \$(INSTALLTOP)${o}lib
341         \$(CP) \$(LIB_D)$o\$(O_CRYPTO) \$(INSTALLTOP)${o}lib
342
343 clean:
344         \$(RM) \$(TMP_D)$o*.*
345
346 vclean:
347         \$(RM) \$(TMP_D)$o*.*
348         \$(RM) \$(OUT_D)$o*.*
349
350 EOF
351
352 #############################################
353 # We parse in input file and 'store' info for later printing.
354 open(IN,"<$infile") || die "unable to open $infile:$!\n";
355 $_=<IN>;
356 for (;;)
357         {
358         chop;
359
360         ($key,$val)=/^([^=]+)=(.*)/;
361         if ($key eq "RELATIVE_DIRECTORY")
362                 {
363                 if ($lib ne "")
364                         {
365                         $uc=$lib;
366                         $uc =~ s/^lib(.*)\.a/$1/;
367                         $uc =~ tr/a-z/A-Z/;
368                         $lib_nam{$uc}=$uc;
369                         $lib_obj{$uc}.=$libobj." ";
370                         }
371                 last if ($val eq "FINISHED");
372                 $lib="";
373                 $libobj="";
374                 $dir=$val;
375                 }
376
377         if ($key eq "TEST")
378                 { $test.=&var_add($dir,$val); }
379
380         if (($key eq "PROGS") || ($key eq "E_OBJ"))
381                 { $e_exe.=&var_add($dir,$val); }
382
383         if ($key eq "LIB")
384                 {
385                 $lib=$val;
386                 $lib =~ s/^.*\/([^\/]+)$/$1/;
387                 }
388
389         if ($key eq "EXHEADER")
390                 { $exheader.=&var_add($dir,$val); }
391
392         if ($key eq "HEADER")
393                 { $header.=&var_add($dir,$val); }
394
395         if ($key eq "LIBOBJ")
396                 { $libobj=&var_add($dir,$val); }
397
398         if (!($_=<IN>))
399                 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
400         }
401 close(IN);
402
403 # Strip of trailing ' '
404 foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
405 $test=&clean_up_ws($test);
406 $e_exe=&clean_up_ws($e_exe);
407 $exheader=&clean_up_ws($exheader);
408 $header=&clean_up_ws($header);
409
410 # First we strip the exheaders from the headers list
411 foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
412 foreach (split(/\s+/,$header))  { $h.=$_." " unless $h{$_}; }
413 chop($h); $header=$h;
414
415 $defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h");
416 $rules.=&do_copy_rule("\$(INCL_D)",$header,".h");
417
418 $defs.=&do_defs("EXHEADER",$exheader,"\$(INC_D)",".h");
419 $rules.=&do_copy_rule("\$(INC_D)",$exheader,".h");
420
421 $defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
422 $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
423
424 $defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
425 $rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
426
427 foreach (values %lib_nam)
428         {
429         $lib_obj=$lib_obj{$_};
430
431         if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
432                 {
433                 $rules.="\$(O_SSL):\n\n"; 
434                 next;
435                 }
436
437         if (($_ eq "RSAGLUE") && $no_rsa)
438                 {
439                 $rules.="\$(O_RSAGLUE):\n\n"; 
440                 next;
441                 }
442
443         if (($bn_mulw_obj ne "") && ($_ eq "CRYPTO"))
444                 {
445                 $lib_obj =~ s/\S*bn_mulw\S*/\$(BN_MULW_OBJ)/;
446                 $rules.=&do_asm_rule($bn_mulw_obj,$bn_mulw_src);
447                 }
448         if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
449                 {
450                 $lib_obj =~ s/\S*des_enc\S*/\$(DES_ENC_OBJ)/;
451                 $lib_obj =~ s/\S*fcrypt_b\S*\s*//;
452                 $rules.=&do_asm_rule($des_enc_obj,$des_enc_src);
453                 }
454         if (($bf_enc_obj ne "") && ($_ eq "CRYPTO"))
455                 {
456                 $lib_obj =~ s/\S*bf_enc\S*/\$(BF_ENC_OBJ)/;
457                 $rules.=&do_asm_rule($bf_enc_obj,$bf_enc_src);
458                 }
459         $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
460         $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},"\$(LIB_CFLAGS)");
461         }
462
463 $defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
464 foreach (split(/\s+/,$test))
465         {
466         $t=&bname($_);
467         $tt="\$(OBJ_D)${o}$t${obj}";
468         $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
469         }
470
471 $rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib);
472 $rules.= &do_lib_rule("\$(RSAGLUEOBJ)","\$(O_RSAGLUE)",$RSAglue,0)
473         unless $no_rsa;
474 $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib);
475
476 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
477
478 print $defs;
479 print "###################################################################\n";
480 print $rules;
481
482 ###############################################
483 # strip off any trailing .[och] and append the relative directory
484 # also remembering to do nothing if we are in one of the dropped
485 # directories
486 sub var_add
487         {
488         local($dir,$val)=@_;
489         local(@a,$_,$ret);
490
491         return("") if $no_idea && $dir =~ /\/idea/;
492         return("") if $no_rc2  && $dir =~ /\/rc2/;
493         return("") if $no_rc4  && $dir =~ /\/rc4/;
494         return("") if $no_rsa  && $dir =~ /\/rsa/;
495         return("") if $no_rsa  && $dir =~ /^rsaref/;
496         return("") if $no_dsa  && $dir =~ /\/dsa/;
497         return("") if $no_dh   && $dir =~ /\/dh/;
498         if ($no_des && $dir =~ /\/des/)
499                 {
500                 if ($val =~ /read_pwd/)
501                         { return("$dir/read_pwd "); }
502                 else
503                         { return(""); }
504                 }
505         return("") if $no_mdc2 && $dir =~ /\/mdc2/;
506         return("") if $no_sock && $dir =~ /\/proxy/;
507         return("") if $no_bf   && $dir =~ /\/bf/;
508
509         $val =~ s/^\s*(.*)\s*$/$1/;
510         @a=split(/\s+/,$val);
511         grep(s/\.[och]$//,@a);
512
513         @a=grep(!/^e_.*_3d$/,@a) if $no_des;
514         @a=grep(!/^e_.*_d$/,@a) if $no_des;
515         @a=grep(!/^e_.*_i$/,@a) if $no_idea;
516         @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
517         @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
518         @a=grep(!/^e_rc4$/,@a) if $no_rc4;
519
520         @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
521         @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
522
523         @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
524
525         @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
526         @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
527
528         @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
529         @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
530         @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
531
532         @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
533         @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
534
535         @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
536
537         @a=grep(!/_dhp$/,@a) if $no_dh;
538
539         @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
540         @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
541         @a=grep(!/_mdc2$/,@a) if $no_mdc2;
542
543         @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa;
544         @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
545         @a=grep(!/^gendsa$/,@a) if $no_sha1;
546         @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
547
548         @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
549
550         grep($_="$dir/$_",@a);
551         @a=grep(!/(^|\/)s_/,@a) if $no_sock;
552         @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
553         $ret=join(' ',@a)." ";
554         return($ret);
555         }
556
557 # change things so that each 'token' is only separated by one space
558 sub clean_up_ws
559         {
560         local($w)=@_;
561
562         $w =~ s/^\s*(.*)\s*$/$1/;
563         $w =~ s/\s+/ /g;
564         return($w);
565         }
566
567 sub do_defs
568         {
569         local($var,$files,$location,$postfix)=@_;
570         local($_,$ret);
571         local(*OUT,$tmp,$t);
572
573         $files =~ s/\//$o/g if $o ne '/';
574         $ret="$var="; 
575         $n=1;
576         $Vars{$var}.="";
577         foreach (split(/ /,$files))
578                 {
579                 $_=&bname($_) unless /^\$/;
580                 if ($n++ == 2)
581                         {
582                         $n=0;
583                         $ret.="\\\n\t";
584                         }
585                 if ($_ =~ /BN_MULW/)
586                         { $t="$_ "; }
587                 elsif ($_ =~ /DES_ENC/)
588                         { $t="$_ "; }
589                 elsif ($_ =~ /BF_ENC/)
590                         { $t="$_ "; }
591                 else    { $t="$location${o}$_$postfix "; }
592
593                 $Vars{$var}.="$t ";
594                 $ret.=$t;
595                 }
596         chop($ret);
597         $ret.="\n\n";
598         return($ret);
599         }
600
601 # return the name with the leading path removed
602 sub bname
603         {
604         local($ret)=@_;
605         $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
606         return($ret);
607         }
608
609 # do a rule for each file that says 'copy' to new direcory on change
610 sub do_copy_rule
611         {
612         local($to,$files,$p)=@_;
613         local($ret,$_,$n);
614         
615         $files =~ s/\//$o/g if $o ne '/';
616         foreach (split(/\s+/,$files))
617                 {
618                 $n=&bname($_);
619                 $ret.="$to${o}$n$p: \$(SRC_D)$o$_$p\n\t\$(CP) \$(SRC_D)$o$_$p $to${o}$n$p\n\n";
620                 }
621         return($ret);
622         }
623
624 ##############################################################
625 # do a rule for each file that says 'compile' to new direcory
626 # compile the files in '$files' into $to
627 sub do_compile_rule
628         {
629         local($to,$files,$ex)=@_;
630         local($ret,$_,$n);
631         
632         $files =~ s/\//$o/g if $o ne '/';
633         foreach (split(/\s+/,$files))
634                 {
635                 $n=&bname($_);
636                 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
637                 }
638         return($ret);
639         }
640
641 ##############################################################
642 # do a rule for each file that says 'compile' to new direcory
643 sub cc_compile_target
644         {
645         local($target,$source,$ex_flags)=@_;
646         local($ret);
647         
648         # EAY EAY
649         $ex_flags.=' -DCFLAGS="\"$(CC) $(CFLAG)\""' if ($source =~ /cversion/);
650         $target =~ s/\//$o/g if $o ne "/";
651         $source =~ s/\//$o/g if $o ne "/";
652         $ret ="$target: \$(SRC_D)$o$source\n\t";
653         $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
654         return($ret);
655         }
656
657 ##############################################################
658 sub do_asm_rule
659         {
660         local($target,$src)=@_;
661         local($ret,@s,@t,$i);
662
663         $target =~ s/\//$o/g if $o ne "/";
664         $src =~ s/\//$o/g if $o ne "/";
665
666         @s=split(/\s+/,$src);
667         @t=split(/\s+/,$target);
668
669         for ($i=0; $i<=$#s; $i++)
670                 {
671                 $ret.="$t[$i]: $s[$i]\n";
672                 $ret.="\t\$(ASM) $afile$t[$i] \$(SRC_D)$o$s[$i]\n\n";
673                 }
674         return($ret);
675         }
676
677 sub do_shlib_rule
678         {
679         local($n,$def)=@_;
680         local($ret,$nn);
681         local($t);
682
683         ($nn=$n) =~ tr/a-z/A-Z/;
684         $ret.="$n.dll: \$(${nn}OBJ)\n";
685         if ($vc && $w32)
686                 {
687                 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n  \$(${nn}OBJ_F)\n<<\n";
688                 }
689         $ret.="\n";
690         return($ret);
691         }
692