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