1ebfedea0SLionel Sambuc#!/usr/local/bin/perl
2ebfedea0SLionel Sambuc# A bit of an evil hack but it post processes the file ../MINFO which
3ebfedea0SLionel Sambuc# is generated by `make files` in the top directory.
4ebfedea0SLionel Sambuc# This script outputs one mega makefile that has no shell stuff or any
5ebfedea0SLionel Sambuc# funny stuff
6ebfedea0SLionel Sambuc#
7ebfedea0SLionel Sambuc
8ebfedea0SLionel Sambuc$INSTALLTOP="/usr/local/ssl";
9ebfedea0SLionel Sambuc$OPENSSLDIR="/usr/local/ssl";
10ebfedea0SLionel Sambuc$OPTIONS="";
11ebfedea0SLionel Sambuc$ssl_version="";
12ebfedea0SLionel Sambuc$banner="\t\@echo Building OpenSSL";
13ebfedea0SLionel Sambuc
14ebfedea0SLionel Sambucmy $no_static_engine = 1;
15ebfedea0SLionel Sambucmy $engines = "";
16ebfedea0SLionel Sambucmy $otherlibs = "";
17ebfedea0SLionel Sambuclocal $zlib_opt = 0;	# 0 = no zlib, 1 = static, 2 = dynamic
18ebfedea0SLionel Sambuclocal $zlib_lib = "";
19ebfedea0SLionel Sambuclocal $perl_asm = 0;	# 1 to autobuild asm files from perl scripts
20ebfedea0SLionel Sambuc
21ebfedea0SLionel Sambucmy $ex_l_libs = "";
22ebfedea0SLionel Sambuc
23ebfedea0SLionel Sambuc# Options to import from top level Makefile
24ebfedea0SLionel Sambuc
25ebfedea0SLionel Sambucmy %mf_import = (
26ebfedea0SLionel Sambuc	VERSION	       => \$ssl_version,
27ebfedea0SLionel Sambuc	OPTIONS        => \$OPTIONS,
28ebfedea0SLionel Sambuc	INSTALLTOP     => \$INSTALLTOP,
29ebfedea0SLionel Sambuc	OPENSSLDIR     => \$OPENSSLDIR,
30ebfedea0SLionel Sambuc	PLATFORM       => \$mf_platform,
31ebfedea0SLionel Sambuc	CFLAG	       => \$mf_cflag,
32ebfedea0SLionel Sambuc	DEPFLAG	       => \$mf_depflag,
33ebfedea0SLionel Sambuc	CPUID_OBJ      => \$mf_cpuid_asm,
34ebfedea0SLionel Sambuc	BN_ASM	       => \$mf_bn_asm,
35ebfedea0SLionel Sambuc	DES_ENC	       => \$mf_des_asm,
36ebfedea0SLionel Sambuc	AES_ENC        => \$mf_aes_asm,
37ebfedea0SLionel Sambuc	BF_ENC	       => \$mf_bf_asm,
38ebfedea0SLionel Sambuc	CAST_ENC       => \$mf_cast_asm,
39ebfedea0SLionel Sambuc	RC4_ENC	       => \$mf_rc4_asm,
40ebfedea0SLionel Sambuc	RC5_ENC        => \$mf_rc5_asm,
41ebfedea0SLionel Sambuc	MD5_ASM_OBJ    => \$mf_md5_asm,
42ebfedea0SLionel Sambuc	SHA1_ASM_OBJ   => \$mf_sha_asm,
43ebfedea0SLionel Sambuc	RMD160_ASM_OBJ => \$mf_rmd_asm,
44ebfedea0SLionel Sambuc	WP_ASM_OBJ     => \$mf_wp_asm,
45ebfedea0SLionel Sambuc	CMLL_ENC       => \$mf_cm_asm,
46ebfedea0SLionel Sambuc	BASEADDR       => \$baseaddr,
47ebfedea0SLionel Sambuc	FIPSDIR        => \$fipsdir,
48ebfedea0SLionel Sambuc);
49ebfedea0SLionel Sambuc
50ebfedea0SLionel Sambuc
51ebfedea0SLionel Sambucopen(IN,"<Makefile") || die "unable to open Makefile!\n";
52ebfedea0SLionel Sambucwhile(<IN>) {
53ebfedea0SLionel Sambuc    my ($mf_opt, $mf_ref);
54ebfedea0SLionel Sambuc    while (($mf_opt, $mf_ref) = each %mf_import) {
55ebfedea0SLionel Sambuc    	if (/^$mf_opt\s*=\s*(.*)$/) {
56ebfedea0SLionel Sambuc	   $$mf_ref = $1;
57ebfedea0SLionel Sambuc	}
58ebfedea0SLionel Sambuc    }
59ebfedea0SLionel Sambuc}
60ebfedea0SLionel Sambucclose(IN);
61ebfedea0SLionel Sambuc
62ebfedea0SLionel Sambuc$debug = 1 if $mf_platform =~ /^debug-/;
63ebfedea0SLionel Sambuc
64ebfedea0SLionel Sambucdie "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
65ebfedea0SLionel Sambuc
66ebfedea0SLionel Sambuc$infile="MINFO";
67ebfedea0SLionel Sambuc
68ebfedea0SLionel Sambuc%ops=(
69ebfedea0SLionel Sambuc	"VC-WIN32",   "Microsoft Visual C++ [4-6] - Windows NT or 9X",
70ebfedea0SLionel Sambuc	"VC-WIN64I",  "Microsoft C/C++ - Win64/IA-64",
71ebfedea0SLionel Sambuc	"VC-WIN64A",  "Microsoft C/C++ - Win64/x64",
72ebfedea0SLionel Sambuc	"VC-CE",   "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
73ebfedea0SLionel Sambuc	"VC-NT",   "Microsoft Visual C++ [4-6] - Windows NT ONLY",
74ebfedea0SLionel Sambuc	"Mingw32", "GNU C++ - Windows NT or 9x",
75ebfedea0SLionel Sambuc	"Mingw32-files", "Create files with DOS copy ...",
76ebfedea0SLionel Sambuc	"BC-NT",   "Borland C++ 4.5 - Windows NT",
77ebfedea0SLionel Sambuc	"linux-elf","Linux elf",
78ebfedea0SLionel Sambuc	"ultrix-mips","DEC mips ultrix",
79ebfedea0SLionel Sambuc	"FreeBSD","FreeBSD distribution",
80ebfedea0SLionel Sambuc	"OS2-EMX", "EMX GCC OS/2",
81ebfedea0SLionel Sambuc	"netware-clib", "CodeWarrior for NetWare - CLib - with WinSock Sockets",
82ebfedea0SLionel Sambuc	"netware-clib-bsdsock", "CodeWarrior for NetWare - CLib - with BSD Sockets",
83ebfedea0SLionel Sambuc	"netware-libc", "CodeWarrior for NetWare - LibC - with WinSock Sockets",
84ebfedea0SLionel Sambuc	"netware-libc-bsdsock", "CodeWarrior for NetWare - LibC - with BSD Sockets",
85ebfedea0SLionel Sambuc	"default","cc under unix",
86ebfedea0SLionel Sambuc	"auto", "auto detect from top level Makefile"
87ebfedea0SLionel Sambuc	);
88ebfedea0SLionel Sambuc
89ebfedea0SLionel Sambuc$platform="";
90ebfedea0SLionel Sambucmy $xcflags="";
91ebfedea0SLionel Sambucforeach (@ARGV)
92ebfedea0SLionel Sambuc	{
93ebfedea0SLionel Sambuc	if (!&read_options && !defined($ops{$_}))
94ebfedea0SLionel Sambuc		{
95ebfedea0SLionel Sambuc		print STDERR "unknown option - $_\n";
96ebfedea0SLionel Sambuc		print STDERR "usage: perl mk1mf.pl [options] [system]\n";
97ebfedea0SLionel Sambuc		print STDERR "\nwhere [system] can be one of the following\n";
98ebfedea0SLionel Sambuc		foreach $i (sort keys %ops)
99ebfedea0SLionel Sambuc		{ printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
100ebfedea0SLionel Sambuc		print STDERR <<"EOF";
101ebfedea0SLionel Sambucand [options] can be one of
102ebfedea0SLionel Sambuc	no-md2 no-md4 no-md5 no-sha no-mdc2	- Skip this digest
103ebfedea0SLionel Sambuc	no-ripemd
104ebfedea0SLionel Sambuc	no-rc2 no-rc4 no-rc5 no-idea no-des     - Skip this symetric cipher
105ebfedea0SLionel Sambuc	no-bf no-cast no-aes no-camellia no-seed
106ebfedea0SLionel Sambuc	no-rsa no-dsa no-dh			- Skip this public key cipher
107ebfedea0SLionel Sambuc	no-ssl2 no-ssl3				- Skip this version of SSL
108ebfedea0SLionel Sambuc	just-ssl				- remove all non-ssl keys/digest
109ebfedea0SLionel Sambuc	no-asm 					- No x86 asm
110ebfedea0SLionel Sambuc	no-krb5					- No KRB5
111ebfedea0SLionel Sambuc	no-srp					- No SRP
112ebfedea0SLionel Sambuc	no-ec					- No EC
113ebfedea0SLionel Sambuc	no-ecdsa				- No ECDSA
114ebfedea0SLionel Sambuc	no-ecdh					- No ECDH
115ebfedea0SLionel Sambuc	no-engine				- No engine
116ebfedea0SLionel Sambuc	no-hw					- No hw
117ebfedea0SLionel Sambuc	nasm 					- Use NASM for x86 asm
118ebfedea0SLionel Sambuc	nw-nasm					- Use NASM x86 asm for NetWare
119ebfedea0SLionel Sambuc	nw-mwasm				- Use Metrowerks x86 asm for NetWare
120ebfedea0SLionel Sambuc	gaswin					- Use GNU as with Mingw32
121ebfedea0SLionel Sambuc	no-socks				- No socket code
122ebfedea0SLionel Sambuc	no-err					- No error strings
123ebfedea0SLionel Sambuc	dll/shlib				- Build shared libraries (MS)
124ebfedea0SLionel Sambuc	debug					- Debug build
125ebfedea0SLionel Sambuc        profile                                 - Profiling build
126ebfedea0SLionel Sambuc	gcc					- Use Gcc (unix)
127ebfedea0SLionel Sambuc
128ebfedea0SLionel SambucValues that can be set
129ebfedea0SLionel SambucTMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
130ebfedea0SLionel Sambuc
131ebfedea0SLionel Sambuc-L<ex_lib_path> -l<ex_lib>			- extra library flags (unix)
132ebfedea0SLionel Sambuc-<ex_cc_flags>					- extra 'cc' flags,
133ebfedea0SLionel Sambuc						  added (MS), or replace (unix)
134ebfedea0SLionel SambucEOF
135ebfedea0SLionel Sambuc		exit(1);
136ebfedea0SLionel Sambuc		}
137ebfedea0SLionel Sambuc	$platform=$_;
138ebfedea0SLionel Sambuc	}
139ebfedea0SLionel Sambucforeach (grep(!/^$/, split(/ /, $OPTIONS)))
140ebfedea0SLionel Sambuc	{
141ebfedea0SLionel Sambuc	print STDERR "unknown option - $_\n" if !&read_options;
142ebfedea0SLionel Sambuc	}
143ebfedea0SLionel Sambuc
144ebfedea0SLionel Sambuc$no_static_engine = 0 if (!$shlib);
145ebfedea0SLionel Sambuc
146ebfedea0SLionel Sambuc$no_mdc2=1 if ($no_des);
147ebfedea0SLionel Sambuc
148ebfedea0SLionel Sambuc$no_ssl3=1 if ($no_md5 || $no_sha);
149ebfedea0SLionel Sambuc$no_ssl3=1 if ($no_rsa && $no_dh);
150ebfedea0SLionel Sambuc
151ebfedea0SLionel Sambuc$no_ssl2=1 if ($no_md5);
152ebfedea0SLionel Sambuc$no_ssl2=1 if ($no_rsa);
153ebfedea0SLionel Sambuc
154ebfedea0SLionel Sambuc$out_def="out";
155ebfedea0SLionel Sambuc$inc_def="outinc";
156ebfedea0SLionel Sambuc$tmp_def="tmp";
157ebfedea0SLionel Sambuc
158ebfedea0SLionel Sambuc$perl="perl" unless defined $perl;
159ebfedea0SLionel Sambuc$mkdir="-mkdir" unless defined $mkdir;
160ebfedea0SLionel Sambuc
161ebfedea0SLionel Sambuc($ssl,$crypto)=("ssl","crypto");
162ebfedea0SLionel Sambuc$ranlib="echo ranlib";
163ebfedea0SLionel Sambuc
164ebfedea0SLionel Sambuc$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
165ebfedea0SLionel Sambuc$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
166ebfedea0SLionel Sambuc$bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
167ebfedea0SLionel Sambuc
168ebfedea0SLionel Sambuc# $bin_dir.=$o causes a core dump on my sparc :-(
169ebfedea0SLionel Sambuc
170ebfedea0SLionel Sambuc
171ebfedea0SLionel Sambuc$NT=0;
172ebfedea0SLionel Sambuc
173ebfedea0SLionel Sambucpush(@INC,"util/pl","pl");
174ebfedea0SLionel Sambuc
175ebfedea0SLionel Sambucif ($platform eq "auto") {
176ebfedea0SLionel Sambuc	$platform = $mf_platform;
177ebfedea0SLionel Sambuc	print STDERR "Imported platform $mf_platform\n";
178ebfedea0SLionel Sambuc}
179ebfedea0SLionel Sambuc
180ebfedea0SLionel Sambucif (($platform =~ /VC-(.+)/))
181ebfedea0SLionel Sambuc	{
182ebfedea0SLionel Sambuc	$FLAVOR=$1;
183ebfedea0SLionel Sambuc	$NT = 1 if $1 eq "NT";
184ebfedea0SLionel Sambuc	require 'VC-32.pl';
185ebfedea0SLionel Sambuc	}
186ebfedea0SLionel Sambucelsif ($platform eq "Mingw32")
187ebfedea0SLionel Sambuc	{
188ebfedea0SLionel Sambuc	require 'Mingw32.pl';
189ebfedea0SLionel Sambuc	}
190ebfedea0SLionel Sambucelsif ($platform eq "Mingw32-files")
191ebfedea0SLionel Sambuc	{
192ebfedea0SLionel Sambuc	require 'Mingw32f.pl';
193ebfedea0SLionel Sambuc	}
194ebfedea0SLionel Sambucelsif ($platform eq "BC-NT")
195ebfedea0SLionel Sambuc	{
196ebfedea0SLionel Sambuc	$bc=1;
197ebfedea0SLionel Sambuc	require 'BC-32.pl';
198ebfedea0SLionel Sambuc	}
199ebfedea0SLionel Sambucelsif ($platform eq "FreeBSD")
200ebfedea0SLionel Sambuc	{
201ebfedea0SLionel Sambuc	require 'unix.pl';
202ebfedea0SLionel Sambuc	$cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
203ebfedea0SLionel Sambuc	}
204ebfedea0SLionel Sambucelsif ($platform eq "linux-elf")
205ebfedea0SLionel Sambuc	{
206ebfedea0SLionel Sambuc	require "unix.pl";
207ebfedea0SLionel Sambuc	require "linux.pl";
208ebfedea0SLionel Sambuc	$unix=1;
209ebfedea0SLionel Sambuc	}
210ebfedea0SLionel Sambucelsif ($platform eq "ultrix-mips")
211ebfedea0SLionel Sambuc	{
212ebfedea0SLionel Sambuc	require "unix.pl";
213ebfedea0SLionel Sambuc	require "ultrix.pl";
214ebfedea0SLionel Sambuc	$unix=1;
215ebfedea0SLionel Sambuc	}
216ebfedea0SLionel Sambucelsif ($platform eq "OS2-EMX")
217ebfedea0SLionel Sambuc	{
218ebfedea0SLionel Sambuc	$wc=1;
219ebfedea0SLionel Sambuc	require 'OS2-EMX.pl';
220ebfedea0SLionel Sambuc	}
221ebfedea0SLionel Sambucelsif (($platform eq "netware-clib") || ($platform eq "netware-libc") ||
222ebfedea0SLionel Sambuc       ($platform eq "netware-clib-bsdsock") || ($platform eq "netware-libc-bsdsock"))
223ebfedea0SLionel Sambuc	{
224ebfedea0SLionel Sambuc	$LIBC=1 if $platform eq "netware-libc" || $platform eq "netware-libc-bsdsock";
225ebfedea0SLionel Sambuc	$BSDSOCK=1 if ($platform eq "netware-libc-bsdsock") || ($platform eq "netware-clib-bsdsock");
226ebfedea0SLionel Sambuc	require 'netware.pl';
227ebfedea0SLionel Sambuc	}
228ebfedea0SLionel Sambucelse
229ebfedea0SLionel Sambuc	{
230ebfedea0SLionel Sambuc	require "unix.pl";
231ebfedea0SLionel Sambuc
232ebfedea0SLionel Sambuc	$unix=1;
233ebfedea0SLionel Sambuc	$cflags.=' -DTERMIO';
234ebfedea0SLionel Sambuc	}
235ebfedea0SLionel Sambuc
236ebfedea0SLionel Sambuc$fipsdir =~ s/\//${o}/g;
237ebfedea0SLionel Sambuc
238ebfedea0SLionel Sambuc$out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
239ebfedea0SLionel Sambuc$tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
240ebfedea0SLionel Sambuc$inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
241ebfedea0SLionel Sambuc
242ebfedea0SLionel Sambuc$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
243ebfedea0SLionel Sambuc
244ebfedea0SLionel Sambuc$cflags= "$xcflags$cflags" if $xcflags ne "";
245ebfedea0SLionel Sambuc
246ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
247ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_AES"  if $no_aes;
248ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_CAMELLIA"  if $no_camellia;
249ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_SEED" if $no_seed;
250ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_RC2"  if $no_rc2;
251ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_RC4"  if $no_rc4;
252ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_RC5"  if $no_rc5;
253ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_MD2"  if $no_md2;
254ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_MD4"  if $no_md4;
255ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_MD5"  if $no_md5;
256ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_SHA"  if $no_sha;
257ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_SHA1" if $no_sha1;
258ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_RIPEMD" if $no_ripemd;
259ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
260ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_BF"  if $no_bf;
261ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
262ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_DES"  if $no_des;
263ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_RSA"  if $no_rsa;
264ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_DSA"  if $no_dsa;
265ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_DH"   if $no_dh;
266ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_WHIRLPOOL"   if $no_whirlpool;
267ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
268ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_SSL2" if $no_ssl2;
269ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
270ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_TLSEXT" if $no_tlsext;
271ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_SRP" if $no_srp;
272ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_CMS" if $no_cms;
273ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_ERR"  if $no_err;
274ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_KRB5" if $no_krb5;
275ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_EC"   if $no_ec;
276ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_ECDSA" if $no_ecdsa;
277ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_ECDH" if $no_ecdh;
278ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_GOST" if $no_gost;
279ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_ENGINE"   if $no_engine;
280ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_HW"   if $no_hw;
281ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_FIPS"    if $fips;
282ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_JPAKE"    if $no_jpake;
283ebfedea0SLionel Sambuc$cflags.=" -DOPENSSL_NO_EC2M"    if $no_ec2m;
284ebfedea0SLionel Sambuc$cflags.= " -DZLIB" if $zlib_opt;
285ebfedea0SLionel Sambuc$cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
286ebfedea0SLionel Sambuc
287ebfedea0SLionel Sambucif ($no_static_engine)
288ebfedea0SLionel Sambuc	{
289ebfedea0SLionel Sambuc	$cflags .= " -DOPENSSL_NO_STATIC_ENGINE";
290ebfedea0SLionel Sambuc	}
291ebfedea0SLionel Sambucelse
292ebfedea0SLionel Sambuc	{
293ebfedea0SLionel Sambuc	$cflags .= " -DOPENSSL_NO_DYNAMIC_ENGINE";
294ebfedea0SLionel Sambuc	}
295ebfedea0SLionel Sambuc
296ebfedea0SLionel Sambuc#$cflags.=" -DRSAref"  if $rsaref ne "";
297ebfedea0SLionel Sambuc
298ebfedea0SLionel Sambuc## if ($unix)
299ebfedea0SLionel Sambuc##	{ $cflags="$c_flags" if ($c_flags ne ""); }
300ebfedea0SLionel Sambuc##else
301ebfedea0SLionel Sambuc	{ $cflags="$c_flags$cflags" if ($c_flags ne ""); }
302ebfedea0SLionel Sambuc
303ebfedea0SLionel Sambuc$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
304ebfedea0SLionel Sambuc
305ebfedea0SLionel Sambuc
306ebfedea0SLionel Sambuc%shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
307ebfedea0SLionel Sambuc		  "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
308ebfedea0SLionel Sambuc
309ebfedea0SLionel Sambucif ($msdos)
310ebfedea0SLionel Sambuc	{
311ebfedea0SLionel Sambuc	$banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
312ebfedea0SLionel Sambuc	$banner.="\t\@echo top level directory, if you don't have perl, you will\n";
313ebfedea0SLionel Sambuc	$banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
314ebfedea0SLionel Sambuc	$banner.="\t\@echo documentation for details.\n";
315ebfedea0SLionel Sambuc	}
316ebfedea0SLionel Sambuc
317ebfedea0SLionel Sambuc# have to do this to allow $(CC) under unix
318ebfedea0SLionel Sambuc$link="$bin_dir$link" if ($link !~ /^\$/);
319ebfedea0SLionel Sambuc
320ebfedea0SLionel Sambuc$INSTALLTOP =~ s|/|$o|g;
321ebfedea0SLionel Sambuc$OPENSSLDIR =~ s|/|$o|g;
322ebfedea0SLionel Sambuc
323ebfedea0SLionel Sambuc#############################################
324ebfedea0SLionel Sambuc# We parse in input file and 'store' info for later printing.
325ebfedea0SLionel Sambucopen(IN,"<$infile") || die "unable to open $infile:$!\n";
326ebfedea0SLionel Sambuc$_=<IN>;
327ebfedea0SLionel Sambucfor (;;)
328ebfedea0SLionel Sambuc	{
329*0a6a1f1dSLionel Sambuc	s/\s*$//; # was chop, didn't work in mixture of perls for Windows...
330ebfedea0SLionel Sambuc
331ebfedea0SLionel Sambuc	($key,$val)=/^([^=]+)=(.*)/;
332ebfedea0SLionel Sambuc	if ($key eq "RELATIVE_DIRECTORY")
333ebfedea0SLionel Sambuc		{
334ebfedea0SLionel Sambuc		if ($lib ne "")
335ebfedea0SLionel Sambuc			{
336ebfedea0SLionel Sambuc			$uc=$lib;
337ebfedea0SLionel Sambuc			$uc =~ s/^lib(.*)\.a/$1/;
338ebfedea0SLionel Sambuc			$uc =~ tr/a-z/A-Z/;
339ebfedea0SLionel Sambuc			$lib_nam{$uc}=$uc;
340ebfedea0SLionel Sambuc			$lib_obj{$uc}.=$libobj." ";
341ebfedea0SLionel Sambuc			}
342ebfedea0SLionel Sambuc		last if ($val eq "FINISHED");
343ebfedea0SLionel Sambuc		$lib="";
344ebfedea0SLionel Sambuc		$libobj="";
345ebfedea0SLionel Sambuc		$dir=$val;
346ebfedea0SLionel Sambuc		}
347ebfedea0SLionel Sambuc
348ebfedea0SLionel Sambuc	if ($key eq "KRB5_INCLUDES")
349ebfedea0SLionel Sambuc		{ $cflags .= " $val";}
350ebfedea0SLionel Sambuc
351ebfedea0SLionel Sambuc	if ($key eq "ZLIB_INCLUDE")
352ebfedea0SLionel Sambuc		{ $cflags .= " $val" if $val ne "";}
353ebfedea0SLionel Sambuc
354ebfedea0SLionel Sambuc	if ($key eq "LIBZLIB")
355ebfedea0SLionel Sambuc		{ $zlib_lib = "$val" if $val ne "";}
356ebfedea0SLionel Sambuc
357ebfedea0SLionel Sambuc	if ($key eq "LIBKRB5")
358ebfedea0SLionel Sambuc		{ $ex_libs .= " $val" if $val ne "";}
359ebfedea0SLionel Sambuc
360ebfedea0SLionel Sambuc	if ($key eq "TEST")
361ebfedea0SLionel Sambuc		{ $test.=&var_add($dir,$val, 0); }
362ebfedea0SLionel Sambuc
363ebfedea0SLionel Sambuc	if (($key eq "PROGS") || ($key eq "E_OBJ"))
364ebfedea0SLionel Sambuc		{ $e_exe.=&var_add($dir,$val, 0); }
365ebfedea0SLionel Sambuc
366ebfedea0SLionel Sambuc	if ($key eq "LIB")
367ebfedea0SLionel Sambuc		{
368ebfedea0SLionel Sambuc		$lib=$val;
369ebfedea0SLionel Sambuc		$lib =~ s/^.*\/([^\/]+)$/$1/;
370ebfedea0SLionel Sambuc		}
371ebfedea0SLionel Sambuc	if ($key eq "LIBNAME" && $no_static_engine)
372ebfedea0SLionel Sambuc		{
373ebfedea0SLionel Sambuc		$lib=$val;
374ebfedea0SLionel Sambuc		$lib =~ s/^.*\/([^\/]+)$/$1/;
375ebfedea0SLionel Sambuc		$otherlibs .= " $lib";
376ebfedea0SLionel Sambuc		}
377ebfedea0SLionel Sambuc
378ebfedea0SLionel Sambuc	if ($key eq "EXHEADER")
379ebfedea0SLionel Sambuc		{ $exheader.=&var_add($dir,$val, 1); }
380ebfedea0SLionel Sambuc
381ebfedea0SLionel Sambuc	if ($key eq "HEADER")
382ebfedea0SLionel Sambuc		{ $header.=&var_add($dir,$val, 1); }
383ebfedea0SLionel Sambuc
384ebfedea0SLionel Sambuc	if ($key eq "LIBOBJ" && ($dir ne "engines" || !$no_static_engine))
385ebfedea0SLionel Sambuc		{ $libobj=&var_add($dir,$val, 0); }
386ebfedea0SLionel Sambuc	if ($key eq "LIBNAMES" && $dir eq "engines" && $no_static_engine)
387ebfedea0SLionel Sambuc 		{ $engines.=$val }
388ebfedea0SLionel Sambuc
389ebfedea0SLionel Sambuc	if (!($_=<IN>))
390ebfedea0SLionel Sambuc		{ $_="RELATIVE_DIRECTORY=FINISHED\n"; }
391ebfedea0SLionel Sambuc	}
392ebfedea0SLionel Sambucclose(IN);
393ebfedea0SLionel Sambuc
394ebfedea0SLionel Sambucif ($shlib)
395ebfedea0SLionel Sambuc	{
396ebfedea0SLionel Sambuc	$extra_install= <<"EOF";
397ebfedea0SLionel Sambuc	\$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}bin\"
398ebfedea0SLionel Sambuc	\$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}bin\"
399ebfedea0SLionel Sambuc	\$(CP) \"\$(L_SSL)\" \"\$(INSTALLTOP)${o}lib\"
400ebfedea0SLionel Sambuc	\$(CP) \"\$(L_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
401ebfedea0SLionel SambucEOF
402ebfedea0SLionel Sambuc	if ($no_static_engine)
403ebfedea0SLionel Sambuc		{
404ebfedea0SLionel Sambuc		$extra_install .= <<"EOF"
405ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
406ebfedea0SLionel Sambuc	\$(CP) \"\$(E_SHLIB)\" \"\$(INSTALLTOP)${o}lib${o}engines\"
407ebfedea0SLionel SambucEOF
408ebfedea0SLionel Sambuc		}
409ebfedea0SLionel Sambuc	}
410ebfedea0SLionel Sambucelse
411ebfedea0SLionel Sambuc	{
412ebfedea0SLionel Sambuc	$extra_install= <<"EOF";
413ebfedea0SLionel Sambuc	\$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}lib\"
414ebfedea0SLionel Sambuc	\$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
415ebfedea0SLionel SambucEOF
416ebfedea0SLionel Sambuc	$ex_libs .= " $zlib_lib" if $zlib_opt == 1;
417ebfedea0SLionel Sambuc	if ($fips)
418ebfedea0SLionel Sambuc		{
419ebfedea0SLionel Sambuc		$build_targets .= " \$(LIB_D)$o$crypto_compat \$(PREMAIN_DSO_EXE)";
420ebfedea0SLionel Sambuc		$ex_l_libs .= " \$(O_FIPSCANISTER)";
421ebfedea0SLionel Sambuc		}
422ebfedea0SLionel Sambuc	}
423ebfedea0SLionel Sambuc
424ebfedea0SLionel Sambuc$defs= <<"EOF";
425ebfedea0SLionel Sambuc# This makefile has been automatically generated from the OpenSSL distribution.
426ebfedea0SLionel Sambuc# This single makefile will build the complete OpenSSL distribution and
427ebfedea0SLionel Sambuc# by default leave the 'intertesting' output files in .${o}out and the stuff
428ebfedea0SLionel Sambuc# that needs deleting in .${o}tmp.
429ebfedea0SLionel Sambuc# The file was generated by running 'make makefile.one', which
430ebfedea0SLionel Sambuc# does a 'make files', which writes all the environment variables from all
431ebfedea0SLionel Sambuc# the makefiles to the file call MINFO.  This file is used by
432ebfedea0SLionel Sambuc# util${o}mk1mf.pl to generate makefile.one.
433ebfedea0SLionel Sambuc# The 'makefile per directory' system suites me when developing this
434ebfedea0SLionel Sambuc# library and also so I can 'distribute' indervidual library sections.
435ebfedea0SLionel Sambuc# The one monster makefile better suits building in non-unix
436ebfedea0SLionel Sambuc# environments.
437ebfedea0SLionel Sambuc
438ebfedea0SLionel SambucEOF
439ebfedea0SLionel Sambuc
440ebfedea0SLionel Sambuc$defs .= $preamble if defined $preamble;
441ebfedea0SLionel Sambuc
442ebfedea0SLionel Sambuc$defs.= <<"EOF";
443ebfedea0SLionel SambucINSTALLTOP=$INSTALLTOP
444ebfedea0SLionel SambucOPENSSLDIR=$OPENSSLDIR
445ebfedea0SLionel Sambuc
446ebfedea0SLionel Sambuc# Set your compiler options
447ebfedea0SLionel SambucPLATFORM=$platform
448ebfedea0SLionel SambucCC=$bin_dir${cc}
449ebfedea0SLionel SambucCFLAG=$cflags
450ebfedea0SLionel SambucAPP_CFLAG=$app_cflag
451ebfedea0SLionel SambucLIB_CFLAG=$lib_cflag
452ebfedea0SLionel SambucSHLIB_CFLAG=$shl_cflag
453ebfedea0SLionel SambucAPP_EX_OBJ=$app_ex_obj
454ebfedea0SLionel SambucSHLIB_EX_OBJ=$shlib_ex_obj
455ebfedea0SLionel Sambuc# add extra libraries to this define, for solaris -lsocket -lnsl would
456ebfedea0SLionel Sambuc# be added
457ebfedea0SLionel SambucEX_LIBS=$ex_libs
458ebfedea0SLionel Sambuc
459ebfedea0SLionel Sambuc# The OpenSSL directory
460ebfedea0SLionel SambucSRC_D=$src_dir
461ebfedea0SLionel Sambuc
462ebfedea0SLionel SambucLINK=$link
463ebfedea0SLionel SambucLFLAGS=$lflags
464ebfedea0SLionel SambucRSC=$rsc
465ebfedea0SLionel Sambuc
466ebfedea0SLionel Sambuc# The output directory for everything intersting
467ebfedea0SLionel SambucOUT_D=$out_dir
468ebfedea0SLionel Sambuc# The output directory for all the temporary muck
469ebfedea0SLionel SambucTMP_D=$tmp_dir
470ebfedea0SLionel Sambuc# The output directory for the header files
471ebfedea0SLionel SambucINC_D=$inc_dir
472ebfedea0SLionel SambucINCO_D=$inc_dir${o}openssl
473ebfedea0SLionel Sambuc
474ebfedea0SLionel SambucPERL=$perl
475ebfedea0SLionel SambucCP=$cp
476ebfedea0SLionel SambucRM=$rm
477ebfedea0SLionel SambucRANLIB=$ranlib
478ebfedea0SLionel SambucMKDIR=$mkdir
479ebfedea0SLionel SambucMKLIB=$bin_dir$mklib
480ebfedea0SLionel SambucMLFLAGS=$mlflags
481ebfedea0SLionel SambucASM=$bin_dir$asm
482ebfedea0SLionel Sambuc
483ebfedea0SLionel Sambuc# FIPS validated module and support file locations
484ebfedea0SLionel Sambuc
485ebfedea0SLionel SambucFIPSDIR=$fipsdir
486ebfedea0SLionel SambucBASEADDR=$baseaddr
487ebfedea0SLionel SambucFIPSLIB_D=\$(FIPSDIR)${o}lib
488ebfedea0SLionel SambucFIPS_PREMAIN_SRC=\$(FIPSLIB_D)${o}fips_premain.c
489ebfedea0SLionel SambucO_FIPSCANISTER=\$(FIPSLIB_D)${o}fipscanister.lib
490ebfedea0SLionel SambucFIPS_SHA1_EXE=\$(FIPSDIR)${o}bin${o}fips_standalone_sha1${exep}
491ebfedea0SLionel SambucE_PREMAIN_DSO=fips_premain_dso
492ebfedea0SLionel SambucPREMAIN_DSO_EXE=\$(BIN_D)${o}fips_premain_dso$exep
493ebfedea0SLionel SambucFIPSLINK=\$(PERL) \$(FIPSDIR)${o}bin${o}fipslink.pl
494ebfedea0SLionel Sambuc
495ebfedea0SLionel Sambuc######################################################
496ebfedea0SLionel Sambuc# You should not need to touch anything below this point
497ebfedea0SLionel Sambuc######################################################
498ebfedea0SLionel Sambuc
499ebfedea0SLionel SambucE_EXE=openssl
500ebfedea0SLionel SambucSSL=$ssl
501ebfedea0SLionel SambucCRYPTO=$crypto
502ebfedea0SLionel Sambuc
503ebfedea0SLionel Sambuc# BIN_D  - Binary output directory
504ebfedea0SLionel Sambuc# TEST_D - Binary test file output directory
505ebfedea0SLionel Sambuc# LIB_D  - library output directory
506ebfedea0SLionel Sambuc# ENG_D  - dynamic engine output directory
507ebfedea0SLionel Sambuc# Note: if you change these point to different directories then uncomment out
508ebfedea0SLionel Sambuc# the lines around the 'NB' comment below.
509ebfedea0SLionel Sambuc#
510ebfedea0SLionel SambucBIN_D=\$(OUT_D)
511ebfedea0SLionel SambucTEST_D=\$(OUT_D)
512ebfedea0SLionel SambucLIB_D=\$(OUT_D)
513ebfedea0SLionel SambucENG_D=\$(OUT_D)
514ebfedea0SLionel Sambuc
515ebfedea0SLionel Sambuc# INCL_D - local library directory
516ebfedea0SLionel Sambuc# OBJ_D  - temp object file directory
517ebfedea0SLionel SambucOBJ_D=\$(TMP_D)
518ebfedea0SLionel SambucINCL_D=\$(TMP_D)
519ebfedea0SLionel Sambuc
520ebfedea0SLionel SambucO_SSL=     \$(LIB_D)$o$plib\$(SSL)$shlibp
521ebfedea0SLionel SambucO_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
522ebfedea0SLionel SambucSO_SSL=    $plib\$(SSL)$so_shlibp
523ebfedea0SLionel SambucSO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
524ebfedea0SLionel SambucL_SSL=     \$(LIB_D)$o$plib\$(SSL)$libp
525ebfedea0SLionel SambucL_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$libp
526ebfedea0SLionel Sambuc
527ebfedea0SLionel SambucL_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs
528ebfedea0SLionel Sambuc
529ebfedea0SLionel Sambuc######################################################
530ebfedea0SLionel Sambuc# Don't touch anything below this point
531ebfedea0SLionel Sambuc######################################################
532ebfedea0SLionel Sambuc
533ebfedea0SLionel SambucINC=-I\$(INC_D) -I\$(INCL_D)
534ebfedea0SLionel SambucAPP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
535ebfedea0SLionel SambucLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
536ebfedea0SLionel SambucSHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
537ebfedea0SLionel SambucLIBS_DEP=\$(O_CRYPTO) \$(O_SSL)
538ebfedea0SLionel Sambuc
539ebfedea0SLionel Sambuc#############################################
540ebfedea0SLionel SambucEOF
541ebfedea0SLionel Sambuc
542ebfedea0SLionel Sambuc$rules=<<"EOF";
543ebfedea0SLionel Sambucall: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe $build_targets
544ebfedea0SLionel Sambuc
545ebfedea0SLionel Sambucbanner:
546ebfedea0SLionel Sambuc$banner
547ebfedea0SLionel Sambuc
548ebfedea0SLionel Sambuc\$(TMP_D):
549ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(TMP_D)\"
550ebfedea0SLionel Sambuc# NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
551ebfedea0SLionel Sambuc#\$(BIN_D):
552ebfedea0SLionel Sambuc#	\$(MKDIR) \$(BIN_D)
553ebfedea0SLionel Sambuc#
554ebfedea0SLionel Sambuc#\$(TEST_D):
555ebfedea0SLionel Sambuc#	\$(MKDIR) \$(TEST_D)
556ebfedea0SLionel Sambuc
557ebfedea0SLionel Sambuc\$(LIB_D):
558ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(LIB_D)\"
559ebfedea0SLionel Sambuc
560ebfedea0SLionel Sambuc\$(INCO_D): \$(INC_D)
561ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(INCO_D)\"
562ebfedea0SLionel Sambuc
563ebfedea0SLionel Sambuc\$(INC_D):
564ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(INC_D)\"
565ebfedea0SLionel Sambuc
566ebfedea0SLionel Sambucheaders: \$(HEADER) \$(EXHEADER)
567ebfedea0SLionel Sambuc	@
568ebfedea0SLionel Sambuc
569ebfedea0SLionel Sambuclib: \$(LIBS_DEP) \$(E_SHLIB)
570ebfedea0SLionel Sambuc
571ebfedea0SLionel Sambucexe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
572ebfedea0SLionel Sambuc
573ebfedea0SLionel Sambucinstall: all
574ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(INSTALLTOP)\"
575ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(INSTALLTOP)${o}bin\"
576ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(INSTALLTOP)${o}include\"
577ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(INSTALLTOP)${o}include${o}openssl\"
578ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
579ebfedea0SLionel Sambuc	\$(CP) \"\$(INCO_D)${o}*.\[ch\]\" \"\$(INSTALLTOP)${o}include${o}openssl\"
580ebfedea0SLionel Sambuc	\$(CP) \"\$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin\"
581ebfedea0SLionel Sambuc	\$(MKDIR) \"\$(OPENSSLDIR)\"
582ebfedea0SLionel Sambuc	\$(CP) apps${o}openssl.cnf \"\$(OPENSSLDIR)\"
583ebfedea0SLionel Sambuc$extra_install
584ebfedea0SLionel Sambuc
585ebfedea0SLionel Sambuc
586ebfedea0SLionel Sambuctest: \$(T_EXE)
587ebfedea0SLionel Sambuc	cd \$(BIN_D)
588ebfedea0SLionel Sambuc	..${o}ms${o}test
589ebfedea0SLionel Sambuc
590ebfedea0SLionel Sambucclean:
591ebfedea0SLionel Sambuc	\$(RM) \$(TMP_D)$o*.*
592ebfedea0SLionel Sambuc
593ebfedea0SLionel Sambucvclean:
594ebfedea0SLionel Sambuc	\$(RM) \$(TMP_D)$o*.*
595ebfedea0SLionel Sambuc	\$(RM) \$(OUT_D)$o*.*
596ebfedea0SLionel Sambuc
597ebfedea0SLionel SambucEOF
598ebfedea0SLionel Sambuc
599ebfedea0SLionel Sambucmy $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
600ebfedea0SLionel Sambuc$platform_cpp_symbol =~ s/-/_/g;
601ebfedea0SLionel Sambucif (open(IN,"crypto/buildinf.h"))
602ebfedea0SLionel Sambuc	{
603ebfedea0SLionel Sambuc	# Remove entry for this platform in existing file buildinf.h.
604ebfedea0SLionel Sambuc
605ebfedea0SLionel Sambuc	my $old_buildinf_h = "";
606ebfedea0SLionel Sambuc	while (<IN>)
607ebfedea0SLionel Sambuc		{
608ebfedea0SLionel Sambuc		if (/^\#ifdef $platform_cpp_symbol$/)
609ebfedea0SLionel Sambuc			{
610ebfedea0SLionel Sambuc			while (<IN>) { last if (/^\#endif/); }
611ebfedea0SLionel Sambuc			}
612ebfedea0SLionel Sambuc		else
613ebfedea0SLionel Sambuc			{
614ebfedea0SLionel Sambuc			$old_buildinf_h .= $_;
615ebfedea0SLionel Sambuc			}
616ebfedea0SLionel Sambuc		}
617ebfedea0SLionel Sambuc	close(IN);
618ebfedea0SLionel Sambuc
619ebfedea0SLionel Sambuc	open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
620ebfedea0SLionel Sambuc	print OUT $old_buildinf_h;
621ebfedea0SLionel Sambuc	close(OUT);
622ebfedea0SLionel Sambuc	}
623ebfedea0SLionel Sambuc
624ebfedea0SLionel Sambucopen (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
625ebfedea0SLionel Sambucprintf OUT <<EOF;
626ebfedea0SLionel Sambuc#ifdef $platform_cpp_symbol
627ebfedea0SLionel Sambuc  /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
628*0a6a1f1dSLionel Sambuc  #define CFLAGS "compiler: $cc $cflags"
629ebfedea0SLionel Sambuc  #define PLATFORM "$platform"
630ebfedea0SLionel SambucEOF
631ebfedea0SLionel Sambucprintf OUT "  #define DATE \"%s\"\n", scalar gmtime();
632ebfedea0SLionel Sambucprintf OUT "#endif\n";
633ebfedea0SLionel Sambucclose(OUT);
634ebfedea0SLionel Sambuc
635ebfedea0SLionel Sambuc# Strip of trailing ' '
636ebfedea0SLionel Sambucforeach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
637ebfedea0SLionel Sambuc$test=&clean_up_ws($test);
638ebfedea0SLionel Sambuc$e_exe=&clean_up_ws($e_exe);
639ebfedea0SLionel Sambuc$exheader=&clean_up_ws($exheader);
640ebfedea0SLionel Sambuc$header=&clean_up_ws($header);
641ebfedea0SLionel Sambuc
642ebfedea0SLionel Sambuc# First we strip the exheaders from the headers list
643ebfedea0SLionel Sambucforeach (split(/\s+/,$exheader)){ $h{$_}=1; }
644ebfedea0SLionel Sambucforeach (split(/\s+/,$header))	{ $h.=$_." " unless $h{$_}; }
645ebfedea0SLionel Sambucchop($h); $header=$h;
646ebfedea0SLionel Sambuc
647ebfedea0SLionel Sambuc$defs.=&do_defs("HEADER",$header,"\$(INCL_D)","");
648ebfedea0SLionel Sambuc$rules.=&do_copy_rule("\$(INCL_D)",$header,"");
649ebfedea0SLionel Sambuc
650ebfedea0SLionel Sambuc$defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)","");
651ebfedea0SLionel Sambuc$rules.=&do_copy_rule("\$(INCO_D)",$exheader,"");
652ebfedea0SLionel Sambuc
653ebfedea0SLionel Sambuc$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
654ebfedea0SLionel Sambuc$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
655ebfedea0SLionel Sambuc
656ebfedea0SLionel Sambuc$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
657ebfedea0SLionel Sambuc$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
658ebfedea0SLionel Sambuc
659ebfedea0SLionel Sambuc# Special case rule for fips_premain_dso
660ebfedea0SLionel Sambuc
661ebfedea0SLionel Sambucif ($fips)
662ebfedea0SLionel Sambuc	{
663ebfedea0SLionel Sambuc	$rules.=&cc_compile_target("\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj",
664ebfedea0SLionel Sambuc		"\$(FIPS_PREMAIN_SRC)",
665ebfedea0SLionel Sambuc		"-DFINGERPRINT_PREMAIN_DSO_LOAD \$(SHLIB_CFLAGS)", "");
666ebfedea0SLionel Sambuc	$rules.=&do_link_rule("\$(PREMAIN_DSO_EXE)","\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj \$(CRYPTOOBJ) \$(O_FIPSCANISTER)","","\$(EX_LIBS)", 1);
667ebfedea0SLionel Sambuc	}
668ebfedea0SLionel Sambuc
669ebfedea0SLionel Sambucforeach (values %lib_nam)
670ebfedea0SLionel Sambuc	{
671ebfedea0SLionel Sambuc	$lib_obj=$lib_obj{$_};
672ebfedea0SLionel Sambuc	local($slib)=$shlib;
673ebfedea0SLionel Sambuc
674ebfedea0SLionel Sambuc	$defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
675ebfedea0SLionel Sambuc	$lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
676ebfedea0SLionel Sambuc	$rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
677ebfedea0SLionel Sambuc	}
678ebfedea0SLionel Sambuc
679ebfedea0SLionel Sambuc# hack to add version info on MSVC
680ebfedea0SLionel Sambucif (($platform eq "VC-WIN32") || ($platform eq "VC-WIN64A")
681ebfedea0SLionel Sambuc	|| ($platform eq "VC-WIN64I") || ($platform eq "VC-NT")) {
682ebfedea0SLionel Sambuc    $rules.= <<"EOF";
683ebfedea0SLionel Sambuc\$(OBJ_D)\\\$(CRYPTO).res: ms\\version32.rc
684ebfedea0SLionel Sambuc	\$(RSC) /fo"\$(OBJ_D)\\\$(CRYPTO).res" /d CRYPTO ms\\version32.rc
685ebfedea0SLionel Sambuc
686ebfedea0SLionel Sambuc\$(OBJ_D)\\\$(SSL).res: ms\\version32.rc
687ebfedea0SLionel Sambuc	\$(RSC) /fo"\$(OBJ_D)\\\$(SSL).res" /d SSL ms\\version32.rc
688ebfedea0SLionel Sambuc
689ebfedea0SLionel SambucEOF
690ebfedea0SLionel Sambuc}
691ebfedea0SLionel Sambuc
692ebfedea0SLionel Sambuc$defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
693ebfedea0SLionel Sambucforeach (split(/\s+/,$test))
694ebfedea0SLionel Sambuc	{
695ebfedea0SLionel Sambuc	$t=&bname($_);
696ebfedea0SLionel Sambuc	$tt="\$(OBJ_D)${o}$t${obj}";
697ebfedea0SLionel Sambuc	$rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
698ebfedea0SLionel Sambuc	}
699ebfedea0SLionel Sambuc
700ebfedea0SLionel Sambuc$defs.=&do_defs("E_SHLIB",$engines . $otherlibs,"\$(ENG_D)",$shlibp);
701ebfedea0SLionel Sambuc
702ebfedea0SLionel Sambucforeach (split(/\s+/,$engines))
703ebfedea0SLionel Sambuc	{
704ebfedea0SLionel Sambuc	$rules.=&do_compile_rule("\$(OBJ_D)","engines${o}e_$_",$lib);
705ebfedea0SLionel Sambuc	$rules.= &do_lib_rule("\$(OBJ_D)${o}e_${_}.obj","\$(ENG_D)$o$_$shlibp","",$shlib,"");
706ebfedea0SLionel Sambuc	}
707ebfedea0SLionel Sambuc
708ebfedea0SLionel Sambuc
709ebfedea0SLionel Sambuc
710ebfedea0SLionel Sambuc$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
711ebfedea0SLionel Sambuc
712ebfedea0SLionel Sambucif ($fips)
713ebfedea0SLionel Sambuc	{
714ebfedea0SLionel Sambuc	if ($shlib)
715ebfedea0SLionel Sambuc		{
716ebfedea0SLionel Sambuc		$rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
717ebfedea0SLionel Sambuc				"\$(O_CRYPTO)", "$crypto",
718ebfedea0SLionel Sambuc				$shlib, "\$(SO_CRYPTO)", "\$(BASEADDR)");
719ebfedea0SLionel Sambuc		}
720ebfedea0SLionel Sambuc	else
721ebfedea0SLionel Sambuc		{
722ebfedea0SLionel Sambuc		$rules.= &do_lib_rule("\$(CRYPTOOBJ)",
723ebfedea0SLionel Sambuc			"\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)", "");
724ebfedea0SLionel Sambuc		$rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
725ebfedea0SLionel Sambuc			"\$(LIB_D)$o$crypto_compat",$crypto,$shlib,"\$(SO_CRYPTO)", "");
726ebfedea0SLionel Sambuc		}
727ebfedea0SLionel Sambuc	}
728ebfedea0SLionel Sambuc	else
729ebfedea0SLionel Sambuc	{
730ebfedea0SLionel Sambuc	$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
731ebfedea0SLionel Sambuc							"\$(SO_CRYPTO)");
732ebfedea0SLionel Sambuc	}
733ebfedea0SLionel Sambuc
734ebfedea0SLionel Sambucforeach (split(" ",$otherlibs))
735ebfedea0SLionel Sambuc	{
736ebfedea0SLionel Sambuc	my $uc = $_;
737ebfedea0SLionel Sambuc	$uc =~ tr /a-z/A-Z/;
738ebfedea0SLionel Sambuc	$rules.= &do_lib_rule("\$(${uc}OBJ)","\$(ENG_D)$o$_$shlibp", "", $shlib, "");
739ebfedea0SLionel Sambuc
740ebfedea0SLionel Sambuc	}
741ebfedea0SLionel Sambuc
742ebfedea0SLionel Sambuc$rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)", ($fips && !$shlib) ? 2 : 0);
743ebfedea0SLionel Sambuc
744ebfedea0SLionel Sambucprint $defs;
745ebfedea0SLionel Sambuc
746ebfedea0SLionel Sambucif ($platform eq "linux-elf") {
747ebfedea0SLionel Sambuc    print <<"EOF";
748ebfedea0SLionel Sambuc# Generate perlasm output files
749ebfedea0SLionel Sambuc%.cpp:
750ebfedea0SLionel Sambuc	(cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
751ebfedea0SLionel SambucEOF
752ebfedea0SLionel Sambuc}
753ebfedea0SLionel Sambucprint "###################################################################\n";
754ebfedea0SLionel Sambucprint $rules;
755ebfedea0SLionel Sambuc
756ebfedea0SLionel Sambuc###############################################
757ebfedea0SLionel Sambuc# strip off any trailing .[och] and append the relative directory
758ebfedea0SLionel Sambuc# also remembering to do nothing if we are in one of the dropped
759ebfedea0SLionel Sambuc# directories
760ebfedea0SLionel Sambucsub var_add
761ebfedea0SLionel Sambuc	{
762ebfedea0SLionel Sambuc	local($dir,$val,$keepext)=@_;
763ebfedea0SLionel Sambuc	local(@a,$_,$ret);
764ebfedea0SLionel Sambuc
765ebfedea0SLionel Sambuc	return("") if $no_engine && $dir =~ /\/engine/;
766ebfedea0SLionel Sambuc	return("") if $no_hw   && $dir =~ /\/hw/;
767ebfedea0SLionel Sambuc	return("") if $no_idea && $dir =~ /\/idea/;
768ebfedea0SLionel Sambuc	return("") if $no_aes  && $dir =~ /\/aes/;
769ebfedea0SLionel Sambuc	return("") if $no_camellia  && $dir =~ /\/camellia/;
770ebfedea0SLionel Sambuc	return("") if $no_seed && $dir =~ /\/seed/;
771ebfedea0SLionel Sambuc	return("") if $no_rc2  && $dir =~ /\/rc2/;
772ebfedea0SLionel Sambuc	return("") if $no_rc4  && $dir =~ /\/rc4/;
773ebfedea0SLionel Sambuc	return("") if $no_rc5  && $dir =~ /\/rc5/;
774ebfedea0SLionel Sambuc	return("") if $no_rsa  && $dir =~ /\/rsa/;
775ebfedea0SLionel Sambuc	return("") if $no_rsa  && $dir =~ /^rsaref/;
776ebfedea0SLionel Sambuc	return("") if $no_dsa  && $dir =~ /\/dsa/;
777ebfedea0SLionel Sambuc	return("") if $no_dh   && $dir =~ /\/dh/;
778ebfedea0SLionel Sambuc	return("") if $no_ec   && $dir =~ /\/ec/;
779ebfedea0SLionel Sambuc	return("") if $no_gost   && $dir =~ /\/ccgost/;
780ebfedea0SLionel Sambuc	return("") if $no_cms  && $dir =~ /\/cms/;
781ebfedea0SLionel Sambuc	return("") if $no_jpake  && $dir =~ /\/jpake/;
782ebfedea0SLionel Sambuc	if ($no_des && $dir =~ /\/des/)
783ebfedea0SLionel Sambuc		{
784ebfedea0SLionel Sambuc		if ($val =~ /read_pwd/)
785ebfedea0SLionel Sambuc			{ return("$dir/read_pwd "); }
786ebfedea0SLionel Sambuc		else
787ebfedea0SLionel Sambuc			{ return(""); }
788ebfedea0SLionel Sambuc		}
789ebfedea0SLionel Sambuc	return("") if $no_mdc2 && $dir =~ /\/mdc2/;
790ebfedea0SLionel Sambuc	return("") if $no_sock && $dir =~ /\/proxy/;
791ebfedea0SLionel Sambuc	return("") if $no_bf   && $dir =~ /\/bf/;
792ebfedea0SLionel Sambuc	return("") if $no_cast && $dir =~ /\/cast/;
793ebfedea0SLionel Sambuc	return("") if $no_whirlpool && $dir =~ /\/whrlpool/;
794ebfedea0SLionel Sambuc
795ebfedea0SLionel Sambuc	$val =~ s/^\s*(.*)\s*$/$1/;
796ebfedea0SLionel Sambuc	@a=split(/\s+/,$val);
797ebfedea0SLionel Sambuc	grep(s/\.[och]$//,@a) unless $keepext;
798ebfedea0SLionel Sambuc
799ebfedea0SLionel Sambuc	@a=grep(!/^e_.*_3d$/,@a) if $no_des;
800ebfedea0SLionel Sambuc	@a=grep(!/^e_.*_d$/,@a) if $no_des;
801ebfedea0SLionel Sambuc	@a=grep(!/^e_.*_ae$/,@a) if $no_idea;
802ebfedea0SLionel Sambuc	@a=grep(!/^e_.*_i$/,@a) if $no_aes;
803ebfedea0SLionel Sambuc	@a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
804ebfedea0SLionel Sambuc	@a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
805ebfedea0SLionel Sambuc	@a=grep(!/^e_.*_bf$/,@a) if $no_bf;
806ebfedea0SLionel Sambuc	@a=grep(!/^e_.*_c$/,@a) if $no_cast;
807ebfedea0SLionel Sambuc	@a=grep(!/^e_rc4$/,@a) if $no_rc4;
808ebfedea0SLionel Sambuc	@a=grep(!/^e_camellia$/,@a) if $no_camellia;
809ebfedea0SLionel Sambuc	@a=grep(!/^e_seed$/,@a) if $no_seed;
810ebfedea0SLionel Sambuc
811ebfedea0SLionel Sambuc	#@a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
812ebfedea0SLionel Sambuc	#@a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
813ebfedea0SLionel Sambuc
814ebfedea0SLionel Sambuc	@a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
815ebfedea0SLionel Sambuc
816ebfedea0SLionel Sambuc	@a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
817ebfedea0SLionel Sambuc	@a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
818ebfedea0SLionel Sambuc	@a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
819ebfedea0SLionel Sambuc	@a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
820ebfedea0SLionel Sambuc
821ebfedea0SLionel Sambuc	@a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
822ebfedea0SLionel Sambuc	@a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
823ebfedea0SLionel Sambuc	@a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
824ebfedea0SLionel Sambuc
825ebfedea0SLionel Sambuc	@a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
826ebfedea0SLionel Sambuc	@a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
827ebfedea0SLionel Sambuc
828ebfedea0SLionel Sambuc	@a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
829ebfedea0SLionel Sambuc
830ebfedea0SLionel Sambuc	@a=grep(!/_dhp$/,@a) if $no_dh;
831ebfedea0SLionel Sambuc
832ebfedea0SLionel Sambuc	@a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
833ebfedea0SLionel Sambuc	@a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
834ebfedea0SLionel Sambuc	@a=grep(!/_mdc2$/,@a) if $no_mdc2;
835ebfedea0SLionel Sambuc
836ebfedea0SLionel Sambuc	@a=grep(!/(srp)/,@a) if $no_srp;
837ebfedea0SLionel Sambuc
838ebfedea0SLionel Sambuc	@a=grep(!/^engine$/,@a) if $no_engine;
839ebfedea0SLionel Sambuc	@a=grep(!/^hw$/,@a) if $no_hw;
840ebfedea0SLionel Sambuc	@a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
841ebfedea0SLionel Sambuc	@a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
842ebfedea0SLionel Sambuc	@a=grep(!/^gendsa$/,@a) if $no_sha1;
843ebfedea0SLionel Sambuc	@a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
844ebfedea0SLionel Sambuc
845ebfedea0SLionel Sambuc	@a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
846ebfedea0SLionel Sambuc
847ebfedea0SLionel Sambuc	grep($_="$dir/$_",@a);
848ebfedea0SLionel Sambuc	@a=grep(!/(^|\/)s_/,@a) if $no_sock;
849ebfedea0SLionel Sambuc	@a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
850ebfedea0SLionel Sambuc	$ret=join(' ',@a)." ";
851ebfedea0SLionel Sambuc	return($ret);
852ebfedea0SLionel Sambuc	}
853ebfedea0SLionel Sambuc
854ebfedea0SLionel Sambuc# change things so that each 'token' is only separated by one space
855ebfedea0SLionel Sambucsub clean_up_ws
856ebfedea0SLionel Sambuc	{
857ebfedea0SLionel Sambuc	local($w)=@_;
858ebfedea0SLionel Sambuc
859ebfedea0SLionel Sambuc	$w =~ s/^\s*(.*)\s*$/$1/;
860ebfedea0SLionel Sambuc	$w =~ s/\s+/ /g;
861ebfedea0SLionel Sambuc	return($w);
862ebfedea0SLionel Sambuc	}
863ebfedea0SLionel Sambuc
864ebfedea0SLionel Sambucsub do_defs
865ebfedea0SLionel Sambuc	{
866ebfedea0SLionel Sambuc	local($var,$files,$location,$postfix)=@_;
867ebfedea0SLionel Sambuc	local($_,$ret,$pf);
868ebfedea0SLionel Sambuc	local(*OUT,$tmp,$t);
869ebfedea0SLionel Sambuc
870ebfedea0SLionel Sambuc	$files =~ s/\//$o/g if $o ne '/';
871ebfedea0SLionel Sambuc	$ret="$var=";
872ebfedea0SLionel Sambuc	$n=1;
873ebfedea0SLionel Sambuc	$Vars{$var}.="";
874ebfedea0SLionel Sambuc	foreach (split(/ /,$files))
875ebfedea0SLionel Sambuc		{
876ebfedea0SLionel Sambuc		$orig=$_;
877ebfedea0SLionel Sambuc		$_=&bname($_) unless /^\$/;
878ebfedea0SLionel Sambuc		if ($n++ == 2)
879ebfedea0SLionel Sambuc			{
880ebfedea0SLionel Sambuc			$n=0;
881ebfedea0SLionel Sambuc			$ret.="\\\n\t";
882ebfedea0SLionel Sambuc			}
883ebfedea0SLionel Sambuc		if (($_ =~ /bss_file/) && ($postfix eq ".h"))
884ebfedea0SLionel Sambuc			{ $pf=".c"; }
885ebfedea0SLionel Sambuc		else	{ $pf=$postfix; }
886ebfedea0SLionel Sambuc		if ($_ =~ /BN_ASM/)	{ $t="$_ "; }
887ebfedea0SLionel Sambuc		elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
888ebfedea0SLionel Sambuc		elsif ($_ =~ /AES_ASM/){ $t="$_ "; }
889ebfedea0SLionel Sambuc		elsif ($_ =~ /DES_ENC/)	{ $t="$_ "; }
890ebfedea0SLionel Sambuc		elsif ($_ =~ /BF_ENC/)	{ $t="$_ "; }
891ebfedea0SLionel Sambuc		elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
892ebfedea0SLionel Sambuc		elsif ($_ =~ /RC4_ENC/)	{ $t="$_ "; }
893ebfedea0SLionel Sambuc		elsif ($_ =~ /RC5_ENC/)	{ $t="$_ "; }
894ebfedea0SLionel Sambuc		elsif ($_ =~ /MD5_ASM/)	{ $t="$_ "; }
895ebfedea0SLionel Sambuc		elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
896ebfedea0SLionel Sambuc		elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
897ebfedea0SLionel Sambuc		elsif ($_ =~ /WHIRLPOOL_ASM/){ $t="$_ "; }
898ebfedea0SLionel Sambuc		elsif ($_ =~ /CPUID_ASM/){ $t="$_ "; }
899ebfedea0SLionel Sambuc		else	{ $t="$location${o}$_$pf "; }
900ebfedea0SLionel Sambuc
901ebfedea0SLionel Sambuc		$Vars{$var}.="$t ";
902ebfedea0SLionel Sambuc		$ret.=$t;
903ebfedea0SLionel Sambuc		}
904ebfedea0SLionel Sambuc	# hack to add version info on MSVC
905ebfedea0SLionel Sambuc	if ($shlib && (($platform eq "VC-WIN32") || ($platfrom eq "VC-WIN64I") || ($platform eq "VC-WIN64A") || ($platform eq "VC-NT")))
906ebfedea0SLionel Sambuc		{
907ebfedea0SLionel Sambuc		if ($var eq "CRYPTOOBJ")
908ebfedea0SLionel Sambuc			{ $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
909ebfedea0SLionel Sambuc		elsif ($var eq "SSLOBJ")
910ebfedea0SLionel Sambuc			{ $ret.="\$(OBJ_D)\\\$(SSL).res "; }
911ebfedea0SLionel Sambuc		}
912ebfedea0SLionel Sambuc	chomp($ret);
913ebfedea0SLionel Sambuc	$ret.="\n\n";
914ebfedea0SLionel Sambuc	return($ret);
915ebfedea0SLionel Sambuc	}
916ebfedea0SLionel Sambuc
917ebfedea0SLionel Sambuc# return the name with the leading path removed
918ebfedea0SLionel Sambucsub bname
919ebfedea0SLionel Sambuc	{
920ebfedea0SLionel Sambuc	local($ret)=@_;
921ebfedea0SLionel Sambuc	$ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
922ebfedea0SLionel Sambuc	return($ret);
923ebfedea0SLionel Sambuc	}
924ebfedea0SLionel Sambuc
925ebfedea0SLionel Sambuc# return the leading path
926ebfedea0SLionel Sambucsub dname
927ebfedea0SLionel Sambuc	{
928ebfedea0SLionel Sambuc	my $ret=shift;
929ebfedea0SLionel Sambuc	$ret =~ s/(^.*)[\\\/][^\\\/]+$/$1/;
930ebfedea0SLionel Sambuc	return($ret);
931ebfedea0SLionel Sambuc	}
932ebfedea0SLionel Sambuc
933ebfedea0SLionel Sambuc##############################################################
934ebfedea0SLionel Sambuc# do a rule for each file that says 'compile' to new direcory
935ebfedea0SLionel Sambuc# compile the files in '$files' into $to
936ebfedea0SLionel Sambucsub do_compile_rule
937ebfedea0SLionel Sambuc	{
938ebfedea0SLionel Sambuc	local($to,$files,$ex)=@_;
939ebfedea0SLionel Sambuc	local($ret,$_,$n,$d,$s);
940ebfedea0SLionel Sambuc
941ebfedea0SLionel Sambuc	$files =~ s/\//$o/g if $o ne '/';
942ebfedea0SLionel Sambuc	foreach (split(/\s+/,$files))
943ebfedea0SLionel Sambuc		{
944ebfedea0SLionel Sambuc		$n=&bname($_);
945ebfedea0SLionel Sambuc		$d=&dname($_);
946ebfedea0SLionel Sambuc		if (-f "${_}.c")
947ebfedea0SLionel Sambuc			{
948ebfedea0SLionel Sambuc			$ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
949ebfedea0SLionel Sambuc			}
950ebfedea0SLionel Sambuc		elsif (-f ($s="${d}${o}asm${o}${n}.pl") or
951ebfedea0SLionel Sambuc		       ($s=~s/sha256/sha512/ and -f $s) or
952ebfedea0SLionel Sambuc		       -f ($s="${d}${o}${n}.pl"))
953ebfedea0SLionel Sambuc			{
954ebfedea0SLionel Sambuc			$ret.=&perlasm_compile_target("$to${o}$n$obj",$s,$n);
955ebfedea0SLionel Sambuc			}
956ebfedea0SLionel Sambuc		elsif (-f ($s="${d}${o}asm${o}${n}.S") or
957ebfedea0SLionel Sambuc		       -f ($s="${d}${o}${n}.S"))
958ebfedea0SLionel Sambuc			{
959ebfedea0SLionel Sambuc			$ret.=&Sasm_compile_target("$to${o}$n$obj",$s,$n);
960ebfedea0SLionel Sambuc			}
961ebfedea0SLionel Sambuc		else	{ die "no rule for $_"; }
962ebfedea0SLionel Sambuc		}
963ebfedea0SLionel Sambuc	return($ret);
964ebfedea0SLionel Sambuc	}
965ebfedea0SLionel Sambuc
966ebfedea0SLionel Sambuc##############################################################
967ebfedea0SLionel Sambuc# do a rule for each file that says 'compile' to new direcory
968ebfedea0SLionel Sambucsub perlasm_compile_target
969ebfedea0SLionel Sambuc	{
970ebfedea0SLionel Sambuc	my($target,$source,$bname)=@_;
971ebfedea0SLionel Sambuc	my($ret);
972ebfedea0SLionel Sambuc
973ebfedea0SLionel Sambuc	$bname =~ s/(.*)\.[^\.]$/$1/;
974ebfedea0SLionel Sambuc	$ret ="\$(TMP_D)$o$bname.asm: $source\n";
975ebfedea0SLionel Sambuc	$ret.="\t\$(PERL) $source $asmtype \$(CFLAG) >\$\@\n\n";
976ebfedea0SLionel Sambuc	$ret.="$target: \$(TMP_D)$o$bname.asm\n";
977ebfedea0SLionel Sambuc	$ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
978ebfedea0SLionel Sambuc	return($ret);
979ebfedea0SLionel Sambuc	}
980ebfedea0SLionel Sambuc
981ebfedea0SLionel Sambucsub Sasm_compile_target
982ebfedea0SLionel Sambuc	{
983ebfedea0SLionel Sambuc	my($target,$source,$bname)=@_;
984ebfedea0SLionel Sambuc	my($ret);
985ebfedea0SLionel Sambuc
986ebfedea0SLionel Sambuc	$bname =~ s/(.*)\.[^\.]$/$1/;
987ebfedea0SLionel Sambuc	$ret ="\$(TMP_D)$o$bname.asm: $source\n";
988ebfedea0SLionel Sambuc	$ret.="\t\$(CC) -E \$(CFLAG) $source >\$\@\n\n";
989ebfedea0SLionel Sambuc	$ret.="$target: \$(TMP_D)$o$bname.asm\n";
990ebfedea0SLionel Sambuc	$ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
991ebfedea0SLionel Sambuc	return($ret);
992ebfedea0SLionel Sambuc	}
993ebfedea0SLionel Sambuc
994ebfedea0SLionel Sambucsub cc_compile_target
995ebfedea0SLionel Sambuc	{
996ebfedea0SLionel Sambuc	local($target,$source,$ex_flags, $srcd)=@_;
997ebfedea0SLionel Sambuc	local($ret);
998ebfedea0SLionel Sambuc
999ebfedea0SLionel Sambuc	$ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
1000ebfedea0SLionel Sambuc	$target =~ s/\//$o/g if $o ne "/";
1001ebfedea0SLionel Sambuc	$source =~ s/\//$o/g if $o ne "/";
1002ebfedea0SLionel Sambuc	$srcd = "\$(SRC_D)$o" unless defined $srcd;
1003ebfedea0SLionel Sambuc	$ret ="$target: $srcd$source\n\t";
1004ebfedea0SLionel Sambuc	$ret.="\$(CC) ${ofile}$target $ex_flags -c $srcd$source\n\n";
1005ebfedea0SLionel Sambuc	return($ret);
1006ebfedea0SLionel Sambuc	}
1007ebfedea0SLionel Sambuc
1008ebfedea0SLionel Sambuc##############################################################
1009ebfedea0SLionel Sambucsub do_asm_rule
1010ebfedea0SLionel Sambuc	{
1011ebfedea0SLionel Sambuc	local($target,$src)=@_;
1012ebfedea0SLionel Sambuc	local($ret,@s,@t,$i);
1013ebfedea0SLionel Sambuc
1014ebfedea0SLionel Sambuc	$target =~ s/\//$o/g if $o ne "/";
1015ebfedea0SLionel Sambuc	$src =~ s/\//$o/g if $o ne "/";
1016ebfedea0SLionel Sambuc
1017ebfedea0SLionel Sambuc	@t=split(/\s+/,$target);
1018ebfedea0SLionel Sambuc	@s=split(/\s+/,$src);
1019ebfedea0SLionel Sambuc
1020ebfedea0SLionel Sambuc
1021ebfedea0SLionel Sambuc	for ($i=0; $i<=$#s; $i++)
1022ebfedea0SLionel Sambuc		{
1023ebfedea0SLionel Sambuc		my $objfile = $t[$i];
1024ebfedea0SLionel Sambuc		my $srcfile = $s[$i];
1025ebfedea0SLionel Sambuc
1026ebfedea0SLionel Sambuc		if ($perl_asm == 1)
1027ebfedea0SLionel Sambuc			{
1028ebfedea0SLionel Sambuc			my $plasm = $objfile;
1029ebfedea0SLionel Sambuc			$plasm =~ s/${obj}/.pl/;
1030ebfedea0SLionel Sambuc			$ret.="$srcfile: $plasm\n";
1031ebfedea0SLionel Sambuc			$ret.="\t\$(PERL) $plasm $asmtype \$(CFLAG) >$srcfile\n\n";
1032ebfedea0SLionel Sambuc			}
1033ebfedea0SLionel Sambuc
1034ebfedea0SLionel Sambuc		$ret.="$objfile: $srcfile\n";
1035ebfedea0SLionel Sambuc		$ret.="\t\$(ASM) $afile$objfile \$(SRC_D)$o$srcfile\n\n";
1036ebfedea0SLionel Sambuc		}
1037ebfedea0SLionel Sambuc	return($ret);
1038ebfedea0SLionel Sambuc	}
1039ebfedea0SLionel Sambuc
1040ebfedea0SLionel Sambucsub do_shlib_rule
1041ebfedea0SLionel Sambuc	{
1042ebfedea0SLionel Sambuc	local($n,$def)=@_;
1043ebfedea0SLionel Sambuc	local($ret,$nn);
1044ebfedea0SLionel Sambuc	local($t);
1045ebfedea0SLionel Sambuc
1046ebfedea0SLionel Sambuc	($nn=$n) =~ tr/a-z/A-Z/;
1047ebfedea0SLionel Sambuc	$ret.="$n.dll: \$(${nn}OBJ)\n";
1048ebfedea0SLionel Sambuc	if ($vc && $w32)
1049ebfedea0SLionel Sambuc		{
1050ebfedea0SLionel Sambuc		$ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n  \$(${nn}OBJ_F)\n<<\n";
1051ebfedea0SLionel Sambuc		}
1052ebfedea0SLionel Sambuc	$ret.="\n";
1053ebfedea0SLionel Sambuc	return($ret);
1054ebfedea0SLionel Sambuc	}
1055ebfedea0SLionel Sambuc
1056ebfedea0SLionel Sambuc# do a rule for each file that says 'copy' to new direcory on change
1057ebfedea0SLionel Sambucsub do_copy_rule
1058ebfedea0SLionel Sambuc	{
1059ebfedea0SLionel Sambuc	local($to,$files,$p)=@_;
1060ebfedea0SLionel Sambuc	local($ret,$_,$n,$pp);
1061ebfedea0SLionel Sambuc
1062ebfedea0SLionel Sambuc	$files =~ s/\//$o/g if $o ne '/';
1063ebfedea0SLionel Sambuc	foreach (split(/\s+/,$files))
1064ebfedea0SLionel Sambuc		{
1065ebfedea0SLionel Sambuc		$n=&bname($_);
1066ebfedea0SLionel Sambuc		if ($n =~ /bss_file/)
1067ebfedea0SLionel Sambuc			{ $pp=".c"; }
1068ebfedea0SLionel Sambuc		else	{ $pp=$p; }
1069ebfedea0SLionel Sambuc		$ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
1070ebfedea0SLionel Sambuc		}
1071ebfedea0SLionel Sambuc	return($ret);
1072ebfedea0SLionel Sambuc	}
1073ebfedea0SLionel Sambuc
1074*0a6a1f1dSLionel Sambuc# Options picked up from the OPTIONS line in the top level Makefile
1075*0a6a1f1dSLionel Sambuc# generated by Configure.
1076*0a6a1f1dSLionel Sambuc
1077ebfedea0SLionel Sambucsub read_options
1078ebfedea0SLionel Sambuc	{
1079ebfedea0SLionel Sambuc	# Many options are handled in a similar way. In particular
1080ebfedea0SLionel Sambuc	# no-xxx sets zero or more scalars to 1.
1081*0a6a1f1dSLionel Sambuc	# Process these using the %valid_options hash containing the option
1082*0a6a1f1dSLionel Sambuc	# name and reference to the scalars to set. In some cases the option
1083*0a6a1f1dSLionel Sambuc	# needs no special handling and can be ignored: this is done by
1084*0a6a1f1dSLionel Sambuc	# setting the value to 0.
1085ebfedea0SLionel Sambuc
1086ebfedea0SLionel Sambuc	my %valid_options = (
1087ebfedea0SLionel Sambuc		"no-rc2" => \$no_rc2,
1088ebfedea0SLionel Sambuc		"no-rc4" => \$no_rc4,
1089ebfedea0SLionel Sambuc		"no-rc5" => \$no_rc5,
1090ebfedea0SLionel Sambuc		"no-idea" => \$no_idea,
1091ebfedea0SLionel Sambuc		"no-aes" => \$no_aes,
1092ebfedea0SLionel Sambuc		"no-camellia" => \$no_camellia,
1093ebfedea0SLionel Sambuc		"no-seed" => \$no_seed,
1094ebfedea0SLionel Sambuc		"no-des" => \$no_des,
1095ebfedea0SLionel Sambuc		"no-bf" => \$no_bf,
1096ebfedea0SLionel Sambuc		"no-cast" => \$no_cast,
1097ebfedea0SLionel Sambuc		"no-md2" => \$no_md2,
1098ebfedea0SLionel Sambuc		"no-md4" => \$no_md4,
1099ebfedea0SLionel Sambuc		"no-md5" => \$no_md5,
1100ebfedea0SLionel Sambuc		"no-sha" => \$no_sha,
1101ebfedea0SLionel Sambuc		"no-sha1" => \$no_sha1,
1102ebfedea0SLionel Sambuc		"no-ripemd" => \$no_ripemd,
1103ebfedea0SLionel Sambuc		"no-mdc2" => \$no_mdc2,
1104ebfedea0SLionel Sambuc		"no-whirlpool" => \$no_whirlpool,
1105ebfedea0SLionel Sambuc		"no-patents" =>
1106ebfedea0SLionel Sambuc			[\$no_rc2, \$no_rc4, \$no_rc5, \$no_idea, \$no_rsa],
1107ebfedea0SLionel Sambuc		"no-rsa" => \$no_rsa,
1108ebfedea0SLionel Sambuc		"no-dsa" => \$no_dsa,
1109ebfedea0SLionel Sambuc		"no-dh" => \$no_dh,
1110ebfedea0SLionel Sambuc		"no-hmac" => \$no_hmac,
1111ebfedea0SLionel Sambuc		"no-asm" => \$no_asm,
1112ebfedea0SLionel Sambuc		"nasm" => \$nasm,
1113ebfedea0SLionel Sambuc		"nw-nasm" => \$nw_nasm,
1114ebfedea0SLionel Sambuc		"nw-mwasm" => \$nw_mwasm,
1115ebfedea0SLionel Sambuc		"gaswin" => \$gaswin,
1116ebfedea0SLionel Sambuc		"no-ssl2" => \$no_ssl2,
1117ebfedea0SLionel Sambuc		"no-ssl3" => \$no_ssl3,
1118*0a6a1f1dSLionel Sambuc		"no-ssl3-method" => 0,
1119ebfedea0SLionel Sambuc		"no-tlsext" => \$no_tlsext,
1120ebfedea0SLionel Sambuc		"no-srp" => \$no_srp,
1121ebfedea0SLionel Sambuc		"no-cms" => \$no_cms,
1122ebfedea0SLionel Sambuc		"no-ec2m" => \$no_ec2m,
1123ebfedea0SLionel Sambuc		"no-jpake" => \$no_jpake,
1124ebfedea0SLionel Sambuc		"no-ec_nistp_64_gcc_128" => 0,
1125ebfedea0SLionel Sambuc		"no-err" => \$no_err,
1126ebfedea0SLionel Sambuc		"no-sock" => \$no_sock,
1127ebfedea0SLionel Sambuc		"no-krb5" => \$no_krb5,
1128ebfedea0SLionel Sambuc		"no-ec" => \$no_ec,
1129ebfedea0SLionel Sambuc		"no-ecdsa" => \$no_ecdsa,
1130ebfedea0SLionel Sambuc		"no-ecdh" => \$no_ecdh,
1131ebfedea0SLionel Sambuc		"no-gost" => \$no_gost,
1132ebfedea0SLionel Sambuc		"no-engine" => \$no_engine,
1133ebfedea0SLionel Sambuc		"no-hw" => \$no_hw,
1134ebfedea0SLionel Sambuc		"no-rsax" => 0,
1135ebfedea0SLionel Sambuc		"just-ssl" =>
1136ebfedea0SLionel Sambuc			[\$no_rc2, \$no_idea, \$no_des, \$no_bf, \$no_cast,
1137ebfedea0SLionel Sambuc			  \$no_md2, \$no_sha, \$no_mdc2, \$no_dsa, \$no_dh,
1138ebfedea0SLionel Sambuc			  \$no_ssl2, \$no_err, \$no_ripemd, \$no_rc5,
1139ebfedea0SLionel Sambuc			  \$no_aes, \$no_camellia, \$no_seed, \$no_srp],
1140ebfedea0SLionel Sambuc		"rsaref" => 0,
1141ebfedea0SLionel Sambuc		"gcc" => \$gcc,
1142ebfedea0SLionel Sambuc		"debug" => \$debug,
1143ebfedea0SLionel Sambuc		"profile" => \$profile,
1144ebfedea0SLionel Sambuc		"shlib" => \$shlib,
1145ebfedea0SLionel Sambuc		"dll" => \$shlib,
1146ebfedea0SLionel Sambuc		"shared" => 0,
1147ebfedea0SLionel Sambuc		"no-sctp" => 0,
1148*0a6a1f1dSLionel Sambuc		"no-srtp" => 0,
1149ebfedea0SLionel Sambuc		"no-gmp" => 0,
1150ebfedea0SLionel Sambuc		"no-rfc3779" => 0,
1151ebfedea0SLionel Sambuc		"no-montasm" => 0,
1152ebfedea0SLionel Sambuc		"no-shared" => 0,
1153ebfedea0SLionel Sambuc		"no-store" => 0,
1154*0a6a1f1dSLionel Sambuc		"no-unit-test" => 0,
1155ebfedea0SLionel Sambuc		"no-zlib" => 0,
1156ebfedea0SLionel Sambuc		"no-zlib-dynamic" => 0,
1157ebfedea0SLionel Sambuc		"fips" => \$fips
1158ebfedea0SLionel Sambuc		);
1159ebfedea0SLionel Sambuc
1160ebfedea0SLionel Sambuc	if (exists $valid_options{$_})
1161ebfedea0SLionel Sambuc		{
1162ebfedea0SLionel Sambuc		my $r = $valid_options{$_};
1163ebfedea0SLionel Sambuc		if ( ref $r eq "SCALAR")
1164ebfedea0SLionel Sambuc			{ $$r = 1;}
1165ebfedea0SLionel Sambuc		elsif ( ref $r eq "ARRAY")
1166ebfedea0SLionel Sambuc			{
1167ebfedea0SLionel Sambuc			my $r2;
1168ebfedea0SLionel Sambuc			foreach $r2 (@$r)
1169ebfedea0SLionel Sambuc				{
1170ebfedea0SLionel Sambuc				$$r2 = 1;
1171ebfedea0SLionel Sambuc				}
1172ebfedea0SLionel Sambuc			}
1173ebfedea0SLionel Sambuc		}
1174ebfedea0SLionel Sambuc	elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; }
1175ebfedea0SLionel Sambuc	elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
1176ebfedea0SLionel Sambuc	elsif (/^enable-zlib-dynamic$/)
1177ebfedea0SLionel Sambuc		{
1178ebfedea0SLionel Sambuc		$zlib_opt = 2;
1179ebfedea0SLionel Sambuc		}
1180ebfedea0SLionel Sambuc	elsif (/^no-static-engine/)
1181ebfedea0SLionel Sambuc		{
1182ebfedea0SLionel Sambuc		$no_static_engine = 1;
1183ebfedea0SLionel Sambuc		}
1184ebfedea0SLionel Sambuc	elsif (/^enable-static-engine/)
1185ebfedea0SLionel Sambuc		{
1186ebfedea0SLionel Sambuc		$no_static_engine = 0;
1187ebfedea0SLionel Sambuc		}
1188ebfedea0SLionel Sambuc	# There are also enable-xxx options which correspond to
1189ebfedea0SLionel Sambuc	# the no-xxx. Since the scalars are enabled by default
1190ebfedea0SLionel Sambuc	# these can be ignored.
1191ebfedea0SLionel Sambuc	elsif (/^enable-/)
1192ebfedea0SLionel Sambuc		{
1193ebfedea0SLionel Sambuc		my $t = $_;
1194ebfedea0SLionel Sambuc		$t =~ s/^enable/no/;
1195ebfedea0SLionel Sambuc		if (exists $valid_options{$t})
1196ebfedea0SLionel Sambuc			{return 1;}
1197ebfedea0SLionel Sambuc		return 0;
1198ebfedea0SLionel Sambuc		}
1199ebfedea0SLionel Sambuc	# experimental-xxx is mostly like enable-xxx, but opensslconf.v
1200ebfedea0SLionel Sambuc	# will still set OPENSSL_NO_xxx unless we set OPENSSL_EXPERIMENTAL_xxx.
1201ebfedea0SLionel Sambuc	# (No need to fail if we don't know the algorithm -- this is for adventurous users only.)
1202ebfedea0SLionel Sambuc	elsif (/^experimental-/)
1203ebfedea0SLionel Sambuc		{
1204ebfedea0SLionel Sambuc		my $algo, $ALGO;
1205ebfedea0SLionel Sambuc		($algo = $_) =~ s/^experimental-//;
1206ebfedea0SLionel Sambuc		($ALGO = $algo) =~ tr/[a-z]/[A-Z]/;
1207ebfedea0SLionel Sambuc
1208ebfedea0SLionel Sambuc		$xcflags="-DOPENSSL_EXPERIMENTAL_$ALGO $xcflags";
1209ebfedea0SLionel Sambuc
1210ebfedea0SLionel Sambuc		}
1211ebfedea0SLionel Sambuc	elsif (/^--with-krb5-flavor=(.*)$/)
1212ebfedea0SLionel Sambuc		{
1213ebfedea0SLionel Sambuc		my $krb5_flavor = $1;
1214ebfedea0SLionel Sambuc		if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
1215ebfedea0SLionel Sambuc			{
1216ebfedea0SLionel Sambuc			$xcflags="-DKRB5_HEIMDAL $xcflags";
1217ebfedea0SLionel Sambuc			}
1218ebfedea0SLionel Sambuc		elsif ($krb5_flavor =~ /^MIT/i)
1219ebfedea0SLionel Sambuc			{
1220ebfedea0SLionel Sambuc			$xcflags="-DKRB5_MIT $xcflags";
1221ebfedea0SLionel Sambuc		 	if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
1222ebfedea0SLionel Sambuc				{
1223ebfedea0SLionel Sambuc				$xcflags="-DKRB5_MIT_OLD11 $xcflags"
1224ebfedea0SLionel Sambuc				}
1225ebfedea0SLionel Sambuc			}
1226ebfedea0SLionel Sambuc		}
1227ebfedea0SLionel Sambuc	elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1228ebfedea0SLionel Sambuc	elsif (/^-[lL].*$/)	{ $l_flags.="$_ "; }
1229ebfedea0SLionel Sambuc	elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
1230ebfedea0SLionel Sambuc		{ $c_flags.="$_ "; }
1231ebfedea0SLionel Sambuc	else { return(0); }
1232ebfedea0SLionel Sambuc	return(1);
1233ebfedea0SLionel Sambuc	}
1234