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