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