mk1mf.pl 32 KB

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