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