Fix incorrect command for assember file generation on IA64
[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 $OPTIONS="";
10 $ssl_version="";
11 $banner="\t\@echo Building OpenSSL";
12
13 local $zlib_opt = 0;    # 0 = no zlib, 1 = static, 2 = dynamic
14 local $zlib_lib = "";
15
16 my $fips_canister_path = "";
17 my $fips_premain_dso_exe_path = "";
18 my $fips_premain_c_path = "";
19 my $fips_sha1_exe_path = "";
20
21 local $fipscanisterbuild = 0;
22
23 my $fipslibdir = "";
24 my $baseaddr = "";
25
26 my $ex_l_libs = "";
27
28
29 open(IN,"<Makefile") || die "unable to open Makefile!\n";
30 while(<IN>) {
31     $ssl_version=$1 if (/^VERSION=(.*)$/);
32     $OPTIONS=$1 if (/^OPTIONS=(.*)$/);
33     $INSTALLTOP=$1 if (/^INSTALLTOP=(.*$)/);
34 }
35 close(IN);
36
37 die "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
38
39 $infile="MINFO";
40
41 %ops=(
42         "VC-WIN32",   "Microsoft Visual C++ [4-6] - Windows NT or 9X",
43         "VC-WIN32-GMAKE", "Microsoft Visual C++ [4-6] - Windows NT or 9X, GNU make",
44         "VC-CE",   "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
45         "VC-NT",   "Microsoft Visual C++ [4-6] - Windows NT ONLY",
46         "VC-W31-16",  "Microsoft Visual C++ 1.52 - Windows 3.1 - 286",
47         "VC-WIN16",   "Alias for VC-W31-32",
48         "VC-W31-32",  "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+",
49         "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS",
50         "Mingw32", "GNU C++ - Windows NT or 9x",
51         "Mingw32-files", "Create files with DOS copy ...",
52         "BC-NT",   "Borland C++ 4.5 - Windows NT",
53         "BC-W31",  "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING",
54         "BC-MSDOS","Borland C++ 4.5 - MSDOS",
55         "linux-elf","Linux elf",
56         "ultrix-mips","DEC mips ultrix",
57         "FreeBSD","FreeBSD distribution",
58         "OS2-EMX", "EMX GCC OS/2",
59         "default","cc under unix",
60         );
61
62 $platform="";
63 my $xcflags="";
64 foreach (@ARGV)
65         {
66         if (!&read_options && !defined($ops{$_}))
67                 {
68                 print STDERR "unknown option - $_\n";
69                 print STDERR "usage: perl mk1mf.pl [options] [system]\n";
70                 print STDERR "\nwhere [system] can be one of the following\n";
71                 foreach $i (sort keys %ops)
72                 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
73                 print STDERR <<"EOF";
74 and [options] can be one of
75         no-md2 no-md4 no-md5 no-sha no-mdc2     - Skip this digest
76         no-ripemd
77         no-rc2 no-rc4 no-rc5 no-idea no-des     - Skip this symetric cipher
78         no-bf no-cast no-aes
79         no-rsa no-dsa no-dh                     - Skip this public key cipher
80         no-ssl2 no-ssl3                         - Skip this version of SSL
81         just-ssl                                - remove all non-ssl keys/digest
82         no-asm                                  - No x86 asm
83         no-krb5                                 - No KRB5
84         no-ec                                   - No EC
85         no-engine                               - No engine
86         no-hw                                   - No hw
87         nasm                                    - Use NASM for x86 asm
88         gaswin                                  - Use GNU as with Mingw32
89         no-socks                                - No socket code
90         no-err                                  - No error strings
91         dll/shlib                               - Build shared libraries (MS)
92         debug                                   - Debug build
93         profile                                 - Profiling build
94         gcc                                     - Use Gcc (unix)
95
96 Values that can be set
97 TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
98
99 -L<ex_lib_path> -l<ex_lib>                      - extra library flags (unix)
100 -<ex_cc_flags>                                  - extra 'cc' flags,
101                                                   added (MS), or replace (unix)
102 EOF
103                 exit(1);
104                 }
105         $platform=$_;
106         }
107 foreach (grep(!/^$/, split(/ /, $OPTIONS)))
108         {
109         print STDERR "unknown option - $_\n" if !&read_options;
110         }
111
112 $no_mdc2=1 if ($no_des);
113
114 $no_ssl3=1 if ($no_md5 || $no_sha);
115 $no_ssl3=1 if ($no_rsa && $no_dh);
116
117 $no_ssl2=1 if ($no_md5);
118 $no_ssl2=1 if ($no_rsa);
119
120 $out_def="out";
121 $inc_def="outinc";
122 $tmp_def="tmp";
123
124 $mkdir="-mkdir";
125 $mkcanister="ld -r -o";
126
127 $ex_build_targets = "";
128
129 ($ssl,$crypto)=("ssl","crypto");
130 $cryptocompat = "";
131 $ranlib="echo ranlib";
132
133 $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
134 $src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
135 $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
136
137 # $bin_dir.=$o causes a core dump on my sparc :-(
138
139 $NT=0;
140
141 push(@INC,"util/pl","pl");
142 if ($platform eq "VC-MSDOS")
143         {
144         $asmbits=16;
145         $msdos=1;
146         require 'VC-16.pl';
147         }
148 elsif ($platform eq "VC-W31-16")
149         {
150         $asmbits=16;
151         $msdos=1; $win16=1;
152         require 'VC-16.pl';
153         }
154 elsif (($platform eq "VC-W31-32") || ($platform eq "VC-WIN16"))
155         {
156         $asmbits=32;
157         $msdos=1; $win16=1;
158         require 'VC-16.pl';
159         }
160 elsif (($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
161         {
162         $NT = 1 if $platform eq "VC-NT";
163         require 'VC-32.pl';
164         }
165 elsif ($platform eq "VC-WIN32-GMAKE")
166         {
167         require 'VC-32-GMAKE.pl';
168         }
169 elsif ($platform eq "VC-CE")
170         {
171         require 'VC-CE.pl';
172         }
173 elsif ($platform eq "Mingw32")
174         {
175         require 'Mingw32.pl';
176         }
177 elsif ($platform eq "Mingw32-files")
178         {
179         require 'Mingw32f.pl';
180         }
181 elsif ($platform eq "BC-NT")
182         {
183         $bc=1;
184         require 'BC-32.pl';
185         }
186 elsif ($platform eq "BC-W31")
187         {
188         $bc=1;
189         $msdos=1; $w16=1;
190         require 'BC-16.pl';
191         }
192 elsif ($platform eq "BC-Q16")
193         {
194         $msdos=1; $w16=1; $shlib=0; $qw=1;
195         require 'BC-16.pl';
196         }
197 elsif ($platform eq "BC-MSDOS")
198         {
199         $asmbits=16;
200         $msdos=1;
201         require 'BC-16.pl';
202         }
203 elsif ($platform eq "FreeBSD")
204         {
205         require 'unix.pl';
206         $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
207         }
208 elsif ($platform eq "linux-elf")
209         {
210         require "unix.pl";
211         require "linux.pl";
212         $unix=1;
213         }
214 elsif ($platform eq "ultrix-mips")
215         {
216         require "unix.pl";
217         require "ultrix.pl";
218         $unix=1;
219         }
220 elsif ($platform eq "OS2-EMX")
221         {
222         $wc=1;
223         require 'OS2-EMX.pl';
224         }
225 else
226         {
227         require "unix.pl";
228
229         $unix=1;
230         $cflags.=' -DTERMIO';
231         }
232
233 $out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
234 $tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
235 $inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
236
237 $bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
238
239 $cflags= "$xcflags$cflags" if $xcflags ne "";
240
241 $cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
242 $cflags.=" -DOPENSSL_NO_AES"  if $no_aes;
243 $cflags.=" -DOPENSSL_NO_RC2"  if $no_rc2;
244 $cflags.=" -DOPENSSL_NO_RC4"  if $no_rc4;
245 $cflags.=" -DOPENSSL_NO_RC5"  if $no_rc5;
246 $cflags.=" -DOPENSSL_NO_MD2"  if $no_md2;
247 $cflags.=" -DOPENSSL_NO_MD4"  if $no_md4;
248 $cflags.=" -DOPENSSL_NO_MD5"  if $no_md5;
249 $cflags.=" -DOPENSSL_NO_SHA"  if $no_sha;
250 $cflags.=" -DOPENSSL_NO_SHA1" if $no_sha1;
251 $cflags.=" -DOPENSSL_NO_RIPEMD" if $no_ripemd;
252 $cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
253 $cflags.=" -DOPENSSL_NO_BF"   if $no_bf;
254 $cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
255 $cflags.=" -DOPENSSL_NO_DES"  if $no_des;
256 $cflags.=" -DOPENSSL_NO_RSA"  if $no_rsa;
257 $cflags.=" -DOPENSSL_NO_DSA"  if $no_dsa;
258 $cflags.=" -DOPENSSL_NO_DH"   if $no_dh;
259 $cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
260 $cflags.=" -DOPENSSL_NO_SSL2" if $no_ssl2;
261 $cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
262 $cflags.=" -DOPENSSL_NO_ERR"  if $no_err;
263 $cflags.=" -DOPENSSL_NO_KRB5" if $no_krb5;
264 $cflags.=" -DOPENSSL_NO_EC"   if $no_ec;
265 $cflags.=" -DOPENSSL_NO_ENGINE"   if $no_engine;
266 $cflags.=" -DOPENSSL_NO_HW"   if $no_hw;
267 $cflags.=" -DOPENSSL_FIPS"    if $fips;
268 #$cflags.=" -DRSAref"  if $rsaref ne "";
269
270 $cflags.= " -DZLIB" if $zlib_opt;
271 $cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
272
273 ## if ($unix)
274 ##      { $cflags="$c_flags" if ($c_flags ne ""); }
275 ##else
276         { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
277
278 $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
279
280
281 %shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
282                   "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO",
283                   "FIPS" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
284
285 if ($msdos)
286         {
287         $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
288         $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
289         $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
290         $banner.="\t\@echo documentation for details.\n";
291         }
292
293 # have to do this to allow $(CC) under unix
294 $link="$bin_dir$link" if ($link !~ /^\$/);
295
296 $INSTALLTOP =~ s|/|$o|g;
297
298 #############################################
299 # We parse in input file and 'store' info for later printing.
300 open(IN,"<$infile") || die "unable to open $infile:$!\n";
301 $_=<IN>;
302 for (;;)
303         {
304         chop;
305
306         ($key,$val)=/^([^=]+)=(.*)/;
307         if ($key eq "RELATIVE_DIRECTORY")
308                 {
309                 if ($lib ne "")
310                         {
311                         if ($fips && $dir =~ /^fips/)
312                                 {
313                                 $uc = "FIPS";
314                                 }
315                         else
316                                 {
317                                 $uc=$lib;
318                                 $uc =~ s/^lib(.*)\.a/$1/;
319                                 $uc =~ tr/a-z/A-Z/;
320                                 }
321                         if (($uc ne "FIPS") || $fipscanisterbuild)
322                                 {
323                                 $lib_nam{$uc}=$uc;
324                                 $lib_obj{$uc}.=$libobj." ";
325                                 }
326                         }
327                 last if ($val eq "FINISHED");
328                 $lib="";
329                 $libobj="";
330                 $dir=$val;
331                 }
332
333         if ($key eq "KRB5_INCLUDES")
334                 { $cflags .= " $val";}
335
336         if ($key eq "ZLIB_INCLUDE")
337                 { $cflags .= " $val" if $val ne "";}
338
339         if ($key eq "LIBZLIB")
340                 { $zlib_lib = "$val" if $val ne "";}
341
342         if ($key eq "LIBKRB5")
343                 { $ex_libs .= " $val" if $val ne "";}
344
345         if ($key eq "TEST")
346                 { $test.=&var_add($dir,$val); }
347
348         if (($key eq "PROGS") || ($key eq "E_OBJ"))
349                 { $e_exe.=&var_add($dir,$val); }
350
351         if ($key eq "LIB")
352                 {
353                 $lib=$val;
354                 $lib =~ s/^.*\/([^\/]+)$/$1/;
355                 }
356
357         if ($key eq "EXHEADER")
358                 { $exheader.=&var_add($dir,$val); }
359
360         if ($key eq "HEADER")
361                 { $header.=&var_add($dir,$val); }
362
363         if ($key eq "LIBOBJ")
364                 { $libobj=&var_add($dir,$val); }
365
366         if ($key eq "FIPS_EX_OBJ")
367                 { 
368                 $fips_ex_obj=&var_add("crypto",$val);
369                 }
370
371         if ($key eq "FIPSLIBDIR")
372                 { $fipslibdir=$val;}
373
374         if ($key eq "BASEADDR")
375                 { $baseaddr=$val;}
376
377         if (!($_=<IN>))
378                 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
379         }
380 close(IN);
381
382
383 if ($fips)
384         {
385          
386         foreach (split " ", $fips_ex_obj)
387                 {
388                 $fips_exclude_obj{$1} = 1 if (/\/([^\/]*)$/);
389                 }
390
391         $fips_exclude_obj{"bn_asm"} = 1;
392
393         my @ltmp = split " ", $lib_obj{"CRYPTO"};
394
395
396         $lib_obj{"CRYPTO"} = "";
397
398         foreach(@ltmp)
399                 {
400                 if (/\/([^\/]*)$/ && exists $fips_exclude_obj{$1})
401                         {
402                         if ($fipscanisterbuild)
403                                 {
404                                 $lib_obj{"FIPS"} .= "$_ ";
405                                 }
406                         }
407                 else
408                         {
409                         $lib_obj{"CRYPTO"} .= "$_ ";
410                         }
411                 }
412
413         }
414
415 if ($fipscanisterbuild)
416         {
417         $fips_canister_path = "\$(LIB_D)${o}fipscanister.o";
418         $fips_premain_c_path = "\$(LIB_D)${o}fips_premain.c";
419         }
420 else
421         {
422         if ($fips_canister_path eq "")
423                 {
424                 $fips_canister_path = "\$(FIPSLIB_D)${o}fipscanister.o";
425                 }
426
427         if ($fips_premain_c_path eq "")
428                 {
429                 $fips_premain_c_path = "\$(FIPSLIB_D)${o}fips_premain.c";
430                 }
431         }
432
433 if ($fips)
434         {
435         if ($fips_sha1_exe_path eq "")
436                 {
437                 $fips_sha1_exe_path =
438                         "\$(BIN_D)${o}fips_standalone_sha1$exep";
439                 }
440         }
441         else
442         {
443         $fips_sha1_exe_path = "";
444         }
445
446 if ($fips_premain_dso_exe_path eq "")
447         {
448         $fips_premain_dso_exe_path = "\$(BIN_D)${o}fips_premain_dso$exep";
449         }
450
451 #       $ex_build_targets .= "\$(BIN_D)${o}\$(E_PREMAIN_DSO)$exep" if ($fips);
452
453 if ($fips)
454         {
455         if (!$shlib)
456                 {
457                 $ex_build_targets .= " \$(LIB_D)$o$crypto_compat \$(PREMAIN_DSO_EXE)";
458                 $ex_l_libs .= " \$(O_FIPSCANISTER)";
459                 }
460         if ($fipscanisterbuild)
461                 {
462                 $fipslibdir = "\$(LIB_D)";
463                 }
464         else
465                 {
466                 if ($fipslibdir eq "")
467                         {
468                         open (IN, "util/fipslib_path.txt") || fipslib_error();
469                         $fipslibdir = <IN>;
470                         chomp $fipslibdir;
471                         close IN;
472                         }
473                 fips_check_files($fipslibdir,
474                                 "fipscanister.o", "fipscanister.o.sha1",
475                                 "fips_premain.c", "fips_premain.c.sha1");
476                 }
477         }
478         
479
480 $defs= <<"EOF";
481 # This makefile has been automatically generated from the OpenSSL distribution.
482 # This single makefile will build the complete OpenSSL distribution and
483 # by default leave the 'intertesting' output files in .${o}out and the stuff
484 # that needs deleting in .${o}tmp.
485 # The file was generated by running 'make makefile.one', which
486 # does a 'make files', which writes all the environment variables from all
487 # the makefiles to the file call MINFO.  This file is used by
488 # util${o}mk1mf.pl to generate makefile.one.
489 # The 'makefile per directory' system suites me when developing this
490 # library and also so I can 'distribute' indervidual library sections.
491 # The one monster makefile better suits building in non-unix
492 # environments.
493
494 EOF
495
496 $defs .= $preamble if defined $preamble;
497
498 if ($platform eq "VC-CE")
499         {
500         $defs.= <<"EOF";
501 !INCLUDE <\$(WCECOMPAT)/wcedefs.mak>
502
503 EOF
504         $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
505         }
506
507 $defs.= <<"EOF";
508 INSTALLTOP=$INSTALLTOP
509
510 # Set your compiler options
511 PLATFORM=$platform
512 CC=$bin_dir${cc}
513 CFLAG=$cflags
514 APP_CFLAG=$app_cflag
515 LIB_CFLAG=$lib_cflag
516 SHLIB_CFLAG=$shl_cflag
517 APP_EX_OBJ=$app_ex_obj
518 SHLIB_EX_OBJ=$shlib_ex_obj
519 # add extra libraries to this define, for solaris -lsocket -lnsl would
520 # be added
521 EX_LIBS=$ex_libs
522
523 # The OpenSSL directory
524 SRC_D=$src_dir
525
526 LINK=$link
527 PERL=perl
528 FIPSLINK=\$(PERL) util${o}fipslink.pl
529 LFLAGS=$lflags
530
531 BN_ASM_OBJ=$bn_asm_obj
532 BN_ASM_SRC=$bn_asm_src
533 BNCO_ASM_OBJ=$bnco_asm_obj
534 BNCO_ASM_SRC=$bnco_asm_src
535 DES_ENC_OBJ=$des_enc_obj
536 DES_ENC_SRC=$des_enc_src
537 BF_ENC_OBJ=$bf_enc_obj
538 BF_ENC_SRC=$bf_enc_src
539 CAST_ENC_OBJ=$cast_enc_obj
540 CAST_ENC_SRC=$cast_enc_src
541 RC4_ENC_OBJ=$rc4_enc_obj
542 RC4_ENC_SRC=$rc4_enc_src
543 RC5_ENC_OBJ=$rc5_enc_obj
544 RC5_ENC_SRC=$rc5_enc_src
545 MD5_ASM_OBJ=$md5_asm_obj
546 MD5_ASM_SRC=$md5_asm_src
547 SHA1_ASM_OBJ=$sha1_asm_obj
548 SHA1_ASM_SRC=$sha1_asm_src
549 RMD160_ASM_OBJ=$rmd160_asm_obj
550 RMD160_ASM_SRC=$rmd160_asm_src
551
552 # The output directory for everything intersting
553 OUT_D=$out_dir
554 # The output directory for all the temporary muck
555 TMP_D=$tmp_dir
556 # The output directory for the header files
557 INC_D=$inc_dir
558 INCO_D=$inc_dir${o}openssl
559
560 # Directory containing FIPS module
561
562
563 CP=$cp
564 RM=$rm
565 RANLIB=$ranlib
566 MKDIR=$mkdir
567 MKLIB=$bin_dir$mklib
568 MLFLAGS=$mlflags
569 ASM=$bin_dir$asm
570 MKCANISTER=$mkcanister
571
572 # FIPS validated module and support file locations
573
574 E_PREMAIN_DSO=fips_premain_dso
575
576 FIPSLIB_D=$fipslibdir
577 BASEADDR=$baseaddr
578 FIPS_PREMAIN_SRC=$fips_premain_c_path
579 O_FIPSCANISTER=$fips_canister_path
580 FIPS_SHA1_EXE=$fips_sha1_exe_path
581 PREMAIN_DSO_EXE=$fips_premain_dso_exe_path
582
583 ######################################################
584 # You should not need to touch anything below this point
585 ######################################################
586
587 E_EXE=openssl
588 SSL=$ssl
589 CRYPTO=$crypto
590
591 # BIN_D  - Binary output directory
592 # TEST_D - Binary test file output directory
593 # LIB_D  - library output directory
594 # Note: if you change these point to different directories then uncomment out
595 # the lines around the 'NB' comment below.
596
597 BIN_D=\$(OUT_D)
598 TEST_D=\$(OUT_D)
599 LIB_D=\$(OUT_D)
600
601 # INCL_D - local library directory
602 # OBJ_D  - temp object file directory
603 OBJ_D=\$(TMP_D)
604 INCL_D=\$(TMP_D)
605
606 O_SSL=     \$(LIB_D)$o$plib\$(SSL)$shlibp
607 O_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
608 SO_SSL=    $plib\$(SSL)$so_shlibp
609 SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
610 L_SSL=     \$(LIB_D)$o$plib\$(SSL)$libp
611 L_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$libp
612
613 L_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs
614
615 ######################################################
616 # Don't touch anything below this point
617 ######################################################
618
619 INC=-I\$(INC_D) -I\$(INCL_D)
620 APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
621 LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
622 SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
623 LIBS_DEP=\$(O_CRYPTO) \$(O_SSL) $ex_libs_dep
624
625 #############################################
626 EOF
627
628 $rules=<<"EOF";
629 all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers \$(FIPS_SHA1_EXE) lib exe $ex_build_targets
630
631 banner:
632 $banner
633
634 \$(TMP_D):
635         \$(MKDIR) \$(TMP_D)
636 # NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
637 #\$(BIN_D):
638 #       \$(MKDIR) \$(BIN_D)
639 #
640 #\$(TEST_D):
641 #       \$(MKDIR) \$(TEST_D)
642
643 \$(LIB_D):
644         \$(MKDIR) \$(LIB_D)
645
646 \$(INCO_D): \$(INC_D)
647         \$(MKDIR) \$(INCO_D)
648
649 \$(INC_D):
650         \$(MKDIR) \$(INC_D)
651
652 headers: \$(HEADER) \$(EXHEADER)
653         @
654
655 lib: \$(LIBS_DEP)
656
657 exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
658
659 install:
660         \$(MKDIR) \$(INSTALLTOP)
661         \$(MKDIR) \$(INSTALLTOP)${o}bin
662         \$(MKDIR) \$(INSTALLTOP)${o}include
663         \$(MKDIR) \$(INSTALLTOP)${o}include${o}openssl
664         \$(MKDIR) \$(INSTALLTOP)${o}lib
665         \$(CP) \$(INCO_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include${o}openssl
666         \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin
667         \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib
668         \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib
669
670 clean:
671         \$(RM) \$(TMP_D)$o*.*
672
673 vclean:
674         \$(RM) \$(TMP_D)$o*.*
675         \$(RM) \$(OUT_D)$o*.*
676
677 EOF
678     
679 my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
680 $platform_cpp_symbol =~ s/-/_/g;
681 if (open(IN,"crypto/buildinf.h"))
682         {
683         # Remove entry for this platform in existing file buildinf.h.
684
685         my $old_buildinf_h = "";
686         while (<IN>)
687                 {
688                 if (/^\#ifdef $platform_cpp_symbol$/)
689                         {
690                         while (<IN>) { last if (/^\#endif/); }
691                         }
692                 else
693                         {
694                         $old_buildinf_h .= $_;
695                         }
696                 }
697         close(IN);
698
699         open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
700         print OUT $old_buildinf_h;
701         close(OUT);
702         }
703
704 open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
705 printf OUT <<EOF;
706 #ifdef $platform_cpp_symbol
707   /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
708   #define CFLAGS "$cc $cflags"
709   #define PLATFORM "$platform"
710 EOF
711 printf OUT "  #define DATE \"%s\"\n", scalar gmtime();
712 printf OUT "#endif\n";
713 close(OUT);
714
715 # Strip of trailing ' '
716 foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
717 $test=&clean_up_ws($test);
718 $e_exe=&clean_up_ws($e_exe);
719 $exheader=&clean_up_ws($exheader);
720 $header=&clean_up_ws($header);
721
722 # First we strip the exheaders from the headers list
723 foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
724 foreach (split(/\s+/,$header))  { $h.=$_." " unless $h{$_}; }
725 chop($h); $header=$h;
726
727 $defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h");
728 $rules.=&do_copy_rule("\$(INCL_D)",$header,".h");
729
730 $defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)",".h");
731 $rules.=&do_copy_rule("\$(INCO_D)",$exheader,".h");
732
733 $defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
734 $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
735
736 $defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
737 $rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
738
739 # Special case rules for fips_start and fips_end fips_premain_dso
740
741 if ($fips)
742         {
743         if ($fipscanisterbuild)
744                 {
745                 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_start$obj",
746                         "fips-1.0${o}fips_canister.c",
747                         "-DFIPS_START \$(SHLIB_CFLAGS)");
748                 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_end$obj",
749                         "fips-1.0${o}fips_canister.c", "\$(SHLIB_CFLAGS)");
750                 }
751         $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_standalone_sha1$obj",
752                 "fips-1.0${o}sha${o}fips_standalone_sha1.c",
753                 "\$(SHLIB_CFLAGS)");
754         $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_sha1dgst$obj",
755                 "fips-1.0${o}sha${o}fips_sha1dgst.c",
756                 "\$(SHLIB_CFLAGS)") unless $fipscanisterbuild;
757         $rules.=&cc_compile_target("\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj",
758                 "fips-1.0${o}fips_premain.c",
759                 "-DFINGERPRINT_PREMAIN_DSO_LOAD \$(SHLIB_CFLAGS)");
760         }
761
762 foreach (values %lib_nam)
763         {
764         $lib_obj=$lib_obj{$_};
765         local($slib)=$shlib;
766
767         if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
768                 {
769                 $rules.="\$(O_SSL):\n\n"; 
770                 next;
771                 }
772
773         if (($bn_asm_obj ne "") && ($_ eq "CRYPTO"))
774                 {
775                 $lib_obj =~ s/\s\S*\/bn_asm\S*/ \$(BN_ASM_OBJ)/;
776                 $rules.=&do_asm_rule($bn_asm_obj,$bn_asm_src);
777                 }
778         if (($bnco_asm_obj ne "") && ($_ eq "CRYPTO"))
779                 {
780                 $lib_obj .= "\$(BNCO_ASM_OBJ)";
781                 $rules.=&do_asm_rule($bnco_asm_obj,$bnco_asm_src);
782                 }
783         if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
784                 {
785                 $lib_obj =~ s/\s\S*des_enc\S*/ \$(DES_ENC_OBJ)/;
786                 $lib_obj =~ s/\s\S*\/fcrypt_b\S*\s*/ /;
787                 $rules.=&do_asm_rule($des_enc_obj,$des_enc_src);
788                 }
789         if (($bf_enc_obj ne "") && ($_ eq "CRYPTO"))
790                 {
791                 $lib_obj =~ s/\s\S*\/bf_enc\S*/ \$(BF_ENC_OBJ)/;
792                 $rules.=&do_asm_rule($bf_enc_obj,$bf_enc_src);
793                 }
794         if (($cast_enc_obj ne "") && ($_ eq "CRYPTO"))
795                 {
796                 $lib_obj =~ s/(\s\S*\/c_enc\S*)/ \$(CAST_ENC_OBJ)/;
797                 $rules.=&do_asm_rule($cast_enc_obj,$cast_enc_src);
798                 }
799         if (($rc4_enc_obj ne "") && ($_ eq "CRYPTO"))
800                 {
801                 $lib_obj =~ s/\s\S*\/rc4_enc\S*/ \$(RC4_ENC_OBJ)/;
802                 $rules.=&do_asm_rule($rc4_enc_obj,$rc4_enc_src);
803                 }
804         if (($rc5_enc_obj ne "") && ($_ eq "CRYPTO"))
805                 {
806                 $lib_obj =~ s/\s\S*\/rc5_enc\S*/ \$(RC5_ENC_OBJ)/;
807                 $rules.=&do_asm_rule($rc5_enc_obj,$rc5_enc_src);
808                 }
809         if (($md5_asm_obj ne "") && ($_ eq "CRYPTO"))
810                 {
811                 $lib_obj =~ s/\s(\S*\/md5_dgst\S*)/ $1 \$(MD5_ASM_OBJ)/;
812                 $rules.=&do_asm_rule($md5_asm_obj,$md5_asm_src);
813                 }
814         if (($sha1_asm_obj ne "") && ($_ eq "CRYPTO"))
815                 {
816                 $lib_obj =~ s/\s(\S*\/sha1dgst\S*)/ $1 \$(SHA1_ASM_OBJ)/;
817                 $rules.=&do_asm_rule($sha1_asm_obj,$sha1_asm_src);
818                 }
819         if (($rmd160_asm_obj ne "") && ($_ eq "CRYPTO"))
820                 {
821                 $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/;
822                 $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src);
823                 }
824         $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
825         $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
826         $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
827         }
828
829 $defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
830 foreach (split(/\s+/,$test))
831         {
832         $t=&bname($_);
833         $tt="\$(OBJ_D)${o}$t${obj}";
834         $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
835         }
836
837 $rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
838
839
840 if ($fips)
841         {
842         if ($shlib)
843                 {
844                 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
845                         "\$(O_CRYPTO)",
846                         "$crypto",
847                         $shlib, "\$(SO_CRYPTO)", "\$(BASEADDR)");
848                 }
849         else
850                 {
851                 $rules.= &do_lib_rule("\$(CRYPTOOBJ)",
852                         "\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)", "");
853                 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
854                         "\$(LIB_D)$o$crypto_compat",$crypto,$shlib,"\$(SO_CRYPTO)", "");
855                 }
856         }
857         else
858         {
859         $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
860                                                         "\$(SO_CRYPTO)");
861         }
862
863
864 if ($fips)
865         {
866         $rules.= &do_rlink_rule("\$(O_FIPSCANISTER)", "\$(OBJ_D)${o}fips_start$obj \$(FIPSOBJ) \$(OBJ_D)${o}fips_end$obj", "\$(FIPS_SHA1_EXE)", "") if $fipscanisterbuild;
867         $rules.=&do_link_rule("\$(PREMAIN_DSO_EXE)","\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj \$(CRYPTOOBJ) \$(O_FIPSCANISTER)","","\$(EX_LIBS)", 1);
868         
869         $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)","\$(OBJ_D)${o}fips_standalone_sha1$obj \$(OBJ_D)${o}fips_sha1dgst$obj","","", 1);
870         }
871
872         $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)",0);
873
874 print $defs;
875
876 if ($platform eq "linux-elf") {
877     print <<"EOF";
878 # Generate perlasm output files
879 %.cpp:
880         (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
881 EOF
882 }
883 print "###################################################################\n";
884 print $rules;
885
886 ###############################################
887 # strip off any trailing .[och] and append the relative directory
888 # also remembering to do nothing if we are in one of the dropped
889 # directories
890 sub var_add
891         {
892         local($dir,$val)=@_;
893         local(@a,$_,$ret);
894
895         return("") if $no_engine && $dir =~ /\/engine/;
896         return("") if $no_hw   && $dir =~ /\/hw/;
897         return("") if $no_idea && $dir =~ /\/idea/;
898         return("") if $no_aes  && $dir =~ /\/aes/;
899         return("") if $no_rc2  && $dir =~ /\/rc2/;
900         return("") if $no_rc4  && $dir =~ /\/rc4/;
901         return("") if $no_rc5  && $dir =~ /\/rc5/;
902         return("") if $no_rsa  && $dir =~ /\/rsa/;
903         return("") if $no_rsa  && $dir =~ /^rsaref/;
904         return("") if $no_dsa  && $dir =~ /\/dsa/;
905         return("") if $no_dh   && $dir =~ /\/dh/;
906         return("") if $no_ec   && $dir =~ /\/ec/;
907         if ($no_des && $dir =~ /\/des/)
908                 {
909                 if ($val =~ /read_pwd/)
910                         { return("$dir/read_pwd "); }
911                 else
912                         { return(""); }
913                 }
914         return("") if $no_mdc2 && $dir =~ /\/mdc2/;
915         return("") if $no_sock && $dir =~ /\/proxy/;
916         return("") if $no_bf   && $dir =~ /\/bf/;
917         return("") if $no_cast && $dir =~ /\/cast/;
918
919         $val =~ s/^\s*(.*)\s*$/$1/;
920         @a=split(/\s+/,$val);
921         grep(s/\.[och]$//,@a);
922
923         @a=grep(!/^e_.*_3d$/,@a) if $no_des;
924         @a=grep(!/^e_.*_d$/,@a) if $no_des;
925         @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
926         @a=grep(!/^e_.*_i$/,@a) if $no_aes;
927         @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
928         @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
929         @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
930         @a=grep(!/^e_.*_c$/,@a) if $no_cast;
931         @a=grep(!/^e_rc4$/,@a) if $no_rc4;
932
933         @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
934         @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
935
936         @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
937
938         @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
939         @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
940         @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
941         @a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
942
943         @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
944         @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
945         @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
946
947         @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
948         @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
949
950         @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
951
952         @a=grep(!/_dhp$/,@a) if $no_dh;
953
954         @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
955         @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
956         @a=grep(!/_mdc2$/,@a) if $no_mdc2;
957
958         @a=grep(!/^engine$/,@a) if $no_engine;
959         @a=grep(!/^hw$/,@a) if $no_hw;
960         @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
961         @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
962         @a=grep(!/^gendsa$/,@a) if $no_sha1;
963         @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
964
965         @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
966
967         grep($_="$dir/$_",@a);
968         @a=grep(!/(^|\/)s_/,@a) if $no_sock;
969         @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
970         $ret=join(' ',@a)." ";
971         return($ret);
972         }
973
974 # change things so that each 'token' is only separated by one space
975 sub clean_up_ws
976         {
977         local($w)=@_;
978
979         $w =~ s/^\s*(.*)\s*$/$1/;
980         $w =~ s/\s+/ /g;
981         return($w);
982         }
983
984 sub do_defs
985         {
986         local($var,$files,$location,$postfix)=@_;
987         local($_,$ret,$pf);
988         local(*OUT,$tmp,$t);
989
990         $files =~ s/\//$o/g if $o ne '/';
991         $ret="$var="; 
992         $n=1;
993         $Vars{$var}.="";
994         foreach (split(/ /,$files))
995                 {
996                 $orig=$_;
997                 $_=&bname($_) unless /^\$/;
998                 if ($n++ == 2)
999                         {
1000                         $n=0;
1001                         $ret.="\\\n\t";
1002                         }
1003                 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
1004                         { $pf=".c"; }
1005                 else    { $pf=$postfix; }
1006                 if ($_ =~ /BN_ASM/)     { $t="$_ "; }
1007                 elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
1008                 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
1009                 elsif ($_ =~ /BF_ENC/)  { $t="$_ "; }
1010                 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
1011                 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
1012                 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
1013                 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
1014                 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
1015                 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
1016                 else    { $t="$location${o}$_$pf "; }
1017
1018                 $Vars{$var}.="$t ";
1019                 $ret.=$t;
1020                 }
1021         chop($ret);
1022         $ret.="\n\n";
1023         return($ret);
1024         }
1025
1026 # return the name with the leading path removed
1027 sub bname
1028         {
1029         local($ret)=@_;
1030         $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
1031         return($ret);
1032         }
1033
1034
1035 ##############################################################
1036 # do a rule for each file that says 'compile' to new direcory
1037 # compile the files in '$files' into $to
1038 sub do_compile_rule
1039         {
1040         local($to,$files,$ex)=@_;
1041         local($ret,$_,$n);
1042         
1043         $files =~ s/\//$o/g if $o ne '/';
1044         foreach (split(/\s+/,$files))
1045                 {
1046                 $n=&bname($_);
1047                 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
1048                 }
1049         return($ret);
1050         }
1051
1052 ##############################################################
1053 # do a rule for each file that says 'compile' to new direcory
1054 sub cc_compile_target
1055         {
1056         local($target,$source,$ex_flags)=@_;
1057         local($ret);
1058         
1059         $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
1060         $target =~ s/\//$o/g if $o ne "/";
1061         $source =~ s/\//$o/g if $o ne "/";
1062         $ret ="$target: \$(SRC_D)$o$source\n\t";
1063         $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
1064         return($ret);
1065         }
1066
1067 ##############################################################
1068 sub do_asm_rule
1069         {
1070         local($target,$src)=@_;
1071         local($ret,@s,@t,$i);
1072
1073         $target =~ s/\//$o/g if $o ne "/";
1074         $src =~ s/\//$o/g if $o ne "/";
1075
1076         @s=split(/\s+/,$src);
1077         @t=split(/\s+/,$target);
1078
1079         for ($i=0; $i<=$#s; $i++)
1080                 {
1081                 $ret.="$t[$i]: $s[$i]\n";
1082                 $ret.="\t\$(ASM) $afile$t[$i] \$(SRC_D)$o$s[$i]\n\n";
1083                 }
1084         return($ret);
1085         }
1086
1087 sub do_shlib_rule
1088         {
1089         local($n,$def)=@_;
1090         local($ret,$nn);
1091         local($t);
1092
1093         ($nn=$n) =~ tr/a-z/A-Z/;
1094         $ret.="$n.dll: \$(${nn}OBJ)\n";
1095         if ($vc && $w32)
1096                 {
1097                 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n  \$(${nn}OBJ_F)\n<<\n";
1098                 }
1099         $ret.="\n";
1100         return($ret);
1101         }
1102
1103 # do a rule for each file that says 'copy' to new direcory on change
1104 sub do_copy_rule
1105         {
1106         local($to,$files,$p)=@_;
1107         local($ret,$_,$n,$pp);
1108         
1109         $files =~ s/\//$o/g if $o ne '/';
1110         foreach (split(/\s+/,$files))
1111                 {
1112                 $n=&bname($_);
1113                 if ($n =~ /bss_file/)
1114                         { $pp=".c"; }
1115                 else    { $pp=$p; }
1116                 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n";
1117                 }
1118         return($ret);
1119         }
1120
1121 sub read_options
1122         {
1123         if    (/^no-rc2$/)      { $no_rc2=1; }
1124         elsif (/^no-rc4$/)      { $no_rc4=1; }
1125         elsif (/^no-rc5$/)      { $no_rc5=1; }
1126         elsif (/^no-idea$/)     { $no_idea=1; }
1127         elsif (/^no-aes$/)      { $no_aes=1; }
1128         elsif (/^no-des$/)      { $no_des=1; }
1129         elsif (/^no-bf$/)       { $no_bf=1; }
1130         elsif (/^no-cast$/)     { $no_cast=1; }
1131         elsif (/^no-md2$/)      { $no_md2=1; }
1132         elsif (/^no-md4$/)      { $no_md4=1; }
1133         elsif (/^no-md5$/)      { $no_md5=1; }
1134         elsif (/^no-sha$/)      { $no_sha=1; }
1135         elsif (/^no-sha1$/)     { $no_sha1=1; }
1136         elsif (/^no-ripemd$/)   { $no_ripemd=1; }
1137         elsif (/^no-mdc2$/)     { $no_mdc2=1; }
1138         elsif (/^no-patents$/)  { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; }
1139         elsif (/^no-rsa$/)      { $no_rsa=1; }
1140         elsif (/^no-dsa$/)      { $no_dsa=1; }
1141         elsif (/^no-dh$/)       { $no_dh=1; }
1142         elsif (/^no-hmac$/)     { $no_hmac=1; }
1143         elsif (/^no-aes$/)      { $no_aes=1; }
1144         elsif (/^no-asm$/)      { $no_asm=1; }
1145         elsif (/^nasm$/)        { $nasm=1; }
1146         elsif (/^gaswin$/)      { $gaswin=1; }
1147         elsif (/^no-ssl2$/)     { $no_ssl2=1; }
1148         elsif (/^no-ssl3$/)     { $no_ssl3=1; }
1149         elsif (/^no-err$/)      { $no_err=1; }
1150         elsif (/^no-sock$/)     { $no_sock=1; }
1151         elsif (/^no-krb5$/)     { $no_krb5=1; }
1152         elsif (/^no-ec$/)       { $no_ec=1; }
1153         elsif (/^no-engine$/)   { $no_engine=1; }
1154         elsif (/^no-hw$/)       { $no_hw=1; }
1155
1156         elsif (/^just-ssl$/)    { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1;
1157                                   $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1;
1158                                   $no_ssl2=$no_err=$no_ripemd=$no_rc5=1;
1159                                   $no_aes=1; }
1160
1161         elsif (/^rsaref$/)      { }
1162         elsif (/^fips$/)        { $fips=1; }
1163         elsif (/^gcc$/)         { $gcc=1; }
1164         elsif (/^debug$/)       { $debug=1; }
1165         elsif (/^profile$/)     { $profile=1; }
1166         elsif (/^shlib$/)       { $shlib=1; }
1167         elsif (/^dll$/)         { $shlib=1; }
1168         elsif (/^shared$/)      { } # We just need to ignore it for now...
1169         elsif (/^zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
1170         elsif (/^zlib-dynamic$/){ $zlib_opt = 2; }
1171         elsif (/^--with-krb5-flavor=(.*)$/)
1172                 {
1173                 my $krb5_flavor = $1;
1174                 if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
1175                         {
1176                         $xcflags="-DKRB5_HEIMDAL $xcflags";
1177                         }
1178                 elsif ($krb5_flavor =~ /^MIT/i)
1179                         {
1180                         $xcflags="-DKRB5_MIT $xcflags";
1181                         if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
1182                                 {
1183                                 $xcflags="-DKRB5_MIT_OLD11 $xcflags"
1184                                 }
1185                         }
1186                 }
1187         elsif (/^--fipscanisterbuild$/)
1188                 {
1189                 $fipscanisterbuild=1;
1190                 }
1191         elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1192         elsif (/^-[lL].*$/)     { $l_flags.="$_ "; }
1193         elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
1194                 { $c_flags.="$_ "; }
1195         else { return(0); }
1196         return(1);
1197         }
1198
1199 sub fipslib_error
1200         {
1201         print STDERR "***FIPS module directory sanity check failed***\n";
1202         print STDERR "FIPS module build failed, or was deleted\n";
1203         print STDERR "Please rebuild FIPS module.\n"; 
1204         exit 1;
1205         }
1206
1207 sub fips_check_files
1208         {
1209         my $dir = shift @_;
1210         my $ret = 1;
1211         if (!-d $dir)
1212                 {
1213                 print STDERR "FIPS module directory $dir does not exist\n";
1214                 fipslib_error();
1215                 }
1216         foreach (@_)
1217                 {
1218                 if (!-f "$dir${o}$_")
1219                         {
1220                         print STDERR "FIPS module file $_ does not exist!\n";
1221                         $ret = 0;
1222                         }
1223                 }
1224         fipslib_error() if ($ret == 0);
1225         }