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 = "";
27 open(IN,"<Makefile") || die "unable to open Makefile!\n";
29 $ssl_version=$1 if (/^VERSION=(.*)$/);
30 $OPTIONS=$1 if (/^OPTIONS=(.*)$/);
31 $INSTALLTOP=$1 if (/^INSTALLTOP=(.*$)/);
35 die "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
40 "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X",
41 "VC-WIN32-GMAKE", "Microsoft Visual C++ [4-6] - Windows NT or 9X, GNU make",
42 "VC-CE", "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
43 "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY",
44 "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286",
45 "VC-WIN16", "Alias for VC-W31-32",
46 "VC-W31-32", "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+",
47 "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS",
48 "Mingw32", "GNU C++ - Windows NT or 9x",
49 "Mingw32-files", "Create files with DOS copy ...",
50 "BC-NT", "Borland C++ 4.5 - Windows NT",
51 "BC-W31", "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING",
52 "BC-MSDOS","Borland C++ 4.5 - MSDOS",
53 "linux-elf","Linux elf",
54 "ultrix-mips","DEC mips ultrix",
55 "FreeBSD","FreeBSD distribution",
56 "OS2-EMX", "EMX GCC OS/2",
57 "default","cc under unix",
64 if (!&read_options && !defined($ops{$_}))
66 print STDERR "unknown option - $_\n";
67 print STDERR "usage: perl mk1mf.pl [options] [system]\n";
68 print STDERR "\nwhere [system] can be one of the following\n";
69 foreach $i (sort keys %ops)
70 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
72 and [options] can be one of
73 no-md2 no-md4 no-md5 no-sha no-mdc2 - Skip this digest
75 no-rc2 no-rc4 no-rc5 no-idea no-des - Skip this symetric cipher
77 no-rsa no-dsa no-dh - Skip this public key cipher
78 no-ssl2 no-ssl3 - Skip this version of SSL
79 just-ssl - remove all non-ssl keys/digest
85 nasm - Use NASM for x86 asm
86 gaswin - Use GNU as with Mingw32
87 no-socks - No socket code
88 no-err - No error strings
89 dll/shlib - Build shared libraries (MS)
91 profile - Profiling build
94 Values that can be set
95 TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
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)
105 foreach (grep(!/^$/, split(/ /, $OPTIONS)))
107 print STDERR "unknown option - $_\n" if !&read_options;
110 $no_mdc2=1 if ($no_des);
112 $no_ssl3=1 if ($no_md5 || $no_sha);
113 $no_ssl3=1 if ($no_rsa && $no_dh);
115 $no_ssl2=1 if ($no_md5);
116 $no_ssl2=1 if ($no_rsa);
123 $mkcanister="ld -r -o";
125 $ex_build_targets = "";
127 ($ssl,$crypto)=("ssl","crypto");
129 $ranlib="echo ranlib";
131 $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
132 $src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
133 $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
135 # $bin_dir.=$o causes a core dump on my sparc :-(
139 push(@INC,"util/pl","pl");
140 if ($platform eq "VC-MSDOS")
146 elsif ($platform eq "VC-W31-16")
152 elsif (($platform eq "VC-W31-32") || ($platform eq "VC-WIN16"))
158 elsif (($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
160 $NT = 1 if $platform eq "VC-NT";
163 elsif ($platform eq "VC-WIN32-GMAKE")
165 require 'VC-32-GMAKE.pl';
167 elsif ($platform eq "VC-CE")
171 elsif ($platform eq "Mingw32")
173 require 'Mingw32.pl';
175 elsif ($platform eq "Mingw32-files")
177 require 'Mingw32f.pl';
179 elsif ($platform eq "BC-NT")
184 elsif ($platform eq "BC-W31")
190 elsif ($platform eq "BC-Q16")
192 $msdos=1; $w16=1; $shlib=0; $qw=1;
195 elsif ($platform eq "BC-MSDOS")
201 elsif ($platform eq "FreeBSD")
204 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
206 elsif ($platform eq "linux-elf")
212 elsif ($platform eq "ultrix-mips")
218 elsif ($platform eq "OS2-EMX")
221 require 'OS2-EMX.pl';
228 $cflags.=' -DTERMIO';
231 $out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
232 $tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
233 $inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
235 $bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
237 $cflags= "$xcflags$cflags" if $xcflags ne "";
239 $cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
240 $cflags.=" -DOPENSSL_NO_AES" if $no_aes;
241 $cflags.=" -DOPENSSL_NO_RC2" if $no_rc2;
242 $cflags.=" -DOPENSSL_NO_RC4" if $no_rc4;
243 $cflags.=" -DOPENSSL_NO_RC5" if $no_rc5;
244 $cflags.=" -DOPENSSL_NO_MD2" if $no_md2;
245 $cflags.=" -DOPENSSL_NO_MD4" if $no_md4;
246 $cflags.=" -DOPENSSL_NO_MD5" if $no_md5;
247 $cflags.=" -DOPENSSL_NO_SHA" if $no_sha;
248 $cflags.=" -DOPENSSL_NO_SHA1" if $no_sha1;
249 $cflags.=" -DOPENSSL_NO_RIPEMD" if $no_ripemd;
250 $cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
251 $cflags.=" -DOPENSSL_NO_BF" if $no_bf;
252 $cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
253 $cflags.=" -DOPENSSL_NO_DES" if $no_des;
254 $cflags.=" -DOPENSSL_NO_RSA" if $no_rsa;
255 $cflags.=" -DOPENSSL_NO_DSA" if $no_dsa;
256 $cflags.=" -DOPENSSL_NO_DH" if $no_dh;
257 $cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
258 $cflags.=" -DOPENSSL_NO_SSL2" if $no_ssl2;
259 $cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
260 $cflags.=" -DOPENSSL_NO_ERR" if $no_err;
261 $cflags.=" -DOPENSSL_NO_KRB5" if $no_krb5;
262 $cflags.=" -DOPENSSL_NO_EC" if $no_ec;
263 $cflags.=" -DOPENSSL_NO_ENGINE" if $no_engine;
264 $cflags.=" -DOPENSSL_NO_HW" if $no_hw;
265 $cflags.=" -DOPENSSL_FIPS" if $fips;
266 #$cflags.=" -DRSAref" if $rsaref ne "";
268 $cflags.= " -DZLIB" if $zlib_opt;
269 $cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
272 ## { $cflags="$c_flags" if ($c_flags ne ""); }
274 { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
276 $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
279 %shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
280 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
284 $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
285 $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
286 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
287 $banner.="\t\@echo documentation for details.\n";
290 # have to do this to allow $(CC) under unix
291 $link="$bin_dir$link" if ($link !~ /^\$/);
293 $INSTALLTOP =~ s|/|$o|g;
295 #############################################
296 # We parse in input file and 'store' info for later printing.
297 open(IN,"<$infile") || die "unable to open $infile:$!\n";
303 ($key,$val)=/^([^=]+)=(.*)/;
304 if ($key eq "RELATIVE_DIRECTORY")
308 if ($fips && $dir =~ /^fips/)
315 $uc =~ s/^lib(.*)\.a/$1/;
318 if (($uc ne "FIPS") || $fips_canister_build)
321 $lib_obj{$uc}.=$libobj." ";
324 last if ($val eq "FINISHED");
330 if ($key eq "KRB5_INCLUDES")
331 { $cflags .= " $val";}
333 if ($key eq "ZLIB_INCLUDE")
334 { $cflags .= " $val" if $val ne "";}
336 if ($key eq "LIBZLIB")
337 { $zlib_lib = "$val" if $val ne "";}
339 if ($key eq "LIBKRB5")
340 { $ex_libs .= " $val" if $val ne "";}
343 { $test.=&var_add($dir,$val); }
345 if (($key eq "PROGS") || ($key eq "E_OBJ"))
346 { $e_exe.=&var_add($dir,$val); }
351 $lib =~ s/^.*\/([^\/]+)$/$1/;
354 if ($key eq "EXHEADER")
355 { $exheader.=&var_add($dir,$val); }
357 if ($key eq "HEADER")
358 { $header.=&var_add($dir,$val); }
360 if ($key eq "LIBOBJ")
361 { $libobj=&var_add($dir,$val); }
363 if ($key eq "FIPSLIBDIR")
366 if ($key eq "BASEADDR")
370 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
374 if ($fips_canister_path eq "")
376 $fips_canister_path = "\$(FIPSLIB_D)${o}fipscanister.o";
379 if ($fips_premain_c_path eq "")
381 $fips_premain_c_path = "\$(FIPSLIB_D)${o}fips_premain.c";
386 if ($fips_sha1_exe_path eq "")
388 $fips_sha1_exe_path =
389 "\$(BIN_D)${o}fips_standalone_sha1$exep";
394 $fips_sha1_exe_path = "";
397 if ($fips_premain_dso_exe_path eq "")
399 $fips_premain_dso_exe_path = "\$(BIN_D)${o}fips_premain_dso$exep";
402 # $ex_build_targets .= "\$(BIN_D)${o}\$(E_PREMAIN_DSO)$exep" if ($fips);
408 $ex_build_targets .= " \$(LIB_D)$o$crypto_compat \$(PREMAIN_DSO_EXE)";
409 $ex_l_libs .= " \$(O_FIPSCANISTER)";
411 if ($fipslibdir eq "")
413 open (IN, "util/fipslib_path.txt") || fipslib_error();
418 fips_check_files($fipslibdir,
419 "fipscanister.o", "fipscanister.o.sha1",
420 "fips_premain.c", "fips_premain.c.sha1");
425 # This makefile has been automatically generated from the OpenSSL distribution.
426 # This single makefile will build the complete OpenSSL distribution and
427 # by default leave the 'intertesting' output files in .${o}out and the stuff
428 # that needs deleting in .${o}tmp.
429 # The file was generated by running 'make makefile.one', which
430 # does a 'make files', which writes all the environment variables from all
431 # the makefiles to the file call MINFO. This file is used by
432 # util${o}mk1mf.pl to generate makefile.one.
433 # The 'makefile per directory' system suites me when developing this
434 # library and also so I can 'distribute' indervidual library sections.
435 # The one monster makefile better suits building in non-unix
440 $defs .= $preamble if defined $preamble;
442 if ($platform eq "VC-CE")
445 !INCLUDE <\$(WCECOMPAT)/wcedefs.mak>
448 $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
452 INSTALLTOP=$INSTALLTOP
454 # Set your compiler options
460 SHLIB_CFLAG=$shl_cflag
461 APP_EX_OBJ=$app_ex_obj
462 SHLIB_EX_OBJ=$shlib_ex_obj
463 # add extra libraries to this define, for solaris -lsocket -lnsl would
467 # The OpenSSL directory
472 FIPSLINK=\$(PERL) util${o}fipslink.pl
475 BN_ASM_OBJ=$bn_asm_obj
476 BN_ASM_SRC=$bn_asm_src
477 BNCO_ASM_OBJ=$bnco_asm_obj
478 BNCO_ASM_SRC=$bnco_asm_src
479 DES_ENC_OBJ=$des_enc_obj
480 DES_ENC_SRC=$des_enc_src
481 BF_ENC_OBJ=$bf_enc_obj
482 BF_ENC_SRC=$bf_enc_src
483 CAST_ENC_OBJ=$cast_enc_obj
484 CAST_ENC_SRC=$cast_enc_src
485 RC4_ENC_OBJ=$rc4_enc_obj
486 RC4_ENC_SRC=$rc4_enc_src
487 RC5_ENC_OBJ=$rc5_enc_obj
488 RC5_ENC_SRC=$rc5_enc_src
489 MD5_ASM_OBJ=$md5_asm_obj
490 MD5_ASM_SRC=$md5_asm_src
491 SHA1_ASM_OBJ=$sha1_asm_obj
492 SHA1_ASM_SRC=$sha1_asm_src
493 RMD160_ASM_OBJ=$rmd160_asm_obj
494 RMD160_ASM_SRC=$rmd160_asm_src
496 # The output directory for everything intersting
498 # The output directory for all the temporary muck
500 # The output directory for the header files
502 INCO_D=$inc_dir${o}openssl
504 # Directory containing FIPS module
514 MKCANISTER=$mkcanister
516 # FIPS validated module and support file locations
518 E_PREMAIN_DSO=fips_premain_dso
520 FIPSLIB_D=$fipslibdir
522 FIPS_PREMAIN_SRC=$fips_premain_c_path
523 O_FIPSCANISTER=$fips_canister_path
524 FIPS_SHA1_EXE=$fips_sha1_exe_path
525 PREMAIN_DSO_EXE=$fips_premain_dso_exe_path
527 ######################################################
528 # You should not need to touch anything below this point
529 ######################################################
535 # BIN_D - Binary output directory
536 # TEST_D - Binary test file output directory
537 # LIB_D - library output directory
538 # Note: if you change these point to different directories then uncomment out
539 # the lines around the 'NB' comment below.
545 # INCL_D - local library directory
546 # OBJ_D - temp object file directory
550 O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
551 O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
552 SO_SSL= $plib\$(SSL)$so_shlibp
553 SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
554 L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp
555 L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp
557 L_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs
559 ######################################################
560 # Don't touch anything below this point
561 ######################################################
563 INC=-I\$(INC_D) -I\$(INCL_D)
564 APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
565 LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
566 SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
567 LIBS_DEP=\$(O_CRYPTO) \$(O_SSL) $ex_libs_dep
569 #############################################
573 all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers \$(FIPS_SHA1_EXE) lib exe $ex_build_targets
580 # NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
582 # \$(MKDIR) \$(BIN_D)
585 # \$(MKDIR) \$(TEST_D)
590 \$(INCO_D): \$(INC_D)
596 headers: \$(HEADER) \$(EXHEADER)
601 exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
604 \$(MKDIR) \$(INSTALLTOP)
605 \$(MKDIR) \$(INSTALLTOP)${o}bin
606 \$(MKDIR) \$(INSTALLTOP)${o}include
607 \$(MKDIR) \$(INSTALLTOP)${o}include${o}openssl
608 \$(MKDIR) \$(INSTALLTOP)${o}lib
609 \$(CP) \$(INCO_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include${o}openssl
610 \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin
611 \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib
612 \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib
615 \$(RM) \$(TMP_D)$o*.*
618 \$(RM) \$(TMP_D)$o*.*
619 \$(RM) \$(OUT_D)$o*.*
623 my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
624 $platform_cpp_symbol =~ s/-/_/g;
625 if (open(IN,"crypto/buildinf.h"))
627 # Remove entry for this platform in existing file buildinf.h.
629 my $old_buildinf_h = "";
632 if (/^\#ifdef $platform_cpp_symbol$/)
634 while (<IN>) { last if (/^\#endif/); }
638 $old_buildinf_h .= $_;
643 open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
644 print OUT $old_buildinf_h;
648 open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
650 #ifdef $platform_cpp_symbol
651 /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
652 #define CFLAGS "$cc $cflags"
653 #define PLATFORM "$platform"
655 printf OUT " #define DATE \"%s\"\n", scalar gmtime();
656 printf OUT "#endif\n";
659 # Strip of trailing ' '
660 foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
661 $test=&clean_up_ws($test);
662 $e_exe=&clean_up_ws($e_exe);
663 $exheader=&clean_up_ws($exheader);
664 $header=&clean_up_ws($header);
666 # First we strip the exheaders from the headers list
667 foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
668 foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; }
669 chop($h); $header=$h;
671 $defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h");
672 $rules.=&do_copy_rule("\$(INCL_D)",$header,".h");
674 $defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)",".h");
675 $rules.=&do_copy_rule("\$(INCO_D)",$exheader,".h");
677 $defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
678 $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
680 $defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
681 $rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
683 # Special case rules for fips_start and fips_end fips_premain_dso
687 if ($fips_canister_build)
689 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_start$obj",
690 "fips-1.0${o}fips_canister.c",
691 "-DFIPS_START \$(SHLIB_CFLAGS)");
692 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_end$obj",
693 "fips-1.0${o}fips_canister.c", "\$(SHLIB_CFLAGS)");
695 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_standalone_sha1$obj",
696 "fips-1.0${o}sha${o}fips_standalone_sha1.c",
698 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_sha1dgst$obj",
699 "fips-1.0${o}sha${o}fips_sha1dgst.c",
700 "\$(SHLIB_CFLAGS)") unless $fips_canister_build;
701 $rules.=&cc_compile_target("\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj",
702 "fips-1.0${o}fips_premain.c",
703 "-DFINGERPRINT_PREMAIN_DSO_LOAD \$(SHLIB_CFLAGS)");
706 foreach (values %lib_nam)
708 $lib_obj=$lib_obj{$_};
711 if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
713 $rules.="\$(O_SSL):\n\n";
717 if (($bn_asm_obj ne "") && ($_ eq "CRYPTO"))
719 $lib_obj =~ s/\s\S*\/bn_asm\S*/ \$(BN_ASM_OBJ)/;
720 $rules.=&do_asm_rule($bn_asm_obj,$bn_asm_src);
722 if (($bnco_asm_obj ne "") && ($_ eq "CRYPTO"))
724 $lib_obj .= "\$(BNCO_ASM_OBJ)";
725 $rules.=&do_asm_rule($bnco_asm_obj,$bnco_asm_src);
727 if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
729 $lib_obj =~ s/\s\S*des_enc\S*/ \$(DES_ENC_OBJ)/;
730 $lib_obj =~ s/\s\S*\/fcrypt_b\S*\s*/ /;
731 $rules.=&do_asm_rule($des_enc_obj,$des_enc_src);
733 if (($bf_enc_obj ne "") && ($_ eq "CRYPTO"))
735 $lib_obj =~ s/\s\S*\/bf_enc\S*/ \$(BF_ENC_OBJ)/;
736 $rules.=&do_asm_rule($bf_enc_obj,$bf_enc_src);
738 if (($cast_enc_obj ne "") && ($_ eq "CRYPTO"))
740 $lib_obj =~ s/(\s\S*\/c_enc\S*)/ \$(CAST_ENC_OBJ)/;
741 $rules.=&do_asm_rule($cast_enc_obj,$cast_enc_src);
743 if (($rc4_enc_obj ne "") && ($_ eq "CRYPTO"))
745 $lib_obj =~ s/\s\S*\/rc4_enc\S*/ \$(RC4_ENC_OBJ)/;
746 $rules.=&do_asm_rule($rc4_enc_obj,$rc4_enc_src);
748 if (($rc5_enc_obj ne "") && ($_ eq "CRYPTO"))
750 $lib_obj =~ s/\s\S*\/rc5_enc\S*/ \$(RC5_ENC_OBJ)/;
751 $rules.=&do_asm_rule($rc5_enc_obj,$rc5_enc_src);
753 if (($md5_asm_obj ne "") && ($_ eq "CRYPTO"))
755 $lib_obj =~ s/\s(\S*\/md5_dgst\S*)/ $1 \$(MD5_ASM_OBJ)/;
756 $rules.=&do_asm_rule($md5_asm_obj,$md5_asm_src);
758 if (($sha1_asm_obj ne "") && ($_ eq "CRYPTO"))
760 $lib_obj =~ s/\s(\S*\/sha1dgst\S*)/ $1 \$(SHA1_ASM_OBJ)/;
761 $rules.=&do_asm_rule($sha1_asm_obj,$sha1_asm_src);
763 if (($rmd160_asm_obj ne "") && ($_ eq "CRYPTO"))
765 $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/;
766 $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src);
768 $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
769 $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
770 $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
773 $defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
774 foreach (split(/\s+/,$test))
777 $tt="\$(OBJ_D)${o}$t${obj}";
778 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
781 $rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
788 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
791 $shlib, "\$(SO_CRYPTO)", "\$(BASEADDR)");
795 $rules.= &do_lib_rule("\$(CRYPTOOBJ)",
796 "\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)", "");
797 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
798 "\$(LIB_D)$o$crypto_compat",$crypto,$shlib,"\$(SO_CRYPTO)", "");
803 $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
810 $rules.= &do_rlink_rule("\$(O_FIPSCANISTER)", "\$(OBJ_D)${o}fips_start$obj \$(FIPSOBJ) \$(OBJ_D)${o}fips_end$obj", "\$(FIPSLIB_D)${o}fips_standalone_sha1$exep", "") if $fips_canister_build;
811 $rules.=&do_link_rule("\$(PREMAIN_DSO_EXE)","\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj \$(CRYPTOOBJ) \$(O_FIPSCANISTER)","","\$(EX_LIBS)", 1);
813 $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)","\$(OBJ_D)${o}fips_standalone_sha1$obj \$(OBJ_D)${o}fips_sha1dgst$obj","","", 1);
816 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)",0);
820 if ($platform eq "linux-elf") {
822 # Generate perlasm output files
824 (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
827 print "###################################################################\n";
830 ###############################################
831 # strip off any trailing .[och] and append the relative directory
832 # also remembering to do nothing if we are in one of the dropped
839 return("") if $no_engine && $dir =~ /\/engine/;
840 return("") if $no_hw && $dir =~ /\/hw/;
841 return("") if $no_idea && $dir =~ /\/idea/;
842 return("") if $no_aes && $dir =~ /\/aes/;
843 return("") if $no_rc2 && $dir =~ /\/rc2/;
844 return("") if $no_rc4 && $dir =~ /\/rc4/;
845 return("") if $no_rc5 && $dir =~ /\/rc5/;
846 return("") if $no_rsa && $dir =~ /\/rsa/;
847 return("") if $no_rsa && $dir =~ /^rsaref/;
848 return("") if $no_dsa && $dir =~ /\/dsa/;
849 return("") if $no_dh && $dir =~ /\/dh/;
850 return("") if $no_ec && $dir =~ /\/ec/;
851 if ($no_des && $dir =~ /\/des/)
853 if ($val =~ /read_pwd/)
854 { return("$dir/read_pwd "); }
858 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
859 return("") if $no_sock && $dir =~ /\/proxy/;
860 return("") if $no_bf && $dir =~ /\/bf/;
861 return("") if $no_cast && $dir =~ /\/cast/;
863 $val =~ s/^\s*(.*)\s*$/$1/;
864 @a=split(/\s+/,$val);
865 grep(s/\.[och]$//,@a);
867 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
868 @a=grep(!/^e_.*_d$/,@a) if $no_des;
869 @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
870 @a=grep(!/^e_.*_i$/,@a) if $no_aes;
871 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
872 @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
873 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
874 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
875 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
877 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
878 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
880 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
882 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
883 @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
884 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
885 @a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
887 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
888 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
889 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
891 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
892 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
894 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
896 @a=grep(!/_dhp$/,@a) if $no_dh;
898 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
899 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
900 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
902 @a=grep(!/^engine$/,@a) if $no_engine;
903 @a=grep(!/^hw$/,@a) if $no_hw;
904 @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
905 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
906 @a=grep(!/^gendsa$/,@a) if $no_sha1;
907 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
909 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
911 grep($_="$dir/$_",@a);
912 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
913 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
914 $ret=join(' ',@a)." ";
918 # change things so that each 'token' is only separated by one space
923 $w =~ s/^\s*(.*)\s*$/$1/;
930 local($var,$files,$location,$postfix)=@_;
934 $files =~ s/\//$o/g if $o ne '/';
938 foreach (split(/ /,$files))
941 $_=&bname($_) unless /^\$/;
947 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
949 else { $pf=$postfix; }
950 if ($_ =~ /BN_ASM/) { $t="$_ "; }
951 elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
952 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
953 elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
954 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
955 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
956 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
957 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
958 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
959 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
960 else { $t="$location${o}$_$pf "; }
970 # return the name with the leading path removed
974 $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
979 ##############################################################
980 # do a rule for each file that says 'compile' to new direcory
981 # compile the files in '$files' into $to
984 local($to,$files,$ex)=@_;
987 $files =~ s/\//$o/g if $o ne '/';
988 foreach (split(/\s+/,$files))
991 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
996 ##############################################################
997 # do a rule for each file that says 'compile' to new direcory
998 sub cc_compile_target
1000 local($target,$source,$ex_flags)=@_;
1003 $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
1004 $target =~ s/\//$o/g if $o ne "/";
1005 $source =~ s/\//$o/g if $o ne "/";
1006 $ret ="$target: \$(SRC_D)$o$source\n\t";
1007 $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
1011 ##############################################################
1014 local($target,$src)=@_;
1015 local($ret,@s,@t,$i);
1017 $target =~ s/\//$o/g if $o ne "/";
1018 $src =~ s/\//$o/g if $o ne "/";
1020 @s=split(/\s+/,$src);
1021 @t=split(/\s+/,$target);
1023 for ($i=0; $i<=$#s; $i++)
1025 $ret.="$t[$i]: $s[$i]\n";
1026 $ret.="\t\$(ASM) $afile$t[$i] \$(SRC_D)$o$s[$i]\n\n";
1037 ($nn=$n) =~ tr/a-z/A-Z/;
1038 $ret.="$n.dll: \$(${nn}OBJ)\n";
1041 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
1047 # do a rule for each file that says 'copy' to new direcory on change
1050 local($to,$files,$p)=@_;
1051 local($ret,$_,$n,$pp);
1053 $files =~ s/\//$o/g if $o ne '/';
1054 foreach (split(/\s+/,$files))
1057 if ($n =~ /bss_file/)
1060 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n";
1067 if (/^no-rc2$/) { $no_rc2=1; }
1068 elsif (/^no-rc4$/) { $no_rc4=1; }
1069 elsif (/^no-rc5$/) { $no_rc5=1; }
1070 elsif (/^no-idea$/) { $no_idea=1; }
1071 elsif (/^no-aes$/) { $no_aes=1; }
1072 elsif (/^no-des$/) { $no_des=1; }
1073 elsif (/^no-bf$/) { $no_bf=1; }
1074 elsif (/^no-cast$/) { $no_cast=1; }
1075 elsif (/^no-md2$/) { $no_md2=1; }
1076 elsif (/^no-md4$/) { $no_md4=1; }
1077 elsif (/^no-md5$/) { $no_md5=1; }
1078 elsif (/^no-sha$/) { $no_sha=1; }
1079 elsif (/^no-sha1$/) { $no_sha1=1; }
1080 elsif (/^no-ripemd$/) { $no_ripemd=1; }
1081 elsif (/^no-mdc2$/) { $no_mdc2=1; }
1082 elsif (/^no-patents$/) { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; }
1083 elsif (/^no-rsa$/) { $no_rsa=1; }
1084 elsif (/^no-dsa$/) { $no_dsa=1; }
1085 elsif (/^no-dh$/) { $no_dh=1; }
1086 elsif (/^no-hmac$/) { $no_hmac=1; }
1087 elsif (/^no-aes$/) { $no_aes=1; }
1088 elsif (/^no-asm$/) { $no_asm=1; }
1089 elsif (/^nasm$/) { $nasm=1; }
1090 elsif (/^gaswin$/) { $gaswin=1; }
1091 elsif (/^no-ssl2$/) { $no_ssl2=1; }
1092 elsif (/^no-ssl3$/) { $no_ssl3=1; }
1093 elsif (/^no-err$/) { $no_err=1; }
1094 elsif (/^no-sock$/) { $no_sock=1; }
1095 elsif (/^no-krb5$/) { $no_krb5=1; }
1096 elsif (/^no-ec$/) { $no_ec=1; }
1097 elsif (/^no-engine$/) { $no_engine=1; }
1098 elsif (/^no-hw$/) { $no_hw=1; }
1100 elsif (/^just-ssl$/) { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1;
1101 $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1;
1102 $no_ssl2=$no_err=$no_ripemd=$no_rc5=1;
1105 elsif (/^rsaref$/) { }
1106 elsif (/^fips$/) { $fips=1; }
1107 elsif (/^gcc$/) { $gcc=1; }
1108 elsif (/^debug$/) { $debug=1; }
1109 elsif (/^profile$/) { $profile=1; }
1110 elsif (/^shlib$/) { $shlib=1; }
1111 elsif (/^dll$/) { $shlib=1; }
1112 elsif (/^shared$/) { } # We just need to ignore it for now...
1113 elsif (/^zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
1114 elsif (/^zlib-dynamic$/){ $zlib_opt = 2; }
1115 elsif (/^--with-krb5-flavor=(.*)$/)
1117 my $krb5_flavor = $1;
1118 if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
1120 $xcflags="-DKRB5_HEIMDAL $xcflags";
1122 elsif ($krb5_flavor =~ /^MIT/i)
1124 $xcflags="-DKRB5_MIT $xcflags";
1125 if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
1127 $xcflags="-DKRB5_MIT_OLD11 $xcflags"
1131 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1132 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
1133 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
1134 { $c_flags.="$_ "; }
1141 print STDERR "***FIPS module directory sanity check failed***\n";
1142 print STDERR "FIPS module build failed, or was deleted\n";
1143 print STDERR "Please rebuild FIPS module.\n";
1147 sub fips_check_files
1153 print STDERR "FIPS module directory $dir does not exist\n";
1158 if (!-f "$dir${o}$_")
1160 print STDERR "FIPS module file $_ does not exist!\n";
1164 fipslib_error() if ($ret == 0);