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