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