mk1mf.pl revision 291719
155714Skris#!/usr/local/bin/perl
255714Skris# A bit of an evil hack but it post processes the file ../MINFO which
355714Skris# is generated by `make files` in the top directory.
455714Skris# This script outputs one mega makefile that has no shell stuff or any
5290207Sjkim# funny stuff (if the target is not "copy").
6290207Sjkim# If the target is "copy", then it tries to create a makefile that can be
7290207Sjkim# safely used with the -j flag and that is compatible with the top-level
8290207Sjkim# Makefile, in the sense that it uses the same options and assembler files etc.
955714Skris
10290207Sjkimuse Cwd;
11290207Sjkim
1255714Skris$INSTALLTOP="/usr/local/ssl";
13238405Sjkim$OPENSSLDIR="/usr/local/ssl";
1455714Skris$OPTIONS="";
1555714Skris$ssl_version="";
1659191Skris$banner="\t\@echo Building OpenSSL";
1755714Skris
18238405Sjkimmy $no_static_engine = 1;
19160814Ssimonmy $engines = "";
20238405Sjkimmy $otherlibs = "";
21160814Ssimonlocal $zlib_opt = 0;	# 0 = no zlib, 1 = static, 2 = dynamic
22160814Ssimonlocal $zlib_lib = "";
23238405Sjkimlocal $perl_asm = 0;	# 1 to autobuild asm files from perl scripts
24160814Ssimon
25238405Sjkimmy $ex_l_libs = "";
26160814Ssimon
27238405Sjkim# Options to import from top level Makefile
28194206Ssimon
29238405Sjkimmy %mf_import = (
30238405Sjkim	VERSION	       => \$ssl_version,
31238405Sjkim	OPTIONS        => \$OPTIONS,
32238405Sjkim	INSTALLTOP     => \$INSTALLTOP,
33238405Sjkim	OPENSSLDIR     => \$OPENSSLDIR,
34238405Sjkim	PLATFORM       => \$mf_platform,
35290207Sjkim	CC             => \$mf_cc,
36238405Sjkim	CFLAG	       => \$mf_cflag,
37238405Sjkim	DEPFLAG	       => \$mf_depflag,
38238405Sjkim	CPUID_OBJ      => \$mf_cpuid_asm,
39238405Sjkim	BN_ASM	       => \$mf_bn_asm,
40238405Sjkim	DES_ENC	       => \$mf_des_asm,
41238405Sjkim	AES_ENC        => \$mf_aes_asm,
42238405Sjkim	BF_ENC	       => \$mf_bf_asm,
43238405Sjkim	CAST_ENC       => \$mf_cast_asm,
44238405Sjkim	RC4_ENC	       => \$mf_rc4_asm,
45238405Sjkim	RC5_ENC        => \$mf_rc5_asm,
46238405Sjkim	MD5_ASM_OBJ    => \$mf_md5_asm,
47238405Sjkim	SHA1_ASM_OBJ   => \$mf_sha_asm,
48238405Sjkim	RMD160_ASM_OBJ => \$mf_rmd_asm,
49238405Sjkim	WP_ASM_OBJ     => \$mf_wp_asm,
50238405Sjkim	CMLL_ENC       => \$mf_cm_asm,
51290207Sjkim	MODES_ASM_OBJ  => \$mf_modes_asm,
52290207Sjkim        ENGINES_ASM_OBJ=> \$mf_engines_asm,
53238405Sjkim	BASEADDR       => \$baseaddr,
54238405Sjkim	FIPSDIR        => \$fipsdir,
55290207Sjkim	EC_ASM	       => \$mf_ec_asm,
56238405Sjkim);
57194206Ssimon
58142425Snectaropen(IN,"<Makefile") || die "unable to open Makefile!\n";
5955714Skriswhile(<IN>) {
60238405Sjkim    my ($mf_opt, $mf_ref);
61238405Sjkim    while (($mf_opt, $mf_ref) = each %mf_import) {
62290207Sjkim    	if (/^$mf_opt\s*=\s*(.*)$/ && !defined($$mfref)) {
63238405Sjkim	   $$mf_ref = $1;
64238405Sjkim	}
65238405Sjkim    }
6655714Skris}
6755714Skrisclose(IN);
6855714Skris
69238405Sjkim$debug = 1 if $mf_platform =~ /^debug-/;
70238405Sjkim
71142425Snectardie "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
7255714Skris
7355714Skris$infile="MINFO";
7455714Skris
7555714Skris%ops=(
7655714Skris	"VC-WIN32",   "Microsoft Visual C++ [4-6] - Windows NT or 9X",
77160814Ssimon	"VC-WIN64I",  "Microsoft C/C++ - Win64/IA-64",
78160814Ssimon	"VC-WIN64A",  "Microsoft C/C++ - Win64/x64",
79109998Smarkm	"VC-CE",   "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
8055714Skris	"VC-NT",   "Microsoft Visual C++ [4-6] - Windows NT ONLY",
8155714Skris	"Mingw32", "GNU C++ - Windows NT or 9x",
8255714Skris	"Mingw32-files", "Create files with DOS copy ...",
8355714Skris	"BC-NT",   "Borland C++ 4.5 - Windows NT",
8455714Skris	"linux-elf","Linux elf",
8555714Skris	"ultrix-mips","DEC mips ultrix",
8655714Skris	"FreeBSD","FreeBSD distribution",
87109998Smarkm	"OS2-EMX", "EMX GCC OS/2",
88160814Ssimon	"netware-clib", "CodeWarrior for NetWare - CLib - with WinSock Sockets",
89194206Ssimon	"netware-clib-bsdsock", "CodeWarrior for NetWare - CLib - with BSD Sockets",
90160814Ssimon	"netware-libc", "CodeWarrior for NetWare - LibC - with WinSock Sockets",
91160814Ssimon	"netware-libc-bsdsock", "CodeWarrior for NetWare - LibC - with BSD Sockets",
9255714Skris	"default","cc under unix",
93290207Sjkim	"auto", "auto detect from top level Makefile",
94290207Sjkim        "copy", "copy from top level Makefile"
9555714Skris	);
9655714Skris
9755714Skris$platform="";
98160814Ssimonmy $xcflags="";
9955714Skrisforeach (@ARGV)
10055714Skris	{
10155714Skris	if (!&read_options && !defined($ops{$_}))
10255714Skris		{
10355714Skris		print STDERR "unknown option - $_\n";
10455714Skris		print STDERR "usage: perl mk1mf.pl [options] [system]\n";
10555714Skris		print STDERR "\nwhere [system] can be one of the following\n";
10655714Skris		foreach $i (sort keys %ops)
10755714Skris		{ printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
10855714Skris		print STDERR <<"EOF";
10955714Skrisand [options] can be one of
11068651Skris	no-md2 no-md4 no-md5 no-sha no-mdc2	- Skip this digest
11168651Skris	no-ripemd
112109998Smarkm	no-rc2 no-rc4 no-rc5 no-idea no-des     - Skip this symetric cipher
113194206Ssimon	no-bf no-cast no-aes no-camellia no-seed
11455714Skris	no-rsa no-dsa no-dh			- Skip this public key cipher
11555714Skris	no-ssl2 no-ssl3				- Skip this version of SSL
11655714Skris	just-ssl				- remove all non-ssl keys/digest
11755714Skris	no-asm 					- No x86 asm
118109998Smarkm	no-krb5					- No KRB5
119238405Sjkim	no-srp					- No SRP
120109998Smarkm	no-ec					- No EC
121160814Ssimon	no-ecdsa				- No ECDSA
122160814Ssimon	no-ecdh					- No ECDH
123111147Snectar	no-engine				- No engine
124111147Snectar	no-hw					- No hw
12555714Skris	nasm 					- Use NASM for x86 asm
126160814Ssimon	nw-nasm					- Use NASM x86 asm for NetWare
127194206Ssimon	nw-mwasm				- Use Metrowerks x86 asm for NetWare
12859191Skris	gaswin					- Use GNU as with Mingw32
12955714Skris	no-socks				- No socket code
13055714Skris	no-err					- No error strings
13155714Skris	dll/shlib				- Build shared libraries (MS)
13255714Skris	debug					- Debug build
13368651Skris        profile                                 - Profiling build
13455714Skris	gcc					- Use Gcc (unix)
13555714Skris
13655714SkrisValues that can be set
13755714SkrisTMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
13855714Skris
13955714Skris-L<ex_lib_path> -l<ex_lib>			- extra library flags (unix)
14055714Skris-<ex_cc_flags>					- extra 'cc' flags,
14155714Skris						  added (MS), or replace (unix)
14255714SkrisEOF
14355714Skris		exit(1);
14455714Skris		}
14555714Skris	$platform=$_;
14655714Skris	}
147109998Smarkmforeach (grep(!/^$/, split(/ /, $OPTIONS)))
14855714Skris	{
14955714Skris	print STDERR "unknown option - $_\n" if !&read_options;
15055714Skris	}
15155714Skris
152160814Ssimon$no_static_engine = 0 if (!$shlib);
153160814Ssimon
15455714Skris$no_mdc2=1 if ($no_des);
15555714Skris
15655714Skris$no_ssl3=1 if ($no_md5 || $no_sha);
15755714Skris$no_ssl3=1 if ($no_rsa && $no_dh);
15855714Skris
159109998Smarkm$no_ssl2=1 if ($no_md5);
16055714Skris$no_ssl2=1 if ($no_rsa);
16155714Skris
16255714Skris$out_def="out";
16355714Skris$inc_def="outinc";
16455714Skris$tmp_def="tmp";
16555714Skris
166160814Ssimon$perl="perl" unless defined $perl;
167160814Ssimon$mkdir="-mkdir" unless defined $mkdir;
16855714Skris
16955714Skris($ssl,$crypto)=("ssl","crypto");
17055714Skris$ranlib="echo ranlib";
17155714Skris
17255714Skris$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
173290207Sjkim$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}: $platform eq 'copy' ? getcwd() : '.';
17455714Skris$bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
17555714Skris
17655714Skris# $bin_dir.=$o causes a core dump on my sparc :-(
17755714Skris
178160814Ssimon
17955714Skris$NT=0;
18055714Skris
18155714Skrispush(@INC,"util/pl","pl");
182238405Sjkim
183290207Sjkimif ($platform eq "auto" || $platform eq 'copy') {
184290207Sjkim	$orig_platform = $platform;
185238405Sjkim	$platform = $mf_platform;
186238405Sjkim	print STDERR "Imported platform $mf_platform\n";
187238405Sjkim}
188238405Sjkim
189160814Ssimonif (($platform =~ /VC-(.+)/))
19055714Skris	{
191160814Ssimon	$FLAVOR=$1;
192160814Ssimon	$NT = 1 if $1 eq "NT";
19355714Skris	require 'VC-32.pl';
19455714Skris	}
19555714Skriselsif ($platform eq "Mingw32")
19655714Skris	{
19755714Skris	require 'Mingw32.pl';
19855714Skris	}
19955714Skriselsif ($platform eq "Mingw32-files")
20055714Skris	{
20155714Skris	require 'Mingw32f.pl';
20255714Skris	}
20355714Skriselsif ($platform eq "BC-NT")
20455714Skris	{
20555714Skris	$bc=1;
20655714Skris	require 'BC-32.pl';
20755714Skris	}
20855714Skriselsif ($platform eq "FreeBSD")
20955714Skris	{
21055714Skris	require 'unix.pl';
21155714Skris	$cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
21255714Skris	}
21355714Skriselsif ($platform eq "linux-elf")
21455714Skris	{
21555714Skris	require "unix.pl";
21655714Skris	require "linux.pl";
21755714Skris	$unix=1;
21855714Skris	}
21955714Skriselsif ($platform eq "ultrix-mips")
22055714Skris	{
22155714Skris	require "unix.pl";
22255714Skris	require "ultrix.pl";
22355714Skris	$unix=1;
22455714Skris	}
225109998Smarkmelsif ($platform eq "OS2-EMX")
226109998Smarkm	{
227109998Smarkm	$wc=1;
228109998Smarkm	require 'OS2-EMX.pl';
229109998Smarkm	}
230160814Ssimonelsif (($platform eq "netware-clib") || ($platform eq "netware-libc") ||
231194206Ssimon       ($platform eq "netware-clib-bsdsock") || ($platform eq "netware-libc-bsdsock"))
232160814Ssimon	{
233160814Ssimon	$LIBC=1 if $platform eq "netware-libc" || $platform eq "netware-libc-bsdsock";
234194206Ssimon	$BSDSOCK=1 if ($platform eq "netware-libc-bsdsock") || ($platform eq "netware-clib-bsdsock");
235160814Ssimon	require 'netware.pl';
236160814Ssimon	}
23755714Skriselse
23855714Skris	{
23955714Skris	require "unix.pl";
24055714Skris
24155714Skris	$unix=1;
24255714Skris	$cflags.=' -DTERMIO';
24355714Skris	}
24455714Skris
245238405Sjkim$fipsdir =~ s/\//${o}/g;
246238405Sjkim
24755714Skris$out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
24855714Skris$tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
24955714Skris$inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
25055714Skris
25155714Skris$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
25255714Skris
253160814Ssimon$cflags= "$xcflags$cflags" if $xcflags ne "";
254160814Ssimon
255109998Smarkm$cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
256109998Smarkm$cflags.=" -DOPENSSL_NO_AES"  if $no_aes;
257162911Ssimon$cflags.=" -DOPENSSL_NO_CAMELLIA"  if $no_camellia;
258194206Ssimon$cflags.=" -DOPENSSL_NO_SEED" if $no_seed;
259109998Smarkm$cflags.=" -DOPENSSL_NO_RC2"  if $no_rc2;
260109998Smarkm$cflags.=" -DOPENSSL_NO_RC4"  if $no_rc4;
261109998Smarkm$cflags.=" -DOPENSSL_NO_RC5"  if $no_rc5;
262109998Smarkm$cflags.=" -DOPENSSL_NO_MD2"  if $no_md2;
263109998Smarkm$cflags.=" -DOPENSSL_NO_MD4"  if $no_md4;
264109998Smarkm$cflags.=" -DOPENSSL_NO_MD5"  if $no_md5;
265109998Smarkm$cflags.=" -DOPENSSL_NO_SHA"  if $no_sha;
266109998Smarkm$cflags.=" -DOPENSSL_NO_SHA1" if $no_sha1;
267111147Snectar$cflags.=" -DOPENSSL_NO_RIPEMD" if $no_ripemd;
268109998Smarkm$cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
269160814Ssimon$cflags.=" -DOPENSSL_NO_BF"  if $no_bf;
270109998Smarkm$cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
271109998Smarkm$cflags.=" -DOPENSSL_NO_DES"  if $no_des;
272109998Smarkm$cflags.=" -DOPENSSL_NO_RSA"  if $no_rsa;
273109998Smarkm$cflags.=" -DOPENSSL_NO_DSA"  if $no_dsa;
274109998Smarkm$cflags.=" -DOPENSSL_NO_DH"   if $no_dh;
275238405Sjkim$cflags.=" -DOPENSSL_NO_WHIRLPOOL"   if $no_whirlpool;
276109998Smarkm$cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
277109998Smarkm$cflags.=" -DOPENSSL_NO_SSL2" if $no_ssl2;
278109998Smarkm$cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
279194206Ssimon$cflags.=" -DOPENSSL_NO_TLSEXT" if $no_tlsext;
280238405Sjkim$cflags.=" -DOPENSSL_NO_SRP" if $no_srp;
281194206Ssimon$cflags.=" -DOPENSSL_NO_CMS" if $no_cms;
282109998Smarkm$cflags.=" -DOPENSSL_NO_ERR"  if $no_err;
283109998Smarkm$cflags.=" -DOPENSSL_NO_KRB5" if $no_krb5;
284109998Smarkm$cflags.=" -DOPENSSL_NO_EC"   if $no_ec;
285160814Ssimon$cflags.=" -DOPENSSL_NO_ECDSA" if $no_ecdsa;
286160814Ssimon$cflags.=" -DOPENSSL_NO_ECDH" if $no_ecdh;
287238405Sjkim$cflags.=" -DOPENSSL_NO_GOST" if $no_gost;
288111147Snectar$cflags.=" -DOPENSSL_NO_ENGINE"   if $no_engine;
289111147Snectar$cflags.=" -DOPENSSL_NO_HW"   if $no_hw;
290194206Ssimon$cflags.=" -DOPENSSL_FIPS"    if $fips;
291238405Sjkim$cflags.=" -DOPENSSL_NO_JPAKE"    if $no_jpake;
292238405Sjkim$cflags.=" -DOPENSSL_NO_EC2M"    if $no_ec2m;
293160814Ssimon$cflags.= " -DZLIB" if $zlib_opt;
294160814Ssimon$cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
295160814Ssimon
296160814Ssimonif ($no_static_engine)
297160814Ssimon	{
298160814Ssimon	$cflags .= " -DOPENSSL_NO_STATIC_ENGINE";
299160814Ssimon	}
300160814Ssimonelse
301160814Ssimon	{
302160814Ssimon	$cflags .= " -DOPENSSL_NO_DYNAMIC_ENGINE";
303160814Ssimon	}
304160814Ssimon
305109998Smarkm#$cflags.=" -DRSAref"  if $rsaref ne "";
30655714Skris
30768651Skris## if ($unix)
30868651Skris##	{ $cflags="$c_flags" if ($c_flags ne ""); }
30968651Skris##else
31068651Skris	{ $cflags="$c_flags$cflags" if ($c_flags ne ""); }
31155714Skris
312290207Sjkimif ($orig_platform eq 'copy') {
313290207Sjkim    $cflags = $mf_cflag;
314290207Sjkim    $cc = $mf_cc;
315290207Sjkim}
316290207Sjkim
31755714Skris$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
31855714Skris
319238405Sjkim
320109998Smarkm%shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
321238405Sjkim		  "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
322109998Smarkm
32355714Skrisif ($msdos)
32455714Skris	{
32555714Skris	$banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
32655714Skris	$banner.="\t\@echo top level directory, if you don't have perl, you will\n";
32755714Skris	$banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
32855714Skris	$banner.="\t\@echo documentation for details.\n";
32955714Skris	}
33055714Skris
33155714Skris# have to do this to allow $(CC) under unix
33255714Skris$link="$bin_dir$link" if ($link !~ /^\$/);
33355714Skris
33455714Skris$INSTALLTOP =~ s|/|$o|g;
335238405Sjkim$OPENSSLDIR =~ s|/|$o|g;
33655714Skris
337160814Ssimon#############################################
338160814Ssimon# We parse in input file and 'store' info for later printing.
339160814Ssimonopen(IN,"<$infile") || die "unable to open $infile:$!\n";
340160814Ssimon$_=<IN>;
341160814Ssimonfor (;;)
342160814Ssimon	{
343284283Sjkim	s/\s*$//; # was chop, didn't work in mixture of perls for Windows...
344160814Ssimon
345160814Ssimon	($key,$val)=/^([^=]+)=(.*)/;
346160814Ssimon	if ($key eq "RELATIVE_DIRECTORY")
347160814Ssimon		{
348160814Ssimon		if ($lib ne "")
349160814Ssimon			{
350238405Sjkim			$uc=$lib;
351238405Sjkim			$uc =~ s/^lib(.*)\.a/$1/;
352238405Sjkim			$uc =~ tr/a-z/A-Z/;
353238405Sjkim			$lib_nam{$uc}=$uc;
354238405Sjkim			$lib_obj{$uc}.=$libobj." ";
355160814Ssimon			}
356160814Ssimon		last if ($val eq "FINISHED");
357160814Ssimon		$lib="";
358160814Ssimon		$libobj="";
359160814Ssimon		$dir=$val;
360160814Ssimon		}
361160814Ssimon
362160814Ssimon	if ($key eq "KRB5_INCLUDES")
363160814Ssimon		{ $cflags .= " $val";}
364160814Ssimon
365160814Ssimon	if ($key eq "ZLIB_INCLUDE")
366160814Ssimon		{ $cflags .= " $val" if $val ne "";}
367160814Ssimon
368160814Ssimon	if ($key eq "LIBZLIB")
369160814Ssimon		{ $zlib_lib = "$val" if $val ne "";}
370160814Ssimon
371160814Ssimon	if ($key eq "LIBKRB5")
372160814Ssimon		{ $ex_libs .= " $val" if $val ne "";}
373160814Ssimon
374160814Ssimon	if ($key eq "TEST")
375160814Ssimon		{ $test.=&var_add($dir,$val, 0); }
376160814Ssimon
377160814Ssimon	if (($key eq "PROGS") || ($key eq "E_OBJ"))
378160814Ssimon		{ $e_exe.=&var_add($dir,$val, 0); }
379160814Ssimon
380160814Ssimon	if ($key eq "LIB")
381160814Ssimon		{
382160814Ssimon		$lib=$val;
383160814Ssimon		$lib =~ s/^.*\/([^\/]+)$/$1/;
384160814Ssimon		}
385238405Sjkim	if ($key eq "LIBNAME" && $no_static_engine)
386238405Sjkim		{
387238405Sjkim		$lib=$val;
388238405Sjkim		$lib =~ s/^.*\/([^\/]+)$/$1/;
389238405Sjkim		$otherlibs .= " $lib";
390238405Sjkim		}
391160814Ssimon
392160814Ssimon	if ($key eq "EXHEADER")
393160814Ssimon		{ $exheader.=&var_add($dir,$val, 1); }
394160814Ssimon
395160814Ssimon	if ($key eq "HEADER")
396160814Ssimon		{ $header.=&var_add($dir,$val, 1); }
397160814Ssimon
398160814Ssimon	if ($key eq "LIBOBJ" && ($dir ne "engines" || !$no_static_engine))
399160814Ssimon		{ $libobj=&var_add($dir,$val, 0); }
400160814Ssimon	if ($key eq "LIBNAMES" && $dir eq "engines" && $no_static_engine)
401160814Ssimon 		{ $engines.=$val }
402160814Ssimon
403160814Ssimon	if (!($_=<IN>))
404160814Ssimon		{ $_="RELATIVE_DIRECTORY=FINISHED\n"; }
405160814Ssimon	}
406160814Ssimonclose(IN);
407160814Ssimon
408290207Sjkimif ($orig_platform eq 'copy')
409290207Sjkim	{
410290207Sjkim	# Remove opensslconf.h so it doesn't get updated if we configure a
411290207Sjkim	# different branch.
412290207Sjkim	$exheader =~ s/[^ ]+\/opensslconf.h//;
413290207Sjkim	$header =~ s/[^ ]+\/opensslconf.h//;
414290207Sjkim	}
415290207Sjkim
416160814Ssimonif ($shlib)
417160814Ssimon	{
418160814Ssimon	$extra_install= <<"EOF";
419194206Ssimon	\$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}bin\"
420194206Ssimon	\$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}bin\"
421194206Ssimon	\$(CP) \"\$(L_SSL)\" \"\$(INSTALLTOP)${o}lib\"
422194206Ssimon	\$(CP) \"\$(L_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
423160814SsimonEOF
424160814Ssimon	if ($no_static_engine)
425160814Ssimon		{
426160814Ssimon		$extra_install .= <<"EOF"
427194206Ssimon	\$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
428194206Ssimon	\$(CP) \"\$(E_SHLIB)\" \"\$(INSTALLTOP)${o}lib${o}engines\"
429160814SsimonEOF
430160814Ssimon		}
431160814Ssimon	}
432160814Ssimonelse
433160814Ssimon	{
434160814Ssimon	$extra_install= <<"EOF";
435194206Ssimon	\$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}lib\"
436194206Ssimon	\$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
437160814SsimonEOF
438160814Ssimon	$ex_libs .= " $zlib_lib" if $zlib_opt == 1;
439238405Sjkim	if ($fips)
440238405Sjkim		{
441238405Sjkim		$build_targets .= " \$(LIB_D)$o$crypto_compat \$(PREMAIN_DSO_EXE)";
442238405Sjkim		$ex_l_libs .= " \$(O_FIPSCANISTER)";
443238405Sjkim		}
444160814Ssimon	}
445160814Ssimon
44655714Skris$defs= <<"EOF";
447290207Sjkim# N.B. You MUST use -j on FreeBSD.
44855714Skris# This makefile has been automatically generated from the OpenSSL distribution.
44955714Skris# This single makefile will build the complete OpenSSL distribution and
450291719Sjkim# by default leave the 'interesting' output files in .${o}out and the stuff
45155714Skris# that needs deleting in .${o}tmp.
45255714Skris# The file was generated by running 'make makefile.one', which
45355714Skris# does a 'make files', which writes all the environment variables from all
45455714Skris# the makefiles to the file call MINFO.  This file is used by
45555714Skris# util${o}mk1mf.pl to generate makefile.one.
45655714Skris# The 'makefile per directory' system suites me when developing this
45755714Skris# library and also so I can 'distribute' indervidual library sections.
45855714Skris# The one monster makefile better suits building in non-unix
45955714Skris# environments.
46055714Skris
461109998SmarkmEOF
462109998Smarkm
463127128Snectar$defs .= $preamble if defined $preamble;
464127128Snectar
465109998Smarkm$defs.= <<"EOF";
46655714SkrisINSTALLTOP=$INSTALLTOP
467238405SjkimOPENSSLDIR=$OPENSSLDIR
46855714Skris
46955714Skris# Set your compiler options
47055714SkrisPLATFORM=$platform
47155714SkrisCC=$bin_dir${cc}
47255714SkrisCFLAG=$cflags
47355714SkrisAPP_CFLAG=$app_cflag
47455714SkrisLIB_CFLAG=$lib_cflag
47555714SkrisSHLIB_CFLAG=$shl_cflag
47655714SkrisAPP_EX_OBJ=$app_ex_obj
47755714SkrisSHLIB_EX_OBJ=$shlib_ex_obj
47855714Skris# add extra libraries to this define, for solaris -lsocket -lnsl would
47955714Skris# be added
48055714SkrisEX_LIBS=$ex_libs
48155714Skris
48255714Skris# The OpenSSL directory
48355714SkrisSRC_D=$src_dir
48455714Skris
48555714SkrisLINK=$link
48655714SkrisLFLAGS=$lflags
487160814SsimonRSC=$rsc
48855714Skris
489290207Sjkim# The output directory for everything interesting
49055714SkrisOUT_D=$out_dir
49155714Skris# The output directory for all the temporary muck
49255714SkrisTMP_D=$tmp_dir
49355714Skris# The output directory for the header files
49455714SkrisINC_D=$inc_dir
49555714SkrisINCO_D=$inc_dir${o}openssl
49655714Skris
497160814SsimonPERL=$perl
49855714SkrisCP=$cp
49955714SkrisRM=$rm
50055714SkrisRANLIB=$ranlib
50155714SkrisMKDIR=$mkdir
50255714SkrisMKLIB=$bin_dir$mklib
50355714SkrisMLFLAGS=$mlflags
50455714SkrisASM=$bin_dir$asm
50555714Skris
506194206Ssimon# FIPS validated module and support file locations
507194206Ssimon
508290207SjkimE_PREMAIN_DSO=fips_premain_dso
509290207Sjkim
510238405SjkimFIPSDIR=$fipsdir
511238405SjkimBASEADDR=$baseaddr
512238405SjkimFIPSLIB_D=\$(FIPSDIR)${o}lib
513238405SjkimFIPS_PREMAIN_SRC=\$(FIPSLIB_D)${o}fips_premain.c
514238405SjkimO_FIPSCANISTER=\$(FIPSLIB_D)${o}fipscanister.lib
515238405SjkimFIPS_SHA1_EXE=\$(FIPSDIR)${o}bin${o}fips_standalone_sha1${exep}
516238405SjkimPREMAIN_DSO_EXE=\$(BIN_D)${o}fips_premain_dso$exep
517238405SjkimFIPSLINK=\$(PERL) \$(FIPSDIR)${o}bin${o}fipslink.pl
518194206Ssimon
51955714Skris######################################################
52055714Skris# You should not need to touch anything below this point
52155714Skris######################################################
52255714Skris
52355714SkrisE_EXE=openssl
52455714SkrisSSL=$ssl
52555714SkrisCRYPTO=$crypto
52655714Skris
52755714Skris# BIN_D  - Binary output directory
52855714Skris# TEST_D - Binary test file output directory
52955714Skris# LIB_D  - library output directory
530160814Ssimon# ENG_D  - dynamic engine output directory
53155714Skris# Note: if you change these point to different directories then uncomment out
53255714Skris# the lines around the 'NB' comment below.
53355714Skris#
53455714SkrisBIN_D=\$(OUT_D)
53555714SkrisTEST_D=\$(OUT_D)
53655714SkrisLIB_D=\$(OUT_D)
537160814SsimonENG_D=\$(OUT_D)
53855714Skris
53955714Skris# INCL_D - local library directory
54055714Skris# OBJ_D  - temp object file directory
54155714SkrisOBJ_D=\$(TMP_D)
54255714SkrisINCL_D=\$(TMP_D)
54355714Skris
54455714SkrisO_SSL=     \$(LIB_D)$o$plib\$(SSL)$shlibp
54555714SkrisO_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
54655714SkrisSO_SSL=    $plib\$(SSL)$so_shlibp
54755714SkrisSO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
54855714SkrisL_SSL=     \$(LIB_D)$o$plib\$(SSL)$libp
54955714SkrisL_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$libp
55055714Skris
551194206SsimonL_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs
55255714Skris
55355714Skris######################################################
55455714Skris# Don't touch anything below this point
55555714Skris######################################################
55655714Skris
55755714SkrisINC=-I\$(INC_D) -I\$(INCL_D)
55855714SkrisAPP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
55955714SkrisLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
56055714SkrisSHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
561238405SjkimLIBS_DEP=\$(O_CRYPTO) \$(O_SSL)
56255714Skris
56355714Skris#############################################
56455714SkrisEOF
56555714Skris
56655714Skris$rules=<<"EOF";
567238405Sjkimall: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe $build_targets
56855714Skris
56955714Skrisbanner:
57055714Skris$banner
57155714Skris
57255714Skris\$(TMP_D):
573194206Ssimon	\$(MKDIR) \"\$(TMP_D)\"
57455714Skris# NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
57555714Skris#\$(BIN_D):
57655714Skris#	\$(MKDIR) \$(BIN_D)
57755714Skris#
57855714Skris#\$(TEST_D):
57955714Skris#	\$(MKDIR) \$(TEST_D)
58055714Skris
58155714Skris\$(LIB_D):
582194206Ssimon	\$(MKDIR) \"\$(LIB_D)\"
58355714Skris
58455714Skris\$(INCO_D): \$(INC_D)
585194206Ssimon	\$(MKDIR) \"\$(INCO_D)\"
58655714Skris
58755714Skris\$(INC_D):
588194206Ssimon	\$(MKDIR) \"\$(INC_D)\"
58955714Skris
590290207Sjkim# This needs to be invoked once, when the makefile is first constructed, or
591290207Sjkim# after cleaning.
592290207Sjkiminit: \$(TMP_D) \$(LIB_D) \$(INC_D) \$(INCO_D) \$(BIN_D) \$(TEST_D) headers
593290207Sjkim	\$(PERL) \$(SRC_D)/util/copy-if-different.pl "\$(SRC_D)/crypto/opensslconf.h" "\$(INCO_D)/opensslconf.h"
594290207Sjkim
59555714Skrisheaders: \$(HEADER) \$(EXHEADER)
59655714Skris
597160814Ssimonlib: \$(LIBS_DEP) \$(E_SHLIB)
59855714Skris
59955714Skrisexe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
60055714Skris
601160814Ssimoninstall: all
602194206Ssimon	\$(MKDIR) \"\$(INSTALLTOP)\"
603194206Ssimon	\$(MKDIR) \"\$(INSTALLTOP)${o}bin\"
604194206Ssimon	\$(MKDIR) \"\$(INSTALLTOP)${o}include\"
605194206Ssimon	\$(MKDIR) \"\$(INSTALLTOP)${o}include${o}openssl\"
606194206Ssimon	\$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
607194206Ssimon	\$(CP) \"\$(INCO_D)${o}*.\[ch\]\" \"\$(INSTALLTOP)${o}include${o}openssl\"
608238405Sjkim	\$(CP) \"\$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin\"
609238405Sjkim	\$(MKDIR) \"\$(OPENSSLDIR)\"
610238405Sjkim	\$(CP) apps${o}openssl.cnf \"\$(OPENSSLDIR)\"
611160814Ssimon$extra_install
61255714Skris
61355714Skrisclean:
61455714Skris	\$(RM) \$(TMP_D)$o*.*
61555714Skris
61655714Skrisvclean:
61755714Skris	\$(RM) \$(TMP_D)$o*.*
61855714Skris	\$(RM) \$(OUT_D)$o*.*
61955714Skris
620290207Sjkimreallyclean:
621290207Sjkim	\$(RM) -rf \$(TMP_D)
622290207Sjkim	\$(RM) -rf \$(BIN_D)
623290207Sjkim	\$(RM) -rf \$(TEST_D)
624290207Sjkim	\$(RM) -rf \$(LIB_D)
625290207Sjkim	\$(RM) -rf \$(INC_D)
626290207Sjkim
62755714SkrisEOF
628290207Sjkim
629290207Sjkimif ($orig_platform ne 'copy')
630290207Sjkim	{
631290207Sjkim        $rules .= <<"EOF";
632290207Sjkimtest: \$(T_EXE)
633290207Sjkim	cd \$(BIN_D)
634290207Sjkim	..${o}ms${o}test
635290207Sjkim
636290207SjkimEOF
637290207Sjkim	}
638290207Sjkim
63955714Skrismy $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
64055714Skris$platform_cpp_symbol =~ s/-/_/g;
64155714Skrisif (open(IN,"crypto/buildinf.h"))
64255714Skris	{
64355714Skris	# Remove entry for this platform in existing file buildinf.h.
64455714Skris
64555714Skris	my $old_buildinf_h = "";
64655714Skris	while (<IN>)
64755714Skris		{
64855714Skris		if (/^\#ifdef $platform_cpp_symbol$/)
64955714Skris			{
65055714Skris			while (<IN>) { last if (/^\#endif/); }
65155714Skris			}
65255714Skris		else
65355714Skris			{
65455714Skris			$old_buildinf_h .= $_;
65555714Skris			}
65655714Skris		}
65755714Skris	close(IN);
65855714Skris
65955714Skris	open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
66055714Skris	print OUT $old_buildinf_h;
66155714Skris	close(OUT);
66255714Skris	}
66355714Skris
66455714Skrisopen (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
66555714Skrisprintf OUT <<EOF;
66655714Skris#ifdef $platform_cpp_symbol
66755714Skris  /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
668277270Sjkim  #define CFLAGS "compiler: $cc $cflags"
66955714Skris  #define PLATFORM "$platform"
67055714SkrisEOF
67155714Skrisprintf OUT "  #define DATE \"%s\"\n", scalar gmtime();
67255714Skrisprintf OUT "#endif\n";
67355714Skrisclose(OUT);
67455714Skris
675290207Sjkim# Strip off trailing ' '
67655714Skrisforeach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
67755714Skris$test=&clean_up_ws($test);
67855714Skris$e_exe=&clean_up_ws($e_exe);
67955714Skris$exheader=&clean_up_ws($exheader);
68055714Skris$header=&clean_up_ws($header);
68155714Skris
68255714Skris# First we strip the exheaders from the headers list
68355714Skrisforeach (split(/\s+/,$exheader)){ $h{$_}=1; }
68455714Skrisforeach (split(/\s+/,$header))	{ $h.=$_." " unless $h{$_}; }
68555714Skrischop($h); $header=$h;
68655714Skris
687160814Ssimon$defs.=&do_defs("HEADER",$header,"\$(INCL_D)","");
688160814Ssimon$rules.=&do_copy_rule("\$(INCL_D)",$header,"");
68955714Skris
690160814Ssimon$defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)","");
691160814Ssimon$rules.=&do_copy_rule("\$(INCO_D)",$exheader,"");
69255714Skris
69355714Skris$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
69455714Skris$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
69555714Skris
69655714Skris$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
69755714Skris$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
69855714Skris
699238405Sjkim# Special case rule for fips_premain_dso
700194206Ssimon
701194206Ssimonif ($fips)
702194206Ssimon	{
703194206Ssimon	$rules.=&cc_compile_target("\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj",
704238405Sjkim		"\$(FIPS_PREMAIN_SRC)",
705290207Sjkim		"-DFINGERPRINT_PREMAIN_DSO_LOAD \$(APP_CFLAGS)", "");
706238405Sjkim	$rules.=&do_link_rule("\$(PREMAIN_DSO_EXE)","\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj \$(CRYPTOOBJ) \$(O_FIPSCANISTER)","","\$(EX_LIBS)", 1);
707194206Ssimon	}
708194206Ssimon
709290207Sjkimsub fix_asm
710290207Sjkim	{
711290207Sjkim	my($asm, $dir) = @_;
712290207Sjkim
713290207Sjkim	return '' if $asm eq '';
714290207Sjkim
715290207Sjkim	$asm = " $asm";
716290207Sjkim	$asm =~ s/\s+/ $dir\//g;
717290207Sjkim	$asm =~ s/\.o//g;
718290207Sjkim	$asm =~ s/^ //;
719290207Sjkim
720290207Sjkim	return $asm . ' ';
721290207Sjkim	}
722290207Sjkim
723290207Sjkimif ($orig_platform eq 'copy') {
724290207Sjkim	$lib_obj{CRYPTO} .= fix_asm($mf_md5_asm, 'crypto/md5');
725290207Sjkim	$lib_obj{CRYPTO} .= fix_asm($mf_bn_asm, 'crypto/bn');
726290207Sjkim	# cpuid is included by the crypto dir
727290207Sjkim	#$lib_obj{CRYPTO} .= fix_asm($mf_cpuid_asm, 'crypto');
728290207Sjkim	# AES asm files DON'T end up included by the aes dir itself
729290207Sjkim	$lib_obj{CRYPTO} .= fix_asm($mf_aes_asm, 'crypto/aes');
730290207Sjkim	$lib_obj{CRYPTO} .= fix_asm($mf_sha_asm, 'crypto/sha');
731290207Sjkim	$lib_obj{CRYPTO} .= fix_asm($mf_engines_asm, 'engines');
732290207Sjkim	$lib_obj{CRYPTO} .= fix_asm($mf_rc4_asm, 'crypto/rc4');
733290207Sjkim	$lib_obj{CRYPTO} .= fix_asm($mf_modes_asm, 'crypto/modes');
734290207Sjkim	$lib_obj{CRYPTO} .= fix_asm($mf_ec_asm, 'crypto/ec');
735290207Sjkim}
736290207Sjkim
73755714Skrisforeach (values %lib_nam)
73855714Skris	{
73955714Skris	$lib_obj=$lib_obj{$_};
74055714Skris	local($slib)=$shlib;
74155714Skris
74255714Skris	$defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
743109998Smarkm	$lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
74455714Skris	$rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
74555714Skris	}
74655714Skris
747160814Ssimon# hack to add version info on MSVC
748205128Ssimonif (($platform eq "VC-WIN32") || ($platform eq "VC-WIN64A")
749205128Ssimon	|| ($platform eq "VC-WIN64I") || ($platform eq "VC-NT")) {
750160814Ssimon    $rules.= <<"EOF";
751160814Ssimon\$(OBJ_D)\\\$(CRYPTO).res: ms\\version32.rc
752160814Ssimon	\$(RSC) /fo"\$(OBJ_D)\\\$(CRYPTO).res" /d CRYPTO ms\\version32.rc
753160814Ssimon
754160814Ssimon\$(OBJ_D)\\\$(SSL).res: ms\\version32.rc
755160814Ssimon	\$(RSC) /fo"\$(OBJ_D)\\\$(SSL).res" /d SSL ms\\version32.rc
756160814Ssimon
757160814SsimonEOF
758160814Ssimon}
759160814Ssimon
76055714Skris$defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
76155714Skrisforeach (split(/\s+/,$test))
76255714Skris	{
76355714Skris	$t=&bname($_);
76455714Skris	$tt="\$(OBJ_D)${o}$t${obj}";
765238405Sjkim	$rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
76655714Skris	}
76755714Skris
768238405Sjkim$defs.=&do_defs("E_SHLIB",$engines . $otherlibs,"\$(ENG_D)",$shlibp);
769160814Ssimon
770160814Ssimonforeach (split(/\s+/,$engines))
771160814Ssimon	{
772160814Ssimon	$rules.=&do_compile_rule("\$(OBJ_D)","engines${o}e_$_",$lib);
773160814Ssimon	$rules.= &do_lib_rule("\$(OBJ_D)${o}e_${_}.obj","\$(ENG_D)$o$_$shlibp","",$shlib,"");
774160814Ssimon	}
775160814Ssimon
776160814Ssimon
777160814Ssimon
77855714Skris$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
77955714Skris
780194206Ssimonif ($fips)
781194206Ssimon	{
782194206Ssimon	if ($shlib)
783194206Ssimon		{
784238405Sjkim		$rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
785194206Ssimon				"\$(O_CRYPTO)", "$crypto",
786194206Ssimon				$shlib, "\$(SO_CRYPTO)", "\$(BASEADDR)");
787194206Ssimon		}
788194206Ssimon	else
789194206Ssimon		{
790194206Ssimon		$rules.= &do_lib_rule("\$(CRYPTOOBJ)",
791194206Ssimon			"\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)", "");
792238405Sjkim		$rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
793194206Ssimon			"\$(LIB_D)$o$crypto_compat",$crypto,$shlib,"\$(SO_CRYPTO)", "");
794194206Ssimon		}
795194206Ssimon	}
796194206Ssimon	else
797194206Ssimon	{
798194206Ssimon	$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
799194206Ssimon							"\$(SO_CRYPTO)");
800194206Ssimon	}
801160814Ssimon
802238405Sjkimforeach (split(" ",$otherlibs))
803194206Ssimon	{
804238405Sjkim	my $uc = $_;
805238405Sjkim	$uc =~ tr /a-z/A-Z/;
806238405Sjkim	$rules.= &do_lib_rule("\$(${uc}OBJ)","\$(ENG_D)$o$_$shlibp", "", $shlib, "");
807194206Ssimon
808194206Ssimon	}
809194206Ssimon
810194206Ssimon$rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)", ($fips && !$shlib) ? 2 : 0);
811194206Ssimon
812290207Sjkim$rules .= get_tests('test/Makefile') if $orig_platform eq 'copy';
813290207Sjkim
81455714Skrisprint $defs;
81568651Skris
81668651Skrisif ($platform eq "linux-elf") {
81768651Skris    print <<"EOF";
81868651Skris# Generate perlasm output files
81968651Skris%.cpp:
820142425Snectar	(cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
82168651SkrisEOF
82268651Skris}
82355714Skrisprint "###################################################################\n";
82455714Skrisprint $rules;
82555714Skris
82655714Skris###############################################
82755714Skris# strip off any trailing .[och] and append the relative directory
82855714Skris# also remembering to do nothing if we are in one of the dropped
82955714Skris# directories
83055714Skrissub var_add
83155714Skris	{
832160814Ssimon	local($dir,$val,$keepext)=@_;
83355714Skris	local(@a,$_,$ret);
83455714Skris
835111147Snectar	return("") if $no_engine && $dir =~ /\/engine/;
836111147Snectar	return("") if $no_hw   && $dir =~ /\/hw/;
83755714Skris	return("") if $no_idea && $dir =~ /\/idea/;
838109998Smarkm	return("") if $no_aes  && $dir =~ /\/aes/;
839162911Ssimon	return("") if $no_camellia  && $dir =~ /\/camellia/;
840194206Ssimon	return("") if $no_seed && $dir =~ /\/seed/;
84155714Skris	return("") if $no_rc2  && $dir =~ /\/rc2/;
84255714Skris	return("") if $no_rc4  && $dir =~ /\/rc4/;
84355714Skris	return("") if $no_rc5  && $dir =~ /\/rc5/;
84455714Skris	return("") if $no_rsa  && $dir =~ /\/rsa/;
84555714Skris	return("") if $no_rsa  && $dir =~ /^rsaref/;
84655714Skris	return("") if $no_dsa  && $dir =~ /\/dsa/;
84755714Skris	return("") if $no_dh   && $dir =~ /\/dh/;
848120631Snectar	return("") if $no_ec   && $dir =~ /\/ec/;
849238405Sjkim	return("") if $no_gost   && $dir =~ /\/ccgost/;
850194206Ssimon	return("") if $no_cms  && $dir =~ /\/cms/;
851194206Ssimon	return("") if $no_jpake  && $dir =~ /\/jpake/;
85255714Skris	if ($no_des && $dir =~ /\/des/)
85355714Skris		{
85455714Skris		if ($val =~ /read_pwd/)
85555714Skris			{ return("$dir/read_pwd "); }
85655714Skris		else
85755714Skris			{ return(""); }
85855714Skris		}
85955714Skris	return("") if $no_mdc2 && $dir =~ /\/mdc2/;
86055714Skris	return("") if $no_sock && $dir =~ /\/proxy/;
86155714Skris	return("") if $no_bf   && $dir =~ /\/bf/;
86255714Skris	return("") if $no_cast && $dir =~ /\/cast/;
863238405Sjkim	return("") if $no_whirlpool && $dir =~ /\/whrlpool/;
86455714Skris
86555714Skris	$val =~ s/^\s*(.*)\s*$/$1/;
86655714Skris	@a=split(/\s+/,$val);
867160814Ssimon	grep(s/\.[och]$//,@a) unless $keepext;
86855714Skris
86955714Skris	@a=grep(!/^e_.*_3d$/,@a) if $no_des;
87055714Skris	@a=grep(!/^e_.*_d$/,@a) if $no_des;
871109998Smarkm	@a=grep(!/^e_.*_ae$/,@a) if $no_idea;
872109998Smarkm	@a=grep(!/^e_.*_i$/,@a) if $no_aes;
87355714Skris	@a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
87455714Skris	@a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
87555714Skris	@a=grep(!/^e_.*_bf$/,@a) if $no_bf;
87655714Skris	@a=grep(!/^e_.*_c$/,@a) if $no_cast;
87755714Skris	@a=grep(!/^e_rc4$/,@a) if $no_rc4;
878162911Ssimon	@a=grep(!/^e_camellia$/,@a) if $no_camellia;
879194206Ssimon	@a=grep(!/^e_seed$/,@a) if $no_seed;
88055714Skris
881238405Sjkim	#@a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
882238405Sjkim	#@a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
88355714Skris
88455714Skris	@a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
88555714Skris
88655714Skris	@a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
88768651Skris	@a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
88855714Skris	@a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
889111147Snectar	@a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
89055714Skris
89155714Skris	@a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
89255714Skris	@a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
89355714Skris	@a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
89455714Skris
89555714Skris	@a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
89655714Skris	@a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
89755714Skris
89855714Skris	@a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
89955714Skris
90055714Skris	@a=grep(!/_dhp$/,@a) if $no_dh;
90155714Skris
90255714Skris	@a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
90355714Skris	@a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
90455714Skris	@a=grep(!/_mdc2$/,@a) if $no_mdc2;
90555714Skris
906238405Sjkim	@a=grep(!/(srp)/,@a) if $no_srp;
907238405Sjkim
908111147Snectar	@a=grep(!/^engine$/,@a) if $no_engine;
909111147Snectar	@a=grep(!/^hw$/,@a) if $no_hw;
91055714Skris	@a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
91155714Skris	@a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
91255714Skris	@a=grep(!/^gendsa$/,@a) if $no_sha1;
91355714Skris	@a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
91455714Skris
91555714Skris	@a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
91655714Skris
91755714Skris	grep($_="$dir/$_",@a);
91855714Skris	@a=grep(!/(^|\/)s_/,@a) if $no_sock;
91955714Skris	@a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
92055714Skris	$ret=join(' ',@a)." ";
92155714Skris	return($ret);
92255714Skris	}
92355714Skris
92455714Skris# change things so that each 'token' is only separated by one space
92555714Skrissub clean_up_ws
92655714Skris	{
92755714Skris	local($w)=@_;
92855714Skris
92955714Skris	$w =~ s/^\s*(.*)\s*$/$1/;
93055714Skris	$w =~ s/\s+/ /g;
93155714Skris	return($w);
93255714Skris	}
93355714Skris
93455714Skrissub do_defs
93555714Skris	{
93655714Skris	local($var,$files,$location,$postfix)=@_;
93755714Skris	local($_,$ret,$pf);
93855714Skris	local(*OUT,$tmp,$t);
93955714Skris
94055714Skris	$files =~ s/\//$o/g if $o ne '/';
94155714Skris	$ret="$var=";
94255714Skris	$n=1;
94355714Skris	$Vars{$var}.="";
94455714Skris	foreach (split(/ /,$files))
94555714Skris		{
94655714Skris		$orig=$_;
94755714Skris		$_=&bname($_) unless /^\$/;
94855714Skris		if ($n++ == 2)
94955714Skris			{
95055714Skris			$n=0;
95155714Skris			$ret.="\\\n\t";
95255714Skris			}
95355714Skris		if (($_ =~ /bss_file/) && ($postfix eq ".h"))
95455714Skris			{ $pf=".c"; }
95555714Skris		else	{ $pf=$postfix; }
95655714Skris		if ($_ =~ /BN_ASM/)	{ $t="$_ "; }
95768651Skris		elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
958238405Sjkim		elsif ($_ =~ /AES_ASM/){ $t="$_ "; }
95955714Skris		elsif ($_ =~ /DES_ENC/)	{ $t="$_ "; }
96055714Skris		elsif ($_ =~ /BF_ENC/)	{ $t="$_ "; }
96155714Skris		elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
96255714Skris		elsif ($_ =~ /RC4_ENC/)	{ $t="$_ "; }
96355714Skris		elsif ($_ =~ /RC5_ENC/)	{ $t="$_ "; }
96455714Skris		elsif ($_ =~ /MD5_ASM/)	{ $t="$_ "; }
96555714Skris		elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
96655714Skris		elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
967238405Sjkim		elsif ($_ =~ /WHIRLPOOL_ASM/){ $t="$_ "; }
968162911Ssimon		elsif ($_ =~ /CPUID_ASM/){ $t="$_ "; }
96955714Skris		else	{ $t="$location${o}$_$pf "; }
97055714Skris
97155714Skris		$Vars{$var}.="$t ";
97255714Skris		$ret.=$t;
97355714Skris		}
974160814Ssimon	# hack to add version info on MSVC
975205128Ssimon	if ($shlib && (($platform eq "VC-WIN32") || ($platfrom eq "VC-WIN64I") || ($platform eq "VC-WIN64A") || ($platform eq "VC-NT")))
976160814Ssimon		{
977160814Ssimon		if ($var eq "CRYPTOOBJ")
978160814Ssimon			{ $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
979160814Ssimon		elsif ($var eq "SSLOBJ")
980160814Ssimon			{ $ret.="\$(OBJ_D)\\\$(SSL).res "; }
981160814Ssimon		}
982160814Ssimon	chomp($ret);
98355714Skris	$ret.="\n\n";
98455714Skris	return($ret);
98555714Skris	}
98655714Skris
98755714Skris# return the name with the leading path removed
98855714Skrissub bname
98955714Skris	{
99055714Skris	local($ret)=@_;
99155714Skris	$ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
99255714Skris	return($ret);
99355714Skris	}
99455714Skris
995238405Sjkim# return the leading path
996238405Sjkimsub dname
997238405Sjkim	{
998238405Sjkim	my $ret=shift;
999238405Sjkim	$ret =~ s/(^.*)[\\\/][^\\\/]+$/$1/;
1000238405Sjkim	return($ret);
1001238405Sjkim	}
100255714Skris
100355714Skris##############################################################
100455714Skris# do a rule for each file that says 'compile' to new direcory
100555714Skris# compile the files in '$files' into $to
100655714Skrissub do_compile_rule
100755714Skris	{
100855714Skris	local($to,$files,$ex)=@_;
1009238405Sjkim	local($ret,$_,$n,$d,$s);
1010238405Sjkim
101155714Skris	$files =~ s/\//$o/g if $o ne '/';
101255714Skris	foreach (split(/\s+/,$files))
101355714Skris		{
101455714Skris		$n=&bname($_);
1015238405Sjkim		$d=&dname($_);
1016238405Sjkim		if (-f "${_}.c")
1017238405Sjkim			{
1018238405Sjkim			$ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
1019238405Sjkim			}
1020238405Sjkim		elsif (-f ($s="${d}${o}asm${o}${n}.pl") or
1021238405Sjkim		       ($s=~s/sha256/sha512/ and -f $s) or
1022238405Sjkim		       -f ($s="${d}${o}${n}.pl"))
1023238405Sjkim			{
1024238405Sjkim			$ret.=&perlasm_compile_target("$to${o}$n$obj",$s,$n);
1025238405Sjkim			}
1026238405Sjkim		elsif (-f ($s="${d}${o}asm${o}${n}.S") or
1027238405Sjkim		       -f ($s="${d}${o}${n}.S"))
1028238405Sjkim			{
1029238405Sjkim			$ret.=&Sasm_compile_target("$to${o}$n$obj",$s,$n);
1030238405Sjkim			}
1031290207Sjkim		elsif (defined &special_compile_target and
1032290207Sjkim		       ($s=special_compile_target($_)))
1033290207Sjkim			{
1034290207Sjkim			$ret.=$s;
1035290207Sjkim			}
1036238405Sjkim		else	{ die "no rule for $_"; }
103755714Skris		}
103855714Skris	return($ret);
103955714Skris	}
104055714Skris
104155714Skris##############################################################
104255714Skris# do a rule for each file that says 'compile' to new direcory
1043238405Sjkimsub perlasm_compile_target
1044238405Sjkim	{
1045238405Sjkim	my($target,$source,$bname)=@_;
1046290207Sjkim
1047290207Sjkim	return platform_perlasm_compile_target($target, $source, $bname)
1048290207Sjkim	    if defined &platform_perlasm_compile_target;
1049290207Sjkim
1050238405Sjkim	my($ret);
1051238405Sjkim
1052238405Sjkim	$bname =~ s/(.*)\.[^\.]$/$1/;
1053238405Sjkim	$ret ="\$(TMP_D)$o$bname.asm: $source\n";
1054238405Sjkim	$ret.="\t\$(PERL) $source $asmtype \$(CFLAG) >\$\@\n\n";
1055238405Sjkim	$ret.="$target: \$(TMP_D)$o$bname.asm\n";
1056238405Sjkim	$ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
1057238405Sjkim	return($ret);
1058238405Sjkim	}
1059238405Sjkim
1060238405Sjkimsub Sasm_compile_target
1061238405Sjkim	{
1062238405Sjkim	my($target,$source,$bname)=@_;
1063238405Sjkim	my($ret);
1064238405Sjkim
1065238405Sjkim	$bname =~ s/(.*)\.[^\.]$/$1/;
1066238405Sjkim	$ret ="\$(TMP_D)$o$bname.asm: $source\n";
1067238405Sjkim	$ret.="\t\$(CC) -E \$(CFLAG) $source >\$\@\n\n";
1068238405Sjkim	$ret.="$target: \$(TMP_D)$o$bname.asm\n";
1069238405Sjkim	$ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
1070238405Sjkim	return($ret);
1071238405Sjkim	}
1072238405Sjkim
107355714Skrissub cc_compile_target
107455714Skris	{
1075238405Sjkim	local($target,$source,$ex_flags, $srcd)=@_;
107655714Skris	local($ret);
107755714Skris
107855714Skris	$ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
107955714Skris	$target =~ s/\//$o/g if $o ne "/";
108055714Skris	$source =~ s/\//$o/g if $o ne "/";
1081290207Sjkim	$srcd = "\$(SRC_D)$o" unless defined $srcd && $platform ne 'copy';
1082238405Sjkim	$ret ="$target: $srcd$source\n\t";
1083290207Sjkim	$ret.="\$(CC)";
1084290207Sjkim	$ret.= " -MMD" if $orig_platform eq "copy";
1085290207Sjkim	$ret.= " ${ofile}$target $ex_flags -c $srcd$source\n\n";
1086290207Sjkim	$target =~ s/\.o$/.d/;
1087290207Sjkim	$ret.=".sinclude \"$target\"\n\n" if $orig_platform eq "copy";
108855714Skris	return($ret);
108955714Skris	}
109055714Skris
109155714Skris##############################################################
109255714Skrissub do_asm_rule
109355714Skris	{
109455714Skris	local($target,$src)=@_;
109555714Skris	local($ret,@s,@t,$i);
109655714Skris
109755714Skris	$target =~ s/\//$o/g if $o ne "/";
109855714Skris	$src =~ s/\//$o/g if $o ne "/";
109955714Skris
1100238405Sjkim	@t=split(/\s+/,$target);
110155714Skris	@s=split(/\s+/,$src);
110255714Skris
1103238405Sjkim
110455714Skris	for ($i=0; $i<=$#s; $i++)
110555714Skris		{
1106238405Sjkim		my $objfile = $t[$i];
1107238405Sjkim		my $srcfile = $s[$i];
1108238405Sjkim
1109238405Sjkim		if ($perl_asm == 1)
1110238405Sjkim			{
1111238405Sjkim			my $plasm = $objfile;
1112238405Sjkim			$plasm =~ s/${obj}/.pl/;
1113238405Sjkim			$ret.="$srcfile: $plasm\n";
1114238405Sjkim			$ret.="\t\$(PERL) $plasm $asmtype \$(CFLAG) >$srcfile\n\n";
1115238405Sjkim			}
1116238405Sjkim
1117238405Sjkim		$ret.="$objfile: $srcfile\n";
1118238405Sjkim		$ret.="\t\$(ASM) $afile$objfile \$(SRC_D)$o$srcfile\n\n";
111955714Skris		}
112055714Skris	return($ret);
112155714Skris	}
112255714Skris
112355714Skrissub do_shlib_rule
112455714Skris	{
112555714Skris	local($n,$def)=@_;
112655714Skris	local($ret,$nn);
112755714Skris	local($t);
112855714Skris
112955714Skris	($nn=$n) =~ tr/a-z/A-Z/;
113055714Skris	$ret.="$n.dll: \$(${nn}OBJ)\n";
113155714Skris	if ($vc && $w32)
113255714Skris		{
113355714Skris		$ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n  \$(${nn}OBJ_F)\n<<\n";
113455714Skris		}
113555714Skris	$ret.="\n";
113655714Skris	return($ret);
113755714Skris	}
113855714Skris
113955714Skris# do a rule for each file that says 'copy' to new direcory on change
114055714Skrissub do_copy_rule
114155714Skris	{
114255714Skris	local($to,$files,$p)=@_;
114355714Skris	local($ret,$_,$n,$pp);
114455714Skris
114555714Skris	$files =~ s/\//$o/g if $o ne '/';
114655714Skris	foreach (split(/\s+/,$files))
114755714Skris		{
114855714Skris		$n=&bname($_);
114955714Skris		if ($n =~ /bss_file/)
115055714Skris			{ $pp=".c"; }
115155714Skris		else	{ $pp=$p; }
1152290207Sjkim		$ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(PERL) \$(SRC_D)${o}util${o}copy-if-different.pl \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
115355714Skris		}
115455714Skris	return($ret);
115555714Skris	}
115655714Skris
1157276861Sjkim# Options picked up from the OPTIONS line in the top level Makefile
1158276861Sjkim# generated by Configure.
1159276861Sjkim
116055714Skrissub read_options
116155714Skris	{
1162160814Ssimon	# Many options are handled in a similar way. In particular
1163160814Ssimon	# no-xxx sets zero or more scalars to 1.
1164276861Sjkim	# Process these using the %valid_options hash containing the option
1165276861Sjkim	# name and reference to the scalars to set. In some cases the option
1166276861Sjkim	# needs no special handling and can be ignored: this is done by
1167276861Sjkim	# setting the value to 0.
116855714Skris
1169160814Ssimon	my %valid_options = (
1170160814Ssimon		"no-rc2" => \$no_rc2,
1171160814Ssimon		"no-rc4" => \$no_rc4,
1172160814Ssimon		"no-rc5" => \$no_rc5,
1173160814Ssimon		"no-idea" => \$no_idea,
1174160814Ssimon		"no-aes" => \$no_aes,
1175162911Ssimon		"no-camellia" => \$no_camellia,
1176194206Ssimon		"no-seed" => \$no_seed,
1177160814Ssimon		"no-des" => \$no_des,
1178160814Ssimon		"no-bf" => \$no_bf,
1179160814Ssimon		"no-cast" => \$no_cast,
1180160814Ssimon		"no-md2" => \$no_md2,
1181160814Ssimon		"no-md4" => \$no_md4,
1182160814Ssimon		"no-md5" => \$no_md5,
1183160814Ssimon		"no-sha" => \$no_sha,
1184160814Ssimon		"no-sha1" => \$no_sha1,
1185160814Ssimon		"no-ripemd" => \$no_ripemd,
1186160814Ssimon		"no-mdc2" => \$no_mdc2,
1187238405Sjkim		"no-whirlpool" => \$no_whirlpool,
1188160814Ssimon		"no-patents" =>
1189160814Ssimon			[\$no_rc2, \$no_rc4, \$no_rc5, \$no_idea, \$no_rsa],
1190160814Ssimon		"no-rsa" => \$no_rsa,
1191160814Ssimon		"no-dsa" => \$no_dsa,
1192160814Ssimon		"no-dh" => \$no_dh,
1193160814Ssimon		"no-hmac" => \$no_hmac,
1194160814Ssimon		"no-asm" => \$no_asm,
1195160814Ssimon		"nasm" => \$nasm,
1196160814Ssimon		"nw-nasm" => \$nw_nasm,
1197160814Ssimon		"nw-mwasm" => \$nw_mwasm,
1198160814Ssimon		"gaswin" => \$gaswin,
1199160814Ssimon		"no-ssl2" => \$no_ssl2,
1200160814Ssimon		"no-ssl3" => \$no_ssl3,
1201276861Sjkim		"no-ssl3-method" => 0,
1202194206Ssimon		"no-tlsext" => \$no_tlsext,
1203238405Sjkim		"no-srp" => \$no_srp,
1204194206Ssimon		"no-cms" => \$no_cms,
1205290207Sjkim		"no-jpake" => \$no_jpake,
1206238405Sjkim		"no-ec2m" => \$no_ec2m,
1207238405Sjkim		"no-ec_nistp_64_gcc_128" => 0,
1208160814Ssimon		"no-err" => \$no_err,
1209160814Ssimon		"no-sock" => \$no_sock,
1210160814Ssimon		"no-krb5" => \$no_krb5,
1211160814Ssimon		"no-ec" => \$no_ec,
1212160814Ssimon		"no-ecdsa" => \$no_ecdsa,
1213160814Ssimon		"no-ecdh" => \$no_ecdh,
1214238405Sjkim		"no-gost" => \$no_gost,
1215160814Ssimon		"no-engine" => \$no_engine,
1216160814Ssimon		"no-hw" => \$no_hw,
1217238405Sjkim		"no-rsax" => 0,
1218160814Ssimon		"just-ssl" =>
1219160814Ssimon			[\$no_rc2, \$no_idea, \$no_des, \$no_bf, \$no_cast,
1220160814Ssimon			  \$no_md2, \$no_sha, \$no_mdc2, \$no_dsa, \$no_dh,
1221160814Ssimon			  \$no_ssl2, \$no_err, \$no_ripemd, \$no_rc5,
1222238405Sjkim			  \$no_aes, \$no_camellia, \$no_seed, \$no_srp],
1223160814Ssimon		"rsaref" => 0,
1224160814Ssimon		"gcc" => \$gcc,
1225160814Ssimon		"debug" => \$debug,
1226160814Ssimon		"profile" => \$profile,
1227160814Ssimon		"shlib" => \$shlib,
1228160814Ssimon		"dll" => \$shlib,
1229160814Ssimon		"shared" => 0,
1230238405Sjkim		"no-sctp" => 0,
1231273144Sjkim		"no-srtp" => 0,
1232160814Ssimon		"no-gmp" => 0,
1233167612Ssimon		"no-rfc3779" => 0,
1234194206Ssimon		"no-montasm" => 0,
1235160814Ssimon		"no-shared" => 0,
1236238405Sjkim		"no-store" => 0,
1237160814Ssimon		"no-zlib" => 0,
1238160814Ssimon		"no-zlib-dynamic" => 0,
1239290207Sjkim		"no-ssl-trace" => 0,
1240290207Sjkim		"no-unit-test" => 0,
1241290207Sjkim		"no-libunbound" => 0,
1242290207Sjkim		"no-multiblock" => 0,
1243238405Sjkim		"fips" => \$fips
1244160814Ssimon		);
124555714Skris
1246160814Ssimon	if (exists $valid_options{$_})
1247160814Ssimon		{
1248160814Ssimon		my $r = $valid_options{$_};
1249160814Ssimon		if ( ref $r eq "SCALAR")
1250160814Ssimon			{ $$r = 1;}
1251160814Ssimon		elsif ( ref $r eq "ARRAY")
1252160814Ssimon			{
1253160814Ssimon			my $r2;
1254160814Ssimon			foreach $r2 (@$r)
1255160814Ssimon				{
1256160814Ssimon				$$r2 = 1;
1257160814Ssimon				}
1258160814Ssimon			}
1259160814Ssimon		}
1260160814Ssimon	elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; }
1261160814Ssimon	elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
1262160814Ssimon	elsif (/^enable-zlib-dynamic$/)
1263160814Ssimon		{
1264160814Ssimon		$zlib_opt = 2;
1265160814Ssimon		}
1266160814Ssimon	elsif (/^no-static-engine/)
1267160814Ssimon		{
1268160814Ssimon		$no_static_engine = 1;
1269160814Ssimon		}
1270160814Ssimon	elsif (/^enable-static-engine/)
1271160814Ssimon		{
1272160814Ssimon		$no_static_engine = 0;
1273160814Ssimon		}
1274160814Ssimon	# There are also enable-xxx options which correspond to
1275160814Ssimon	# the no-xxx. Since the scalars are enabled by default
1276160814Ssimon	# these can be ignored.
1277160814Ssimon	elsif (/^enable-/)
1278160814Ssimon		{
1279160814Ssimon		my $t = $_;
1280160814Ssimon		$t =~ s/^enable/no/;
1281160814Ssimon		if (exists $valid_options{$t})
1282160814Ssimon			{return 1;}
1283160814Ssimon		return 0;
1284160814Ssimon		}
1285194206Ssimon	# experimental-xxx is mostly like enable-xxx, but opensslconf.v
1286194206Ssimon	# will still set OPENSSL_NO_xxx unless we set OPENSSL_EXPERIMENTAL_xxx.
1287194206Ssimon	# (No need to fail if we don't know the algorithm -- this is for adventurous users only.)
1288194206Ssimon	elsif (/^experimental-/)
1289194206Ssimon		{
1290194206Ssimon		my $algo, $ALGO;
1291194206Ssimon		($algo = $_) =~ s/^experimental-//;
1292194206Ssimon		($ALGO = $algo) =~ tr/[a-z]/[A-Z]/;
1293194206Ssimon
1294194206Ssimon		$xcflags="-DOPENSSL_EXPERIMENTAL_$ALGO $xcflags";
1295194206Ssimon
1296194206Ssimon		}
1297160814Ssimon	elsif (/^--with-krb5-flavor=(.*)$/)
1298160814Ssimon		{
1299160814Ssimon		my $krb5_flavor = $1;
1300160814Ssimon		if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
1301160814Ssimon			{
1302160814Ssimon			$xcflags="-DKRB5_HEIMDAL $xcflags";
1303160814Ssimon			}
1304160814Ssimon		elsif ($krb5_flavor =~ /^MIT/i)
1305160814Ssimon			{
1306160814Ssimon			$xcflags="-DKRB5_MIT $xcflags";
1307160814Ssimon		 	if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
1308160814Ssimon				{
1309160814Ssimon				$xcflags="-DKRB5_MIT_OLD11 $xcflags"
1310160814Ssimon				}
1311160814Ssimon			}
1312160814Ssimon		}
131355714Skris	elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
131455714Skris	elsif (/^-[lL].*$/)	{ $l_flags.="$_ "; }
131555714Skris	elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
131655714Skris		{ $c_flags.="$_ "; }
131755714Skris	else { return(0); }
131855714Skris	return(1);
131955714Skris	}
1320