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