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