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