Redirect RSA keygen, sign, verify to FIPS module.
[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.= " -DZLIB" if $zlib_opt;
277 $cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
278
279 if ($no_static_engine)
280         {
281         $cflags .= " -DOPENSSL_NO_STATIC_ENGINE";
282         }
283 else
284         {
285         $cflags .= " -DOPENSSL_NO_DYNAMIC_ENGINE";
286         }
287
288 #$cflags.=" -DRSAref"  if $rsaref ne "";
289
290 ## if ($unix)
291 ##      { $cflags="$c_flags" if ($c_flags ne ""); }
292 ##else
293         { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
294
295 $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
296
297
298 %shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
299                   "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
300
301 if ($msdos)
302         {
303         $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
304         $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
305         $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
306         $banner.="\t\@echo documentation for details.\n";
307         }
308
309 # have to do this to allow $(CC) under unix
310 $link="$bin_dir$link" if ($link !~ /^\$/);
311
312 $INSTALLTOP =~ s|/|$o|g;
313 $OPENSSLDIR =~ s|/|$o|g;
314
315 #############################################
316 # We parse in input file and 'store' info for later printing.
317 open(IN,"<$infile") || die "unable to open $infile:$!\n";
318 $_=<IN>;
319 for (;;)
320         {
321         chop;
322
323         ($key,$val)=/^([^=]+)=(.*)/;
324         if ($key eq "RELATIVE_DIRECTORY")
325                 {
326                 if ($lib ne "")
327                         {
328                         $uc=$lib;
329                         $uc =~ s/^lib(.*)\.a/$1/;
330                         $uc =~ tr/a-z/A-Z/;
331                         $lib_nam{$uc}=$uc;
332                         $lib_obj{$uc}.=$libobj." ";
333                         }
334                 last if ($val eq "FINISHED");
335                 $lib="";
336                 $libobj="";
337                 $dir=$val;
338                 }
339
340         if ($key eq "KRB5_INCLUDES")
341                 { $cflags .= " $val";}
342
343         if ($key eq "ZLIB_INCLUDE")
344                 { $cflags .= " $val" if $val ne "";}
345
346         if ($key eq "LIBZLIB")
347                 { $zlib_lib = "$val" if $val ne "";}
348
349         if ($key eq "LIBKRB5")
350                 { $ex_libs .= " $val" if $val ne "";}
351
352         if ($key eq "TEST")
353                 { $test.=&var_add($dir,$val, 0); }
354
355         if (($key eq "PROGS") || ($key eq "E_OBJ"))
356                 { $e_exe.=&var_add($dir,$val, 0); }
357
358         if ($key eq "LIB")
359                 {
360                 $lib=$val;
361                 $lib =~ s/^.*\/([^\/]+)$/$1/;
362                 }
363         if ($key eq "LIBNAME" && $no_static_engine)
364                 {
365                 $lib=$val;
366                 $lib =~ s/^.*\/([^\/]+)$/$1/;
367                 $otherlibs .= " $lib";
368                 }
369
370         if ($key eq "EXHEADER")
371                 { $exheader.=&var_add($dir,$val, 1); }
372
373         if ($key eq "HEADER")
374                 { $header.=&var_add($dir,$val, 1); }
375
376         if ($key eq "LIBOBJ" && ($dir ne "engines" || !$no_static_engine))
377                 { $libobj=&var_add($dir,$val, 0); }
378         if ($key eq "LIBNAMES" && $dir eq "engines" && $no_static_engine)
379                 { $engines.=$val }
380
381         if (!($_=<IN>))
382                 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
383         }
384 close(IN);
385
386 if ($shlib)
387         {
388         $extra_install= <<"EOF";
389         \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}bin\"
390         \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}bin\"
391         \$(CP) \"\$(L_SSL)\" \"\$(INSTALLTOP)${o}lib\"
392         \$(CP) \"\$(L_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
393 EOF
394         if ($no_static_engine)
395                 {
396                 $extra_install .= <<"EOF"
397         \$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
398         \$(CP) \"\$(E_SHLIB)\" \"\$(INSTALLTOP)${o}lib${o}engines\"
399 EOF
400                 }
401         }
402 else
403         {
404         $extra_install= <<"EOF";
405         \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}lib\"
406         \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
407 EOF
408         $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
409         }
410
411 $defs= <<"EOF";
412 # This makefile has been automatically generated from the OpenSSL distribution.
413 # This single makefile will build the complete OpenSSL distribution and
414 # by default leave the 'intertesting' output files in .${o}out and the stuff
415 # that needs deleting in .${o}tmp.
416 # The file was generated by running 'make makefile.one', which
417 # does a 'make files', which writes all the environment variables from all
418 # the makefiles to the file call MINFO.  This file is used by
419 # util${o}mk1mf.pl to generate makefile.one.
420 # The 'makefile per directory' system suites me when developing this
421 # library and also so I can 'distribute' indervidual library sections.
422 # The one monster makefile better suits building in non-unix
423 # environments.
424
425 EOF
426
427 $defs .= $preamble if defined $preamble;
428
429 $defs.= <<"EOF";
430 INSTALLTOP=$INSTALLTOP
431 OPENSSLDIR=$OPENSSLDIR
432
433 # Set your compiler options
434 PLATFORM=$platform
435 CC=$bin_dir${cc}
436 CFLAG=$cflags
437 APP_CFLAG=$app_cflag
438 LIB_CFLAG=$lib_cflag
439 SHLIB_CFLAG=$shl_cflag
440 APP_EX_OBJ=$app_ex_obj
441 SHLIB_EX_OBJ=$shlib_ex_obj
442 # add extra libraries to this define, for solaris -lsocket -lnsl would
443 # be added
444 EX_LIBS=$ex_libs
445
446 # The OpenSSL directory
447 SRC_D=$src_dir
448
449 LINK=$link
450 LFLAGS=$lflags
451 RSC=$rsc
452
453 # The output directory for everything intersting
454 OUT_D=$out_dir
455 # The output directory for all the temporary muck
456 TMP_D=$tmp_dir
457 # The output directory for the header files
458 INC_D=$inc_dir
459 INCO_D=$inc_dir${o}openssl
460
461 PERL=$perl
462 CP=$cp
463 RM=$rm
464 RANLIB=$ranlib
465 MKDIR=$mkdir
466 MKLIB=$bin_dir$mklib
467 MLFLAGS=$mlflags
468 ASM=$bin_dir$asm
469
470 ######################################################
471 # You should not need to touch anything below this point
472 ######################################################
473
474 E_EXE=openssl
475 SSL=$ssl
476 CRYPTO=$crypto
477
478 # BIN_D  - Binary output directory
479 # TEST_D - Binary test file output directory
480 # LIB_D  - library output directory
481 # ENG_D  - dynamic engine output directory
482 # Note: if you change these point to different directories then uncomment out
483 # the lines around the 'NB' comment below.
484
485 BIN_D=\$(OUT_D)
486 TEST_D=\$(OUT_D)
487 LIB_D=\$(OUT_D)
488 ENG_D=\$(OUT_D)
489
490 # INCL_D - local library directory
491 # OBJ_D  - temp object file directory
492 OBJ_D=\$(TMP_D)
493 INCL_D=\$(TMP_D)
494
495 O_SSL=     \$(LIB_D)$o$plib\$(SSL)$shlibp
496 O_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
497 SO_SSL=    $plib\$(SSL)$so_shlibp
498 SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
499 L_SSL=     \$(LIB_D)$o$plib\$(SSL)$libp
500 L_CRYPTO=  \$(LIB_D)$o$plib\$(CRYPTO)$libp
501
502 L_LIBS= \$(L_SSL) \$(L_CRYPTO)
503
504 ######################################################
505 # Don't touch anything below this point
506 ######################################################
507
508 INC=-I\$(INC_D) -I\$(INCL_D)
509 APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
510 LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
511 SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
512 LIBS_DEP=\$(O_CRYPTO) \$(O_SSL)
513
514 #############################################
515 EOF
516
517 $rules=<<"EOF";
518 all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe
519
520 banner:
521 $banner
522
523 \$(TMP_D):
524         \$(MKDIR) \"\$(TMP_D)\"
525 # NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
526 #\$(BIN_D):
527 #       \$(MKDIR) \$(BIN_D)
528 #
529 #\$(TEST_D):
530 #       \$(MKDIR) \$(TEST_D)
531
532 \$(LIB_D):
533         \$(MKDIR) \"\$(LIB_D)\"
534
535 \$(INCO_D): \$(INC_D)
536         \$(MKDIR) \"\$(INCO_D)\"
537
538 \$(INC_D):
539         \$(MKDIR) \"\$(INC_D)\"
540
541 headers: \$(HEADER) \$(EXHEADER)
542         @
543
544 lib: \$(LIBS_DEP) \$(E_SHLIB)
545
546 exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
547
548 install: all
549         \$(MKDIR) \"\$(INSTALLTOP)\"
550         \$(MKDIR) \"\$(INSTALLTOP)${o}bin\"
551         \$(MKDIR) \"\$(INSTALLTOP)${o}include\"
552         \$(MKDIR) \"\$(INSTALLTOP)${o}include${o}openssl\"
553         \$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
554         \$(CP) \"\$(INCO_D)${o}*.\[ch\]\" \"\$(INSTALLTOP)${o}include${o}openssl\"
555         \$(CP) \"\$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin\"
556         \$(MKDIR) \"\$(OPENSSLDIR)\"
557         \$(CP) apps${o}openssl.cnf \"\$(OPENSSLDIR)\"
558 $extra_install
559
560
561 test: \$(T_EXE)
562         cd \$(BIN_D)
563         ..${o}ms${o}test
564
565 clean:
566         \$(RM) \$(TMP_D)$o*.*
567
568 vclean:
569         \$(RM) \$(TMP_D)$o*.*
570         \$(RM) \$(OUT_D)$o*.*
571
572 EOF
573     
574 my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
575 $platform_cpp_symbol =~ s/-/_/g;
576 if (open(IN,"crypto/buildinf.h"))
577         {
578         # Remove entry for this platform in existing file buildinf.h.
579
580         my $old_buildinf_h = "";
581         while (<IN>)
582                 {
583                 if (/^\#ifdef $platform_cpp_symbol$/)
584                         {
585                         while (<IN>) { last if (/^\#endif/); }
586                         }
587                 else
588                         {
589                         $old_buildinf_h .= $_;
590                         }
591                 }
592         close(IN);
593
594         open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
595         print OUT $old_buildinf_h;
596         close(OUT);
597         }
598
599 open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
600 printf OUT <<EOF;
601 #ifdef $platform_cpp_symbol
602   /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
603   #define CFLAGS "$cc $cflags"
604   #define PLATFORM "$platform"
605 EOF
606 printf OUT "  #define DATE \"%s\"\n", scalar gmtime();
607 printf OUT "#endif\n";
608 close(OUT);
609
610 # Strip of trailing ' '
611 foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
612 $test=&clean_up_ws($test);
613 $e_exe=&clean_up_ws($e_exe);
614 $exheader=&clean_up_ws($exheader);
615 $header=&clean_up_ws($header);
616
617 # First we strip the exheaders from the headers list
618 foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
619 foreach (split(/\s+/,$header))  { $h.=$_." " unless $h{$_}; }
620 chop($h); $header=$h;
621
622 $defs.=&do_defs("HEADER",$header,"\$(INCL_D)","");
623 $rules.=&do_copy_rule("\$(INCL_D)",$header,"");
624
625 $defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)","");
626 $rules.=&do_copy_rule("\$(INCO_D)",$exheader,"");
627
628 $defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
629 $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
630
631 $defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
632 $rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
633
634 foreach (values %lib_nam)
635         {
636         $lib_obj=$lib_obj{$_};
637         local($slib)=$shlib;
638
639         if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
640                 {
641                 $rules.="\$(O_SSL):\n\n"; 
642                 next;
643                 }
644
645         $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
646         $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
647         $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
648         }
649
650 # hack to add version info on MSVC
651 if (($platform eq "VC-WIN32") || ($platform eq "VC-WIN64A")
652         || ($platform eq "VC-WIN64I") || ($platform eq "VC-NT")) {
653     $rules.= <<"EOF";
654 \$(OBJ_D)\\\$(CRYPTO).res: ms\\version32.rc
655         \$(RSC) /fo"\$(OBJ_D)\\\$(CRYPTO).res" /d CRYPTO ms\\version32.rc
656
657 \$(OBJ_D)\\\$(SSL).res: ms\\version32.rc
658         \$(RSC) /fo"\$(OBJ_D)\\\$(SSL).res" /d SSL ms\\version32.rc
659
660 EOF
661 }
662
663 $defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
664 foreach (split(/\s+/,$test))
665         {
666         $t=&bname($_);
667         $tt="\$(OBJ_D)${o}$t${obj}";
668         $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
669         }
670
671 $defs.=&do_defs("E_SHLIB",$engines . $otherlibs,"\$(ENG_D)",$shlibp);
672
673 foreach (split(/\s+/,$engines))
674         {
675         $rules.=&do_compile_rule("\$(OBJ_D)","engines${o}e_$_",$lib);
676         $rules.= &do_lib_rule("\$(OBJ_D)${o}e_${_}.obj","\$(ENG_D)$o$_$shlibp","",$shlib,"");
677         }
678
679
680
681 $rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
682 $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
683
684 foreach (split(" ",$otherlibs))
685         {
686         my $uc = $_;
687         $uc =~ tr /a-z/A-Z/;    
688         $rules.= &do_lib_rule("\$(${uc}OBJ)","\$(ENG_D)$o$_$shlibp", "", $shlib, "");
689
690         }
691
692 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
693
694 print $defs;
695
696 if ($platform eq "linux-elf") {
697     print <<"EOF";
698 # Generate perlasm output files
699 %.cpp:
700         (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
701 EOF
702 }
703 print "###################################################################\n";
704 print $rules;
705
706 ###############################################
707 # strip off any trailing .[och] and append the relative directory
708 # also remembering to do nothing if we are in one of the dropped
709 # directories
710 sub var_add
711         {
712         local($dir,$val,$keepext)=@_;
713         local(@a,$_,$ret);
714
715         return("") if $no_engine && $dir =~ /\/engine/;
716         return("") if $no_hw   && $dir =~ /\/hw/;
717         return("") if $no_idea && $dir =~ /\/idea/;
718         return("") if $no_aes  && $dir =~ /\/aes/;
719         return("") if $no_camellia  && $dir =~ /\/camellia/;
720         return("") if $no_seed && $dir =~ /\/seed/;
721         return("") if $no_rc2  && $dir =~ /\/rc2/;
722         return("") if $no_rc4  && $dir =~ /\/rc4/;
723         return("") if $no_rc5  && $dir =~ /\/rc5/;
724         return("") if $no_rsa  && $dir =~ /\/rsa/;
725         return("") if $no_rsa  && $dir =~ /^rsaref/;
726         return("") if $no_dsa  && $dir =~ /\/dsa/;
727         return("") if $no_dh   && $dir =~ /\/dh/;
728         return("") if $no_ec   && $dir =~ /\/ec/;
729         return("") if $no_gost   && $dir =~ /\/ccgost/;
730         return("") if $no_cms  && $dir =~ /\/cms/;
731         return("") if $no_jpake  && $dir =~ /\/jpake/;
732         if ($no_des && $dir =~ /\/des/)
733                 {
734                 if ($val =~ /read_pwd/)
735                         { return("$dir/read_pwd "); }
736                 else
737                         { return(""); }
738                 }
739         return("") if $no_mdc2 && $dir =~ /\/mdc2/;
740         return("") if $no_sock && $dir =~ /\/proxy/;
741         return("") if $no_bf   && $dir =~ /\/bf/;
742         return("") if $no_cast && $dir =~ /\/cast/;
743         return("") if $no_whirlpool && $dir =~ /\/whrlpool/;
744
745         $val =~ s/^\s*(.*)\s*$/$1/;
746         @a=split(/\s+/,$val);
747         grep(s/\.[och]$//,@a) unless $keepext;
748
749         @a=grep(!/^e_.*_3d$/,@a) if $no_des;
750         @a=grep(!/^e_.*_d$/,@a) if $no_des;
751         @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
752         @a=grep(!/^e_.*_i$/,@a) if $no_aes;
753         @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
754         @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
755         @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
756         @a=grep(!/^e_.*_c$/,@a) if $no_cast;
757         @a=grep(!/^e_rc4$/,@a) if $no_rc4;
758         @a=grep(!/^e_camellia$/,@a) if $no_camellia;
759         @a=grep(!/^e_seed$/,@a) if $no_seed;
760
761         #@a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
762         #@a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
763
764         @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
765
766         @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
767         @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
768         @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
769         @a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
770
771         @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
772         @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
773         @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
774
775         @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
776         @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
777
778         @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
779
780         @a=grep(!/_dhp$/,@a) if $no_dh;
781
782         @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
783         @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
784         @a=grep(!/_mdc2$/,@a) if $no_mdc2;
785
786         @a=grep(!/(srp)/,@a) if $no_srp;
787
788         @a=grep(!/^engine$/,@a) if $no_engine;
789         @a=grep(!/^hw$/,@a) if $no_hw;
790         @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
791         @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
792         @a=grep(!/^gendsa$/,@a) if $no_sha1;
793         @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
794
795         @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
796
797         grep($_="$dir/$_",@a);
798         @a=grep(!/(^|\/)s_/,@a) if $no_sock;
799         @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
800         $ret=join(' ',@a)." ";
801         return($ret);
802         }
803
804 # change things so that each 'token' is only separated by one space
805 sub clean_up_ws
806         {
807         local($w)=@_;
808
809         $w =~ s/^\s*(.*)\s*$/$1/;
810         $w =~ s/\s+/ /g;
811         return($w);
812         }
813
814 sub do_defs
815         {
816         local($var,$files,$location,$postfix)=@_;
817         local($_,$ret,$pf);
818         local(*OUT,$tmp,$t);
819
820         $files =~ s/\//$o/g if $o ne '/';
821         $ret="$var="; 
822         $n=1;
823         $Vars{$var}.="";
824         foreach (split(/ /,$files))
825                 {
826                 $orig=$_;
827                 $_=&bname($_) unless /^\$/;
828                 if ($n++ == 2)
829                         {
830                         $n=0;
831                         $ret.="\\\n\t";
832                         }
833                 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
834                         { $pf=".c"; }
835                 else    { $pf=$postfix; }
836                 if ($_ =~ /BN_ASM/)     { $t="$_ "; }
837                 elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
838                 elsif ($_ =~ /AES_ASM/){ $t="$_ "; }
839                 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
840                 elsif ($_ =~ /BF_ENC/)  { $t="$_ "; }
841                 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
842                 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
843                 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
844                 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
845                 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
846                 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
847                 elsif ($_ =~ /WHIRLPOOL_ASM/){ $t="$_ "; }
848                 elsif ($_ =~ /CPUID_ASM/){ $t="$_ "; }
849                 else    { $t="$location${o}$_$pf "; }
850
851                 $Vars{$var}.="$t ";
852                 $ret.=$t;
853                 }
854         # hack to add version info on MSVC
855         if ($shlib && (($platform eq "VC-WIN32") || ($platfrom eq "VC-WIN64I") || ($platform eq "VC-WIN64A") || ($platform eq "VC-NT")))
856                 {
857                 if ($var eq "CRYPTOOBJ")
858                         { $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
859                 elsif ($var eq "SSLOBJ")
860                         { $ret.="\$(OBJ_D)\\\$(SSL).res "; }
861                 }
862         chomp($ret);
863         $ret.="\n\n";
864         return($ret);
865         }
866
867 # return the name with the leading path removed
868 sub bname
869         {
870         local($ret)=@_;
871         $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
872         return($ret);
873         }
874
875 # return the leading path
876 sub dname
877         {
878         my $ret=shift;
879         $ret =~ s/(^.*)[\\\/][^\\\/]+$/$1/;
880         return($ret);
881         }
882
883 ##############################################################
884 # do a rule for each file that says 'compile' to new direcory
885 # compile the files in '$files' into $to
886 sub do_compile_rule
887         {
888         local($to,$files,$ex)=@_;
889         local($ret,$_,$n,$d,$s);
890
891         $files =~ s/\//$o/g if $o ne '/';
892         foreach (split(/\s+/,$files))
893                 {
894                 $n=&bname($_);
895                 $d=&dname($_);
896                 if (-f "${_}.c")
897                         {
898                         $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
899                         }
900                 elsif (-f ($s="${d}${o}asm${o}${n}.pl") or
901                        ($s=~s/sha256/sha512/ and -f $s) or
902                        -f ($s="${d}${o}${n}.pl"))
903                         {
904                         $ret.=&perlasm_compile_target("$to${o}$n$obj",$s,$n);
905                         }
906                 elsif (-f ($s="${d}${o}asm${o}${n}.S") or
907                        -f ($s="${d}${o}${n}.S"))
908                         {
909                         $ret.=&Sasm_compile_target("$to${o}$n$obj",$s,$n);
910                         }
911                 else    { die "no rule for $_"; }
912                 }
913         return($ret);
914         }
915
916 ##############################################################
917 # do a rule for each file that says 'compile' to new direcory
918 sub perlasm_compile_target
919         {
920         my($target,$source,$bname)=@_;
921         my($ret);
922
923         $bname =~ s/(.*)\.[^\.]$/$1/;
924         $ret ="\$(TMP_D)$o$bname.asm: $source\n";
925         $ret.="\t\$(PERL) $source $asmtype \$(CFLAG) >\$\@\n\n";
926         $ret.="$target: \$(TMP_D)$o$bname.asm\n";
927         $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
928         return($ret);
929         }
930
931 sub Sasm_compile_target
932         {
933         my($target,$source,$bname)=@_;
934         my($ret);
935
936         $bname =~ s/(.*)\.[^\.]$/$1/;
937         $ret ="\$(TMP_D)$o$bname.asm: $source\n";
938         $ret.="\t\$(CC) -E \$(CFLAG) $source >\$\@\n\n";
939         $ret.="$target: \$(TMP_D)$o$bname.asm\n";
940         $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
941         return($ret);
942         }
943
944 sub cc_compile_target
945         {
946         local($target,$source,$ex_flags)=@_;
947         local($ret);
948         
949         $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
950         $target =~ s/\//$o/g if $o ne "/";
951         $source =~ s/\//$o/g if $o ne "/";
952         $ret ="$target: \$(SRC_D)$o$source\n\t";
953         $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
954         return($ret);
955         }
956
957 ##############################################################
958 sub do_asm_rule
959         {
960         local($target,$src)=@_;
961         local($ret,@s,@t,$i);
962
963         $target =~ s/\//$o/g if $o ne "/";
964         $src =~ s/\//$o/g if $o ne "/";
965
966         @t=split(/\s+/,$target);
967         @s=split(/\s+/,$src);
968
969
970         for ($i=0; $i<=$#s; $i++)
971                 {
972                 my $objfile = $t[$i];
973                 my $srcfile = $s[$i];
974
975                 if ($perl_asm == 1)
976                         {
977                         my $plasm = $objfile;
978                         $plasm =~ s/${obj}/.pl/;
979                         $ret.="$srcfile: $plasm\n";
980                         $ret.="\t\$(PERL) $plasm $asmtype \$(CFLAG) >$srcfile\n\n";
981                         }
982
983                 $ret.="$objfile: $srcfile\n";
984                 $ret.="\t\$(ASM) $afile$objfile \$(SRC_D)$o$srcfile\n\n";
985                 }
986         return($ret);
987         }
988
989 sub do_shlib_rule
990         {
991         local($n,$def)=@_;
992         local($ret,$nn);
993         local($t);
994
995         ($nn=$n) =~ tr/a-z/A-Z/;
996         $ret.="$n.dll: \$(${nn}OBJ)\n";
997         if ($vc && $w32)
998                 {
999                 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n  \$(${nn}OBJ_F)\n<<\n";
1000                 }
1001         $ret.="\n";
1002         return($ret);
1003         }
1004
1005 # do a rule for each file that says 'copy' to new direcory on change
1006 sub do_copy_rule
1007         {
1008         local($to,$files,$p)=@_;
1009         local($ret,$_,$n,$pp);
1010         
1011         $files =~ s/\//$o/g if $o ne '/';
1012         foreach (split(/\s+/,$files))
1013                 {
1014                 $n=&bname($_);
1015                 if ($n =~ /bss_file/)
1016                         { $pp=".c"; }
1017                 else    { $pp=$p; }
1018                 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
1019                 }
1020         return($ret);
1021         }
1022
1023 sub read_options
1024         {
1025         # Many options are handled in a similar way. In particular
1026         # no-xxx sets zero or more scalars to 1.
1027         # Process these using a hash containing the option name and
1028         # reference to the scalars to set.
1029
1030         my %valid_options = (
1031                 "no-rc2" => \$no_rc2,
1032                 "no-rc4" => \$no_rc4,
1033                 "no-rc5" => \$no_rc5,
1034                 "no-idea" => \$no_idea,
1035                 "no-aes" => \$no_aes,
1036                 "no-camellia" => \$no_camellia,
1037                 "no-seed" => \$no_seed,
1038                 "no-des" => \$no_des,
1039                 "no-bf" => \$no_bf,
1040                 "no-cast" => \$no_cast,
1041                 "no-md2" => \$no_md2,
1042                 "no-md4" => \$no_md4,
1043                 "no-md5" => \$no_md5,
1044                 "no-sha" => \$no_sha,
1045                 "no-sha1" => \$no_sha1,
1046                 "no-ripemd" => \$no_ripemd,
1047                 "no-mdc2" => \$no_mdc2,
1048                 "no-whirlpool" => \$no_whirlpool,
1049                 "no-patents" => 
1050                         [\$no_rc2, \$no_rc4, \$no_rc5, \$no_idea, \$no_rsa],
1051                 "no-rsa" => \$no_rsa,
1052                 "no-dsa" => \$no_dsa,
1053                 "no-dh" => \$no_dh,
1054                 "no-hmac" => \$no_hmac,
1055                 "no-asm" => \$no_asm,
1056                 "nasm" => \$nasm,
1057                 "nw-nasm" => \$nw_nasm,
1058                 "nw-mwasm" => \$nw_mwasm,
1059                 "gaswin" => \$gaswin,
1060                 "no-ssl2" => \$no_ssl2,
1061                 "no-ssl3" => \$no_ssl3,
1062                 "no-tlsext" => \$no_tlsext,
1063                 "no-srp" => \$no_srp,
1064                 "no-cms" => \$no_cms,
1065                 "no-jpake" => \$no_jpake,
1066                 "no-ec-nistp224-64-gcc-128" => 0,
1067                 "no-err" => \$no_err,
1068                 "no-sock" => \$no_sock,
1069                 "no-krb5" => \$no_krb5,
1070                 "no-ec" => \$no_ec,
1071                 "no-ecdsa" => \$no_ecdsa,
1072                 "no-ecdh" => \$no_ecdh,
1073                 "no-gost" => \$no_gost,
1074                 "no-engine" => \$no_engine,
1075                 "no-hw" => \$no_hw,
1076                 "just-ssl" =>
1077                         [\$no_rc2, \$no_idea, \$no_des, \$no_bf, \$no_cast,
1078                           \$no_md2, \$no_sha, \$no_mdc2, \$no_dsa, \$no_dh,
1079                           \$no_ssl2, \$no_err, \$no_ripemd, \$no_rc5,
1080                           \$no_aes, \$no_camellia, \$no_seed, \$no_srp],
1081                 "rsaref" => 0,
1082                 "gcc" => \$gcc,
1083                 "debug" => \$debug,
1084                 "profile" => \$profile,
1085                 "shlib" => \$shlib,
1086                 "dll" => \$shlib,
1087                 "shared" => 0,
1088                 "no-gmp" => 0,
1089                 "no-rfc3779" => 0,
1090                 "no-montasm" => 0,
1091                 "no-shared" => 0,
1092                 "no-store" => 0,
1093                 "no-zlib" => 0,
1094                 "no-zlib-dynamic" => 0,
1095                 );
1096
1097         if (exists $valid_options{$_})
1098                 {
1099                 my $r = $valid_options{$_};
1100                 if ( ref $r eq "SCALAR")
1101                         { $$r = 1;}
1102                 elsif ( ref $r eq "ARRAY")
1103                         {
1104                         my $r2;
1105                         foreach $r2 (@$r)
1106                                 {
1107                                 $$r2 = 1;
1108                                 }
1109                         }
1110                 }
1111         elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; }
1112         elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
1113         elsif (/^enable-zlib-dynamic$/)
1114                 {
1115                 $zlib_opt = 2;
1116                 }
1117         elsif (/^no-static-engine/)
1118                 {
1119                 $no_static_engine = 1;
1120                 }
1121         elsif (/^enable-static-engine/)
1122                 {
1123                 $no_static_engine = 0;
1124                 }
1125         # There are also enable-xxx options which correspond to
1126         # the no-xxx. Since the scalars are enabled by default
1127         # these can be ignored.
1128         elsif (/^enable-/)
1129                 {
1130                 my $t = $_;
1131                 $t =~ s/^enable/no/;
1132                 if (exists $valid_options{$t})
1133                         {return 1;}
1134                 return 0;
1135                 }
1136         # experimental-xxx is mostly like enable-xxx, but opensslconf.v
1137         # will still set OPENSSL_NO_xxx unless we set OPENSSL_EXPERIMENTAL_xxx.
1138         # (No need to fail if we don't know the algorithm -- this is for adventurous users only.)
1139         elsif (/^experimental-/)
1140                 {
1141                 my $algo, $ALGO;
1142                 ($algo = $_) =~ s/^experimental-//;
1143                 ($ALGO = $algo) =~ tr/[a-z]/[A-Z]/;
1144
1145                 $xcflags="-DOPENSSL_EXPERIMENTAL_$ALGO $xcflags";
1146                 
1147                 }
1148         elsif (/^--with-krb5-flavor=(.*)$/)
1149                 {
1150                 my $krb5_flavor = $1;
1151                 if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
1152                         {
1153                         $xcflags="-DKRB5_HEIMDAL $xcflags";
1154                         }
1155                 elsif ($krb5_flavor =~ /^MIT/i)
1156                         {
1157                         $xcflags="-DKRB5_MIT $xcflags";
1158                         if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
1159                                 {
1160                                 $xcflags="-DKRB5_MIT_OLD11 $xcflags"
1161                                 }
1162                         }
1163                 }
1164         elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1165         elsif (/^-[lL].*$/)     { $l_flags.="$_ "; }
1166         elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
1167                 { $c_flags.="$_ "; }
1168         else { return(0); }
1169         return(1);
1170         }