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;
16 local $zlib_opt = 0; # 0 = no zlib, 1 = static, 2 = dynamic
18 local $perl_asm = 0; # 1 to autobuild asm files from perl scripts
20 # Options to import from top level Makefile
23 VERSION => \$ssl_version,
25 INSTALLTOP => \$INSTALLTOP,
26 OPENSSLDIR => \$OPENSSLDIR,
27 PLATFORM => \$mf_platform,
29 DEPFLAG => \$mf_depflag,
30 CPUID_OBJ => \$mf_cpuid_asm,
31 BN_ASM => \$mf_bn_asm,
32 DES_ENC => \$mf_des_asm,
33 AES_ENC => \$mf_aes_asm,
34 BF_ENC => \$mf_bf_asm,
35 CAST_ENC => \$mf_cast_asm,
36 RC4_ENC => \$mf_rc4_asm,
37 RC5_ENC => \$mf_rc5_asm,
38 MD5_ASM_OBJ => \$mf_md5_asm,
39 SHA1_ASM_OBJ => \$mf_sha_asm,
40 RMD160_ASM_OBJ => \$mf_rmd_asm,
41 WP_ASM_OBJ => \$mf_wp_asm,
42 CMLL_ENC => \$mf_cm_asm
46 open(IN,"<Makefile") || die "unable to open Makefile!\n";
48 my ($mf_opt, $mf_ref);
49 while (($mf_opt, $mf_ref) = each %mf_import) {
50 if (/^$mf_opt\s*=\s*(.*)$/) {
57 die "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
62 "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X",
63 "VC-WIN64I", "Microsoft C/C++ - Win64/IA-64",
64 "VC-WIN64A", "Microsoft C/C++ - Win64/x64",
65 "VC-CE", "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
66 "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY",
67 "Mingw32", "GNU C++ - Windows NT or 9x",
68 "Mingw32-files", "Create files with DOS copy ...",
69 "BC-NT", "Borland C++ 4.5 - Windows NT",
70 "linux-elf","Linux elf",
71 "ultrix-mips","DEC mips ultrix",
72 "FreeBSD","FreeBSD distribution",
73 "OS2-EMX", "EMX GCC OS/2",
74 "netware-clib", "CodeWarrior for NetWare - CLib - with WinSock Sockets",
75 "netware-clib-bsdsock", "CodeWarrior for NetWare - CLib - with BSD Sockets",
76 "netware-libc", "CodeWarrior for NetWare - LibC - with WinSock Sockets",
77 "netware-libc-bsdsock", "CodeWarrior for NetWare - LibC - with BSD Sockets",
78 "default","cc under unix",
79 "auto", "auto detect from top level Makefile"
86 if (!&read_options && !defined($ops{$_}))
88 print STDERR "unknown option - $_\n";
89 print STDERR "usage: perl mk1mf.pl [options] [system]\n";
90 print STDERR "\nwhere [system] can be one of the following\n";
91 foreach $i (sort keys %ops)
92 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
94 and [options] can be one of
95 no-md2 no-md4 no-md5 no-sha no-mdc2 - Skip this digest
97 no-rc2 no-rc4 no-rc5 no-idea no-des - Skip this symetric cipher
98 no-bf no-cast no-aes no-camellia no-seed
99 no-rsa no-dsa no-dh - Skip this public key cipher
100 no-ssl2 no-ssl3 - Skip this version of SSL
101 just-ssl - remove all non-ssl keys/digest
107 no-engine - No engine
109 nasm - Use NASM for x86 asm
110 nw-nasm - Use NASM x86 asm for NetWare
111 nw-mwasm - Use Metrowerks x86 asm for NetWare
112 gaswin - Use GNU as with Mingw32
113 no-socks - No socket code
114 no-err - No error strings
115 dll/shlib - Build shared libraries (MS)
117 profile - Profiling build
120 Values that can be set
121 TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
123 -L<ex_lib_path> -l<ex_lib> - extra library flags (unix)
124 -<ex_cc_flags> - extra 'cc' flags,
125 added (MS), or replace (unix)
131 foreach (grep(!/^$/, split(/ /, $OPTIONS)))
133 print STDERR "unknown option - $_\n" if !&read_options;
136 $no_static_engine = 0 if (!$shlib);
138 $no_mdc2=1 if ($no_des);
140 $no_ssl3=1 if ($no_md5 || $no_sha);
141 $no_ssl3=1 if ($no_rsa && $no_dh);
143 $no_ssl2=1 if ($no_md5);
144 $no_ssl2=1 if ($no_rsa);
150 $perl="perl" unless defined $perl;
151 $mkdir="-mkdir" unless defined $mkdir;
153 ($ssl,$crypto)=("ssl","crypto");
154 $ranlib="echo ranlib";
156 $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
157 $src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
158 $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
160 # $bin_dir.=$o causes a core dump on my sparc :-(
165 push(@INC,"util/pl","pl");
167 if ($platform eq "auto") {
168 $platform = $mf_platform;
169 print STDERR "Imported platform $mf_platform\n";
172 if (($platform =~ /VC-(.+)/))
175 $NT = 1 if $1 eq "NT";
178 elsif ($platform eq "Mingw32")
180 require 'Mingw32.pl';
182 elsif ($platform eq "Mingw32-files")
184 require 'Mingw32f.pl';
186 elsif ($platform eq "BC-NT")
191 elsif ($platform eq "FreeBSD")
194 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
196 elsif ($platform eq "linux-elf")
202 elsif ($platform eq "ultrix-mips")
208 elsif ($platform eq "OS2-EMX")
211 require 'OS2-EMX.pl';
213 elsif (($platform eq "netware-clib") || ($platform eq "netware-libc") ||
214 ($platform eq "netware-clib-bsdsock") || ($platform eq "netware-libc-bsdsock"))
216 $LIBC=1 if $platform eq "netware-libc" || $platform eq "netware-libc-bsdsock";
217 $BSDSOCK=1 if ($platform eq "netware-libc-bsdsock") || ($platform eq "netware-clib-bsdsock");
218 require 'netware.pl';
225 $cflags.=' -DTERMIO';
228 $out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
229 $tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
230 $inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
232 $bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
234 $cflags= "$xcflags$cflags" if $xcflags ne "";
236 $cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
237 $cflags.=" -DOPENSSL_NO_AES" if $no_aes;
238 $cflags.=" -DOPENSSL_NO_CAMELLIA" if $no_camellia;
239 $cflags.=" -DOPENSSL_NO_SEED" if $no_seed;
240 $cflags.=" -DOPENSSL_NO_RC2" if $no_rc2;
241 $cflags.=" -DOPENSSL_NO_RC4" if $no_rc4;
242 $cflags.=" -DOPENSSL_NO_RC5" if $no_rc5;
243 $cflags.=" -DOPENSSL_NO_MD2" if $no_md2;
244 $cflags.=" -DOPENSSL_NO_MD4" if $no_md4;
245 $cflags.=" -DOPENSSL_NO_MD5" if $no_md5;
246 $cflags.=" -DOPENSSL_NO_SHA" if $no_sha;
247 $cflags.=" -DOPENSSL_NO_SHA1" if $no_sha1;
248 $cflags.=" -DOPENSSL_NO_RIPEMD" if $no_ripemd;
249 $cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
250 $cflags.=" -DOPENSSL_NO_BF" if $no_bf;
251 $cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
252 $cflags.=" -DOPENSSL_NO_DES" if $no_des;
253 $cflags.=" -DOPENSSL_NO_RSA" if $no_rsa;
254 $cflags.=" -DOPENSSL_NO_DSA" if $no_dsa;
255 $cflags.=" -DOPENSSL_NO_DH" if $no_dh;
256 $cflags.=" -DOPENSSL_NO_WHIRLPOOL" if $no_whirlpool;
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_TLSEXT" if $no_tlsext;
261 $cflags.=" -DOPENSSL_NO_ERR" if $no_err;
262 $cflags.=" -DOPENSSL_NO_KRB5" if $no_krb5;
263 $cflags.=" -DOPENSSL_NO_EC" if $no_ec;
264 $cflags.=" -DOPENSSL_NO_ECDSA" if $no_ecdsa;
265 $cflags.=" -DOPENSSL_NO_ECDH" if $no_ecdh;
266 $cflags.=" -DOPENSSL_NO_ENGINE" if $no_engine;
267 $cflags.=" -DOPENSSL_NO_HW" if $no_hw;
269 $cflags.= " -DZLIB" if $zlib_opt;
270 $cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
272 if ($no_static_engine)
274 $cflags .= " -DOPENSSL_NO_STATIC_ENGINE";
278 $cflags .= " -DOPENSSL_NO_DYNAMIC_ENGINE";
281 #$cflags.=" -DRSAref" if $rsaref ne "";
284 ## { $cflags="$c_flags" if ($c_flags ne ""); }
286 { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
288 $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
291 %shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
292 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
296 $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
297 $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
298 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
299 $banner.="\t\@echo documentation for details.\n";
302 # have to do this to allow $(CC) under unix
303 $link="$bin_dir$link" if ($link !~ /^\$/);
305 $INSTALLTOP =~ s|/|$o|g;
306 $OPENSSLDIR =~ s|/|$o|g;
308 #############################################
309 # We parse in input file and 'store' info for later printing.
310 open(IN,"<$infile") || die "unable to open $infile:$!\n";
316 ($key,$val)=/^([^=]+)=(.*)/;
317 if ($key eq "RELATIVE_DIRECTORY")
322 $uc =~ s/^lib(.*)\.a/$1/;
325 $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, 0); }
348 if (($key eq "PROGS") || ($key eq "E_OBJ"))
349 { $e_exe.=&var_add($dir,$val, 0); }
354 $lib =~ s/^.*\/([^\/]+)$/$1/;
357 if ($key eq "EXHEADER")
358 { $exheader.=&var_add($dir,$val, 1); }
360 if ($key eq "HEADER")
361 { $header.=&var_add($dir,$val, 1); }
363 if ($key eq "LIBOBJ" && ($dir ne "engines" || !$no_static_engine))
364 { $libobj=&var_add($dir,$val, 0); }
365 if ($key eq "LIBNAMES" && $dir eq "engines" && $no_static_engine)
369 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
375 $extra_install= <<"EOF";
376 \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}bin\"
377 \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}bin\"
378 \$(CP) \"\$(L_SSL)\" \"\$(INSTALLTOP)${o}lib\"
379 \$(CP) \"\$(L_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
381 if ($no_static_engine)
383 $extra_install .= <<"EOF"
384 \$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
385 \$(CP) \"\$(E_SHLIB)\" \"\$(INSTALLTOP)${o}lib${o}engines\"
391 $extra_install= <<"EOF";
392 \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}lib\"
393 \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
395 $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
399 # This makefile has been automatically generated from the OpenSSL distribution.
400 # This single makefile will build the complete OpenSSL distribution and
401 # by default leave the 'intertesting' output files in .${o}out and the stuff
402 # that needs deleting in .${o}tmp.
403 # The file was generated by running 'make makefile.one', which
404 # does a 'make files', which writes all the environment variables from all
405 # the makefiles to the file call MINFO. This file is used by
406 # util${o}mk1mf.pl to generate makefile.one.
407 # The 'makefile per directory' system suites me when developing this
408 # library and also so I can 'distribute' indervidual library sections.
409 # The one monster makefile better suits building in non-unix
414 $defs .= $preamble if defined $preamble;
417 INSTALLTOP=$INSTALLTOP
418 OPENSSLDIR=$OPENSSLDIR
420 # Set your compiler options
426 SHLIB_CFLAG=$shl_cflag
427 APP_EX_OBJ=$app_ex_obj
428 SHLIB_EX_OBJ=$shlib_ex_obj
429 # add extra libraries to this define, for solaris -lsocket -lnsl would
433 # The OpenSSL directory
440 # The output directory for everything intersting
442 # The output directory for all the temporary muck
444 # The output directory for the header files
446 INCO_D=$inc_dir${o}openssl
457 ######################################################
458 # You should not need to touch anything below this point
459 ######################################################
465 # BIN_D - Binary output directory
466 # TEST_D - Binary test file output directory
467 # LIB_D - library output directory
468 # ENG_D - dynamic engine output directory
469 # Note: if you change these point to different directories then uncomment out
470 # the lines around the 'NB' comment below.
477 # INCL_D - local library directory
478 # OBJ_D - temp object file directory
482 O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
483 O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
484 SO_SSL= $plib\$(SSL)$so_shlibp
485 SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
486 L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp
487 L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp
489 L_LIBS= \$(L_SSL) \$(L_CRYPTO)
491 ######################################################
492 # Don't touch anything below this point
493 ######################################################
495 INC=-I\$(INC_D) -I\$(INCL_D)
496 APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
497 LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
498 SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
499 LIBS_DEP=\$(O_CRYPTO) \$(O_SSL)
501 #############################################
505 all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe
511 \$(MKDIR) \"\$(TMP_D)\"
512 # NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
514 # \$(MKDIR) \$(BIN_D)
517 # \$(MKDIR) \$(TEST_D)
520 \$(MKDIR) \"\$(LIB_D)\"
522 \$(INCO_D): \$(INC_D)
523 \$(MKDIR) \"\$(INCO_D)\"
526 \$(MKDIR) \"\$(INC_D)\"
528 headers: \$(HEADER) \$(EXHEADER)
531 lib: \$(LIBS_DEP) \$(E_SHLIB)
533 exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
536 \$(MKDIR) \"\$(INSTALLTOP)\"
537 \$(MKDIR) \"\$(INSTALLTOP)${o}bin\"
538 \$(MKDIR) \"\$(INSTALLTOP)${o}include\"
539 \$(MKDIR) \"\$(INSTALLTOP)${o}include${o}openssl\"
540 \$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
541 \$(CP) \"\$(INCO_D)${o}*.\[ch\]\" \"\$(INSTALLTOP)${o}include${o}openssl\"
542 \$(CP) \"\$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin\"
543 \$(MKDIR) \"\$(OPENSSLDIR)\"
544 \$(CP) apps${o}openssl.cnf \"\$(OPENSSLDIR)\"
553 \$(RM) \$(TMP_D)$o*.*
556 \$(RM) \$(TMP_D)$o*.*
557 \$(RM) \$(OUT_D)$o*.*
561 my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
562 $platform_cpp_symbol =~ s/-/_/g;
563 if (open(IN,"crypto/buildinf.h"))
565 # Remove entry for this platform in existing file buildinf.h.
567 my $old_buildinf_h = "";
570 if (/^\#ifdef $platform_cpp_symbol$/)
572 while (<IN>) { last if (/^\#endif/); }
576 $old_buildinf_h .= $_;
581 open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
582 print OUT $old_buildinf_h;
586 open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
588 #ifdef $platform_cpp_symbol
589 /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
590 #define CFLAGS "$cc $cflags"
591 #define PLATFORM "$platform"
593 printf OUT " #define DATE \"%s\"\n", scalar gmtime();
594 printf OUT "#endif\n";
597 # Strip of trailing ' '
598 foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
599 $test=&clean_up_ws($test);
600 $e_exe=&clean_up_ws($e_exe);
601 $exheader=&clean_up_ws($exheader);
602 $header=&clean_up_ws($header);
604 # First we strip the exheaders from the headers list
605 foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
606 foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; }
607 chop($h); $header=$h;
609 $defs.=&do_defs("HEADER",$header,"\$(INCL_D)","");
610 $rules.=&do_copy_rule("\$(INCL_D)",$header,"");
612 $defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)","");
613 $rules.=&do_copy_rule("\$(INCO_D)",$exheader,"");
615 $defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
616 $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
618 $defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
619 $rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
621 foreach (values %lib_nam)
623 $lib_obj=$lib_obj{$_};
626 if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
628 $rules.="\$(O_SSL):\n\n";
632 $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
633 $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
634 $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
637 # hack to add version info on MSVC
638 if (($platform eq "VC-WIN32") || ($platform eq "VC-NT")) {
640 \$(OBJ_D)\\\$(CRYPTO).res: ms\\version32.rc
641 \$(RSC) /fo"\$(OBJ_D)\\\$(CRYPTO).res" /d CRYPTO ms\\version32.rc
643 \$(OBJ_D)\\\$(SSL).res: ms\\version32.rc
644 \$(RSC) /fo"\$(OBJ_D)\\\$(SSL).res" /d SSL ms\\version32.rc
649 $defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
650 foreach (split(/\s+/,$test))
653 $tt="\$(OBJ_D)${o}$t${obj}";
654 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
657 $defs.=&do_defs("E_SHLIB",$engines,"\$(ENG_D)",$shlibp);
659 foreach (split(/\s+/,$engines))
661 $rules.=&do_compile_rule("\$(OBJ_D)","engines${o}e_$_",$lib);
662 $rules.= &do_lib_rule("\$(OBJ_D)${o}e_${_}.obj","\$(ENG_D)$o$_$shlibp","",$shlib,"");
667 $rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
668 $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
670 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
674 if ($platform eq "linux-elf") {
676 # Generate perlasm output files
678 (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
681 print "###################################################################\n";
684 ###############################################
685 # strip off any trailing .[och] and append the relative directory
686 # also remembering to do nothing if we are in one of the dropped
690 local($dir,$val,$keepext)=@_;
693 return("") if $no_engine && $dir =~ /\/engine/;
694 return("") if $no_hw && $dir =~ /\/hw/;
695 return("") if $no_idea && $dir =~ /\/idea/;
696 return("") if $no_aes && $dir =~ /\/aes/;
697 return("") if $no_camellia && $dir =~ /\/camellia/;
698 return("") if $no_seed && $dir =~ /\/seed/;
699 return("") if $no_rc2 && $dir =~ /\/rc2/;
700 return("") if $no_rc4 && $dir =~ /\/rc4/;
701 return("") if $no_rc5 && $dir =~ /\/rc5/;
702 return("") if $no_rsa && $dir =~ /\/rsa/;
703 return("") if $no_rsa && $dir =~ /^rsaref/;
704 return("") if $no_dsa && $dir =~ /\/dsa/;
705 return("") if $no_dh && $dir =~ /\/dh/;
706 return("") if $no_ec && $dir =~ /\/ec/;
707 if ($no_des && $dir =~ /\/des/)
709 if ($val =~ /read_pwd/)
710 { return("$dir/read_pwd "); }
714 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
715 return("") if $no_sock && $dir =~ /\/proxy/;
716 return("") if $no_bf && $dir =~ /\/bf/;
717 return("") if $no_cast && $dir =~ /\/cast/;
718 return("") if $no_whirlpool && $dir =~ /\/whrlpool/;
720 $val =~ s/^\s*(.*)\s*$/$1/;
721 @a=split(/\s+/,$val);
722 grep(s/\.[och]$//,@a) unless $keepext;
724 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
725 @a=grep(!/^e_.*_d$/,@a) if $no_des;
726 @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
727 @a=grep(!/^e_.*_i$/,@a) if $no_aes;
728 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
729 @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
730 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
731 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
732 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
733 @a=grep(!/^e_camellia$/,@a) if $no_camellia;
734 @a=grep(!/^e_seed$/,@a) if $no_seed;
736 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
737 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
739 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
741 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
742 @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
743 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
744 @a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
746 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
747 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
748 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
750 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
751 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
753 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
755 @a=grep(!/_dhp$/,@a) if $no_dh;
757 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
758 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
759 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
761 @a=grep(!/^engine$/,@a) if $no_engine;
762 @a=grep(!/^hw$/,@a) if $no_hw;
763 @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
764 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
765 @a=grep(!/^gendsa$/,@a) if $no_sha1;
766 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
768 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
770 grep($_="$dir/$_",@a);
771 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
772 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
773 $ret=join(' ',@a)." ";
777 # change things so that each 'token' is only separated by one space
782 $w =~ s/^\s*(.*)\s*$/$1/;
789 local($var,$files,$location,$postfix)=@_;
793 $files =~ s/\//$o/g if $o ne '/';
797 foreach (split(/ /,$files))
800 $_=&bname($_) unless /^\$/;
806 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
808 else { $pf=$postfix; }
809 if ($_ =~ /BN_ASM/) { $t="$_ "; }
810 elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
811 elsif ($_ =~ /AES_ASM/){ $t="$_ "; }
812 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
813 elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
814 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
815 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
816 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
817 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
818 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
819 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
820 elsif ($_ =~ /WHIRLPOOL_ASM/){ $t="$_ "; }
821 elsif ($_ =~ /CPUID_ASM/){ $t="$_ "; }
822 else { $t="$location${o}$_$pf "; }
827 # hack to add version info on MSVC
828 if ($shlib && (($platform eq "VC-WIN32") || ($platform eq "VC-NT")))
830 if ($var eq "CRYPTOOBJ")
831 { $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
832 elsif ($var eq "SSLOBJ")
833 { $ret.="\$(OBJ_D)\\\$(SSL).res "; }
840 # return the name with the leading path removed
844 $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
848 # return the leading path
852 $ret =~ s/(^.*)[\\\/][^\\\/]+$/$1/;
856 ##############################################################
857 # do a rule for each file that says 'compile' to new direcory
858 # compile the files in '$files' into $to
861 local($to,$files,$ex)=@_;
862 local($ret,$_,$n,$d,$s);
864 $files =~ s/\//$o/g if $o ne '/';
865 foreach (split(/\s+/,$files))
871 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
873 elsif (-f ($s="${d}${o}asm${o}${n}.pl") or
874 -f ($s="${d}${o}${n}.pl"))
876 $ret.=&perlasm_compile_target("$to${o}$n$obj",$s,$n);
878 elsif (-f ($s="${d}${o}asm${o}${n}.S") or
879 -f ($s="${d}${o}${n}.S"))
881 $ret.=&Sasm_compile_target("$to${o}$n$obj",$s,$n);
883 else { die "no rule for $_"; }
888 ##############################################################
889 # do a rule for each file that says 'compile' to new direcory
890 sub perlasm_compile_target
892 my($target,$source,$bname)=@_;
895 $bname =~ s/(.*)\.[^\.]$/$1/;
896 $ret ="\$(TMP_D)$o$bname.asm: $source\n";
897 $ret.="\t\$(PERL) $source $asmtype \$(CFLAG) >\$\@\n\n";
898 $ret.="$target: \$(TMP_D)$o$bname.asm\n";
899 $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
903 sub Sasm_compile_target
905 my($target,$source,$bname)=@_;
908 $bname =~ s/(.*)\.[^\.]$/$1/;
909 $ret ="\$(TMP_D)$o$bname.asm: $source\n";
910 $ret.="\t\$(CC) -E \$(CFLAG) $source >\$\@\n\n";
911 $ret.="$target: \$(TMP_D)$o$bname.asm\n";
912 $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
916 sub cc_compile_target
918 local($target,$source,$ex_flags)=@_;
921 $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
922 $target =~ s/\//$o/g if $o ne "/";
923 $source =~ s/\//$o/g if $o ne "/";
924 $ret ="$target: \$(SRC_D)$o$source\n\t";
925 $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
929 ##############################################################
932 local($target,$src)=@_;
933 local($ret,@s,@t,$i);
935 $target =~ s/\//$o/g if $o ne "/";
936 $src =~ s/\//$o/g if $o ne "/";
938 @t=split(/\s+/,$target);
939 @s=split(/\s+/,$src);
942 for ($i=0; $i<=$#s; $i++)
944 my $objfile = $t[$i];
945 my $srcfile = $s[$i];
949 my $plasm = $objfile;
950 $plasm =~ s/${obj}/.pl/;
951 $ret.="$srcfile: $plasm\n";
952 $ret.="\t\$(PERL) $plasm $asmtype \$(CFLAG) >$srcfile\n\n";
955 $ret.="$objfile: $srcfile\n";
956 $ret.="\t\$(ASM) $afile$objfile \$(SRC_D)$o$srcfile\n\n";
967 ($nn=$n) =~ tr/a-z/A-Z/;
968 $ret.="$n.dll: \$(${nn}OBJ)\n";
971 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
977 # do a rule for each file that says 'copy' to new direcory on change
980 local($to,$files,$p)=@_;
981 local($ret,$_,$n,$pp);
983 $files =~ s/\//$o/g if $o ne '/';
984 foreach (split(/\s+/,$files))
987 if ($n =~ /bss_file/)
990 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
997 # Many options are handled in a similar way. In particular
998 # no-xxx sets zero or more scalars to 1.
999 # Process these using a hash containing the option name and
1000 # reference to the scalars to set.
1002 my %valid_options = (
1003 "no-rc2" => \$no_rc2,
1004 "no-rc4" => \$no_rc4,
1005 "no-rc5" => \$no_rc5,
1006 "no-idea" => \$no_idea,
1007 "no-aes" => \$no_aes,
1008 "no-camellia" => \$no_camellia,
1009 "no-seed" => \$no_seed,
1010 "no-des" => \$no_des,
1012 "no-cast" => \$no_cast,
1013 "no-md2" => \$no_md2,
1014 "no-md4" => \$no_md4,
1015 "no-md5" => \$no_md5,
1016 "no-sha" => \$no_sha,
1017 "no-sha1" => \$no_sha1,
1018 "no-ripemd" => \$no_ripemd,
1019 "no-mdc2" => \$no_mdc2,
1020 "no-whirlpool" => \$no_whirlpool,
1022 [\$no_rc2, \$no_rc4, \$no_rc5, \$no_idea, \$no_rsa],
1023 "no-rsa" => \$no_rsa,
1024 "no-dsa" => \$no_dsa,
1026 "no-hmac" => \$no_hmac,
1027 "no-asm" => \$no_asm,
1029 "nw-nasm" => \$nw_nasm,
1030 "nw-mwasm" => \$nw_mwasm,
1031 "gaswin" => \$gaswin,
1032 "no-ssl2" => \$no_ssl2,
1033 "no-ssl3" => \$no_ssl3,
1034 "no-tlsext" => \$no_tlsext,
1035 "no-err" => \$no_err,
1036 "no-sock" => \$no_sock,
1037 "no-krb5" => \$no_krb5,
1039 "no-ecdsa" => \$no_ecdsa,
1040 "no-ecdh" => \$no_ecdh,
1041 "no-engine" => \$no_engine,
1044 [\$no_rc2, \$no_idea, \$no_des, \$no_bf, \$no_cast,
1045 \$no_md2, \$no_sha, \$no_mdc2, \$no_dsa, \$no_dh,
1046 \$no_ssl2, \$no_err, \$no_ripemd, \$no_rc5,
1047 \$no_aes, \$no_camellia, \$no_seed],
1051 "profile" => \$profile,
1059 "no-zlib-dynamic" => 0,
1062 if (exists $valid_options{$_})
1064 my $r = $valid_options{$_};
1065 if ( ref $r eq "SCALAR")
1067 elsif ( ref $r eq "ARRAY")
1076 elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; }
1077 elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
1078 elsif (/^enable-zlib-dynamic$/)
1082 elsif (/^no-static-engine/)
1084 $no_static_engine = 1;
1086 elsif (/^enable-static-engine/)
1088 $no_static_engine = 0;
1090 # There are also enable-xxx options which correspond to
1091 # the no-xxx. Since the scalars are enabled by default
1092 # these can be ignored.
1096 $t =~ s/^enable/no/;
1097 if (exists $valid_options{$t})
1101 elsif (/^--with-krb5-flavor=(.*)$/)
1103 my $krb5_flavor = $1;
1104 if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
1106 $xcflags="-DKRB5_HEIMDAL $xcflags";
1108 elsif ($krb5_flavor =~ /^MIT/i)
1110 $xcflags="-DKRB5_MIT $xcflags";
1111 if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
1113 $xcflags="-DKRB5_MIT_OLD11 $xcflags"
1117 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1118 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
1119 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
1120 { $c_flags.="$_ "; }