]> git.ipfire.org Git - thirdparty/openssl.git/blame - util/mk1mf.pl
Modify apps to use NCONF code instead of old CONF code.
[thirdparty/openssl.git] / util / mk1mf.pl
CommitLineData
d02b48c6
RE
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
559b52ac 8$INSTALLTOP="/usr/local/ssl";
31ff97b2
UM
9$OPTIONS="";
10$ssl_version="";
eff5f612 11$banner="\t\@echo Building OpenSSL";
d02b48c6 12
31ff97b2
UM
13open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n";
14while(<IN>) {
15 $ssl_version=$1 if (/^VERSION=(.*)$/);
f76a8084 16 $OPTIONS=$1 if (/^OPTIONS=(.*)$/);
31ff97b2
UM
17 $INSTALLTOP=$1 if (/^INSTALLTOP=(.*$)/);
18}
ce457a54 19close(IN);
31ff97b2
UM
20
21die "Makefile.ssl is not the toplevel Makefile!\n" if $ssl_version eq "";
58964a49 22
d02b48c6
RE
23$infile="MINFO";
24
25%ops=(
06c68491
DSH
26 "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X",
27 "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY",
d02b48c6
RE
28 "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286",
29 "VC-WIN16", "Alias for VC-W31-32",
30 "VC-W31-32", "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+",
31 "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS",
31a674d8 32 "Mingw32", "GNU C++ - Windows NT or 9x",
12d7d32f 33 "Mingw32-files", "Create files with DOS copy ...",
31a674d8 34 "BC-NT", "Borland C++ 4.5 - Windows NT",
d02b48c6
RE
35 "BC-W31", "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING",
36 "BC-MSDOS","Borland C++ 4.5 - MSDOS",
58964a49 37 "linux-elf","Linux elf",
dfeab068 38 "ultrix-mips","DEC mips ultrix",
d02b48c6
RE
39 "FreeBSD","FreeBSD distribution",
40 "default","cc under unix",
41 );
42
dfeab068 43$platform="";
d02b48c6
RE
44foreach (@ARGV)
45 {
31ff97b2 46 if (!&read_options && !defined($ops{$_}))
d02b48c6 47 {
31ff97b2 48 print STDERR "unknown option - $_\n";
748365ee 49 print STDERR "usage: perl mk1mf.pl [options] [system]\n";
31ff97b2
UM
50 print STDERR "\nwhere [system] can be one of the following\n";
51 foreach $i (sort keys %ops)
52 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
53 print STDERR <<"EOF";
d02b48c6 54and [options] can be one of
3009458e
RL
55 no-md2 no-md4 no-md5 no-sha no-mdc2 - Skip this digest
56 no-ripemd
77dd9c18
RL
57 no-rc2 no-rc4 no-rc5 no-idea no-des - Skip this symetric cipher
58 no-bf no-cast no-aes
d02b48c6
RE
59 no-rsa no-dsa no-dh - Skip this public key cipher
60 no-ssl2 no-ssl3 - Skip this version of SSL
61 just-ssl - remove all non-ssl keys/digest
62 no-asm - No x86 asm
97f56446 63 no-krb5 - No KRB5
bbdb5438 64 nasm - Use NASM for x86 asm
2da0c119 65 gaswin - Use GNU as with Mingw32
d02b48c6
RE
66 no-socks - No socket code
67 no-err - No error strings
68 dll/shlib - Build shared libraries (MS)
69 debug - Debug build
d55a3cf1 70 profile - Profiling build
d02b48c6 71 gcc - Use Gcc (unix)
d02b48c6
RE
72
73Values that can be set
58964a49 74TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
d02b48c6
RE
75
76-L<ex_lib_path> -l<ex_lib> - extra library flags (unix)
77-<ex_cc_flags> - extra 'cc' flags,
78 added (MS), or replace (unix)
79EOF
31ff97b2 80 exit(1);
d02b48c6 81 }
31ff97b2
UM
82 $platform=$_;
83 }
7f2113a2 84foreach (grep(!/^$/, split(/ /, $OPTIONS)))
31ff97b2
UM
85 {
86 print STDERR "unknown option - $_\n" if !&read_options;
d02b48c6
RE
87 }
88
89$no_mdc2=1 if ($no_des);
90
8cf65228 91$no_ssl3=1 if ($no_md5 || $no_sha);
d02b48c6
RE
92$no_ssl3=1 if ($no_rsa && $no_dh);
93
94$no_ssl2=1 if ($no_md5 || $no_rsa);
95$no_ssl2=1 if ($no_rsa);
96
58964a49
RE
97$out_def="out";
98$inc_def="outinc";
99$tmp_def="tmp";
100
12d7d32f 101$mkdir="mkdir";
d02b48c6
RE
102
103($ssl,$crypto)=("ssl","crypto");
d02b48c6
RE
104$ranlib="echo ranlib";
105
58964a49
RE
106$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
107$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
108$bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
109
110# $bin_dir.=$o causes a core dump on my sparc :-(
111
06c68491
DSH
112$NT=0;
113
d02b48c6 114push(@INC,"util/pl","pl");
dfeab068 115if ($platform eq "VC-MSDOS")
d02b48c6
RE
116 {
117 $asmbits=16;
118 $msdos=1;
119 require 'VC-16.pl';
120 }
dfeab068 121elsif ($platform eq "VC-W31-16")
d02b48c6
RE
122 {
123 $asmbits=16;
124 $msdos=1; $win16=1;
125 require 'VC-16.pl';
126 }
dfeab068 127elsif (($platform eq "VC-W31-32") || ($platform eq "VC-WIN16"))
d02b48c6
RE
128 {
129 $asmbits=32;
130 $msdos=1; $win16=1;
131 require 'VC-16.pl';
132 }
dfeab068 133elsif (($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
d02b48c6 134 {
06c68491 135 $NT = 1 if $platform eq "VC-NT";
d02b48c6
RE
136 require 'VC-32.pl';
137 }
31a674d8
UM
138elsif ($platform eq "Mingw32")
139 {
140 require 'Mingw32.pl';
141 }
12d7d32f
UM
142elsif ($platform eq "Mingw32-files")
143 {
144 require 'Mingw32f.pl';
145 }
dfeab068 146elsif ($platform eq "BC-NT")
d02b48c6
RE
147 {
148 $bc=1;
149 require 'BC-32.pl';
150 }
dfeab068 151elsif ($platform eq "BC-W31")
d02b48c6
RE
152 {
153 $bc=1;
154 $msdos=1; $w16=1;
155 require 'BC-16.pl';
156 }
dfeab068 157elsif ($platform eq "BC-Q16")
d02b48c6
RE
158 {
159 $msdos=1; $w16=1; $shlib=0; $qw=1;
160 require 'BC-16.pl';
161 }
dfeab068 162elsif ($platform eq "BC-MSDOS")
d02b48c6
RE
163 {
164 $asmbits=16;
165 $msdos=1;
166 require 'BC-16.pl';
167 }
dfeab068 168elsif ($platform eq "FreeBSD")
d02b48c6
RE
169 {
170 require 'unix.pl';
171 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
172 }
dfeab068 173elsif ($platform eq "linux-elf")
58964a49
RE
174 {
175 require "unix.pl";
176 require "linux.pl";
177 $unix=1;
178 }
dfeab068
RE
179elsif ($platform eq "ultrix-mips")
180 {
181 require "unix.pl";
182 require "ultrix.pl";
183 $unix=1;
184 }
d02b48c6
RE
185else
186 {
187 require "unix.pl";
188
189 $unix=1;
190 $cflags.=' -DTERMIO';
191 }
192
58964a49
RE
193$out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
194$tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
195$inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
196
d02b48c6
RE
197$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
198
cf1b7d96 199$cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
77dd9c18 200$cflags.=" -DOPENSSL_NO_AES" if $no_aes;
cf1b7d96
RL
201$cflags.=" -DOPENSSL_NO_RC2" if $no_rc2;
202$cflags.=" -DOPENSSL_NO_RC4" if $no_rc4;
203$cflags.=" -DOPENSSL_NO_RC5" if $no_rc5;
204$cflags.=" -DOPENSSL_NO_MD2" if $no_md2;
205$cflags.=" -DOPENSSL_NO_MD4" if $no_md4;
206$cflags.=" -DOPENSSL_NO_MD5" if $no_md5;
207$cflags.=" -DOPENSSL_NO_SHA" if $no_sha;
208$cflags.=" -DOPENSSL_NO_SHA1" if $no_sha1;
209$cflags.=" -DOPENSSL_NO_RIPEMD" if $no_rmd160;
210$cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
211$cflags.=" -DOPENSSL_NO_BF" if $no_bf;
212$cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
213$cflags.=" -DOPENSSL_NO_DES" if $no_des;
214$cflags.=" -DOPENSSL_NO_RSA" if $no_rsa;
215$cflags.=" -DOPENSSL_NO_DSA" if $no_dsa;
216$cflags.=" -DOPENSSL_NO_DH" if $no_dh;
217$cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
218$cflags.=" -DOPENSSL_NO_SSL2" if $no_ssl2;
219$cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
220$cflags.=" -DOPENSSL_NO_ERR" if $no_err;
221$cflags.=" -DOPENSSL_NO_KRB5" if $no_krb5;
ccb9643f 222#$cflags.=" -DRSAref" if $rsaref ne "";
d02b48c6 223
d55a3cf1
UM
224## if ($unix)
225## { $cflags="$c_flags" if ($c_flags ne ""); }
226##else
227 { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
d02b48c6
RE
228
229$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
230
f09628e4
RL
231%shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
232 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
233
d02b48c6
RE
234if ($msdos)
235 {
dfeab068 236 $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
d02b48c6
RE
237 $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
238 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
239 $banner.="\t\@echo documentation for details.\n";
240 }
241
242# have to do this to allow $(CC) under unix
243$link="$bin_dir$link" if ($link !~ /^\$/);
244
245$INSTALLTOP =~ s|/|$o|g;
246
247$defs= <<"EOF";
e527ba09
DSH
248# This makefile has been automatically generated from the OpenSSL distribution.
249# This single makefile will build the complete OpenSSL distribution and
d02b48c6
RE
250# by default leave the 'intertesting' output files in .${o}out and the stuff
251# that needs deleting in .${o}tmp.
252# The file was generated by running 'make makefile.one', which
253# does a 'make files', which writes all the environment variables from all
254# the makefiles to the file call MINFO. This file is used by
255# util${o}mk1mf.pl to generate makefile.one.
256# The 'makefile per directory' system suites me when developing this
257# library and also so I can 'distribute' indervidual library sections.
258# The one monster makefile better suits building in non-unix
259# environments.
260
261INSTALLTOP=$INSTALLTOP
262
263# Set your compiler options
dfeab068 264PLATFORM=$platform
d02b48c6
RE
265CC=$bin_dir${cc}
266CFLAG=$cflags
267APP_CFLAG=$app_cflag
268LIB_CFLAG=$lib_cflag
58964a49 269SHLIB_CFLAG=$shl_cflag
d02b48c6
RE
270APP_EX_OBJ=$app_ex_obj
271SHLIB_EX_OBJ=$shlib_ex_obj
272# add extra libraries to this define, for solaris -lsocket -lnsl would
273# be added
274EX_LIBS=$ex_libs
275
e527ba09 276# The OpenSSL directory
d02b48c6
RE
277SRC_D=$src_dir
278
279LINK=$link
280LFLAGS=$lflags
281
dfeab068
RE
282BN_ASM_OBJ=$bn_asm_obj
283BN_ASM_SRC=$bn_asm_src
b222eb64
UM
284BNCO_ASM_OBJ=$bnco_asm_obj
285BNCO_ASM_SRC=$bnco_asm_src
d02b48c6
RE
286DES_ENC_OBJ=$des_enc_obj
287DES_ENC_SRC=$des_enc_src
d02b48c6
RE
288BF_ENC_OBJ=$bf_enc_obj
289BF_ENC_SRC=$bf_enc_src
58964a49
RE
290CAST_ENC_OBJ=$cast_enc_obj
291CAST_ENC_SRC=$cast_enc_src
292RC4_ENC_OBJ=$rc4_enc_obj
293RC4_ENC_SRC=$rc4_enc_src
294RC5_ENC_OBJ=$rc5_enc_obj
295RC5_ENC_SRC=$rc5_enc_src
296MD5_ASM_OBJ=$md5_asm_obj
297MD5_ASM_SRC=$md5_asm_src
298SHA1_ASM_OBJ=$sha1_asm_obj
299SHA1_ASM_SRC=$sha1_asm_src
300RMD160_ASM_OBJ=$rmd160_asm_obj
301RMD160_ASM_SRC=$rmd160_asm_src
d02b48c6
RE
302
303# The output directory for everything intersting
304OUT_D=$out_dir
305# The output directory for all the temporary muck
306TMP_D=$tmp_dir
58964a49
RE
307# The output directory for the header files
308INC_D=$inc_dir
ec577822 309INCO_D=$inc_dir${o}openssl
d02b48c6
RE
310
311CP=$cp
312RM=$rm
313RANLIB=$ranlib
12d7d32f 314MKDIR=$mkdir
d02b48c6
RE
315MKLIB=$bin_dir$mklib
316MLFLAGS=$mlflags
317ASM=$bin_dir$asm
318
319######################################################
320# You should not need to touch anything below this point
321######################################################
322
e527ba09 323E_EXE=openssl
d02b48c6
RE
324SSL=$ssl
325CRYPTO=$crypto
d02b48c6
RE
326
327# BIN_D - Binary output directory
328# TEST_D - Binary test file output directory
329# LIB_D - library output directory
e2e044fa
DSH
330# Note: if you change these point to different directories then uncomment out
331# the lines around the 'NB' comment below.
332#
d02b48c6
RE
333BIN_D=\$(OUT_D)
334TEST_D=\$(OUT_D)
335LIB_D=\$(OUT_D)
d02b48c6
RE
336
337# INCL_D - local library directory
338# OBJ_D - temp object file directory
339OBJ_D=\$(TMP_D)
340INCL_D=\$(TMP_D)
341
342O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
343O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
58964a49
RE
344SO_SSL= $plib\$(SSL)$so_shlibp
345SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
31a674d8
UM
346L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp
347L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp
d02b48c6
RE
348
349L_LIBS= \$(L_SSL) \$(L_CRYPTO)
d02b48c6
RE
350
351######################################################
352# Don't touch anything below this point
353######################################################
354
58964a49 355INC=-I\$(INC_D) -I\$(INCL_D)
d02b48c6
RE
356APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
357LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
58964a49 358SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
f09628e4 359LIBS_DEP=\$(O_CRYPTO) \$(O_SSL)
d02b48c6
RE
360
361#############################################
362EOF
363
364$rules=<<"EOF";
ec577822 365all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe
d02b48c6
RE
366
367banner:
368$banner
369
d02b48c6
RE
370\$(TMP_D):
371 \$(MKDIR) \$(TMP_D)
e2e044fa
DSH
372# NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
373#\$(BIN_D):
374# \$(MKDIR) \$(BIN_D)
375#
376#\$(TEST_D):
377# \$(MKDIR) \$(TEST_D)
58964a49
RE
378
379\$(LIB_D):
380 \$(MKDIR) \$(LIB_D)
381
ec577822 382\$(INCO_D): \$(INC_D)
31a674d8 383 \$(MKDIR) \$(INCO_D)
ec577822 384
58964a49
RE
385\$(INC_D):
386 \$(MKDIR) \$(INC_D)
387
d02b48c6 388headers: \$(HEADER) \$(EXHEADER)
b222eb64 389 @
d02b48c6
RE
390
391lib: \$(LIBS_DEP)
392
393exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
394
395install:
396 \$(MKDIR) \$(INSTALLTOP)
397 \$(MKDIR) \$(INSTALLTOP)${o}bin
398 \$(MKDIR) \$(INSTALLTOP)${o}include
ec577822 399 \$(MKDIR) \$(INSTALLTOP)${o}include${o}openssl
d02b48c6 400 \$(MKDIR) \$(INSTALLTOP)${o}lib
ec577822 401 \$(CP) \$(INCO_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include${o}openssl
d02b48c6 402 \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin
58964a49
RE
403 \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib
404 \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib
d02b48c6
RE
405
406clean:
407 \$(RM) \$(TMP_D)$o*.*
408
409vclean:
410 \$(RM) \$(TMP_D)$o*.*
411 \$(RM) \$(OUT_D)$o*.*
412
413EOF
2e0fc875
BM
414
415my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
e9185df4 416$platform_cpp_symbol =~ s/-/_/g;
57119943 417if (open(IN,"crypto/buildinf.h"))
2e0fc875 418 {
57119943 419 # Remove entry for this platform in existing file buildinf.h.
2e0fc875 420
57119943 421 my $old_buildinf_h = "";
2e0fc875
BM
422 while (<IN>)
423 {
424 if (/^\#ifdef $platform_cpp_symbol$/)
425 {
426 while (<IN>) { last if (/^\#endif/); }
427 }
428 else
429 {
57119943 430 $old_buildinf_h .= $_;
2e0fc875
BM
431 }
432 }
7fbd8db1 433 close(IN);
2e0fc875 434
57119943
BM
435 open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
436 print OUT $old_buildinf_h;
7fbd8db1 437 close(OUT);
2e0fc875
BM
438 }
439
57119943 440open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
2e0fc875
BM
441printf OUT <<EOF;
442#ifdef $platform_cpp_symbol
57119943 443 /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
2e0fc875
BM
444 #define CFLAGS "$cc $cflags"
445 #define PLATFORM "$platform"
446EOF
447printf OUT " #define DATE \"%s\"\n", scalar gmtime();
448printf OUT "#endif\n";
449close(OUT);
d02b48c6
RE
450
451#############################################
452# We parse in input file and 'store' info for later printing.
453open(IN,"<$infile") || die "unable to open $infile:$!\n";
454$_=<IN>;
455for (;;)
456 {
457 chop;
458
459 ($key,$val)=/^([^=]+)=(.*)/;
460 if ($key eq "RELATIVE_DIRECTORY")
461 {
462 if ($lib ne "")
463 {
464 $uc=$lib;
465 $uc =~ s/^lib(.*)\.a/$1/;
466 $uc =~ tr/a-z/A-Z/;
467 $lib_nam{$uc}=$uc;
468 $lib_obj{$uc}.=$libobj." ";
469 }
470 last if ($val eq "FINISHED");
471 $lib="";
472 $libobj="";
473 $dir=$val;
474 }
475
476 if ($key eq "TEST")
477 { $test.=&var_add($dir,$val); }
478
479 if (($key eq "PROGS") || ($key eq "E_OBJ"))
480 { $e_exe.=&var_add($dir,$val); }
481
482 if ($key eq "LIB")
483 {
484 $lib=$val;
485 $lib =~ s/^.*\/([^\/]+)$/$1/;
486 }
487
488 if ($key eq "EXHEADER")
489 { $exheader.=&var_add($dir,$val); }
490
491 if ($key eq "HEADER")
492 { $header.=&var_add($dir,$val); }
493
494 if ($key eq "LIBOBJ")
495 { $libobj=&var_add($dir,$val); }
496
497 if (!($_=<IN>))
498 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
499 }
500close(IN);
501
502# Strip of trailing ' '
503foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
504$test=&clean_up_ws($test);
505$e_exe=&clean_up_ws($e_exe);
506$exheader=&clean_up_ws($exheader);
507$header=&clean_up_ws($header);
508
509# First we strip the exheaders from the headers list
510foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
511foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; }
512chop($h); $header=$h;
513
514$defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h");
515$rules.=&do_copy_rule("\$(INCL_D)",$header,".h");
516
ec577822
BM
517$defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)",".h");
518$rules.=&do_copy_rule("\$(INCO_D)",$exheader,".h");
d02b48c6
RE
519
520$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
521$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
522
523$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
524$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
525
526foreach (values %lib_nam)
527 {
528 $lib_obj=$lib_obj{$_};
58964a49
RE
529 local($slib)=$shlib;
530
d02b48c6
RE
531 if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
532 {
533 $rules.="\$(O_SSL):\n\n";
534 next;
535 }
536
dfeab068 537 if (($bn_asm_obj ne "") && ($_ eq "CRYPTO"))
d02b48c6 538 {
dfeab068
RE
539 $lib_obj =~ s/\s\S*\/bn_asm\S*/ \$(BN_ASM_OBJ)/;
540 $rules.=&do_asm_rule($bn_asm_obj,$bn_asm_src);
d02b48c6 541 }
b222eb64
UM
542 if (($bnco_asm_obj ne "") && ($_ eq "CRYPTO"))
543 {
544 $lib_obj .= "\$(BNCO_ASM_OBJ)";
545 $rules.=&do_asm_rule($bnco_asm_obj,$bnco_asm_src);
546 }
d02b48c6
RE
547 if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
548 {
58964a49
RE
549 $lib_obj =~ s/\s\S*des_enc\S*/ \$(DES_ENC_OBJ)/;
550 $lib_obj =~ s/\s\S*\/fcrypt_b\S*\s*/ /;
d02b48c6
RE
551 $rules.=&do_asm_rule($des_enc_obj,$des_enc_src);
552 }
553 if (($bf_enc_obj ne "") && ($_ eq "CRYPTO"))
554 {
58964a49 555 $lib_obj =~ s/\s\S*\/bf_enc\S*/ \$(BF_ENC_OBJ)/;
d02b48c6
RE
556 $rules.=&do_asm_rule($bf_enc_obj,$bf_enc_src);
557 }
58964a49
RE
558 if (($cast_enc_obj ne "") && ($_ eq "CRYPTO"))
559 {
560 $lib_obj =~ s/(\s\S*\/c_enc\S*)/ \$(CAST_ENC_OBJ)/;
561 $rules.=&do_asm_rule($cast_enc_obj,$cast_enc_src);
562 }
563 if (($rc4_enc_obj ne "") && ($_ eq "CRYPTO"))
564 {
565 $lib_obj =~ s/\s\S*\/rc4_enc\S*/ \$(RC4_ENC_OBJ)/;
566 $rules.=&do_asm_rule($rc4_enc_obj,$rc4_enc_src);
567 }
568 if (($rc5_enc_obj ne "") && ($_ eq "CRYPTO"))
569 {
570 $lib_obj =~ s/\s\S*\/rc5_enc\S*/ \$(RC5_ENC_OBJ)/;
571 $rules.=&do_asm_rule($rc5_enc_obj,$rc5_enc_src);
572 }
573 if (($md5_asm_obj ne "") && ($_ eq "CRYPTO"))
574 {
575 $lib_obj =~ s/\s(\S*\/md5_dgst\S*)/ $1 \$(MD5_ASM_OBJ)/;
576 $rules.=&do_asm_rule($md5_asm_obj,$md5_asm_src);
577 }
578 if (($sha1_asm_obj ne "") && ($_ eq "CRYPTO"))
579 {
580 $lib_obj =~ s/\s(\S*\/sha1dgst\S*)/ $1 \$(SHA1_ASM_OBJ)/;
581 $rules.=&do_asm_rule($sha1_asm_obj,$sha1_asm_src);
582 }
583 if (($rmd160_asm_obj ne "") && ($_ eq "CRYPTO"))
584 {
585 $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/;
586 $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src);
587 }
d02b48c6 588 $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
f09628e4 589 $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
58964a49 590 $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
d02b48c6
RE
591 }
592
593$defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
594foreach (split(/\s+/,$test))
595 {
596 $t=&bname($_);
597 $tt="\$(OBJ_D)${o}$t${obj}";
598 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
599 }
600
58964a49 601$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
58964a49 602$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
d02b48c6
RE
603
604$rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
605
606print $defs;
eb206eb8
UM
607
608if ($platform eq "linux-elf") {
609 print <<"EOF";
610# Generate perlasm output files
611%.cpp:
612 (cd \$(\@D)/..; PERL=perl make -f Makefile.ssl asm/\$(\@F))
613EOF
614}
d02b48c6
RE
615print "###################################################################\n";
616print $rules;
617
618###############################################
619# strip off any trailing .[och] and append the relative directory
620# also remembering to do nothing if we are in one of the dropped
621# directories
622sub var_add
623 {
624 local($dir,$val)=@_;
625 local(@a,$_,$ret);
626
627 return("") if $no_idea && $dir =~ /\/idea/;
77dd9c18 628 return("") if $no_aes && $dir =~ /\/aes/;
d02b48c6
RE
629 return("") if $no_rc2 && $dir =~ /\/rc2/;
630 return("") if $no_rc4 && $dir =~ /\/rc4/;
58964a49 631 return("") if $no_rc5 && $dir =~ /\/rc5/;
d02b48c6
RE
632 return("") if $no_rsa && $dir =~ /\/rsa/;
633 return("") if $no_rsa && $dir =~ /^rsaref/;
634 return("") if $no_dsa && $dir =~ /\/dsa/;
635 return("") if $no_dh && $dir =~ /\/dh/;
636 if ($no_des && $dir =~ /\/des/)
637 {
638 if ($val =~ /read_pwd/)
639 { return("$dir/read_pwd "); }
640 else
641 { return(""); }
642 }
643 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
644 return("") if $no_sock && $dir =~ /\/proxy/;
645 return("") if $no_bf && $dir =~ /\/bf/;
58964a49 646 return("") if $no_cast && $dir =~ /\/cast/;
d02b48c6
RE
647
648 $val =~ s/^\s*(.*)\s*$/$1/;
649 @a=split(/\s+/,$val);
650 grep(s/\.[och]$//,@a);
651
652 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
653 @a=grep(!/^e_.*_d$/,@a) if $no_des;
77dd9c18
RL
654 @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
655 @a=grep(!/^e_.*_i$/,@a) if $no_aes;
d02b48c6 656 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
58964a49 657 @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
d02b48c6 658 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
58964a49 659 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
d02b48c6
RE
660 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
661
662 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
663 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
664
665 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
666
667 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
3009458e 668 @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
d02b48c6 669 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
dfeab068 670 @a=grep(!/(rmd)|(ripemd)/,@a) if $no_rmd160;
d02b48c6
RE
671
672 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
673 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
674 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
675
676 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
677 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
678
679 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
680
681 @a=grep(!/_dhp$/,@a) if $no_dh;
682
683 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
684 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
685 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
686
13e91dd3 687 @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
d02b48c6
RE
688 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
689 @a=grep(!/^gendsa$/,@a) if $no_sha1;
690 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
691
692 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
693
694 grep($_="$dir/$_",@a);
695 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
696 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
697 $ret=join(' ',@a)." ";
698 return($ret);
699 }
700
701# change things so that each 'token' is only separated by one space
702sub clean_up_ws
703 {
704 local($w)=@_;
705
706 $w =~ s/^\s*(.*)\s*$/$1/;
707 $w =~ s/\s+/ /g;
708 return($w);
709 }
710
711sub do_defs
712 {
713 local($var,$files,$location,$postfix)=@_;
58964a49 714 local($_,$ret,$pf);
d02b48c6
RE
715 local(*OUT,$tmp,$t);
716
717 $files =~ s/\//$o/g if $o ne '/';
718 $ret="$var=";
719 $n=1;
720 $Vars{$var}.="";
721 foreach (split(/ /,$files))
722 {
58964a49 723 $orig=$_;
d02b48c6
RE
724 $_=&bname($_) unless /^\$/;
725 if ($n++ == 2)
726 {
727 $n=0;
728 $ret.="\\\n\t";
729 }
58964a49
RE
730 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
731 { $pf=".c"; }
732 else { $pf=$postfix; }
dfeab068 733 if ($_ =~ /BN_ASM/) { $t="$_ "; }
b222eb64 734 elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
58964a49
RE
735 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
736 elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
737 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
738 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
739 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
740 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
741 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
742 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
743 else { $t="$location${o}$_$pf "; }
d02b48c6
RE
744
745 $Vars{$var}.="$t ";
746 $ret.=$t;
747 }
748 chop($ret);
749 $ret.="\n\n";
750 return($ret);
751 }
752
753# return the name with the leading path removed
754sub bname
755 {
756 local($ret)=@_;
757 $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
758 return($ret);
759 }
760
d02b48c6
RE
761
762##############################################################
763# do a rule for each file that says 'compile' to new direcory
764# compile the files in '$files' into $to
765sub do_compile_rule
766 {
767 local($to,$files,$ex)=@_;
768 local($ret,$_,$n);
769
770 $files =~ s/\//$o/g if $o ne '/';
771 foreach (split(/\s+/,$files))
772 {
773 $n=&bname($_);
774 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
775 }
776 return($ret);
777 }
778
779##############################################################
780# do a rule for each file that says 'compile' to new direcory
781sub cc_compile_target
782 {
783 local($target,$source,$ex_flags)=@_;
784 local($ret);
785
2e0fc875 786 $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
d02b48c6
RE
787 $target =~ s/\//$o/g if $o ne "/";
788 $source =~ s/\//$o/g if $o ne "/";
789 $ret ="$target: \$(SRC_D)$o$source\n\t";
790 $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
791 return($ret);
792 }
793
794##############################################################
795sub do_asm_rule
796 {
797 local($target,$src)=@_;
798 local($ret,@s,@t,$i);
799
800 $target =~ s/\//$o/g if $o ne "/";
801 $src =~ s/\//$o/g if $o ne "/";
802
803 @s=split(/\s+/,$src);
804 @t=split(/\s+/,$target);
805
806 for ($i=0; $i<=$#s; $i++)
807 {
808 $ret.="$t[$i]: $s[$i]\n";
809 $ret.="\t\$(ASM) $afile$t[$i] \$(SRC_D)$o$s[$i]\n\n";
810 }
811 return($ret);
812 }
813
814sub do_shlib_rule
815 {
816 local($n,$def)=@_;
817 local($ret,$nn);
818 local($t);
819
820 ($nn=$n) =~ tr/a-z/A-Z/;
821 $ret.="$n.dll: \$(${nn}OBJ)\n";
822 if ($vc && $w32)
823 {
824 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
825 }
826 $ret.="\n";
827 return($ret);
828 }
829
dfeab068
RE
830# do a rule for each file that says 'copy' to new direcory on change
831sub do_copy_rule
832 {
833 local($to,$files,$p)=@_;
834 local($ret,$_,$n,$pp);
835
836 $files =~ s/\//$o/g if $o ne '/';
837 foreach (split(/\s+/,$files))
838 {
839 $n=&bname($_);
840 if ($n =~ /bss_file/)
841 { $pp=".c"; }
842 else { $pp=$p; }
843 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n";
844 }
845 return($ret);
846 }
31ff97b2
UM
847
848sub read_options
849 {
850 if (/^no-rc2$/) { $no_rc2=1; }
851 elsif (/^no-rc4$/) { $no_rc4=1; }
852 elsif (/^no-rc5$/) { $no_rc5=1; }
853 elsif (/^no-idea$/) { $no_idea=1; }
77dd9c18 854 elsif (/^no-aes$/) { $no_aes=1; }
31ff97b2
UM
855 elsif (/^no-des$/) { $no_des=1; }
856 elsif (/^no-bf$/) { $no_bf=1; }
857 elsif (/^no-cast$/) { $no_cast=1; }
858 elsif (/^no-md2$/) { $no_md2=1; }
3009458e 859 elsif (/^no-md4$/) { $no_md4=1; }
31ff97b2
UM
860 elsif (/^no-md5$/) { $no_md5=1; }
861 elsif (/^no-sha$/) { $no_sha=1; }
862 elsif (/^no-sha1$/) { $no_sha1=1; }
863 elsif (/^no-ripemd$/) { $no_ripemd=1; }
864 elsif (/^no-mdc2$/) { $no_mdc2=1; }
865 elsif (/^no-patents$/) { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; }
866 elsif (/^no-rsa$/) { $no_rsa=1; }
867 elsif (/^no-dsa$/) { $no_dsa=1; }
868 elsif (/^no-dh$/) { $no_dh=1; }
869 elsif (/^no-hmac$/) { $no_hmac=1; }
993ea851 870 elsif (/^no-rijndael$/) { $no_rijndael=1; }
31ff97b2 871 elsif (/^no-asm$/) { $no_asm=1; }
bbdb5438 872 elsif (/^nasm$/) { $nasm=1; }
2da0c119 873 elsif (/^gaswin$/) { $gaswin=1; }
31ff97b2
UM
874 elsif (/^no-ssl2$/) { $no_ssl2=1; }
875 elsif (/^no-ssl3$/) { $no_ssl3=1; }
876 elsif (/^no-err$/) { $no_err=1; }
877 elsif (/^no-sock$/) { $no_sock=1; }
97f56446 878 elsif (/^no-krb5$/) { $no_krb5=1; }
31ff97b2
UM
879
880 elsif (/^just-ssl$/) { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1;
881 $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1;
77dd9c18
RL
882 $no_ssl2=$no_err=$no_rmd160=$no_rc5=1;
883 $no_aes=1; }
31ff97b2 884
ccb9643f 885 elsif (/^rsaref$/) { }
31ff97b2
UM
886 elsif (/^gcc$/) { $gcc=1; }
887 elsif (/^debug$/) { $debug=1; }
d55a3cf1 888 elsif (/^profile$/) { $profile=1; }
31ff97b2
UM
889 elsif (/^shlib$/) { $shlib=1; }
890 elsif (/^dll$/) { $shlib=1; }
8886f118 891 elsif (/^shared$/) { } # We just need to ignore it for now...
31ff97b2
UM
892 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
893 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
894 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
895 { $c_flags.="$_ "; }
ad2cb8b4
BM
896 else { return(0); }
897 return(1);
31ff97b2 898 }