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
8 $INSTALLTOP="/usr/local/ssl";
11 $banner="\t\@echo Building OpenSSL";
13 local $zlib_opt = 0; # 0 = no zlib, 1 = static, 2 = dynamic
16 my $fips_canister_path = "";
17 my $fips_premain_dso_exe_path = "";
18 my $fips_premain_c_path = "";
19 my $fips_sha1_exe_path = "";
21 local $fipscanisterbuild = 0;
29 open(IN,"<Makefile") || die "unable to open Makefile!\n";
31 $ssl_version=$1 if (/^VERSION=(.*)$/);
32 $OPTIONS=$1 if (/^OPTIONS=(.*)$/);
33 $INSTALLTOP=$1 if (/^INSTALLTOP=(.*$)/);
37 die "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
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",
66 if (!&read_options && !defined($ops{$_}))
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}; }
74 and [options] can be one of
75 no-md2 no-md4 no-md5 no-sha no-mdc2 - Skip this digest
77 no-rc2 no-rc4 no-rc5 no-idea no-des - Skip this symetric cipher
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
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)
93 profile - Profiling build
96 Values that can be set
97 TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
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)
107 foreach (grep(!/^$/, split(/ /, $OPTIONS)))
109 print STDERR "unknown option - $_\n" if !&read_options;
112 $no_mdc2=1 if ($no_des);
114 $no_ssl3=1 if ($no_md5 || $no_sha);
115 $no_ssl3=1 if ($no_rsa && $no_dh);
117 $no_ssl2=1 if ($no_md5);
118 $no_ssl2=1 if ($no_rsa);
125 $mkcanister="ld -r -o";
127 $ex_build_targets = "";
129 ($ssl,$crypto)=("ssl","crypto");
131 $ranlib="echo ranlib";
133 $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
134 $src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
135 $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
137 # $bin_dir.=$o causes a core dump on my sparc :-(
141 push(@INC,"util/pl","pl");
142 if ($platform eq "VC-MSDOS")
148 elsif ($platform eq "VC-W31-16")
154 elsif (($platform eq "VC-W31-32") || ($platform eq "VC-WIN16"))
160 elsif (($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
162 $NT = 1 if $platform eq "VC-NT";
165 elsif ($platform eq "VC-WIN32-GMAKE")
167 require 'VC-32-GMAKE.pl';
169 elsif ($platform eq "VC-CE")
173 elsif ($platform eq "Mingw32")
175 require 'Mingw32.pl';
177 elsif ($platform eq "Mingw32-files")
179 require 'Mingw32f.pl';
181 elsif ($platform eq "BC-NT")
186 elsif ($platform eq "BC-W31")
192 elsif ($platform eq "BC-Q16")
194 $msdos=1; $w16=1; $shlib=0; $qw=1;
197 elsif ($platform eq "BC-MSDOS")
203 elsif ($platform eq "FreeBSD")
206 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
208 elsif ($platform eq "linux-elf")
214 elsif ($platform eq "ultrix-mips")
220 elsif ($platform eq "OS2-EMX")
223 require 'OS2-EMX.pl';
230 $cflags.=' -DTERMIO';
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;
237 $bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
239 $cflags= "$xcflags$cflags" if $xcflags ne "";
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 "";
270 $cflags.= " -DZLIB" if $zlib_opt;
271 $cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
274 ## { $cflags="$c_flags" if ($c_flags ne ""); }
276 { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
278 $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
281 %shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
282 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO",
283 "FIPS" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
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";
293 # have to do this to allow $(CC) under unix
294 $link="$bin_dir$link" if ($link !~ /^\$/);
296 $INSTALLTOP =~ s|/|$o|g;
298 #############################################
299 # We parse in input file and 'store' info for later printing.
300 open(IN,"<$infile") || die "unable to open $infile:$!\n";
306 ($key,$val)=/^([^=]+)=(.*)/;
307 if ($key eq "RELATIVE_DIRECTORY")
311 if ($fips && $dir =~ /^fips/)
318 $uc =~ s/^lib(.*)\.a/$1/;
321 if (($uc ne "FIPS") || $fipscanisterbuild)
324 $lib_obj{$uc}.=$libobj." ";
327 last if ($val eq "FINISHED");
333 if ($key eq "KRB5_INCLUDES")
334 { $cflags .= " $val";}
336 if ($key eq "ZLIB_INCLUDE")
337 { $cflags .= " $val" if $val ne "";}
339 if ($key eq "LIBZLIB")
340 { $zlib_lib = "$val" if $val ne "";}
342 if ($key eq "LIBKRB5")
343 { $ex_libs .= " $val" if $val ne "";}
346 { $test.=&var_add($dir,$val); }
348 if (($key eq "PROGS") || ($key eq "E_OBJ"))
349 { $e_exe.=&var_add($dir,$val); }
354 $lib =~ s/^.*\/([^\/]+)$/$1/;
357 if ($key eq "EXHEADER")
358 { $exheader.=&var_add($dir,$val); }
360 if ($key eq "HEADER")
361 { $header.=&var_add($dir,$val); }
363 if ($key eq "LIBOBJ")
364 { $libobj=&var_add($dir,$val); }
366 if ($key eq "FIPS_EX_OBJ")
368 $fips_ex_obj=&var_add("crypto",$val);
371 if ($key eq "FIPSLIBDIR")
374 if ($key eq "BASEADDR")
378 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
386 foreach (split " ", $fips_ex_obj)
388 $fips_exclude_obj{$1} = 1 if (/\/([^\/]*)$/);
391 $fips_exclude_obj{"bn_asm"} = 1;
393 my @ltmp = split " ", $lib_obj{"CRYPTO"};
396 $lib_obj{"CRYPTO"} = "";
400 if (/\/([^\/]*)$/ && exists $fips_exclude_obj{$1})
402 if ($fipscanisterbuild)
404 $lib_obj{"FIPS"} .= "$_ ";
409 $lib_obj{"CRYPTO"} .= "$_ ";
415 if ($fipscanisterbuild)
417 $fips_canister_path = "\$(LIB_D)${o}fipscanister.o";
418 $fips_premain_c_path = "\$(LIB_D)${o}fips_premain.c";
422 if ($fips_canister_path eq "")
424 $fips_canister_path = "\$(FIPSLIB_D)${o}fipscanister.o";
427 if ($fips_premain_c_path eq "")
429 $fips_premain_c_path = "\$(FIPSLIB_D)${o}fips_premain.c";
435 if ($fips_sha1_exe_path eq "")
437 $fips_sha1_exe_path =
438 "\$(BIN_D)${o}fips_standalone_sha1$exep";
443 $fips_sha1_exe_path = "";
446 if ($fips_premain_dso_exe_path eq "")
448 $fips_premain_dso_exe_path = "\$(BIN_D)${o}fips_premain_dso$exep";
451 # $ex_build_targets .= "\$(BIN_D)${o}\$(E_PREMAIN_DSO)$exep" if ($fips);
457 $ex_build_targets .= " \$(LIB_D)$o$crypto_compat \$(PREMAIN_DSO_EXE)";
458 $ex_l_libs .= " \$(O_FIPSCANISTER)";
460 if ($fipscanisterbuild)
462 $fipslibdir = "\$(LIB_D)";
466 if ($fipslibdir eq "")
468 open (IN, "util/fipslib_path.txt") || fipslib_error();
473 fips_check_files($fipslibdir,
474 "fipscanister.o", "fipscanister.o.sha1",
475 "fips_premain.c", "fips_premain.c.sha1");
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
496 $defs .= $preamble if defined $preamble;
498 if ($platform eq "VC-CE")
501 !INCLUDE <\$(WCECOMPAT)/wcedefs.mak>
504 $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
508 INSTALLTOP=$INSTALLTOP
510 # Set your compiler options
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
523 # The OpenSSL directory
528 FIPSLINK=\$(PERL) util${o}fipslink.pl
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
552 # The output directory for everything intersting
554 # The output directory for all the temporary muck
556 # The output directory for the header files
558 INCO_D=$inc_dir${o}openssl
560 # Directory containing FIPS module
570 MKCANISTER=$mkcanister
572 # FIPS validated module and support file locations
574 E_PREMAIN_DSO=fips_premain_dso
576 FIPSLIB_D=$fipslibdir
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
583 ######################################################
584 # You should not need to touch anything below this point
585 ######################################################
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.
601 # INCL_D - local library directory
602 # OBJ_D - temp object file directory
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
613 L_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs
615 ######################################################
616 # Don't touch anything below this point
617 ######################################################
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
625 #############################################
629 all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers \$(FIPS_SHA1_EXE) lib exe $ex_build_targets
636 # NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
638 # \$(MKDIR) \$(BIN_D)
641 # \$(MKDIR) \$(TEST_D)
646 \$(INCO_D): \$(INC_D)
652 headers: \$(HEADER) \$(EXHEADER)
657 exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
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
671 \$(RM) \$(TMP_D)$o*.*
674 \$(RM) \$(TMP_D)$o*.*
675 \$(RM) \$(OUT_D)$o*.*
679 my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
680 $platform_cpp_symbol =~ s/-/_/g;
681 if (open(IN,"crypto/buildinf.h"))
683 # Remove entry for this platform in existing file buildinf.h.
685 my $old_buildinf_h = "";
688 if (/^\#ifdef $platform_cpp_symbol$/)
690 while (<IN>) { last if (/^\#endif/); }
694 $old_buildinf_h .= $_;
699 open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
700 print OUT $old_buildinf_h;
704 open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
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"
711 printf OUT " #define DATE \"%s\"\n", scalar gmtime();
712 printf OUT "#endif\n";
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);
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;
727 $defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h");
728 $rules.=&do_copy_rule("\$(INCL_D)",$header,".h");
730 $defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)",".h");
731 $rules.=&do_copy_rule("\$(INCO_D)",$exheader,".h");
733 $defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
734 $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
736 $defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
737 $rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
739 # Special case rules for fips_start and fips_end fips_premain_dso
743 if ($fipscanisterbuild)
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)");
751 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_standalone_sha1$obj",
752 "fips-1.0${o}sha${o}fips_standalone_sha1.c",
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)");
762 foreach (values %lib_nam)
764 $lib_obj=$lib_obj{$_};
767 if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
769 $rules.="\$(O_SSL):\n\n";
773 if (($bn_asm_obj ne "") && ($_ eq "CRYPTO"))
775 $lib_obj =~ s/\s\S*\/bn_asm\S*/ \$(BN_ASM_OBJ)/;
776 $rules.=&do_asm_rule($bn_asm_obj,$bn_asm_src);
778 if (($bnco_asm_obj ne "") && ($_ eq "CRYPTO"))
780 $lib_obj .= "\$(BNCO_ASM_OBJ)";
781 $rules.=&do_asm_rule($bnco_asm_obj,$bnco_asm_src);
783 if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
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);
789 if (($bf_enc_obj ne "") && ($_ eq "CRYPTO"))
791 $lib_obj =~ s/\s\S*\/bf_enc\S*/ \$(BF_ENC_OBJ)/;
792 $rules.=&do_asm_rule($bf_enc_obj,$bf_enc_src);
794 if (($cast_enc_obj ne "") && ($_ eq "CRYPTO"))
796 $lib_obj =~ s/(\s\S*\/c_enc\S*)/ \$(CAST_ENC_OBJ)/;
797 $rules.=&do_asm_rule($cast_enc_obj,$cast_enc_src);
799 if (($rc4_enc_obj ne "") && ($_ eq "CRYPTO"))
801 $lib_obj =~ s/\s\S*\/rc4_enc\S*/ \$(RC4_ENC_OBJ)/;
802 $rules.=&do_asm_rule($rc4_enc_obj,$rc4_enc_src);
804 if (($rc5_enc_obj ne "") && ($_ eq "CRYPTO"))
806 $lib_obj =~ s/\s\S*\/rc5_enc\S*/ \$(RC5_ENC_OBJ)/;
807 $rules.=&do_asm_rule($rc5_enc_obj,$rc5_enc_src);
809 if (($md5_asm_obj ne "") && ($_ eq "CRYPTO"))
811 $lib_obj =~ s/\s(\S*\/md5_dgst\S*)/ $1 \$(MD5_ASM_OBJ)/;
812 $rules.=&do_asm_rule($md5_asm_obj,$md5_asm_src);
814 if (($sha1_asm_obj ne "") && ($_ eq "CRYPTO"))
816 $lib_obj =~ s/\s(\S*\/sha1dgst\S*)/ $1 \$(SHA1_ASM_OBJ)/;
817 $rules.=&do_asm_rule($sha1_asm_obj,$sha1_asm_src);
819 if (($rmd160_asm_obj ne "") && ($_ eq "CRYPTO"))
821 $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/;
822 $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src);
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);
829 $defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
830 foreach (split(/\s+/,$test))
833 $tt="\$(OBJ_D)${o}$t${obj}";
834 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
837 $rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
844 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
847 $shlib, "\$(SO_CRYPTO)", "\$(BASEADDR)");
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)", "");
859 $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
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);
869 $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)","\$(OBJ_D)${o}fips_standalone_sha1$obj \$(OBJ_D)${o}fips_sha1dgst$obj","","", 1);
872 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)",0);
876 if ($platform eq "linux-elf") {
878 # Generate perlasm output files
880 (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
883 print "###################################################################\n";
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
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/)
909 if ($val =~ /read_pwd/)
910 { return("$dir/read_pwd "); }
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/;
919 $val =~ s/^\s*(.*)\s*$/$1/;
920 @a=split(/\s+/,$val);
921 grep(s/\.[och]$//,@a);
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;
933 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
934 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
936 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
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;
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;
947 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
948 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
950 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
952 @a=grep(!/_dhp$/,@a) if $no_dh;
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;
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;
965 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
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)." ";
974 # change things so that each 'token' is only separated by one space
979 $w =~ s/^\s*(.*)\s*$/$1/;
986 local($var,$files,$location,$postfix)=@_;
990 $files =~ s/\//$o/g if $o ne '/';
994 foreach (split(/ /,$files))
997 $_=&bname($_) unless /^\$/;
1003 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
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 "; }
1026 # return the name with the leading path removed
1030 $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
1035 ##############################################################
1036 # do a rule for each file that says 'compile' to new direcory
1037 # compile the files in '$files' into $to
1040 local($to,$files,$ex)=@_;
1043 $files =~ s/\//$o/g if $o ne '/';
1044 foreach (split(/\s+/,$files))
1047 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
1052 ##############################################################
1053 # do a rule for each file that says 'compile' to new direcory
1054 sub cc_compile_target
1056 local($target,$source,$ex_flags)=@_;
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";
1067 ##############################################################
1070 local($target,$src)=@_;
1071 local($ret,@s,@t,$i);
1073 $target =~ s/\//$o/g if $o ne "/";
1074 $src =~ s/\//$o/g if $o ne "/";
1076 @s=split(/\s+/,$src);
1077 @t=split(/\s+/,$target);
1079 for ($i=0; $i<=$#s; $i++)
1081 $ret.="$t[$i]: $s[$i]\n";
1082 $ret.="\t\$(ASM) $afile$t[$i] \$(SRC_D)$o$s[$i]\n\n";
1093 ($nn=$n) =~ tr/a-z/A-Z/;
1094 $ret.="$n.dll: \$(${nn}OBJ)\n";
1097 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
1103 # do a rule for each file that says 'copy' to new direcory on change
1106 local($to,$files,$p)=@_;
1107 local($ret,$_,$n,$pp);
1109 $files =~ s/\//$o/g if $o ne '/';
1110 foreach (split(/\s+/,$files))
1113 if ($n =~ /bss_file/)
1116 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n";
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; }
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;
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=(.*)$/)
1173 my $krb5_flavor = $1;
1174 if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
1176 $xcflags="-DKRB5_HEIMDAL $xcflags";
1178 elsif ($krb5_flavor =~ /^MIT/i)
1180 $xcflags="-DKRB5_MIT $xcflags";
1181 if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
1183 $xcflags="-DKRB5_MIT_OLD11 $xcflags"
1187 elsif (/^--fipscanisterbuild$/)
1189 $fipscanisterbuild=1;
1191 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1192 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
1193 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
1194 { $c_flags.="$_ "; }
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";
1207 sub fips_check_files
1213 print STDERR "FIPS module directory $dir does not exist\n";
1218 if (!-f "$dir${o}$_")
1220 print STDERR "FIPS module file $_ does not exist!\n";
1224 fipslib_error() if ($ret == 0);