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";
9 $OPENSSLDIR="/usr/local/ssl";
12 $banner="\t\@echo Building OpenSSL";
14 my $no_static_engine = 1;
17 local $zlib_opt = 0; # 0 = no zlib, 1 = static, 2 = dynamic
19 local $perl_asm = 0; # 1 to autobuild asm files from perl scripts
21 local $fips_canister_path = "";
22 my $fips_premain_dso_exe_path = "";
23 my $fips_premain_c_path = "";
24 my $fips_sha1_exe_path = "";
26 local $fipscanisterbuild = 0;
33 # Options to import from top level Makefile
36 VERSION => \$ssl_version,
38 INSTALLTOP => \$INSTALLTOP,
39 OPENSSLDIR => \$OPENSSLDIR,
40 PLATFORM => \$mf_platform,
42 DEPFLAG => \$mf_depflag,
43 CPUID_OBJ => \$mf_cpuid_asm,
44 BN_ASM => \$mf_bn_asm,
45 DES_ENC => \$mf_des_asm,
46 AES_ENC => \$mf_aes_asm,
47 BF_ENC => \$mf_bf_asm,
48 CAST_ENC => \$mf_cast_asm,
49 RC4_ENC => \$mf_rc4_asm,
50 RC5_ENC => \$mf_rc5_asm,
51 MD5_ASM_OBJ => \$mf_md5_asm,
52 SHA1_ASM_OBJ => \$mf_sha_asm,
53 RMD160_ASM_OBJ => \$mf_rmd_asm,
54 WP_ASM_OBJ => \$mf_wp_asm,
55 CMLL_ENC => \$mf_cm_asm
58 open(IN,"<Makefile") || die "unable to open Makefile!\n";
60 my ($mf_opt, $mf_ref);
61 while (($mf_opt, $mf_ref) = each %mf_import) {
62 if (/^$mf_opt\s*=\s*(.*)$/) {
69 $debug = 1 if $mf_platform =~ /^debug-/;
71 die "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
76 "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X",
77 "VC-WIN64I", "Microsoft C/C++ - Win64/IA-64",
78 "VC-WIN64A", "Microsoft C/C++ - Win64/x64",
79 "VC-CE", "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
80 "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY",
81 "Mingw32", "GNU C++ - Windows NT or 9x",
82 "Mingw32-files", "Create files with DOS copy ...",
83 "BC-NT", "Borland C++ 4.5 - Windows NT",
84 "linux-elf","Linux elf",
85 "ultrix-mips","DEC mips ultrix",
86 "FreeBSD","FreeBSD distribution",
87 "OS2-EMX", "EMX GCC OS/2",
88 "netware-clib", "CodeWarrior for NetWare - CLib - with WinSock Sockets",
89 "netware-clib-bsdsock", "CodeWarrior for NetWare - CLib - with BSD Sockets",
90 "netware-libc", "CodeWarrior for NetWare - LibC - with WinSock Sockets",
91 "netware-libc-bsdsock", "CodeWarrior for NetWare - LibC - with BSD Sockets",
92 "default","cc under unix",
93 "auto", "auto detect from top level Makefile"
100 if (!&read_options && !defined($ops{$_}))
102 print STDERR "unknown option - $_\n";
103 print STDERR "usage: perl mk1mf.pl [options] [system]\n";
104 print STDERR "\nwhere [system] can be one of the following\n";
105 foreach $i (sort keys %ops)
106 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
107 print STDERR <<"EOF";
108 and [options] can be one of
109 no-md2 no-md4 no-md5 no-sha no-mdc2 - Skip this digest
111 no-rc2 no-rc4 no-rc5 no-idea no-des - Skip this symetric cipher
112 no-bf no-cast no-aes no-camellia no-seed
113 no-rsa no-dsa no-dh - Skip this public key cipher
114 no-ssl2 no-ssl3 - Skip this version of SSL
115 just-ssl - remove all non-ssl keys/digest
121 no-engine - No engine
123 nasm - Use NASM for x86 asm
124 nw-nasm - Use NASM x86 asm for NetWare
125 nw-mwasm - Use Metrowerks x86 asm for NetWare
126 gaswin - Use GNU as with Mingw32
127 no-socks - No socket code
128 no-err - No error strings
129 dll/shlib - Build shared libraries (MS)
131 profile - Profiling build
134 Values that can be set
135 TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
137 -L<ex_lib_path> -l<ex_lib> - extra library flags (unix)
138 -<ex_cc_flags> - extra 'cc' flags,
139 added (MS), or replace (unix)
145 foreach (grep(!/^$/, split(/ /, $OPTIONS)))
147 print STDERR "unknown option - $_\n" if !&read_options;
150 $no_static_engine = 0 if (!$shlib);
152 $no_mdc2=1 if ($no_des);
154 $no_ssl3=1 if ($no_md5 || $no_sha);
155 $no_ssl3=1 if ($no_rsa && $no_dh);
157 $no_ssl2=1 if ($no_md5);
158 $no_ssl2=1 if ($no_rsa);
164 $perl="perl" unless defined $perl;
165 $mkdir="-mkdir" unless defined $mkdir;
167 ($ssl,$crypto)=("ssl","crypto");
168 $ranlib="echo ranlib";
170 $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
171 $src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
172 $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
174 # $bin_dir.=$o causes a core dump on my sparc :-(
179 push(@INC,"util/pl","pl");
181 if ($platform eq "auto") {
182 $platform = $mf_platform;
183 print STDERR "Imported platform $mf_platform\n";
186 if (($platform =~ /VC-(.+)/))
189 $NT = 1 if $1 eq "NT";
192 elsif ($platform eq "Mingw32")
194 require 'Mingw32.pl';
196 elsif ($platform eq "Mingw32-files")
198 require 'Mingw32f.pl';
200 elsif ($platform eq "BC-NT")
205 elsif ($platform eq "FreeBSD")
208 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
210 elsif ($platform eq "linux-elf")
216 elsif ($platform eq "ultrix-mips")
222 elsif ($platform eq "OS2-EMX")
225 require 'OS2-EMX.pl';
227 elsif (($platform eq "netware-clib") || ($platform eq "netware-libc") ||
228 ($platform eq "netware-clib-bsdsock") || ($platform eq "netware-libc-bsdsock"))
230 $LIBC=1 if $platform eq "netware-libc" || $platform eq "netware-libc-bsdsock";
231 $BSDSOCK=1 if ($platform eq "netware-libc-bsdsock") || ($platform eq "netware-clib-bsdsock");
232 require 'netware.pl';
239 $cflags.=' -DTERMIO';
242 $out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
243 $tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
244 $inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
246 $bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
248 $cflags= "$xcflags$cflags" if $xcflags ne "";
250 $cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
251 $cflags.=" -DOPENSSL_NO_AES" if $no_aes;
252 $cflags.=" -DOPENSSL_NO_CAMELLIA" if $no_camellia;
253 $cflags.=" -DOPENSSL_NO_SEED" if $no_seed;
254 $cflags.=" -DOPENSSL_NO_RC2" if $no_rc2;
255 $cflags.=" -DOPENSSL_NO_RC4" if $no_rc4;
256 $cflags.=" -DOPENSSL_NO_RC5" if $no_rc5;
257 $cflags.=" -DOPENSSL_NO_MD2" if $no_md2;
258 $cflags.=" -DOPENSSL_NO_MD4" if $no_md4;
259 $cflags.=" -DOPENSSL_NO_MD5" if $no_md5;
260 $cflags.=" -DOPENSSL_NO_SHA" if $no_sha;
261 $cflags.=" -DOPENSSL_NO_SHA1" if $no_sha1;
262 $cflags.=" -DOPENSSL_NO_RIPEMD" if $no_ripemd;
263 $cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
264 $cflags.=" -DOPENSSL_NO_BF" if $no_bf;
265 $cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
266 $cflags.=" -DOPENSSL_NO_DES" if $no_des;
267 $cflags.=" -DOPENSSL_NO_RSA" if $no_rsa;
268 $cflags.=" -DOPENSSL_NO_DSA" if $no_dsa;
269 $cflags.=" -DOPENSSL_NO_DH" if $no_dh;
270 $cflags.=" -DOPENSSL_NO_WHIRLPOOL" if $no_whirlpool;
271 $cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
272 $cflags.=" -DOPENSSL_NO_SSL2" if $no_ssl2;
273 $cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
274 $cflags.=" -DOPENSSL_NO_TLSEXT" if $no_tlsext;
275 $cflags.=" -DOPENSSL_NO_CMS" if $no_cms;
276 $cflags.=" -DOPENSSL_NO_ERR" if $no_err;
277 $cflags.=" -DOPENSSL_NO_KRB5" if $no_krb5;
278 $cflags.=" -DOPENSSL_NO_EC" if $no_ec;
279 $cflags.=" -DOPENSSL_NO_ECDSA" if $no_ecdsa;
280 $cflags.=" -DOPENSSL_NO_ECDH" if $no_ecdh;
281 $cflags.=" -DOPENSSL_NO_GOST" if $no_gost;
282 $cflags.=" -DOPENSSL_NO_ENGINE" if $no_engine;
283 $cflags.=" -DOPENSSL_NO_HW" if $no_hw;
284 $cflags.=" -DOPENSSL_FIPS" if $fips;
285 $cflags.=" -DOPENSSL_NO_JPAKE" if $no_jpake;
286 $cflags.= " -DZLIB" if $zlib_opt;
287 $cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
289 if ($no_static_engine)
291 $cflags .= " -DOPENSSL_NO_STATIC_ENGINE";
295 $cflags .= " -DOPENSSL_NO_DYNAMIC_ENGINE";
298 #$cflags.=" -DRSAref" if $rsaref ne "";
301 ## { $cflags="$c_flags" if ($c_flags ne ""); }
303 { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
305 $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
308 %shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
309 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
313 $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
314 $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
315 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
316 $banner.="\t\@echo documentation for details.\n";
319 # have to do this to allow $(CC) under unix
320 $link="$bin_dir$link" if ($link !~ /^\$/);
322 $INSTALLTOP =~ s|/|$o|g;
323 $OPENSSLDIR =~ s|/|$o|g;
325 #############################################
326 # We parse in input file and 'store' info for later printing.
327 open(IN,"<$infile") || die "unable to open $infile:$!\n";
333 ($key,$val)=/^([^=]+)=(.*)/;
334 if ($key eq "RELATIVE_DIRECTORY")
338 if ($fips && $dir =~ /^fips/)
345 $uc =~ s/^lib(.*)\.a/$1/;
348 if (($uc ne "FIPS") || $fipscanisterbuild)
351 $lib_obj{$uc}.=$libobj." ";
354 last if ($val eq "FINISHED");
360 if ($key eq "KRB5_INCLUDES")
361 { $cflags .= " $val";}
363 if ($key eq "ZLIB_INCLUDE")
364 { $cflags .= " $val" if $val ne "";}
366 if ($key eq "LIBZLIB")
367 { $zlib_lib = "$val" if $val ne "";}
369 if ($key eq "LIBKRB5")
370 { $ex_libs .= " $val" if $val ne "";}
373 { $test.=&var_add($dir,$val, 0); }
375 if (($key eq "PROGS") || ($key eq "E_OBJ"))
376 { $e_exe.=&var_add($dir,$val, 0); }
381 $lib =~ s/^.*\/([^\/]+)$/$1/;
383 if ($key eq "LIBNAME" && $no_static_engine)
386 $lib =~ s/^.*\/([^\/]+)$/$1/;
387 $otherlibs .= " $lib";
390 if ($key eq "EXHEADER")
391 { $exheader.=&var_add($dir,$val, 1); }
393 if ($key eq "HEADER")
394 { $header.=&var_add($dir,$val, 1); }
396 if ($key eq "LIBOBJ" && ($dir ne "engines" || !$no_static_engine))
397 { $libobj=&var_add($dir,$val, 0); }
398 if ($key eq "LIBNAMES" && $dir eq "engines" && $no_static_engine)
401 if ($key eq "FIPS_EX_OBJ")
403 $fips_ex_obj=&var_add("crypto",$val,0);
406 if ($key eq "FIPSLIBDIR")
409 $fipslibdir =~ s/\/$//;
410 $fipslibdir =~ s/\//$o/g;
413 if ($key eq "BASEADDR")
417 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
424 foreach (split " ", $fips_ex_obj)
426 $fips_exclude_obj{$1} = 1 if (/\/([^\/]*)$/);
429 "$mf_cpuid_asm $mf_aes_asm $mf_sha_asm $mf_bn_asm $mf_des_asm")
432 $fips_exclude_obj{$_} = 1;
434 my @ltmp = split " ", $lib_obj{"CRYPTO"};
437 $lib_obj{"CRYPTO"} = "";
441 if (/\/([^\/]*)$/ && exists $fips_exclude_obj{$1})
443 if ($fipscanisterbuild)
445 $lib_obj{"FIPS"} .= "$_ ";
450 $lib_obj{"CRYPTO"} .= "$_ ";
456 if ($fipscanisterbuild)
458 $fips_canister_path = "\$(LIB_D)${o}fipscanister.lib" if $fips_canister_path eq "";
459 $fips_premain_c_path = "\$(LIB_D)${o}fips_premain.c";
463 if ($fips_canister_path eq "")
465 $fips_canister_path = "\$(FIPSLIB_D)${o}fipscanister.lib";
468 if ($fips_premain_c_path eq "")
470 $fips_premain_c_path = "\$(FIPSLIB_D)${o}fips_premain.c";
476 if ($fips_sha1_exe_path eq "")
478 $fips_sha1_exe_path =
479 "\$(BIN_D)${o}fips_standalone_sha1$exep";
484 $fips_sha1_exe_path = "";
487 if ($fips_premain_dso_exe_path eq "")
489 $fips_premain_dso_exe_path = "\$(BIN_D)${o}fips_premain_dso$exep";
492 # $ex_build_targets .= "\$(BIN_D)${o}\$(E_PREMAIN_DSO)$exep" if ($fips);
498 $ex_build_targets .= " \$(LIB_D)$o$crypto_compat \$(PREMAIN_DSO_EXE)";
499 $ex_l_libs .= " \$(O_FIPSCANISTER)";
500 $ex_libs_dep .= " \$(O_FIPSCANISTER)" if $fipscanisterbuild;
502 if ($fipscanisterbuild)
504 $fipslibdir = "\$(LIB_D)";
508 if ($fipslibdir eq "")
510 open (IN, "util/fipslib_path.txt") || fipslib_error();
515 fips_check_files($fipslibdir,
516 "fipscanister.lib", "fipscanister.lib.sha1",
517 "fips_premain.c", "fips_premain.c.sha1");
523 $extra_install= <<"EOF";
524 \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}bin\"
525 \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}bin\"
526 \$(CP) \"\$(L_SSL)\" \"\$(INSTALLTOP)${o}lib\"
527 \$(CP) \"\$(L_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
529 if ($no_static_engine)
531 $extra_install .= <<"EOF"
532 \$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
533 \$(CP) \"\$(E_SHLIB)\" \"\$(INSTALLTOP)${o}lib${o}engines\"
539 $extra_install= <<"EOF";
540 \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}lib\"
541 \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
543 $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
547 # This makefile has been automatically generated from the OpenSSL distribution.
548 # This single makefile will build the complete OpenSSL distribution and
549 # by default leave the 'intertesting' output files in .${o}out and the stuff
550 # that needs deleting in .${o}tmp.
551 # The file was generated by running 'make makefile.one', which
552 # does a 'make files', which writes all the environment variables from all
553 # the makefiles to the file call MINFO. This file is used by
554 # util${o}mk1mf.pl to generate makefile.one.
555 # The 'makefile per directory' system suites me when developing this
556 # library and also so I can 'distribute' indervidual library sections.
557 # The one monster makefile better suits building in non-unix
562 $defs .= $preamble if defined $preamble;
565 INSTALLTOP=$INSTALLTOP
566 OPENSSLDIR=$OPENSSLDIR
568 # Set your compiler options
574 SHLIB_CFLAG=$shl_cflag
575 APP_EX_OBJ=$app_ex_obj
576 SHLIB_EX_OBJ=$shlib_ex_obj
577 # add extra libraries to this define, for solaris -lsocket -lnsl would
581 # The OpenSSL directory
587 FIPSLINK=\$(PERL) util${o}fipslink.pl
589 # The output directory for everything intersting
591 # The output directory for all the temporary muck
593 # The output directory for the header files
595 INCO_D=$inc_dir${o}openssl
606 # FIPS validated module and support file locations
608 E_PREMAIN_DSO=fips_premain_dso
610 FIPSLIB_D=$fipslibdir
612 FIPS_PREMAIN_SRC=$fips_premain_c_path
613 O_FIPSCANISTER=$fips_canister_path
614 FIPS_SHA1_EXE=$fips_sha1_exe_path
615 PREMAIN_DSO_EXE=$fips_premain_dso_exe_path
617 ######################################################
618 # You should not need to touch anything below this point
619 ######################################################
625 # BIN_D - Binary output directory
626 # TEST_D - Binary test file output directory
627 # LIB_D - library output directory
628 # ENG_D - dynamic engine output directory
629 # Note: if you change these point to different directories then uncomment out
630 # the lines around the 'NB' comment below.
637 # INCL_D - local library directory
638 # OBJ_D - temp object file directory
642 O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
643 O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
644 SO_SSL= $plib\$(SSL)$so_shlibp
645 SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
646 L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp
647 L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp
649 L_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs
651 ######################################################
652 # Don't touch anything below this point
653 ######################################################
655 INC=-I\$(INC_D) -I\$(INCL_D)
656 APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
657 LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
658 SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
659 LIBS_DEP=\$(O_CRYPTO) \$(O_SSL) $ex_libs_dep
661 #############################################
665 all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers \$(FIPS_SHA1_EXE) lib exe $ex_build_targets
671 \$(MKDIR) \"\$(TMP_D)\"
672 # NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
674 # \$(MKDIR) \$(BIN_D)
677 # \$(MKDIR) \$(TEST_D)
680 \$(MKDIR) \"\$(LIB_D)\"
682 \$(INCO_D): \$(INC_D)
683 \$(MKDIR) \"\$(INCO_D)\"
686 \$(MKDIR) \"\$(INC_D)\"
688 headers: \$(HEADER) \$(EXHEADER)
691 lib: \$(LIBS_DEP) \$(E_SHLIB)
693 exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
696 \$(MKDIR) \"\$(INSTALLTOP)\"
697 \$(MKDIR) \"\$(INSTALLTOP)${o}bin\"
698 \$(MKDIR) \"\$(INSTALLTOP)${o}include\"
699 \$(MKDIR) \"\$(INSTALLTOP)${o}include${o}openssl\"
700 \$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
701 \$(CP) \"\$(INCO_D)${o}*.\[ch\]\" \"\$(INSTALLTOP)${o}include${o}openssl\"
702 \$(CP) \"\$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin\"
703 \$(MKDIR) \"\$(OPENSSLDIR)\"
704 \$(CP) apps${o}openssl.cnf \"\$(OPENSSLDIR)\"
713 \$(RM) \$(TMP_D)$o*.*
716 \$(RM) \$(TMP_D)$o*.*
717 \$(RM) \$(OUT_D)$o*.*
721 my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
722 $platform_cpp_symbol =~ s/-/_/g;
723 if (open(IN,"crypto/buildinf.h"))
725 # Remove entry for this platform in existing file buildinf.h.
727 my $old_buildinf_h = "";
730 if (/^\#ifdef $platform_cpp_symbol$/)
732 while (<IN>) { last if (/^\#endif/); }
736 $old_buildinf_h .= $_;
741 open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
742 print OUT $old_buildinf_h;
746 open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
748 #ifdef $platform_cpp_symbol
749 /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
750 #define CFLAGS "$cc $cflags"
751 #define PLATFORM "$platform"
753 printf OUT " #define DATE \"%s\"\n", scalar gmtime();
754 printf OUT "#endif\n";
757 # Strip of trailing ' '
758 foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
759 $test=&clean_up_ws($test);
760 $e_exe=&clean_up_ws($e_exe);
761 $exheader=&clean_up_ws($exheader);
762 $header=&clean_up_ws($header);
764 # First we strip the exheaders from the headers list
765 foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
766 foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; }
767 chop($h); $header=$h;
769 $defs.=&do_defs("HEADER",$header,"\$(INCL_D)","");
770 $rules.=&do_copy_rule("\$(INCL_D)",$header,"");
772 $defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)","");
773 $rules.=&do_copy_rule("\$(INCO_D)",$exheader,"");
775 $defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
776 $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
778 $defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
779 $rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
781 # Special case rules for fips_start and fips_end fips_premain_dso
785 if ($fipscanisterbuild)
787 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_start$obj",
788 "fips${o}fips_canister.c",
789 "-DFIPS_START \$(SHLIB_CFLAGS)");
790 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_end$obj",
791 "fips${o}fips_canister.c", "\$(SHLIB_CFLAGS)");
793 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_standalone_sha1$obj",
794 "fips${o}sha${o}fips_standalone_sha1.c",
796 $rules.=&cc_compile_target("\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj",
797 "fips${o}fips_premain.c",
798 "-DFINGERPRINT_PREMAIN_DSO_LOAD \$(SHLIB_CFLAGS)");
801 foreach (values %lib_nam)
803 $lib_obj=$lib_obj{$_};
806 if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
808 $rules.="\$(O_SSL):\n\n";
812 $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
813 $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
814 $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
817 # hack to add version info on MSVC
818 if (($platform eq "VC-WIN32") || ($platform eq "VC-WIN64A")
819 || ($platform eq "VC-WIN64I") || ($platform eq "VC-NT")) {
821 \$(OBJ_D)\\\$(CRYPTO).res: ms\\version32.rc
822 \$(RSC) /fo"\$(OBJ_D)\\\$(CRYPTO).res" /d CRYPTO ms\\version32.rc
824 \$(OBJ_D)\\\$(SSL).res: ms\\version32.rc
825 \$(RSC) /fo"\$(OBJ_D)\\\$(SSL).res" /d SSL ms\\version32.rc
830 $defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
831 foreach (split(/\s+/,$test))
836 # Check to see if test program is FIPS
839 # If fips perform static link to
841 $t_libs = "\$(O_FIPSCANISTER)";
846 $t_libs = "\$(L_LIBS)";
850 $tt="\$(OBJ_D)${o}$t${obj}";
851 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","$t_libs \$(EX_LIBS)", $ltype);
853 foreach (split(/\s+/,$test))
856 $tt="\$(OBJ_D)${o}$t${obj}";
857 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
860 $defs.=&do_defs("E_SHLIB",$engines . $otherlibs,"\$(ENG_D)",$shlibp);
862 foreach (split(/\s+/,$engines))
864 $rules.=&do_compile_rule("\$(OBJ_D)","engines${o}e_$_",$lib);
865 $rules.= &do_lib_rule("\$(OBJ_D)${o}e_${_}.obj","\$(ENG_D)$o$_$shlibp","",$shlib,"");
870 $rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
871 #$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
873 foreach (split(" ",$otherlibs))
877 $rules.= &do_lib_rule("\$(${uc}OBJ)","\$(ENG_D)$o$_$shlibp", "", $shlib, "");
885 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
886 "\$(O_CRYPTO)", "$crypto",
887 $shlib, "\$(SO_CRYPTO)", "\$(BASEADDR)");
891 $rules.= &do_lib_rule("\$(CRYPTOOBJ)",
892 "\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)", "");
893 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(FIPSOBJ)",
894 "\$(LIB_D)$o$crypto_compat",$crypto,$shlib,"\$(SO_CRYPTO)", "");
899 $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
905 if ($fipscanisterbuild)
907 $rules.= &do_rlink_rule("\$(O_FIPSCANISTER)",
908 "\$(OBJ_D)${o}fips_start$obj",
910 "\$(OBJ_D)${o}fips_end$obj",
911 "\$(FIPS_SHA1_EXE)", "");
913 $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)",
914 "\$(OBJ_D)${o}fips_standalone_sha1$obj \$(OBJ_D)${o}sha1dgst$obj $sha1_asm_obj",
915 "","\$(EX_LIBS)", 1);
919 $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)",
920 "\$(OBJ_D)${o}fips_standalone_sha1$obj \$(O_FIPSCANISTER)",
924 $rules.=&do_link_rule("\$(PREMAIN_DSO_EXE)","\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj \$(CRYPTOOBJ) \$(O_FIPSCANISTER)","","\$(EX_LIBS)", 1);
928 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)", ($fips && !$shlib) ? 2 : 0);
932 if ($platform eq "linux-elf") {
934 # Generate perlasm output files
936 (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
939 print "###################################################################\n";
942 ###############################################
943 # strip off any trailing .[och] and append the relative directory
944 # also remembering to do nothing if we are in one of the dropped
948 local($dir,$val,$keepext)=@_;
951 return("") if $no_engine && $dir =~ /\/engine/;
952 return("") if $no_hw && $dir =~ /\/hw/;
953 return("") if $no_idea && $dir =~ /\/idea/;
954 return("") if $no_aes && $dir =~ /\/aes/;
955 return("") if $no_camellia && $dir =~ /\/camellia/;
956 return("") if $no_seed && $dir =~ /\/seed/;
957 return("") if $no_rc2 && $dir =~ /\/rc2/;
958 return("") if $no_rc4 && $dir =~ /\/rc4/;
959 return("") if $no_rc5 && $dir =~ /\/rc5/;
960 return("") if $no_rsa && $dir =~ /\/rsa/;
961 return("") if $no_rsa && $dir =~ /^rsaref/;
962 return("") if $no_dsa && $dir =~ /\/dsa/;
963 return("") if $no_dh && $dir =~ /\/dh/;
964 return("") if $no_ec && $dir =~ /\/ec/;
965 return("") if $no_gost && $dir =~ /\/ccgost/;
966 return("") if $no_cms && $dir =~ /\/cms/;
967 return("") if $no_jpake && $dir =~ /\/jpake/;
968 return("") if !$fips && $dir =~ /^fips/;
969 if ($no_des && $dir =~ /\/des/)
971 if ($val =~ /read_pwd/)
972 { return("$dir/read_pwd "); }
976 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
977 return("") if $no_sock && $dir =~ /\/proxy/;
978 return("") if $no_bf && $dir =~ /\/bf/;
979 return("") if $no_cast && $dir =~ /\/cast/;
980 return("") if $no_whirlpool && $dir =~ /\/whrlpool/;
982 $val =~ s/^\s*(.*)\s*$/$1/;
983 @a=split(/\s+/,$val);
984 grep(s/\.[och]$//,@a) unless $keepext;
986 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
987 @a=grep(!/^e_.*_d$/,@a) if $no_des;
988 @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
989 @a=grep(!/^e_.*_i$/,@a) if $no_aes;
990 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
991 @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
992 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
993 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
994 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
995 @a=grep(!/^e_camellia$/,@a) if $no_camellia;
996 @a=grep(!/^e_seed$/,@a) if $no_seed;
998 #@a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
999 #@a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
1001 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
1003 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
1004 @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
1005 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
1006 @a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
1008 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
1009 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
1010 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
1012 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
1013 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
1015 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
1017 @a=grep(!/_dhp$/,@a) if $no_dh;
1019 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
1020 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
1021 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
1023 @a=grep(!/^engine$/,@a) if $no_engine;
1024 @a=grep(!/^hw$/,@a) if $no_hw;
1025 @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
1026 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
1027 @a=grep(!/^gendsa$/,@a) if $no_sha1;
1028 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
1030 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
1032 grep($_="$dir/$_",@a);
1033 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
1034 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
1035 $ret=join(' ',@a)." ";
1039 # change things so that each 'token' is only separated by one space
1044 $w =~ s/^\s*(.*)\s*$/$1/;
1051 local($var,$files,$location,$postfix)=@_;
1053 local(*OUT,$tmp,$t);
1055 $files =~ s/\//$o/g if $o ne '/';
1059 foreach (split(/ /,$files))
1062 $_=&bname($_) unless /^\$/;
1068 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
1070 else { $pf=$postfix; }
1071 if ($_ =~ /BN_ASM/) { $t="$_ "; }
1072 elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
1073 elsif ($_ =~ /AES_ASM/){ $t="$_ "; }
1074 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
1075 elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
1076 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
1077 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
1078 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
1079 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
1080 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
1081 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
1082 elsif ($_ =~ /WHIRLPOOL_ASM/){ $t="$_ "; }
1083 elsif ($_ =~ /CPUID_ASM/){ $t="$_ "; }
1084 else { $t="$location${o}$_$pf "; }
1089 # hack to add version info on MSVC
1090 if ($shlib && (($platform eq "VC-WIN32") || ($platfrom eq "VC-WIN64I") || ($platform eq "VC-WIN64A") || ($platform eq "VC-NT")))
1092 if ($var eq "CRYPTOOBJ")
1093 { $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
1094 elsif ($var eq "SSLOBJ")
1095 { $ret.="\$(OBJ_D)\\\$(SSL).res "; }
1102 # return the name with the leading path removed
1106 $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
1110 # return the leading path
1114 $ret =~ s/(^.*)[\\\/][^\\\/]+$/$1/;
1118 ##############################################################
1119 # do a rule for each file that says 'compile' to new direcory
1120 # compile the files in '$files' into $to
1123 local($to,$files,$ex)=@_;
1124 local($ret,$_,$n,$d,$s);
1126 $files =~ s/\//$o/g if $o ne '/';
1127 foreach (split(/\s+/,$files))
1133 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
1135 elsif (-f ($s="${d}${o}asm${o}${n}.pl") or
1136 ($s=~s/sha256/sha512/ and -f $s) or
1137 -f ($s="${d}${o}${n}.pl"))
1139 $ret.=&perlasm_compile_target("$to${o}$n$obj",$s,$n);
1141 elsif (-f ($s="${d}${o}asm${o}${n}.S") or
1142 -f ($s="${d}${o}${n}.S"))
1144 $ret.=&Sasm_compile_target("$to${o}$n$obj",$s,$n);
1146 else { die "no rule for $_"; }
1151 ##############################################################
1152 # do a rule for each file that says 'compile' to new direcory
1153 sub perlasm_compile_target
1155 my($target,$source,$bname)=@_;
1158 $bname =~ s/(.*)\.[^\.]$/$1/;
1159 $ret ="\$(TMP_D)$o$bname.asm: $source\n";
1160 $ret.="\t\$(PERL) $source $asmtype \$(CFLAG) >\$\@\n\n";
1161 $ret.="$target: \$(TMP_D)$o$bname.asm\n";
1162 $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
1166 sub Sasm_compile_target
1168 my($target,$source,$bname)=@_;
1171 $bname =~ s/(.*)\.[^\.]$/$1/;
1172 $ret ="\$(TMP_D)$o$bname.asm: $source\n";
1173 $ret.="\t\$(CC) -E \$(CFLAG) $source >\$\@\n\n";
1174 $ret.="$target: \$(TMP_D)$o$bname.asm\n";
1175 $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
1179 sub cc_compile_target
1181 local($target,$source,$ex_flags)=@_;
1184 $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
1185 $target =~ s/\//$o/g if $o ne "/";
1186 $source =~ s/\//$o/g if $o ne "/";
1187 $ret ="$target: \$(SRC_D)$o$source\n\t";
1188 $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
1192 ##############################################################
1195 local($target,$src)=@_;
1196 local($ret,@s,@t,$i);
1198 $target =~ s/\//$o/g if $o ne "/";
1199 $src =~ s/\//$o/g if $o ne "/";
1201 @t=split(/\s+/,$target);
1202 @s=split(/\s+/,$src);
1205 for ($i=0; $i<=$#s; $i++)
1207 my $objfile = $t[$i];
1208 my $srcfile = $s[$i];
1212 my $plasm = $objfile;
1213 $plasm =~ s/${obj}/.pl/;
1214 $ret.="$srcfile: $plasm\n";
1215 $ret.="\t\$(PERL) $plasm $asmtype \$(CFLAG) >$srcfile\n\n";
1218 $ret.="$objfile: $srcfile\n";
1219 $ret.="\t\$(ASM) $afile$objfile \$(SRC_D)$o$srcfile\n\n";
1230 ($nn=$n) =~ tr/a-z/A-Z/;
1231 $ret.="$n.dll: \$(${nn}OBJ)\n";
1234 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
1240 # do a rule for each file that says 'copy' to new direcory on change
1243 local($to,$files,$p)=@_;
1244 local($ret,$_,$n,$pp);
1246 $files =~ s/\//$o/g if $o ne '/';
1247 foreach (split(/\s+/,$files))
1250 if ($n =~ /bss_file/)
1253 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
1260 # Many options are handled in a similar way. In particular
1261 # no-xxx sets zero or more scalars to 1.
1262 # Process these using a hash containing the option name and
1263 # reference to the scalars to set.
1265 my %valid_options = (
1266 "no-rc2" => \$no_rc2,
1267 "no-rc4" => \$no_rc4,
1268 "no-rc5" => \$no_rc5,
1269 "no-idea" => \$no_idea,
1270 "no-aes" => \$no_aes,
1271 "no-camellia" => \$no_camellia,
1272 "no-seed" => \$no_seed,
1273 "no-des" => \$no_des,
1275 "no-cast" => \$no_cast,
1276 "no-md2" => \$no_md2,
1277 "no-md4" => \$no_md4,
1278 "no-md5" => \$no_md5,
1279 "no-sha" => \$no_sha,
1280 "no-sha1" => \$no_sha1,
1281 "no-ripemd" => \$no_ripemd,
1282 "no-mdc2" => \$no_mdc2,
1283 "no-whirlpool" => \$no_whirlpool,
1285 [\$no_rc2, \$no_rc4, \$no_rc5, \$no_idea, \$no_rsa],
1286 "no-rsa" => \$no_rsa,
1287 "no-dsa" => \$no_dsa,
1289 "no-hmac" => \$no_hmac,
1290 "no-asm" => \$no_asm,
1292 "nw-nasm" => \$nw_nasm,
1293 "nw-mwasm" => \$nw_mwasm,
1294 "gaswin" => \$gaswin,
1295 "no-ssl2" => \$no_ssl2,
1296 "no-ssl3" => \$no_ssl3,
1297 "no-tlsext" => \$no_tlsext,
1298 "no-cms" => \$no_cms,
1299 "no-jpake" => \$no_jpake,
1300 "no-err" => \$no_err,
1301 "no-sock" => \$no_sock,
1302 "no-krb5" => \$no_krb5,
1304 "no-ecdsa" => \$no_ecdsa,
1305 "no-ecdh" => \$no_ecdh,
1306 "no-gost" => \$no_gost,
1307 "no-engine" => \$no_engine,
1310 [\$no_rc2, \$no_idea, \$no_des, \$no_bf, \$no_cast,
1311 \$no_md2, \$no_sha, \$no_mdc2, \$no_dsa, \$no_dh,
1312 \$no_ssl2, \$no_err, \$no_ripemd, \$no_rc5,
1313 \$no_aes, \$no_camellia, \$no_seed],
1317 "profile" => \$profile,
1327 "no-zlib-dynamic" => 0,
1329 "fipscanisterbuild" => [\$fips, \$fipscanisterbuild],
1332 if (exists $valid_options{$_})
1334 my $r = $valid_options{$_};
1335 if ( ref $r eq "SCALAR")
1337 elsif ( ref $r eq "ARRAY")
1346 elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; }
1347 elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
1348 elsif (/^enable-zlib-dynamic$/)
1352 elsif (/^no-static-engine/)
1354 $no_static_engine = 1;
1356 elsif (/^enable-static-engine/)
1358 $no_static_engine = 0;
1360 # There are also enable-xxx options which correspond to
1361 # the no-xxx. Since the scalars are enabled by default
1362 # these can be ignored.
1366 $t =~ s/^enable/no/;
1367 if (exists $valid_options{$t})
1371 # experimental-xxx is mostly like enable-xxx, but opensslconf.v
1372 # will still set OPENSSL_NO_xxx unless we set OPENSSL_EXPERIMENTAL_xxx.
1373 # (No need to fail if we don't know the algorithm -- this is for adventurous users only.)
1374 elsif (/^experimental-/)
1377 ($algo = $_) =~ s/^experimental-//;
1378 ($ALGO = $algo) =~ tr/[a-z]/[A-Z]/;
1380 $xcflags="-DOPENSSL_EXPERIMENTAL_$ALGO $xcflags";
1383 elsif (/^--with-krb5-flavor=(.*)$/)
1385 my $krb5_flavor = $1;
1386 if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
1388 $xcflags="-DKRB5_HEIMDAL $xcflags";
1390 elsif ($krb5_flavor =~ /^MIT/i)
1392 $xcflags="-DKRB5_MIT $xcflags";
1393 if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
1395 $xcflags="-DKRB5_MIT_OLD11 $xcflags"
1399 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1400 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
1401 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
1402 { $c_flags.="$_ "; }
1409 print STDERR "***FIPS module directory sanity check failed***\n";
1410 print STDERR "FIPS module build failed, or was deleted\n";
1411 print STDERR "Please rebuild FIPS module.\n";
1415 sub fips_check_files
1421 print STDERR "FIPS module directory $dir does not exist\n";
1426 if (!-f "$dir${o}$_")
1428 print STDERR "FIPS module file $_ does not exist!\n";
1432 fipslib_error() if ($ret == 0);