]> git.ipfire.org Git - thirdparty/openssl.git/blame - util/mk1mf.pl
Fix some issues near recent chomp changes.
[thirdparty/openssl.git] / util / mk1mf.pl
CommitLineData
63116812 1#!/usr/bin/env perl
d02b48c6
RE
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
3b4d86bf
BL
5# funny stuff (if the target is not "copy").
6# If the target is "copy", then it tries to create a makefile that can be
7# safely used with the -j flag and that is compatible with the top-level
8# Makefile, in the sense that it uses the same options and assembler files etc.
9
10use Cwd;
d02b48c6 11
d74dfafd 12$INSTALLTOP="/usr/local";
b8bb15fb 13$OPENSSLDIR="/usr/local/ssl";
e09621ff 14$ENGINESDIR="/usr/local/lib/engines";
31ff97b2
UM
15$OPTIONS="";
16$ssl_version="";
eff5f612 17$banner="\t\@echo Building OpenSSL";
d02b48c6 18
f858d222 19my $no_static_engine = 1;
fbf002bb 20my $engines = "";
2b1f17f8 21my @engines_obj = "";
223c59ea 22my $otherlibs = "";
ad2695b1
DSH
23local $zlib_opt = 0; # 0 = no zlib, 1 = static, 2 = dynamic
24local $zlib_lib = "";
73980531
DSH
25local $perl_asm = 0; # 1 to autobuild asm files from perl scripts
26
06b433ac
DSH
27local $fips_canister_path = "";
28my $fips_premain_dso_exe_path = "";
29my $fips_premain_c_path = "";
30my $fips_sha1_exe_path = "";
31
32local $fipscanisterbuild = 0;
33
d989e4f8
DSH
34my $fipscanisteronly = 0;
35
06b433ac
DSH
36my $fipslibdir = "";
37my $baseaddr = "";
38
39my $ex_l_libs = "";
40
d989e4f8
DSH
41my $build_targets = "lib exe";
42my $libs_dep = "\$(O_CRYPTO) \$(O_SSL)";
43
73980531
DSH
44# Options to import from top level Makefile
45
46my %mf_import = (
47 VERSION => \$ssl_version,
48 OPTIONS => \$OPTIONS,
49 INSTALLTOP => \$INSTALLTOP,
50 OPENSSLDIR => \$OPENSSLDIR,
e09621ff 51 ENGINESDIR => \$ENGINESDIR,
73980531 52 PLATFORM => \$mf_platform,
5108690f 53 CC => \$mf_cc,
73980531 54 CFLAG => \$mf_cflag,
f4a748a1 55 CFLAG_Q => \$mf_cflag_q,
ced2c2c5 56 DEPFLAG => \$mf_depflag,
73980531
DSH
57 CPUID_OBJ => \$mf_cpuid_asm,
58 BN_ASM => \$mf_bn_asm,
59 DES_ENC => \$mf_des_asm,
60 AES_ENC => \$mf_aes_asm,
61 BF_ENC => \$mf_bf_asm,
62 CAST_ENC => \$mf_cast_asm,
63 RC4_ENC => \$mf_rc4_asm,
64 RC5_ENC => \$mf_rc5_asm,
65 MD5_ASM_OBJ => \$mf_md5_asm,
66 SHA1_ASM_OBJ => \$mf_sha_asm,
67 RMD160_ASM_OBJ => \$mf_rmd_asm,
68 WP_ASM_OBJ => \$mf_wp_asm,
dc527a62 69 CMLL_ENC => \$mf_cm_asm,
e161120e 70 MODES_ASM_OBJ => \$mf_modes_asm,
656829b7 71 ENGINES_ASM_OBJ=> \$mf_engines_asm,
5444b11b 72 PERLASM_SCHEME => \$mf_perlasm_scheme,
cb551bfa 73 FIPSCANISTERONLY => \$mf_fipscanisteronly,
71614df4
BL
74 FIPSCANISTERINTERNAL => \$mf_fipscanisterinternal,
75 EC_ASM => \$mf_ec_asm,
73980531 76);
fbf002bb 77
f68854b4 78open(IN,"<Makefile") || die "unable to open Makefile!\n";
31ff97b2 79while(<IN>) {
73980531
DSH
80 my ($mf_opt, $mf_ref);
81 while (($mf_opt, $mf_ref) = each %mf_import) {
7bbb8c56 82 if (/^$mf_opt\s*=\s*(.*)$/ && !defined($$mfref)) {
73980531
DSH
83 $$mf_ref = $1;
84 }
85 }
31ff97b2 86}
ce457a54 87close(IN);
31ff97b2 88
ce025892 89if ($mf_fipscanisterinternal eq "y") {
e161120e
DSH
90 $fips = 1;
91 $fipscanisterbuild = 1;
92 $fipscanisteronly = 1;
93}
94
95
a7a90b2f 96die "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
58964a49 97
d02b48c6
RE
98$infile="MINFO";
99
100%ops=(
06c68491 101 "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X",
1875e6db
AP
102 "VC-WIN64I", "Microsoft C/C++ - Win64/IA-64",
103 "VC-WIN64A", "Microsoft C/C++ - Win64/x64",
0bf23d9b 104 "VC-CE", "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
06c68491 105 "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY",
31a674d8 106 "Mingw32", "GNU C++ - Windows NT or 9x",
12d7d32f 107 "Mingw32-files", "Create files with DOS copy ...",
31a674d8 108 "BC-NT", "Borland C++ 4.5 - Windows NT",
58964a49 109 "linux-elf","Linux elf",
dfeab068 110 "ultrix-mips","DEC mips ultrix",
d02b48c6 111 "FreeBSD","FreeBSD distribution",
dc01b6b1 112 "OS2-EMX", "EMX GCC OS/2",
b764ab95 113 "netware-clib", "CodeWarrior for NetWare - CLib - with WinSock Sockets",
eef0c1f3 114 "netware-clib-bsdsock", "CodeWarrior for NetWare - CLib - with BSD Sockets",
b764ab95
RL
115 "netware-libc", "CodeWarrior for NetWare - LibC - with WinSock Sockets",
116 "netware-libc-bsdsock", "CodeWarrior for NetWare - LibC - with BSD Sockets",
d02b48c6 117 "default","cc under unix",
d0aeeee1
BL
118 "auto", "auto detect from top level Makefile",
119 "copy", "copy from top level Makefile"
d02b48c6
RE
120 );
121
dfeab068 122$platform="";
6bc8e6b8 123my $xcflags="";
d02b48c6
RE
124foreach (@ARGV)
125 {
31ff97b2 126 if (!&read_options && !defined($ops{$_}))
d02b48c6 127 {
31ff97b2 128 print STDERR "unknown option - $_\n";
748365ee 129 print STDERR "usage: perl mk1mf.pl [options] [system]\n";
31ff97b2
UM
130 print STDERR "\nwhere [system] can be one of the following\n";
131 foreach $i (sort keys %ops)
132 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
133 print STDERR <<"EOF";
d02b48c6 134and [options] can be one of
3009458e
RL
135 no-md2 no-md4 no-md5 no-sha no-mdc2 - Skip this digest
136 no-ripemd
77dd9c18 137 no-rc2 no-rc4 no-rc5 no-idea no-des - Skip this symetric cipher
96afc1cf 138 no-bf no-cast no-aes no-camellia no-seed
d02b48c6 139 no-rsa no-dsa no-dh - Skip this public key cipher
45f55f6a 140 no-ssl3 - Skip this version of SSL
d02b48c6
RE
141 just-ssl - remove all non-ssl keys/digest
142 no-asm - No x86 asm
edc032b5 143 no-srp - No SRP
01682a8b 144 no-ec - No EC
0b13e9f0 145 no-engine - No engine
0423f812 146 no-egd - No EGD
5cd48abf 147 no-hw - No hw
b184e3ef
MC
148 no-async - No Async (use NULL)
149 no-autoalginit - Don't auto load algorithms in libcrypto
498abff0 150 no-autoerrinit - Don't auto load error strings for libcrypto or libssl
bbdb5438 151 nasm - Use NASM for x86 asm
4d8743f4 152 nw-nasm - Use NASM x86 asm for NetWare
eef0c1f3 153 nw-mwasm - Use Metrowerks x86 asm for NetWare
2da0c119 154 gaswin - Use GNU as with Mingw32
d02b48c6
RE
155 no-socks - No socket code
156 no-err - No error strings
157 dll/shlib - Build shared libraries (MS)
158 debug - Debug build
d55a3cf1 159 profile - Profiling build
d02b48c6 160 gcc - Use Gcc (unix)
d02b48c6
RE
161
162Values that can be set
58964a49 163TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
d02b48c6
RE
164
165-L<ex_lib_path> -l<ex_lib> - extra library flags (unix)
166-<ex_cc_flags> - extra 'cc' flags,
167 added (MS), or replace (unix)
168EOF
31ff97b2 169 exit(1);
d02b48c6 170 }
31ff97b2
UM
171 $platform=$_;
172 }
7f2113a2 173foreach (grep(!/^$/, split(/ /, $OPTIONS)))
31ff97b2
UM
174 {
175 print STDERR "unknown option - $_\n" if !&read_options;
d02b48c6
RE
176 }
177
fbf002bb
DSH
178$no_static_engine = 0 if (!$shlib);
179
d02b48c6
RE
180$no_mdc2=1 if ($no_des);
181
474e469b 182$no_ssl3=1 if ($no_md5);
d02b48c6
RE
183$no_ssl3=1 if ($no_rsa && $no_dh);
184
58964a49
RE
185$out_def="out";
186$inc_def="outinc";
187$tmp_def="tmp";
188
2e9f1bf0
DSH
189$perl="perl" unless defined $perl;
190$mkdir="-mkdir" unless defined $mkdir;
db73bd22 191$mv="mv" unless defined $mv;
d02b48c6
RE
192
193($ssl,$crypto)=("ssl","crypto");
d02b48c6
RE
194$ranlib="echo ranlib";
195
58964a49 196$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
f3a39032 197$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}: $platform eq 'copy' ? getcwd() : '.';
58964a49
RE
198$bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
199
200# $bin_dir.=$o causes a core dump on my sparc :-(
201
6bc8e6b8 202
06c68491
DSH
203$NT=0;
204
d02b48c6 205push(@INC,"util/pl","pl");
73980531 206
d0aeeee1 207if ($platform eq "auto" || $platform eq 'copy') {
3c76bcde 208 $orig_platform = $platform;
73980531
DSH
209 $platform = $mf_platform;
210 print STDERR "Imported platform $mf_platform\n";
211}
212
1875e6db 213if (($platform =~ /VC-(.+)/))
d02b48c6 214 {
1875e6db
AP
215 $FLAVOR=$1;
216 $NT = 1 if $1 eq "NT";
d02b48c6
RE
217 require 'VC-32.pl';
218 }
31a674d8
UM
219elsif ($platform eq "Mingw32")
220 {
221 require 'Mingw32.pl';
222 }
12d7d32f
UM
223elsif ($platform eq "Mingw32-files")
224 {
225 require 'Mingw32f.pl';
226 }
dfeab068 227elsif ($platform eq "BC-NT")
d02b48c6
RE
228 {
229 $bc=1;
230 require 'BC-32.pl';
231 }
dfeab068 232elsif ($platform eq "FreeBSD")
d02b48c6
RE
233 {
234 require 'unix.pl';
235 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
236 }
dfeab068 237elsif ($platform eq "linux-elf")
58964a49
RE
238 {
239 require "unix.pl";
240 require "linux.pl";
241 $unix=1;
242 }
dfeab068
RE
243elsif ($platform eq "ultrix-mips")
244 {
245 require "unix.pl";
246 require "ultrix.pl";
247 $unix=1;
248 }
dc01b6b1
RL
249elsif ($platform eq "OS2-EMX")
250 {
251 $wc=1;
252 require 'OS2-EMX.pl';
253 }
b764ab95 254elsif (($platform eq "netware-clib") || ($platform eq "netware-libc") ||
eef0c1f3 255 ($platform eq "netware-clib-bsdsock") || ($platform eq "netware-libc-bsdsock"))
4d8743f4 256 {
b764ab95 257 $LIBC=1 if $platform eq "netware-libc" || $platform eq "netware-libc-bsdsock";
eef0c1f3 258 $BSDSOCK=1 if ($platform eq "netware-libc-bsdsock") || ($platform eq "netware-clib-bsdsock");
4d8743f4
RL
259 require 'netware.pl';
260 }
d02b48c6
RE
261else
262 {
263 require "unix.pl";
264
265 $unix=1;
266 $cflags.=' -DTERMIO';
267 }
268
58964a49
RE
269$out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
270$tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
271$inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
272
d02b48c6
RE
273$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
274
6bc8e6b8
DSH
275$cflags= "$xcflags$cflags" if $xcflags ne "";
276
cf1b7d96 277$cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
77dd9c18 278$cflags.=" -DOPENSSL_NO_AES" if $no_aes;
f3dea9a5 279$cflags.=" -DOPENSSL_NO_CAMELLIA" if $no_camellia;
96afc1cf 280$cflags.=" -DOPENSSL_NO_SEED" if $no_seed;
cf1b7d96
RL
281$cflags.=" -DOPENSSL_NO_RC2" if $no_rc2;
282$cflags.=" -DOPENSSL_NO_RC4" if $no_rc4;
283$cflags.=" -DOPENSSL_NO_RC5" if $no_rc5;
284$cflags.=" -DOPENSSL_NO_MD2" if $no_md2;
285$cflags.=" -DOPENSSL_NO_MD4" if $no_md4;
286$cflags.=" -DOPENSSL_NO_MD5" if $no_md5;
4b618848 287$cflags.=" -DOPENSSL_NO_RMD160" if $no_ripemd;
cf1b7d96
RL
288$cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
289$cflags.=" -DOPENSSL_NO_BF" if $no_bf;
290$cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
291$cflags.=" -DOPENSSL_NO_DES" if $no_des;
292$cflags.=" -DOPENSSL_NO_RSA" if $no_rsa;
293$cflags.=" -DOPENSSL_NO_DSA" if $no_dsa;
294$cflags.=" -DOPENSSL_NO_DH" if $no_dh;
ec645d90 295$cflags.=" -DOPENSSL_NO_WHIRLPOOL" if $no_whirlpool;
cf1b7d96 296$cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
cf1b7d96 297$cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
edc032b5 298$cflags.=" -DOPENSSL_NO_SRP" if $no_srp;
88db4e6b 299$cflags.=" -DOPENSSL_NO_CMS" if $no_cms;
cf1b7d96 300$cflags.=" -DOPENSSL_NO_ERR" if $no_err;
01682a8b 301$cflags.=" -DOPENSSL_NO_EC" if $no_ec;
4ed7b78b 302$cflags.=" -DOPENSSL_NO_GOST" if $no_gost;
0b13e9f0 303$cflags.=" -DOPENSSL_NO_ENGINE" if $no_engine;
5cd48abf 304$cflags.=" -DOPENSSL_NO_HW" if $no_hw;
52739e40 305$cflags.=" -DOPENSSL_NO_ASYNC" if $no_async;
b184e3ef 306$cflags.=" -DOPENSSL_NO_AUTOALGINIT" if $no_autoalginit;
498abff0 307$cflags.=" -DOPENSSL_NO_AUTOERRINIT" if $no_autoerrinit;
06b433ac 308$cflags.=" -DOPENSSL_FIPS" if $fips;
79bd20fd 309$cflags.=" -DOPENSSL_NO_JPAKE" if $no_jpake;
36246be9 310$cflags.=" -DOPENSSL_NO_EC2M" if $no_ec2m;
ad2695b1
DSH
311$cflags.= " -DZLIB" if $zlib_opt;
312$cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
313
fbf002bb
DSH
314if ($no_static_engine)
315 {
316 $cflags .= " -DOPENSSL_NO_STATIC_ENGINE";
317 }
318else
319 {
320 $cflags .= " -DOPENSSL_NO_DYNAMIC_ENGINE";
321 }
322
ccb9643f 323#$cflags.=" -DRSAref" if $rsaref ne "";
d02b48c6 324
d55a3cf1
UM
325## if ($unix)
326## { $cflags="$c_flags" if ($c_flags ne ""); }
327##else
328 { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
d02b48c6 329
d0aeeee1
BL
330if ($orig_platform eq 'copy') {
331 $cflags = $mf_cflag;
332 $cc = $mf_cc;
333}
3c76bcde 334
d02b48c6
RE
335$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
336
ad2695b1 337
f09628e4
RL
338%shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
339 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
340
d02b48c6
RE
341if ($msdos)
342 {
dfeab068 343 $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
d02b48c6
RE
344 $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
345 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
346 $banner.="\t\@echo documentation for details.\n";
347 }
348
349# have to do this to allow $(CC) under unix
350$link="$bin_dir$link" if ($link !~ /^\$/);
351
352$INSTALLTOP =~ s|/|$o|g;
b8bb15fb 353$OPENSSLDIR =~ s|/|$o|g;
d02b48c6 354
2dc08d5f
DSH
355#############################################
356# We parse in input file and 'store' info for later printing.
357open(IN,"<$infile") || die "unable to open $infile:$!\n";
358$_=<IN>;
359for (;;)
360 {
7bb98eee 361 s/\s*$//; # was chop, didn't work in mixture of perls for Windows...
2dc08d5f
DSH
362
363 ($key,$val)=/^([^=]+)=(.*)/;
364 if ($key eq "RELATIVE_DIRECTORY")
365 {
366 if ($lib ne "")
367 {
06b433ac
DSH
368 if ($fips && $dir =~ /^fips/)
369 {
370 $uc = "FIPS";
371 }
372 else
373 {
374 $uc=$lib;
375 $uc =~ s/^lib(.*)\.a/$1/;
376 $uc =~ tr/a-z/A-Z/;
377 }
378 if (($uc ne "FIPS") || $fipscanisterbuild)
379 {
380 $lib_nam{$uc}=$uc;
381 $lib_obj{$uc}.=$libobj." ";
382 }
2dc08d5f
DSH
383 }
384 last if ($val eq "FINISHED");
385 $lib="";
386 $libobj="";
387 $dir=$val;
388 }
389
ad2695b1 390 if ($key eq "ZLIB_INCLUDE")
1291dfde 391 { $cflags .= " $val" if $val ne "";}
ad2695b1
DSH
392
393 if ($key eq "LIBZLIB")
394 { $zlib_lib = "$val" if $val ne "";}
395
8bf5b8ab
RL
396 if ($key eq "EX_LIBS")
397 { $ex_libs .= " $val" if $val ne "";}
398
9e842a52
RL
399 # There was a condition here before:
400 # !$fipscanisteronly || $dir =~ /^fips/
401 # It currently fills no function and needs to be rewritten anyway, so
402 # removed for now.
403 if ($dir eq "test" && $key eq "EXE")
404 {
405 foreach my $t (split /\s+/, $val) {
406 $test.=&var_add($dir,$t, 0) if $t; }
407 }
2dc08d5f 408
4c140896 409 if ($key eq "EXE_OBJ")
c51f2d42 410 { $e_exe.=&var_add($dir,$val, 0); }
2dc08d5f
DSH
411
412 if ($key eq "LIB")
413 {
414 $lib=$val;
415 $lib =~ s/^.*\/([^\/]+)$/$1/;
416 }
223c59ea
DSH
417 if ($key eq "LIBNAME" && $no_static_engine)
418 {
419 $lib=$val;
420 $lib =~ s/^.*\/([^\/]+)$/$1/;
421 $otherlibs .= " $lib";
422 }
2dc08d5f 423
2dc08d5f 424 if ($key eq "HEADER")
c51f2d42 425 { $header.=&var_add($dir,$val, 1); }
2dc08d5f 426
2b1f17f8
AP
427 if ($key eq "LIBOBJ")
428 {
429 if ($dir ne "engines" || !$no_static_engine)
c51f2d42 430 { $libobj=&var_add($dir,$val, 0); }
2b1f17f8
AP
431 else
432 { push(@engines_obj,split(/\s+/,&var_add($dir,$val,0))); }
433 }
fbf002bb
DSH
434 if ($key eq "LIBNAMES" && $dir eq "engines" && $no_static_engine)
435 { $engines.=$val }
2dc08d5f 436
06b433ac
DSH
437 if ($key eq "FIPS_EX_OBJ")
438 {
439 $fips_ex_obj=&var_add("crypto",$val,0);
440 }
441
442 if ($key eq "FIPSLIBDIR")
443 {
444 $fipslibdir=$val;
445 $fipslibdir =~ s/\/$//;
446 $fipslibdir =~ s/\//$o/g;
447 }
448
449 if ($key eq "BASEADDR")
450 { $baseaddr=$val;}
451
2dc08d5f
DSH
452 if (!($_=<IN>))
453 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
454 }
455close(IN);
456
a50f7186
DSH
457if ($orig_platform eq 'copy')
458 {
459 # Remove opensslconf.h so it doesn't get updated if we configure a
460 # different branch.
a50f7186
DSH
461 $header =~ s/[^ ]+\/opensslconf.h//;
462 }
894172f2 463
06b433ac
DSH
464if ($fips)
465 {
466
467 foreach (split " ", $fips_ex_obj)
468 {
469 $fips_exclude_obj{$1} = 1 if (/\/([^\/]*)$/);
470 }
471 foreach (split " ",
dc527a62
DSH
472 "$mf_cpuid_asm $mf_aes_asm $mf_sha_asm $mf_bn_asm " .
473 "$mf_des_asm $mf_modes_asm")
06b433ac
DSH
474 {
475 s/\.o//;
476 $fips_exclude_obj{$_} = 1;
477 }
478 my @ltmp = split " ", $lib_obj{"CRYPTO"};
479
480
481 $lib_obj{"CRYPTO"} = "";
482
483 foreach(@ltmp)
484 {
485 if (/\/([^\/]*)$/ && exists $fips_exclude_obj{$1})
486 {
487 if ($fipscanisterbuild)
488 {
489 $lib_obj{"FIPS"} .= "$_ ";
490 }
491 }
d989e4f8 492 elsif (!$fipscanisteronly)
06b433ac
DSH
493 {
494 $lib_obj{"CRYPTO"} .= "$_ ";
495 }
496 }
497
498 }
499
500if ($fipscanisterbuild)
501 {
502 $fips_canister_path = "\$(LIB_D)${o}fipscanister.lib" if $fips_canister_path eq "";
503 $fips_premain_c_path = "\$(LIB_D)${o}fips_premain.c";
504 }
505else
506 {
507 if ($fips_canister_path eq "")
508 {
509 $fips_canister_path = "\$(FIPSLIB_D)${o}fipscanister.lib";
510 }
511
512 if ($fips_premain_c_path eq "")
513 {
514 $fips_premain_c_path = "\$(FIPSLIB_D)${o}fips_premain.c";
515 }
516 }
517
518if ($fips)
519 {
520 if ($fips_sha1_exe_path eq "")
521 {
522 $fips_sha1_exe_path =
523 "\$(BIN_D)${o}fips_standalone_sha1$exep";
524 }
525 }
526 else
527 {
528 $fips_sha1_exe_path = "";
529 }
530
531if ($fips_premain_dso_exe_path eq "")
532 {
533 $fips_premain_dso_exe_path = "\$(BIN_D)${o}fips_premain_dso$exep";
534 }
535
536# $ex_build_targets .= "\$(BIN_D)${o}\$(E_PREMAIN_DSO)$exep" if ($fips);
537
538if ($fips)
539 {
540 if (!$shlib)
541 {
d989e4f8 542 $build_targets .= " \$(LIB_D)$o$crypto_compat \$(PREMAIN_DSO_EXE)";
06b433ac
DSH
543 $ex_l_libs .= " \$(O_FIPSCANISTER)";
544 $ex_libs_dep .= " \$(O_FIPSCANISTER)" if $fipscanisterbuild;
545 }
546 if ($fipscanisterbuild)
547 {
548 $fipslibdir = "\$(LIB_D)";
549 }
550 else
551 {
552 if ($fipslibdir eq "")
553 {
554 open (IN, "util/fipslib_path.txt") || fipslib_error();
555 $fipslibdir = <IN>;
06b433ac 556 close IN;
ce3d25d3
VD
557 $fipslibdir = "" unless defined($fipslibdir);
558 $fipslibdir =~ s{\R$}{};
559 fipslib_error() if ($fipslibdir eq "");
06b433ac
DSH
560 }
561 fips_check_files($fipslibdir,
562 "fipscanister.lib", "fipscanister.lib.sha1",
563 "fips_premain.c", "fips_premain.c.sha1");
564 }
565 }
566
d989e4f8
DSH
567if ($fipscanisteronly)
568 {
569 $build_targets = "\$(O_FIPSCANISTER) \$(T_EXE)";
570 $libs_dep = "";
571 }
d989e4f8 572
0b41fcc2
DSH
573$cp2 = $cp unless defined $cp2;
574
c3de647e 575$extra_install= <<"EOF";
0190de80 576 \$(CP) \"include${o}openssl${o}*.\[ch\]\" \"\$(INSTALLTOP)${o}include${o}openssl\"
c3de647e
DSH
577 \$(CP) \"\$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin\"
578 \$(MKDIR) \"\$(OPENSSLDIR)\"
579 \$(CP) apps${o}openssl.cnf \"\$(OPENSSLDIR)\"
580EOF
581
582if ($fipscanisteronly)
2e9f1bf0 583 {
c3de647e
DSH
584 $extra_install = <<"EOF";
585 \$(CP) \"\$(O_FIPSCANISTER)\" \"\$(INSTALLTOP)${o}lib\"
586 \$(CP) \"\$(O_FIPSCANISTER).sha1\" \"\$(INSTALLTOP)${o}lib\"
0b41fcc2 587 \$(CP2) \"fips${o}fips_premain.c\" \"\$(INSTALLTOP)${o}lib\"
c3de647e 588 \$(CP) \"fips${o}fips_premain.c.sha1\" \"\$(INSTALLTOP)${o}lib\"
0190de80
RL
589 \$(CP) \"include${o}openssl${o}fips.h\" \"\$(INSTALLTOP)${o}include${o}openssl\"
590 \$(CP) \"include${o}openssl${o}fips_rand.h\" \"\$(INSTALLTOP)${o}include${o}openssl\"
c3de647e
DSH
591 \$(CP) "\$(BIN_D)${o}fips_standalone_sha1$exep" \"\$(INSTALLTOP)${o}bin\"
592 \$(CP) \"util${o}fipslink.pl\" \"\$(INSTALLTOP)${o}bin\"
593EOF
594 }
595elsif ($shlib)
596 {
597 $extra_install .= <<"EOF";
96fc37f1
DSH
598 \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}bin\"
599 \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}bin\"
600 \$(CP) \"\$(L_SSL)\" \"\$(INSTALLTOP)${o}lib\"
601 \$(CP) \"\$(L_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
2e9f1bf0
DSH
602EOF
603 if ($no_static_engine)
604 {
605 $extra_install .= <<"EOF"
96fc37f1
DSH
606 \$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
607 \$(CP) \"\$(E_SHLIB)\" \"\$(INSTALLTOP)${o}lib${o}engines\"
2e9f1bf0
DSH
608EOF
609 }
610 }
611else
612 {
c3de647e 613 $extra_install .= <<"EOF";
96fc37f1
DSH
614 \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}lib\"
615 \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
2e9f1bf0 616EOF
ad2695b1 617 $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
2e9f1bf0
DSH
618 }
619
70857a4a
DSH
620my $asm_def = $orig_platform eq 'copy' ? "" : "ASM=$bin_dir$asm";
621
f4a748a1
RL
622$cflags =~ s/\((ENGINESDIR|OPENSSLDIR)\)/\(${1}_QQ\)/g;
623(my $cflags_q = $cflags) =~ s/([\\"])/\\$1/g;
624(my $INSTALLTOP_Q = $INSTALLTOP) =~ s/([\\"])/\\$1/g;
625(my $INSTALLTOP_QQ = $INSTALLTOP_Q) =~ s/\\/\\\\/g;
626(my $OPENSSLDIR_Q = $OPENSSLDIR) =~ s/([\\"])/\\$1/g;
627(my $OPENSSLDIR_QQ = $OPENSSLDIR_Q) =~ s/\\/\\\\/g;
628(my $ENGINESDIR_Q = $ENGINESDIR) =~ s/([\\"])/\\$1/g;
629(my $ENGINESDIR_QQ = $ENGINESDIR_Q) =~ s/\\/\\\\/g;
630
d02b48c6 631$defs= <<"EOF";
3675fb88 632# N.B. You MUST use -j on FreeBSD.
e527ba09
DSH
633# This makefile has been automatically generated from the OpenSSL distribution.
634# This single makefile will build the complete OpenSSL distribution and
ad282e63 635# by default leave the 'interesting' output files in .${o}out and the stuff
d02b48c6
RE
636# that needs deleting in .${o}tmp.
637# The file was generated by running 'make makefile.one', which
638# does a 'make files', which writes all the environment variables from all
639# the makefiles to the file call MINFO. This file is used by
640# util${o}mk1mf.pl to generate makefile.one.
641# The 'makefile per directory' system suites me when developing this
642# library and also so I can 'distribute' indervidual library sections.
643# The one monster makefile better suits building in non-unix
644# environments.
645
7a1f92fd
RL
646EOF
647
0b352c58
RL
648$defs .= $preamble if defined $preamble;
649
7a1f92fd 650$defs.= <<"EOF";
d02b48c6 651INSTALLTOP=$INSTALLTOP
f4a748a1 652INSTALLTOP_QQ=$INSTALLTOP_QQ
b8bb15fb 653OPENSSLDIR=$OPENSSLDIR
f4a748a1 654OPENSSLDIR_QQ=$OPENSSLDIR_QQ
e09621ff 655ENGINESDIR=$ENGINESDIR
f4a748a1 656ENGINESDIR_QQ=$ENGINESDIR_QQ
d02b48c6
RE
657
658# Set your compiler options
dfeab068 659PLATFORM=$platform
d02b48c6
RE
660CC=$bin_dir${cc}
661CFLAG=$cflags
f4a748a1 662CFLAG_Q=$cflags_q
d02b48c6
RE
663APP_CFLAG=$app_cflag
664LIB_CFLAG=$lib_cflag
58964a49 665SHLIB_CFLAG=$shl_cflag
d02b48c6
RE
666APP_EX_OBJ=$app_ex_obj
667SHLIB_EX_OBJ=$shlib_ex_obj
668# add extra libraries to this define, for solaris -lsocket -lnsl would
669# be added
670EX_LIBS=$ex_libs
671
e527ba09 672# The OpenSSL directory
d02b48c6
RE
673SRC_D=$src_dir
674
d44bb1c3 675LINK_CMD=$link
d02b48c6 676LFLAGS=$lflags
fc6a6a10 677RSC=$rsc
06b433ac 678FIPSLINK=\$(PERL) util${o}fipslink.pl
d02b48c6 679
7067cbc8 680# The output directory for everything interesting
d02b48c6
RE
681OUT_D=$out_dir
682# The output directory for all the temporary muck
683TMP_D=$tmp_dir
684
2e9f1bf0 685PERL=$perl
5444b11b 686PERLASM_SCHEME=$mf_perlasm_scheme
d02b48c6 687CP=$cp
0b41fcc2 688CP2=$cp2
d02b48c6 689RM=$rm
db73bd22 690MV=$mv
d02b48c6 691RANLIB=$ranlib
12d7d32f 692MKDIR=$mkdir
d02b48c6
RE
693MKLIB=$bin_dir$mklib
694MLFLAGS=$mlflags
70857a4a 695$asm_def
d02b48c6 696
06b433ac
DSH
697# FIPS validated module and support file locations
698
699E_PREMAIN_DSO=fips_premain_dso
700
701FIPSLIB_D=$fipslibdir
702BASEADDR=$baseaddr
703FIPS_PREMAIN_SRC=$fips_premain_c_path
704O_FIPSCANISTER=$fips_canister_path
705FIPS_SHA1_EXE=$fips_sha1_exe_path
706PREMAIN_DSO_EXE=$fips_premain_dso_exe_path
707
d02b48c6
RE
708######################################################
709# You should not need to touch anything below this point
710######################################################
711
e527ba09 712E_EXE=openssl
d02b48c6
RE
713SSL=$ssl
714CRYPTO=$crypto
d02b48c6
RE
715
716# BIN_D - Binary output directory
717# TEST_D - Binary test file output directory
718# LIB_D - library output directory
fbf002bb 719# ENG_D - dynamic engine output directory
e2e044fa
DSH
720# Note: if you change these point to different directories then uncomment out
721# the lines around the 'NB' comment below.
722#
d02b48c6
RE
723BIN_D=\$(OUT_D)
724TEST_D=\$(OUT_D)
725LIB_D=\$(OUT_D)
fbf002bb 726ENG_D=\$(OUT_D)
d02b48c6
RE
727
728# INCL_D - local library directory
729# OBJ_D - temp object file directory
730OBJ_D=\$(TMP_D)
731INCL_D=\$(TMP_D)
732
733O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
734O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
58964a49
RE
735SO_SSL= $plib\$(SSL)$so_shlibp
736SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
31a674d8
UM
737L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp
738L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp
d02b48c6 739
06b433ac 740L_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs
d02b48c6
RE
741
742######################################################
743# Don't touch anything below this point
744######################################################
745
0190de80 746INC=-I\$(SRC_D)${o}include -I\$(INCL_D) -I\$(SRC_D)${o}crypto${o}include
d02b48c6
RE
747APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
748LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
58964a49 749SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
d989e4f8 750LIBS_DEP=$libs_dep
d02b48c6
RE
751
752#############################################
753EOF
754
755$rules=<<"EOF";
0190de80 756all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) headers \$(FIPS_SHA1_EXE) $build_targets
d02b48c6
RE
757
758banner:
759$banner
760
d02b48c6 761\$(TMP_D):
96fc37f1 762 \$(MKDIR) \"\$(TMP_D)\"
e2e044fa
DSH
763# NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
764#\$(BIN_D):
765# \$(MKDIR) \$(BIN_D)
766#
767#\$(TEST_D):
768# \$(MKDIR) \$(TEST_D)
58964a49
RE
769
770\$(LIB_D):
96fc37f1 771 \$(MKDIR) \"\$(LIB_D)\"
58964a49 772
3b4d86bf
BL
773# This needs to be invoked once, when the makefile is first constructed, or
774# after cleaning.
0190de80 775init: \$(TMP_D) \$(LIB_D) \$(BIN_D) \$(TEST_D) headers
3b4d86bf 776
0190de80 777headers: \$(HEADER)
d02b48c6 778
fbf002bb 779lib: \$(LIBS_DEP) \$(E_SHLIB)
d02b48c6 780
e8cdcd52
RL
781exe: apps tools testapps
782apps: \$(BIN_D)$o\$(E_EXE)$exep \$(BIN_D)${o}CA.pl
fd9ad230 783testapps: \$(T_EXE)
e8cdcd52 784tools: \$(BIN_D)${o}c_rehash
d02b48c6 785
2e9f1bf0 786install: all
96fc37f1
DSH
787 \$(MKDIR) \"\$(INSTALLTOP)\"
788 \$(MKDIR) \"\$(INSTALLTOP)${o}bin\"
789 \$(MKDIR) \"\$(INSTALLTOP)${o}include\"
790 \$(MKDIR) \"\$(INSTALLTOP)${o}include${o}openssl\"
791 \$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
e09621ff 792 \$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
2e9f1bf0
DSH
793$extra_install
794
d02b48c6
RE
795clean:
796 \$(RM) \$(TMP_D)$o*.*
797
798vclean:
799 \$(RM) \$(TMP_D)$o*.*
800 \$(RM) \$(OUT_D)$o*.*
801
f953c2d0
BL
802reallyclean:
803 \$(RM) -rf \$(TMP_D)
804 \$(RM) -rf \$(BIN_D)
805 \$(RM) -rf \$(TEST_D)
806 \$(RM) -rf \$(LIB_D)
f953c2d0 807
d02b48c6 808EOF
3b4d86bf 809
e8cdcd52 810$rules .= &do_rehash_rule("rehash.time", "certs/demo apps tools");
82987e61 811$rules .= &do_test_rule("test", "rehash.time", "run_tests.pl");
3b4d86bf 812
f4a748a1
RL
813$rules .= <<"EOF";
814crypto${o}buildinf.h : MINFO
815 \$(PERL) util${o}mkbuildinf.pl "\$(CC) \$(CFLAG_Q)" "\$(PLATFORM)" > crypto${o}buildinf.h
816$(OBJ_D)${o}cversion${obj} : crypto${o}buildinf.h
2e0fc875 817EOF
d02b48c6 818
a32d9eaf 819# Strip off trailing ' '
d02b48c6
RE
820foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
821$test=&clean_up_ws($test);
822$e_exe=&clean_up_ws($e_exe);
d02b48c6
RE
823$header=&clean_up_ws($header);
824
c51f2d42
DSH
825$defs.=&do_defs("HEADER",$header,"\$(INCL_D)","");
826$rules.=&do_copy_rule("\$(INCL_D)",$header,"");
d02b48c6 827
d02b48c6
RE
828$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
829$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
830
831$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
832$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
833
06b433ac
DSH
834# Special case rules for fips_start and fips_end fips_premain_dso
835
836if ($fips)
837 {
838 if ($fipscanisterbuild)
839 {
840 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_start$obj",
841 "fips${o}fips_canister.c",
842 "-DFIPS_START \$(SHLIB_CFLAGS)");
843 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_end$obj",
844 "fips${o}fips_canister.c", "\$(SHLIB_CFLAGS)");
845 }
846 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_standalone_sha1$obj",
847 "fips${o}sha${o}fips_standalone_sha1.c",
1e981690 848 "\$(APP_CFLAGS)");
06b433ac
DSH
849 $rules.=&cc_compile_target("\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj",
850 "fips${o}fips_premain.c",
1e981690 851 "-DFINGERPRINT_PREMAIN_DSO_LOAD \$(APP_CFLAGS)");
06b433ac
DSH
852 }
853
656829b7
BL
854sub fix_asm
855 {
856 my($asm, $dir) = @_;
857
858 $asm = " $asm";
859 $asm =~ s/\s+/ $dir\//g;
860 $asm =~ s/\.o//g;
861 $asm =~ s/^ //;
862
863 return $asm . ' ';
864 }
865
71a16946
DSH
866if ($orig_platform eq 'copy') {
867 $lib_obj{CRYPTO} .= fix_asm($mf_md5_asm, 'crypto/md5');
868 $lib_obj{CRYPTO} .= fix_asm($mf_bn_asm, 'crypto/bn');
35ced1f7 869 # cpuid is included by the crypto dir
63d86d06 870 #$lib_obj{CRYPTO} .= fix_asm($mf_cpuid_asm, 'crypto');
71a16946
DSH
871 # AES asm files end up included by the aes dir itself
872 #$lib_obj{CRYPTO} .= fix_asm($mf_aes_asm, 'crypto/aes');
873 $lib_obj{CRYPTO} .= fix_asm($mf_sha_asm, 'crypto/sha');
874 $lib_obj{CRYPTO} .= fix_asm($mf_engines_asm, 'engines');
875 $lib_obj{CRYPTO} .= fix_asm($mf_rc4_asm, 'crypto/rc4');
876 $lib_obj{CRYPTO} .= fix_asm($mf_modes_asm, 'crypto/modes');
71614df4 877 $lib_obj{CRYPTO} .= fix_asm($mf_ec_asm, 'crypto/ec');
71a16946 878}
656829b7 879
d02b48c6
RE
880foreach (values %lib_nam)
881 {
882 $lib_obj=$lib_obj{$_};
58964a49
RE
883 local($slib)=$shlib;
884
d02b48c6 885 $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
f09628e4 886 $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
58964a49 887 $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
d02b48c6
RE
888 }
889
fc6a6a10 890# hack to add version info on MSVC
1d42dbaf 891if (($platform eq "VC-WIN32") || ($platform eq "VC-WIN64A")
23129dec 892 || ($platform eq "VC-WIN64I") || ($platform eq "VC-NT")) {
fc6a6a10
DSH
893 $rules.= <<"EOF";
894\$(OBJ_D)\\\$(CRYPTO).res: ms\\version32.rc
895 \$(RSC) /fo"\$(OBJ_D)\\\$(CRYPTO).res" /d CRYPTO ms\\version32.rc
896
897\$(OBJ_D)\\\$(SSL).res: ms\\version32.rc
898 \$(RSC) /fo"\$(OBJ_D)\\\$(SSL).res" /d SSL ms\\version32.rc
899
900EOF
901}
902
d02b48c6 903$defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
06b433ac
DSH
904foreach (split(/\s+/,$test))
905 {
906 my $t_libs;
907 $t=&bname($_);
908 my $ltype;
909 # Check to see if test program is FIPS
910 if ($fips && /fips/)
911 {
912 # If fips perform static link to
913 # $(O_FIPSCANISTER)
914 $t_libs = "\$(O_FIPSCANISTER)";
915 $ltype = 2;
916 }
917 else
918 {
919 $t_libs = "\$(L_LIBS)";
920 $ltype = 0;
921 }
922
923 $tt="\$(OBJ_D)${o}$t${obj}";
924 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","$t_libs \$(EX_LIBS)", $ltype);
925 }
d02b48c6 926
223c59ea 927$defs.=&do_defs("E_SHLIB",$engines . $otherlibs,"\$(ENG_D)",$shlibp);
fbf002bb
DSH
928
929foreach (split(/\s+/,$engines))
930 {
2b1f17f8 931 my $engine = $_;
16190a71 932 my @objs = grep {/e_$engine/} @engines_obj;
2b1f17f8 933 $rules.=&do_compile_rule("\$(OBJ_D)",join(" ",@objs),$lib);
16190a71 934 map {$_=~s/.*\/([^\/]+)$/\$(OBJ_D)${o}$1$obj/} @objs;
2b1f17f8 935 $rules.= &do_lib_rule(join(" ",@objs),"\$(ENG_D)$o$engine$shlibp","",$shlib,"");
fbf002bb
DSH
936 }
937
938
939
58964a49 940$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
06b433ac 941#$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
d02b48c6 942
ef3026a3 943foreach (split(" ",$otherlibs))
223c59ea
DSH
944 {
945 my $uc = $_;
946 $uc =~ tr /a-z/A-Z/;
947 $rules.= &do_lib_rule("\$(${uc}OBJ)","\$(ENG_D)$o$_$shlibp", "", $shlib, "");
948
949 }
950
06b433ac
DSH
951if ($fips)
952 {
953 if ($shlib)
954 {
955 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
956 "\$(O_CRYPTO)", "$crypto",
957 $shlib, "\$(SO_CRYPTO)", "\$(BASEADDR)");
958 }
959 else
960 {
961 $rules.= &do_lib_rule("\$(CRYPTOOBJ)",
962 "\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)", "");
0b41fcc2 963 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
06b433ac
DSH
964 "\$(LIB_D)$o$crypto_compat",$crypto,$shlib,"\$(SO_CRYPTO)", "");
965 }
966 }
967 else
968 {
969 $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
970 "\$(SO_CRYPTO)");
971 }
972
973if ($fips)
974 {
975 if ($fipscanisterbuild)
976 {
977 $rules.= &do_rlink_rule("\$(O_FIPSCANISTER)",
978 "\$(OBJ_D)${o}fips_start$obj",
979 "\$(FIPSOBJ)",
980 "\$(OBJ_D)${o}fips_end$obj",
981 "\$(FIPS_SHA1_EXE)", "");
982 # FIXME
983 $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)",
984 "\$(OBJ_D)${o}fips_standalone_sha1$obj \$(OBJ_D)${o}sha1dgst$obj $sha1_asm_obj",
985 "","\$(EX_LIBS)", 1);
986 }
987 else
988 {
989 $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)",
990 "\$(OBJ_D)${o}fips_standalone_sha1$obj \$(O_FIPSCANISTER)",
991 "","", 1);
992
993 }
994 $rules.=&do_link_rule("\$(PREMAIN_DSO_EXE)","\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj \$(CRYPTOOBJ) \$(O_FIPSCANISTER)","","\$(EX_LIBS)", 1);
995
996 }
997
998$rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)", ($fips && !$shlib) ? 2 : 0);
d02b48c6 999
e8cdcd52
RL
1000$rules.=&do_dofile_rule("\$(BIN_D)","c_rehash","tools/c_rehash.in");
1001$rules.=&do_dofile_rule("\$(BIN_D)","CA.pl","apps/CA.pl.in");
1002
d02b48c6 1003print $defs;
eb206eb8
UM
1004
1005if ($platform eq "linux-elf") {
1006 print <<"EOF";
1007# Generate perlasm output files
1008%.cpp:
cd202fe2 1009 (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
eb206eb8
UM
1010EOF
1011}
d02b48c6
RE
1012print "###################################################################\n";
1013print $rules;
1014
1015###############################################
1016# strip off any trailing .[och] and append the relative directory
1017# also remembering to do nothing if we are in one of the dropped
1018# directories
1019sub var_add
1020 {
c51f2d42 1021 local($dir,$val,$keepext)=@_;
d02b48c6
RE
1022 local(@a,$_,$ret);
1023
0b13e9f0 1024 return("") if $no_engine && $dir =~ /\/engine/;
5cd48abf 1025 return("") if $no_hw && $dir =~ /\/hw/;
d02b48c6 1026 return("") if $no_idea && $dir =~ /\/idea/;
77dd9c18 1027 return("") if $no_aes && $dir =~ /\/aes/;
f3dea9a5 1028 return("") if $no_camellia && $dir =~ /\/camellia/;
96afc1cf 1029 return("") if $no_seed && $dir =~ /\/seed/;
d02b48c6
RE
1030 return("") if $no_rc2 && $dir =~ /\/rc2/;
1031 return("") if $no_rc4 && $dir =~ /\/rc4/;
58964a49 1032 return("") if $no_rc5 && $dir =~ /\/rc5/;
d02b48c6
RE
1033 return("") if $no_rsa && $dir =~ /\/rsa/;
1034 return("") if $no_rsa && $dir =~ /^rsaref/;
1035 return("") if $no_dsa && $dir =~ /\/dsa/;
1036 return("") if $no_dh && $dir =~ /\/dh/;
e8e0e371 1037 return("") if $no_ec && $dir =~ /\/ec/;
68190507 1038 return("") if $no_cms && $dir =~ /\/cms/;
79bd20fd 1039 return("") if $no_jpake && $dir =~ /\/jpake/;
06b433ac 1040 return("") if !$fips && $dir =~ /^fips/;
d02b48c6
RE
1041 if ($no_des && $dir =~ /\/des/)
1042 {
1043 if ($val =~ /read_pwd/)
1044 { return("$dir/read_pwd "); }
1045 else
1046 { return(""); }
1047 }
1048 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
1049 return("") if $no_sock && $dir =~ /\/proxy/;
1050 return("") if $no_bf && $dir =~ /\/bf/;
58964a49 1051 return("") if $no_cast && $dir =~ /\/cast/;
ec645d90 1052 return("") if $no_whirlpool && $dir =~ /\/whrlpool/;
d02b48c6
RE
1053
1054 $val =~ s/^\s*(.*)\s*$/$1/;
1055 @a=split(/\s+/,$val);
c51f2d42 1056 grep(s/\.[och]$//,@a) unless $keepext;
d02b48c6
RE
1057
1058 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
1059 @a=grep(!/^e_.*_d$/,@a) if $no_des;
77dd9c18
RL
1060 @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
1061 @a=grep(!/^e_.*_i$/,@a) if $no_aes;
d02b48c6 1062 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
58964a49 1063 @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
d02b48c6 1064 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
58964a49 1065 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
d02b48c6 1066 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
f3dea9a5 1067 @a=grep(!/^e_camellia$/,@a) if $no_camellia;
96afc1cf 1068 @a=grep(!/^e_seed$/,@a) if $no_seed;
d02b48c6 1069
06ddf8eb 1070 #@a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
d02b48c6
RE
1071
1072 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
1073
1074 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
3009458e 1075 @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
d02b48c6 1076 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
7e38616d 1077 @a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
d02b48c6
RE
1078
1079 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
0c1badc8 1080 @a=grep(!/(^p_open$)/,@a) if $no_rsa;
d02b48c6
RE
1081
1082 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
1083 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
1084
1085 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
1086
1087 @a=grep(!/_dhp$/,@a) if $no_dh;
1088
d02b48c6
RE
1089 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
1090
edc032b5
BL
1091 @a=grep(!/(srp)/,@a) if $no_srp;
1092
0b13e9f0 1093 @a=grep(!/^engine$/,@a) if $no_engine;
5cd48abf 1094 @a=grep(!/^hw$/,@a) if $no_hw;
13e91dd3 1095 @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
d02b48c6 1096 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
d02b48c6
RE
1097 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
1098
d02b48c6
RE
1099 grep($_="$dir/$_",@a);
1100 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
1101 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
1102 $ret=join(' ',@a)." ";
1103 return($ret);
1104 }
1105
1106# change things so that each 'token' is only separated by one space
1107sub clean_up_ws
1108 {
1109 local($w)=@_;
1110
1111 $w =~ s/^\s*(.*)\s*$/$1/;
1112 $w =~ s/\s+/ /g;
1113 return($w);
1114 }
1115
1116sub do_defs
1117 {
1118 local($var,$files,$location,$postfix)=@_;
58964a49 1119 local($_,$ret,$pf);
d02b48c6
RE
1120 local(*OUT,$tmp,$t);
1121
1122 $files =~ s/\//$o/g if $o ne '/';
1123 $ret="$var=";
1124 $n=1;
1125 $Vars{$var}.="";
1126 foreach (split(/ /,$files))
1127 {
58964a49 1128 $orig=$_;
d02b48c6
RE
1129 $_=&bname($_) unless /^\$/;
1130 if ($n++ == 2)
1131 {
1132 $n=0;
1133 $ret.="\\\n\t";
1134 }
58964a49
RE
1135 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
1136 { $pf=".c"; }
1137 else { $pf=$postfix; }
dfeab068 1138 if ($_ =~ /BN_ASM/) { $t="$_ "; }
b222eb64 1139 elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
4664eb52 1140 elsif ($_ =~ /AES_ASM/){ $t="$_ "; }
58964a49
RE
1141 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
1142 elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
1143 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
1144 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
1145 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
1146 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
1147 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
1148 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
7c510d6f 1149 elsif ($_ =~ /WHIRLPOOL_ASM/){ $t="$_ "; }
a4c886e4 1150 elsif ($_ =~ /CPUID_ASM/){ $t="$_ "; }
58964a49 1151 else { $t="$location${o}$_$pf "; }
d02b48c6
RE
1152
1153 $Vars{$var}.="$t ";
1154 $ret.=$t;
1155 }
fc6a6a10 1156 # hack to add version info on MSVC
1d42dbaf 1157 if ($shlib && (($platform eq "VC-WIN32") || ($platfrom eq "VC-WIN64I") || ($platform eq "VC-WIN64A") || ($platform eq "VC-NT")))
fc6a6a10
DSH
1158 {
1159 if ($var eq "CRYPTOOBJ")
1160 { $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
1161 elsif ($var eq "SSLOBJ")
1162 { $ret.="\$(OBJ_D)\\\$(SSL).res "; }
1163 }
9ba96fbb 1164 chomp($ret); # Does this actually do something? /RL
d02b48c6
RE
1165 $ret.="\n\n";
1166 return($ret);
1167 }
1168
1169# return the name with the leading path removed
1170sub bname
1171 {
1172 local($ret)=@_;
1173 $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
1174 return($ret);
1175 }
1176
4287ade5
AP
1177# return the leading path
1178sub dname
1179 {
1180 my $ret=shift;
1181 $ret =~ s/(^.*)[\\\/][^\\\/]+$/$1/;
1182 return($ret);
1183 }
d02b48c6
RE
1184
1185##############################################################
1186# do a rule for each file that says 'compile' to new direcory
1187# compile the files in '$files' into $to
1188sub do_compile_rule
1189 {
1190 local($to,$files,$ex)=@_;
4287ade5
AP
1191 local($ret,$_,$n,$d,$s);
1192
d02b48c6
RE
1193 $files =~ s/\//$o/g if $o ne '/';
1194 foreach (split(/\s+/,$files))
1195 {
1196 $n=&bname($_);
4287ade5
AP
1197 $d=&dname($_);
1198 if (-f "${_}.c")
1199 {
1200 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
1201 }
1202 elsif (-f ($s="${d}${o}asm${o}${n}.pl") or
f63e4be3 1203 ($s=~s/sha256/sha512/ and -f $s) or
4287ade5
AP
1204 -f ($s="${d}${o}${n}.pl"))
1205 {
1206 $ret.=&perlasm_compile_target("$to${o}$n$obj",$s,$n);
1207 }
1208 elsif (-f ($s="${d}${o}asm${o}${n}.S") or
1209 -f ($s="${d}${o}${n}.S"))
1210 {
1211 $ret.=&Sasm_compile_target("$to${o}$n$obj",$s,$n);
1212 }
656829b7
BL
1213 elsif (defined &special_compile_target and
1214 ($s=special_compile_target($_)))
1215 {
1216 $ret.=$s;
1217 }
4287ade5 1218 else { die "no rule for $_"; }
d02b48c6
RE
1219 }
1220 return($ret);
1221 }
1222
1223##############################################################
1224# do a rule for each file that says 'compile' to new direcory
4287ade5
AP
1225sub perlasm_compile_target
1226 {
1227 my($target,$source,$bname)=@_;
656829b7
BL
1228
1229 return platform_perlasm_compile_target($target, $source, $bname)
1230 if defined &platform_perlasm_compile_target;
1231
4287ade5 1232 my($ret);
4287ade5 1233 $bname =~ s/(.*)\.[^\.]$/$1/;
045b2809 1234 $ret ="\$(TMP_D)$o$bname$asm_suffix: $source\n";
548b4763 1235 $ret.="\t\$(PERL) $source $asmtype \$(CFLAG) >\$\@\n";
ce025892 1236 if ($fipscanisteronly)
548b4763 1237 {
045b2809 1238 $ret .= "\t\$(PERL) util$o.pl . \$@ norunasm \$(CFLAG)\n";
548b4763
DSH
1239 }
1240 $ret .= "\n";
045b2809
DSH
1241 $ret.="$target: \$(TMP_D)$o$bname$asm_suffix\n";
1242 $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname$asm_suffix\n\n";
4287ade5
AP
1243 return($ret);
1244 }
1245
1246sub Sasm_compile_target
1247 {
1248 my($target,$source,$bname)=@_;
1249 my($ret);
1250
1251 $bname =~ s/(.*)\.[^\.]$/$1/;
1252 $ret ="\$(TMP_D)$o$bname.asm: $source\n";
16190a71
AP
1253 $ret.="\t\$(CC) -E \$(CFLAG) $source >\$\@\n";
1254 $ret.="\t\$(PERL) util\\fipsas.pl . \$@ norunasm \$(CFLAG)\n" if $fipscanisteronly;
1255 $ret.="\n";
4287ade5
AP
1256 $ret.="$target: \$(TMP_D)$o$bname.asm\n";
1257 $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
1258 return($ret);
1259 }
1260
d02b48c6
RE
1261sub cc_compile_target
1262 {
1263 local($target,$source,$ex_flags)=@_;
1264 local($ret);
1265
d02b48c6
RE
1266 $target =~ s/\//$o/g if $o ne "/";
1267 $source =~ s/\//$o/g if $o ne "/";
3b4d86bf 1268 $ret ="$target: \$(SRC_D)$o$source\n\t";
afdf3669 1269 $ret.="\$(CC)";
fed45e18
DSH
1270 $ret.= " -MMD" if $orig_platform eq "copy";
1271 $ret.= " ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
3b4d86bf 1272 $target =~ s/\.o$/.d/;
fed45e18 1273 $ret.=".sinclude \"$target\"\n\n" if $orig_platform eq "copy";
d02b48c6
RE
1274 return($ret);
1275 }
1276
1277##############################################################
1278sub do_asm_rule
1279 {
1280 local($target,$src)=@_;
1281 local($ret,@s,@t,$i);
1282
1283 $target =~ s/\//$o/g if $o ne "/";
1284 $src =~ s/\//$o/g if $o ne "/";
1285
d02b48c6 1286 @t=split(/\s+/,$target);
73980531
DSH
1287 @s=split(/\s+/,$src);
1288
d02b48c6
RE
1289
1290 for ($i=0; $i<=$#s; $i++)
1291 {
73980531
DSH
1292 my $objfile = $t[$i];
1293 my $srcfile = $s[$i];
1294
1295 if ($perl_asm == 1)
1296 {
1297 my $plasm = $objfile;
1298 $plasm =~ s/${obj}/.pl/;
1299 $ret.="$srcfile: $plasm\n";
1300 $ret.="\t\$(PERL) $plasm $asmtype \$(CFLAG) >$srcfile\n\n";
1301 }
1302
1303 $ret.="$objfile: $srcfile\n";
1304 $ret.="\t\$(ASM) $afile$objfile \$(SRC_D)$o$srcfile\n\n";
d02b48c6
RE
1305 }
1306 return($ret);
1307 }
1308
1309sub do_shlib_rule
1310 {
1311 local($n,$def)=@_;
1312 local($ret,$nn);
1313 local($t);
1314
1315 ($nn=$n) =~ tr/a-z/A-Z/;
1316 $ret.="$n.dll: \$(${nn}OBJ)\n";
1317 if ($vc && $w32)
1318 {
1319 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
1320 }
1321 $ret.="\n";
1322 return($ret);
1323 }
1324
dfeab068
RE
1325# do a rule for each file that says 'copy' to new direcory on change
1326sub do_copy_rule
1327 {
1328 local($to,$files,$p)=@_;
1329 local($ret,$_,$n,$pp);
1330
e8cdcd52 1331
dfeab068
RE
1332 $files =~ s/\//$o/g if $o ne '/';
1333 foreach (split(/\s+/,$files))
1334 {
1335 $n=&bname($_);
1336 if ($n =~ /bss_file/)
1337 { $pp=".c"; }
1338 else { $pp=$p; }
1a70fe95 1339 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(PERL) \$(SRC_D)${o}util${o}copy-if-different.pl \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
dfeab068
RE
1340 }
1341 return($ret);
1342 }
31ff97b2 1343
e8cdcd52
RL
1344sub do_dofile_rule
1345 {
1346 (my $to, my $file, my $tmpl) = @_;
1347
1348 $file =~ s|/|$o|g if $o ne '/';
1349 return <<"EOF";
1350$to${o}$file: $tmpl
1351 \$(PERL) "-I." "-Mconfigdata" util/dofile.pl "$tmpl" > "$to${o}$file.new"
db73bd22 1352 \$(MV) "$to${o}$file.new" "$to${o}$file"
e8cdcd52
RL
1353EOF
1354 }
1355
3881d810
DSH
1356# Options picked up from the OPTIONS line in the top level Makefile
1357# generated by Configure.
1358
31ff97b2
UM
1359sub read_options
1360 {
00b8abee
DSH
1361 # Many options are handled in a similar way. In particular
1362 # no-xxx sets zero or more scalars to 1.
3881d810
DSH
1363 # Process these using the %valid_options hash containing the option
1364 # name and reference to the scalars to set. In some cases the option
1365 # needs no special handling and can be ignored: this is done by
1366 # setting the value to 0.
00b8abee
DSH
1367
1368 my %valid_options = (
1369 "no-rc2" => \$no_rc2,
1370 "no-rc4" => \$no_rc4,
1371 "no-rc5" => \$no_rc5,
1372 "no-idea" => \$no_idea,
1373 "no-aes" => \$no_aes,
f3dea9a5 1374 "no-camellia" => \$no_camellia,
96afc1cf 1375 "no-seed" => \$no_seed,
00b8abee
DSH
1376 "no-des" => \$no_des,
1377 "no-bf" => \$no_bf,
1378 "no-cast" => \$no_cast,
1379 "no-md2" => \$no_md2,
1380 "no-md4" => \$no_md4,
1381 "no-md5" => \$no_md5,
00b8abee
DSH
1382 "no-ripemd" => \$no_ripemd,
1383 "no-mdc2" => \$no_mdc2,
ec645d90 1384 "no-whirlpool" => \$no_whirlpool,
00b8abee
DSH
1385 "no-patents" =>
1386 [\$no_rc2, \$no_rc4, \$no_rc5, \$no_idea, \$no_rsa],
1387 "no-rsa" => \$no_rsa,
1388 "no-dsa" => \$no_dsa,
1389 "no-dh" => \$no_dh,
00b8abee
DSH
1390 "no-asm" => \$no_asm,
1391 "nasm" => \$nasm,
1392 "nw-nasm" => \$nw_nasm,
1393 "nw-mwasm" => \$nw_mwasm,
1394 "gaswin" => \$gaswin,
00b8abee 1395 "no-ssl3" => \$no_ssl3,
3881d810 1396 "no-ssl3-method" => 0,
edc032b5 1397 "no-srp" => \$no_srp,
88db4e6b 1398 "no-cms" => \$no_cms,
79bd20fd 1399 "no-jpake" => \$no_jpake,
36246be9 1400 "no-ec2m" => \$no_ec2m,
6b0ac883 1401 "no-ec_nistp_64_gcc_128" => 0,
00b8abee
DSH
1402 "no-err" => \$no_err,
1403 "no-sock" => \$no_sock,
00b8abee 1404 "no-ec" => \$no_ec,
4ed7b78b 1405 "no-gost" => \$no_gost,
00b8abee 1406 "no-engine" => \$no_engine,
0423f812 1407 "no-egd" => 0,
00b8abee 1408 "no-hw" => \$no_hw,
52739e40 1409 "no-async" => \$no_async,
b184e3ef 1410 "no-autoalginit" => \$no_autoalginit,
498abff0 1411 "no-autoerrinit" => \$no_autoerrinit,
00b8abee
DSH
1412 "just-ssl" =>
1413 [\$no_rc2, \$no_idea, \$no_des, \$no_bf, \$no_cast,
474e469b 1414 \$no_md2, \$no_mdc2, \$no_dsa, \$no_dh,
45f55f6a 1415 \$no_err, \$no_ripemd, \$no_rc5,
edc032b5 1416 \$no_aes, \$no_camellia, \$no_seed, \$no_srp],
00b8abee
DSH
1417 "rsaref" => 0,
1418 "gcc" => \$gcc,
1419 "debug" => \$debug,
a33b1312 1420 "--debug" => \$debug,
00b8abee
DSH
1421 "profile" => \$profile,
1422 "shlib" => \$shlib,
bf2336f4 1423 "dll" => \$shlib,
00b8abee 1424 "shared" => 0,
995a6b10 1425 "no-sctp" => 0,
3dd814ac 1426 "no-srtp" => 0,
00b8abee 1427 "no-gmp" => 0,
d137b56a 1428 "no-rfc3779" => 0,
64ddafc6 1429 "no-montasm" => 0,
00b8abee 1430 "no-shared" => 0,
d6e460d4 1431 "no-store" => 0,
00b8abee
DSH
1432 "no-zlib" => 0,
1433 "no-zlib-dynamic" => 0,
8fdb4f1a 1434 "no-ssl-trace" => 0,
e0fc7961 1435 "no-unit-test" => 0,
732192a0 1436 "no-deprecated" => 0,
dc0e9a35 1437 "no-ocb" => 0,
7de1f072 1438 "no-crypto-mdebug" => 0,
06b433ac
DSH
1439 "fips" => \$fips,
1440 "fipscanisterbuild" => [\$fips, \$fipscanisterbuild],
d989e4f8 1441 "fipscanisteronly" => [\$fips, \$fipscanisterbuild, \$fipscanisteronly],
01f06617 1442 "fipscheck" => [\$fips, \$fipscanisterbuild, \$fipscanisteronly],
00b8abee
DSH
1443 );
1444
1445 if (exists $valid_options{$_})
1446 {
1447 my $r = $valid_options{$_};
1448 if ( ref $r eq "SCALAR")
1449 { $$r = 1;}
1450 elsif ( ref $r eq "ARRAY")
1451 {
1452 my $r2;
1453 foreach $r2 (@$r)
1454 {
1455 $$r2 = 1;
1456 }
1457 }
1458 }
231b98a5 1459 elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; }
ad2695b1 1460 elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
6bc8e6b8
DSH
1461 elsif (/^enable-zlib-dynamic$/)
1462 {
ad2695b1 1463 $zlib_opt = 2;
6bc8e6b8 1464 }
fbf002bb
DSH
1465 elsif (/^no-static-engine/)
1466 {
1467 $no_static_engine = 1;
1468 }
1469 elsif (/^enable-static-engine/)
1470 {
1471 $no_static_engine = 0;
1472 }
00b8abee
DSH
1473 # There are also enable-xxx options which correspond to
1474 # the no-xxx. Since the scalars are enabled by default
1475 # these can be ignored.
1476 elsif (/^enable-/)
1477 {
1478 my $t = $_;
1479 $t =~ s/^enable/no/;
1480 if (exists $valid_options{$t})
1481 {return 1;}
1482 return 0;
48114ec9
BM
1483 }
1484 # experimental-xxx is mostly like enable-xxx, but opensslconf.v
1485 # will still set OPENSSL_NO_xxx unless we set OPENSSL_EXPERIMENTAL_xxx.
1486 # (No need to fail if we don't know the algorithm -- this is for adventurous users only.)
1487 elsif (/^experimental-/)
1488 {
1489 my $algo, $ALGO;
1490 ($algo = $_) =~ s/^experimental-//;
1491 ($ALGO = $algo) =~ tr/[a-z]/[A-Z]/;
1492
1493 $xcflags="-DOPENSSL_EXPERIMENTAL_$ALGO $xcflags";
1494
00b8abee 1495 }
31ff97b2
UM
1496 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1497 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
1498 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
1499 { $c_flags.="$_ "; }
ad2cb8b4
BM
1500 else { return(0); }
1501 return(1);
31ff97b2 1502 }
06b433ac
DSH
1503
1504sub fipslib_error
1505 {
1506 print STDERR "***FIPS module directory sanity check failed***\n";
1507 print STDERR "FIPS module build failed, or was deleted\n";
1508 print STDERR "Please rebuild FIPS module.\n";
1509 exit 1;
1510 }
1511
1512sub fips_check_files
1513 {
1514 my $dir = shift @_;
1515 my $ret = 1;
1516 if (!-d $dir)
1517 {
1518 print STDERR "FIPS module directory $dir does not exist\n";
1519 fipslib_error();
1520 }
1521 foreach (@_)
1522 {
1523 if (!-f "$dir${o}$_")
1524 {
1525 print STDERR "FIPS module file $_ does not exist!\n";
1526 $ret = 0;
1527 }
1528 }
1529 fipslib_error() if ($ret == 0);
1530 }