mk1mf.pl 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  1. #!/usr/bin/env 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 (if the target is not "copy").
  6. # If the target is "copy", then it tries to create a makefile that can be
  7. # safely used with the -j flag and that is compatible with the top-level
  8. # Makefile, in the sense that it uses the same options and assembler files etc.
  9. use Cwd;
  10. $INSTALLTOP="/usr/local";
  11. $OPENSSLDIR="/usr/local/ssl";
  12. $ENGINESDIR="/usr/local/lib/engines";
  13. $OPTIONS="";
  14. $ssl_version="";
  15. $banner="\t\@echo Building OpenSSL";
  16. my $no_static_engine = 1;
  17. my $engines = "";
  18. my @engines_obj = "";
  19. my $otherlibs = "";
  20. local $zlib_opt = 0; # 0 = no zlib, 1 = static, 2 = dynamic
  21. local $zlib_lib = "";
  22. local $perl_asm = 0; # 1 to autobuild asm files from perl scripts
  23. local $fips_canister_path = "";
  24. my $fips_premain_dso_exe_path = "";
  25. my $fips_premain_c_path = "";
  26. my $fips_sha1_exe_path = "";
  27. local $fipscanisterbuild = 0;
  28. my $fipscanisteronly = 0;
  29. my $fipslibdir = "";
  30. my $baseaddr = "";
  31. my $ex_l_libs = "";
  32. my $build_targets = "lib exe";
  33. my $libs_dep = "\$(O_CRYPTO) \$(O_SSL)";
  34. # Options to import from top level Makefile
  35. my %mf_import = (
  36. VERSION => \$ssl_version,
  37. OPTIONS => \$OPTIONS,
  38. INSTALLTOP => \$INSTALLTOP,
  39. OPENSSLDIR => \$OPENSSLDIR,
  40. ENGINESDIR => \$ENGINESDIR,
  41. PLATFORM => \$mf_platform,
  42. CC => \$mf_cc,
  43. CFLAG => \$mf_cflag,
  44. CFLAG_Q => \$mf_cflag_q,
  45. DEPFLAG => \$mf_depflag,
  46. CPUID_OBJ => \$mf_cpuid_asm,
  47. BN_ASM => \$mf_bn_asm,
  48. DES_ENC => \$mf_des_asm,
  49. AES_ENC => \$mf_aes_asm,
  50. BF_ENC => \$mf_bf_asm,
  51. CAST_ENC => \$mf_cast_asm,
  52. RC4_ENC => \$mf_rc4_asm,
  53. RC5_ENC => \$mf_rc5_asm,
  54. MD5_ASM_OBJ => \$mf_md5_asm,
  55. SHA1_ASM_OBJ => \$mf_sha_asm,
  56. RMD160_ASM_OBJ => \$mf_rmd_asm,
  57. WP_ASM_OBJ => \$mf_wp_asm,
  58. CMLL_ENC => \$mf_cm_asm,
  59. MODES_ASM_OBJ => \$mf_modes_asm,
  60. ENGINES_ASM_OBJ=> \$mf_engines_asm,
  61. PERLASM_SCHEME => \$mf_perlasm_scheme,
  62. FIPSCANISTERONLY => \$mf_fipscanisteronly,
  63. FIPSCANISTERINTERNAL => \$mf_fipscanisterinternal,
  64. EC_ASM => \$mf_ec_asm,
  65. );
  66. open(IN,"<Makefile") || die "unable to open Makefile!\n";
  67. while(<IN>) {
  68. my ($mf_opt, $mf_ref);
  69. while (($mf_opt, $mf_ref) = each %mf_import) {
  70. if (/^$mf_opt\s*=\s*(.*)$/ && !defined($$mfref)) {
  71. $$mf_ref = $1;
  72. }
  73. }
  74. }
  75. close(IN);
  76. if ($mf_fipscanisterinternal eq "y") {
  77. $fips = 1;
  78. $fipscanisterbuild = 1;
  79. $fipscanisteronly = 1;
  80. }
  81. die "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
  82. $infile="MINFO";
  83. %ops=(
  84. "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X",
  85. "VC-WIN64I", "Microsoft C/C++ - Win64/IA-64",
  86. "VC-WIN64A", "Microsoft C/C++ - Win64/x64",
  87. "VC-CE", "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
  88. "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY",
  89. "Mingw32", "GNU C++ - Windows NT or 9x",
  90. "Mingw32-files", "Create files with DOS copy ...",
  91. "BC-NT", "Borland C++ 4.5 - Windows NT",
  92. "linux-elf","Linux elf",
  93. "ultrix-mips","DEC mips ultrix",
  94. "FreeBSD","FreeBSD distribution",
  95. "OS2-EMX", "EMX GCC OS/2",
  96. "netware-clib", "CodeWarrior for NetWare - CLib - with WinSock Sockets",
  97. "netware-clib-bsdsock", "CodeWarrior for NetWare - CLib - with BSD Sockets",
  98. "netware-libc", "CodeWarrior for NetWare - LibC - with WinSock Sockets",
  99. "netware-libc-bsdsock", "CodeWarrior for NetWare - LibC - with BSD Sockets",
  100. "default","cc under unix",
  101. "auto", "auto detect from top level Makefile",
  102. "copy", "copy from top level Makefile"
  103. );
  104. $platform="";
  105. my $xcflags="";
  106. foreach (@ARGV)
  107. {
  108. if (!&read_options && !defined($ops{$_}))
  109. {
  110. print STDERR "unknown option - $_\n";
  111. print STDERR "usage: perl mk1mf.pl [options] [system]\n";
  112. print STDERR "\nwhere [system] can be one of the following\n";
  113. foreach $i (sort keys %ops)
  114. { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
  115. print STDERR <<"EOF";
  116. and [options] can be one of
  117. no-md2 no-md4 no-md5 no-sha no-mdc2 - Skip this digest
  118. no-ripemd
  119. no-rc2 no-rc4 no-rc5 no-idea no-des - Skip this symetric cipher
  120. no-bf no-cast no-aes no-camellia no-seed
  121. no-rsa no-dsa no-dh - Skip this public key cipher
  122. no-ssl3 - Skip this version of SSL
  123. just-ssl - remove all non-ssl keys/digest
  124. no-asm - No x86 asm
  125. no-srp - No SRP
  126. no-ec - No EC
  127. no-engine - No engine
  128. no-egd - No EGD
  129. no-hw - No hw
  130. no-async - No Async (use NULL)
  131. no-autoalginit - Don't auto load algorithms in libcrypto
  132. no-autoerrinit - Don't auto load error strings for libcrypto or libssl
  133. nasm - Use NASM for x86 asm
  134. nw-nasm - Use NASM x86 asm for NetWare
  135. nw-mwasm - Use Metrowerks x86 asm for NetWare
  136. gaswin - Use GNU as with Mingw32
  137. no-socks - No socket code
  138. no-err - No error strings
  139. dll/shlib - Build shared libraries (MS)
  140. debug - Debug build
  141. profile - Profiling build
  142. gcc - Use Gcc (unix)
  143. Values that can be set
  144. TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
  145. -L<ex_lib_path> -l<ex_lib> - extra library flags (unix)
  146. -<ex_cc_flags> - extra 'cc' flags,
  147. added (MS), or replace (unix)
  148. EOF
  149. exit(1);
  150. }
  151. $platform=$_;
  152. }
  153. foreach (grep(!/^$/, split(/ /, $OPTIONS)))
  154. {
  155. print STDERR "unknown option - $_\n" if !&read_options;
  156. }
  157. $no_static_engine = 0 if (!$shlib);
  158. $no_mdc2=1 if ($no_des);
  159. $no_ssl3=1 if ($no_md5);
  160. $no_ssl3=1 if ($no_rsa && $no_dh);
  161. $out_def="out";
  162. $inc_def="outinc";
  163. $tmp_def="tmp";
  164. $perl="perl" unless defined $perl;
  165. $mkdir="-mkdir" unless defined $mkdir;
  166. $mv="mv" unless defined $mv;
  167. ($ssl,$crypto)=("ssl","crypto");
  168. $ranlib="echo ranlib";
  169. $cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
  170. $src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}: $platform eq 'copy' ? getcwd() : '.';
  171. $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
  172. # $bin_dir.=$o causes a core dump on my sparc :-(
  173. $NT=0;
  174. push(@INC,"util/pl","pl");
  175. if ($platform eq "auto" || $platform eq 'copy') {
  176. $orig_platform = $platform;
  177. $platform = $mf_platform;
  178. print STDERR "Imported platform $mf_platform\n";
  179. }
  180. if (($platform =~ /VC-(.+)/))
  181. {
  182. $FLAVOR=$1;
  183. $NT = 1 if $1 eq "NT";
  184. require 'VC-32.pl';
  185. }
  186. elsif ($platform eq "Mingw32")
  187. {
  188. require 'Mingw32.pl';
  189. }
  190. elsif ($platform eq "Mingw32-files")
  191. {
  192. require 'Mingw32f.pl';
  193. }
  194. elsif ($platform eq "BC-NT")
  195. {
  196. $bc=1;
  197. require 'BC-32.pl';
  198. }
  199. elsif ($platform eq "FreeBSD")
  200. {
  201. require 'unix.pl';
  202. $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
  203. }
  204. elsif ($platform eq "linux-elf")
  205. {
  206. require "unix.pl";
  207. require "linux.pl";
  208. $unix=1;
  209. }
  210. elsif ($platform eq "ultrix-mips")
  211. {
  212. require "unix.pl";
  213. require "ultrix.pl";
  214. $unix=1;
  215. }
  216. elsif ($platform eq "OS2-EMX")
  217. {
  218. $wc=1;
  219. require 'OS2-EMX.pl';
  220. }
  221. elsif (($platform eq "netware-clib") || ($platform eq "netware-libc") ||
  222. ($platform eq "netware-clib-bsdsock") || ($platform eq "netware-libc-bsdsock"))
  223. {
  224. $LIBC=1 if $platform eq "netware-libc" || $platform eq "netware-libc-bsdsock";
  225. $BSDSOCK=1 if ($platform eq "netware-libc-bsdsock") || ($platform eq "netware-clib-bsdsock");
  226. require 'netware.pl';
  227. }
  228. else
  229. {
  230. require "unix.pl";
  231. $unix=1;
  232. $cflags.=' -DTERMIO';
  233. }
  234. $out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
  235. $tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
  236. $inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
  237. $bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
  238. $cflags= "$xcflags$cflags" if $xcflags ne "";
  239. $cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
  240. $cflags.=" -DOPENSSL_NO_AES" if $no_aes;
  241. $cflags.=" -DOPENSSL_NO_CAMELLIA" if $no_camellia;
  242. $cflags.=" -DOPENSSL_NO_SEED" if $no_seed;
  243. $cflags.=" -DOPENSSL_NO_RC2" if $no_rc2;
  244. $cflags.=" -DOPENSSL_NO_RC4" if $no_rc4;
  245. $cflags.=" -DOPENSSL_NO_RC5" if $no_rc5;
  246. $cflags.=" -DOPENSSL_NO_MD2" if $no_md2;
  247. $cflags.=" -DOPENSSL_NO_MD4" if $no_md4;
  248. $cflags.=" -DOPENSSL_NO_MD5" if $no_md5;
  249. $cflags.=" -DOPENSSL_NO_RMD160" if $no_ripemd;
  250. $cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
  251. $cflags.=" -DOPENSSL_NO_BF" if $no_bf;
  252. $cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
  253. $cflags.=" -DOPENSSL_NO_DES" if $no_des;
  254. $cflags.=" -DOPENSSL_NO_RSA" if $no_rsa;
  255. $cflags.=" -DOPENSSL_NO_DSA" if $no_dsa;
  256. $cflags.=" -DOPENSSL_NO_DH" if $no_dh;
  257. $cflags.=" -DOPENSSL_NO_WHIRLPOOL" if $no_whirlpool;
  258. $cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
  259. $cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
  260. $cflags.=" -DOPENSSL_NO_SRP" if $no_srp;
  261. $cflags.=" -DOPENSSL_NO_CMS" if $no_cms;
  262. $cflags.=" -DOPENSSL_NO_ERR" if $no_err;
  263. $cflags.=" -DOPENSSL_NO_EC" if $no_ec;
  264. $cflags.=" -DOPENSSL_NO_GOST" if $no_gost;
  265. $cflags.=" -DOPENSSL_NO_ENGINE" if $no_engine;
  266. $cflags.=" -DOPENSSL_NO_HW" if $no_hw;
  267. $cflags.=" -DOPENSSL_NO_ASYNC" if $no_async;
  268. $cflags.=" -DOPENSSL_NO_AUTOALGINIT" if $no_autoalginit;
  269. $cflags.=" -DOPENSSL_NO_AUTOERRINIT" if $no_autoerrinit;
  270. $cflags.=" -DOPENSSL_FIPS" if $fips;
  271. $cflags.=" -DOPENSSL_NO_JPAKE" if $no_jpake;
  272. $cflags.=" -DOPENSSL_NO_EC2M" if $no_ec2m;
  273. $cflags.= " -DZLIB" if $zlib_opt;
  274. $cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
  275. if ($no_static_engine)
  276. {
  277. $cflags .= " -DOPENSSL_NO_STATIC_ENGINE";
  278. }
  279. else
  280. {
  281. $cflags .= " -DOPENSSL_NO_DYNAMIC_ENGINE";
  282. }
  283. #$cflags.=" -DRSAref" if $rsaref ne "";
  284. ## if ($unix)
  285. ## { $cflags="$c_flags" if ($c_flags ne ""); }
  286. ##else
  287. { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
  288. if ($orig_platform eq 'copy') {
  289. $cflags = $mf_cflag;
  290. $cc = $mf_cc;
  291. }
  292. $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
  293. %shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
  294. "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
  295. if ($msdos)
  296. {
  297. $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
  298. $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
  299. $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
  300. $banner.="\t\@echo documentation for details.\n";
  301. }
  302. # have to do this to allow $(CC) under unix
  303. $link="$bin_dir$link" if ($link !~ /^\$/);
  304. $INSTALLTOP =~ s|/|$o|g;
  305. $OPENSSLDIR =~ s|/|$o|g;
  306. #############################################
  307. # We parse in input file and 'store' info for later printing.
  308. open(IN,"<$infile") || die "unable to open $infile:$!\n";
  309. $_=<IN>;
  310. for (;;)
  311. {
  312. s/\s*$//; # was chop, didn't work in mixture of perls for Windows...
  313. ($key,$val)=/^([^=]+)=(.*)/;
  314. if ($key eq "RELATIVE_DIRECTORY")
  315. {
  316. if ($lib ne "")
  317. {
  318. if ($fips && $dir =~ /^fips/)
  319. {
  320. $uc = "FIPS";
  321. }
  322. else
  323. {
  324. $uc=$lib;
  325. $uc =~ s/^lib(.*)\.a/$1/;
  326. $uc =~ tr/a-z/A-Z/;
  327. }
  328. if (($uc ne "FIPS") || $fipscanisterbuild)
  329. {
  330. $lib_nam{$uc}=$uc;
  331. $lib_obj{$uc}.=$libobj." ";
  332. }
  333. }
  334. last if ($val eq "FINISHED");
  335. $lib="";
  336. $libobj="";
  337. $dir=$val;
  338. }
  339. if ($key eq "ZLIB_INCLUDE")
  340. { $cflags .= " $val" if $val ne "";}
  341. if ($key eq "LIBZLIB")
  342. { $zlib_lib = "$val" if $val ne "";}
  343. if ($key eq "EX_LIBS")
  344. { $ex_libs .= " $val" if $val ne "";}
  345. # There was a condition here before:
  346. # !$fipscanisteronly || $dir =~ /^fips/
  347. # It currently fills no function and needs to be rewritten anyway, so
  348. # removed for now.
  349. if ($dir eq "test" && $key eq "EXE")
  350. {
  351. foreach my $t (split /\s+/, $val) {
  352. $test.=&var_add($dir,$t, 0) if $t; }
  353. }
  354. if ($key eq "EXE_OBJ")
  355. { $e_exe.=&var_add($dir,$val, 0); }
  356. if ($key eq "LIB")
  357. {
  358. $lib=$val;
  359. $lib =~ s/^.*\/([^\/]+)$/$1/;
  360. }
  361. if ($key eq "LIBNAME" && $no_static_engine)
  362. {
  363. $lib=$val;
  364. $lib =~ s/^.*\/([^\/]+)$/$1/;
  365. $otherlibs .= " $lib";
  366. }
  367. if ($key eq "HEADER")
  368. { $header.=&var_add($dir,$val, 1); }
  369. if ($key eq "LIBOBJ")
  370. {
  371. if ($dir ne "engines" || !$no_static_engine)
  372. { $libobj=&var_add($dir,$val, 0); }
  373. else
  374. { push(@engines_obj,split(/\s+/,&var_add($dir,$val,0))); }
  375. }
  376. if ($key eq "LIBNAMES" && $dir eq "engines" && $no_static_engine)
  377. { $engines.=$val }
  378. if ($key eq "FIPS_EX_OBJ")
  379. {
  380. $fips_ex_obj=&var_add("crypto",$val,0);
  381. }
  382. if ($key eq "FIPSLIBDIR")
  383. {
  384. $fipslibdir=$val;
  385. $fipslibdir =~ s/\/$//;
  386. $fipslibdir =~ s/\//$o/g;
  387. }
  388. if ($key eq "BASEADDR")
  389. { $baseaddr=$val;}
  390. if (!($_=<IN>))
  391. { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
  392. }
  393. close(IN);
  394. if ($orig_platform eq 'copy')
  395. {
  396. # Remove opensslconf.h so it doesn't get updated if we configure a
  397. # different branch.
  398. $header =~ s/[^ ]+\/opensslconf.h//;
  399. }
  400. if ($fips)
  401. {
  402. foreach (split " ", $fips_ex_obj)
  403. {
  404. $fips_exclude_obj{$1} = 1 if (/\/([^\/]*)$/);
  405. }
  406. foreach (split " ",
  407. "$mf_cpuid_asm $mf_aes_asm $mf_sha_asm $mf_bn_asm " .
  408. "$mf_des_asm $mf_modes_asm")
  409. {
  410. s/\.o//;
  411. $fips_exclude_obj{$_} = 1;
  412. }
  413. my @ltmp = split " ", $lib_obj{"CRYPTO"};
  414. $lib_obj{"CRYPTO"} = "";
  415. foreach(@ltmp)
  416. {
  417. if (/\/([^\/]*)$/ && exists $fips_exclude_obj{$1})
  418. {
  419. if ($fipscanisterbuild)
  420. {
  421. $lib_obj{"FIPS"} .= "$_ ";
  422. }
  423. }
  424. elsif (!$fipscanisteronly)
  425. {
  426. $lib_obj{"CRYPTO"} .= "$_ ";
  427. }
  428. }
  429. }
  430. if ($fipscanisterbuild)
  431. {
  432. $fips_canister_path = "\$(LIB_D)${o}fipscanister.lib" if $fips_canister_path eq "";
  433. $fips_premain_c_path = "\$(LIB_D)${o}fips_premain.c";
  434. }
  435. else
  436. {
  437. if ($fips_canister_path eq "")
  438. {
  439. $fips_canister_path = "\$(FIPSLIB_D)${o}fipscanister.lib";
  440. }
  441. if ($fips_premain_c_path eq "")
  442. {
  443. $fips_premain_c_path = "\$(FIPSLIB_D)${o}fips_premain.c";
  444. }
  445. }
  446. if ($fips)
  447. {
  448. if ($fips_sha1_exe_path eq "")
  449. {
  450. $fips_sha1_exe_path =
  451. "\$(BIN_D)${o}fips_standalone_sha1$exep";
  452. }
  453. }
  454. else
  455. {
  456. $fips_sha1_exe_path = "";
  457. }
  458. if ($fips_premain_dso_exe_path eq "")
  459. {
  460. $fips_premain_dso_exe_path = "\$(BIN_D)${o}fips_premain_dso$exep";
  461. }
  462. # $ex_build_targets .= "\$(BIN_D)${o}\$(E_PREMAIN_DSO)$exep" if ($fips);
  463. if ($fips)
  464. {
  465. if (!$shlib)
  466. {
  467. $build_targets .= " \$(LIB_D)$o$crypto_compat \$(PREMAIN_DSO_EXE)";
  468. $ex_l_libs .= " \$(O_FIPSCANISTER)";
  469. $ex_libs_dep .= " \$(O_FIPSCANISTER)" if $fipscanisterbuild;
  470. }
  471. if ($fipscanisterbuild)
  472. {
  473. $fipslibdir = "\$(LIB_D)";
  474. }
  475. else
  476. {
  477. if ($fipslibdir eq "")
  478. {
  479. open (IN, "util/fipslib_path.txt") || fipslib_error();
  480. $fipslibdir = <IN>;
  481. close IN;
  482. $fipslibdir = "" unless defined($fipslibdir);
  483. $fipslibdir =~ s{\R$}{};
  484. fipslib_error() if ($fipslibdir eq "");
  485. }
  486. fips_check_files($fipslibdir,
  487. "fipscanister.lib", "fipscanister.lib.sha1",
  488. "fips_premain.c", "fips_premain.c.sha1");
  489. }
  490. }
  491. if ($fipscanisteronly)
  492. {
  493. $build_targets = "\$(O_FIPSCANISTER) \$(T_EXE)";
  494. $libs_dep = "";
  495. }
  496. $cp2 = $cp unless defined $cp2;
  497. $extra_install= <<"EOF";
  498. \$(CP) \"include${o}openssl${o}*.\[ch\]\" \"\$(INSTALLTOP)${o}include${o}openssl\"
  499. \$(CP) \"\$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin\"
  500. \$(MKDIR) \"\$(OPENSSLDIR)\"
  501. \$(CP) apps${o}openssl.cnf \"\$(OPENSSLDIR)\"
  502. EOF
  503. if ($fipscanisteronly)
  504. {
  505. $extra_install = <<"EOF";
  506. \$(CP) \"\$(O_FIPSCANISTER)\" \"\$(INSTALLTOP)${o}lib\"
  507. \$(CP) \"\$(O_FIPSCANISTER).sha1\" \"\$(INSTALLTOP)${o}lib\"
  508. \$(CP2) \"fips${o}fips_premain.c\" \"\$(INSTALLTOP)${o}lib\"
  509. \$(CP) \"fips${o}fips_premain.c.sha1\" \"\$(INSTALLTOP)${o}lib\"
  510. \$(CP) \"include${o}openssl${o}fips.h\" \"\$(INSTALLTOP)${o}include${o}openssl\"
  511. \$(CP) \"include${o}openssl${o}fips_rand.h\" \"\$(INSTALLTOP)${o}include${o}openssl\"
  512. \$(CP) "\$(BIN_D)${o}fips_standalone_sha1$exep" \"\$(INSTALLTOP)${o}bin\"
  513. \$(CP) \"util${o}fipslink.pl\" \"\$(INSTALLTOP)${o}bin\"
  514. EOF
  515. }
  516. elsif ($shlib)
  517. {
  518. $extra_install .= <<"EOF";
  519. \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}bin\"
  520. \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}bin\"
  521. \$(CP) \"\$(L_SSL)\" \"\$(INSTALLTOP)${o}lib\"
  522. \$(CP) \"\$(L_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
  523. EOF
  524. if ($no_static_engine)
  525. {
  526. $extra_install .= <<"EOF"
  527. \$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
  528. \$(CP) \"\$(E_SHLIB)\" \"\$(INSTALLTOP)${o}lib${o}engines\"
  529. EOF
  530. }
  531. }
  532. else
  533. {
  534. $extra_install .= <<"EOF";
  535. \$(CP) \"\$(O_SSL)\" \"\$(INSTALLTOP)${o}lib\"
  536. \$(CP) \"\$(O_CRYPTO)\" \"\$(INSTALLTOP)${o}lib\"
  537. EOF
  538. $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
  539. }
  540. my $asm_def = $orig_platform eq 'copy' ? "" : "ASM=$bin_dir$asm";
  541. $cflags =~ s/\((ENGINESDIR|OPENSSLDIR)\)/\(${1}_QQ\)/g;
  542. (my $cflags_q = $cflags) =~ s/([\\"])/\\$1/g;
  543. (my $INSTALLTOP_Q = $INSTALLTOP) =~ s/([\\"])/\\$1/g;
  544. (my $INSTALLTOP_QQ = $INSTALLTOP_Q) =~ s/\\/\\\\/g;
  545. (my $OPENSSLDIR_Q = $OPENSSLDIR) =~ s/([\\"])/\\$1/g;
  546. (my $OPENSSLDIR_QQ = $OPENSSLDIR_Q) =~ s/\\/\\\\/g;
  547. (my $ENGINESDIR_Q = $ENGINESDIR) =~ s/([\\"])/\\$1/g;
  548. (my $ENGINESDIR_QQ = $ENGINESDIR_Q) =~ s/\\/\\\\/g;
  549. $defs= <<"EOF";
  550. # N.B. You MUST use -j on FreeBSD.
  551. # This makefile has been automatically generated from the OpenSSL distribution.
  552. # This single makefile will build the complete OpenSSL distribution and
  553. # by default leave the 'interesting' output files in .${o}out and the stuff
  554. # that needs deleting in .${o}tmp.
  555. # The file was generated by running 'make makefile.one', which
  556. # does a 'make files', which writes all the environment variables from all
  557. # the makefiles to the file call MINFO. This file is used by
  558. # util${o}mk1mf.pl to generate makefile.one.
  559. # The 'makefile per directory' system suites me when developing this
  560. # library and also so I can 'distribute' indervidual library sections.
  561. # The one monster makefile better suits building in non-unix
  562. # environments.
  563. EOF
  564. $defs .= $preamble if defined $preamble;
  565. $defs.= <<"EOF";
  566. INSTALLTOP=$INSTALLTOP
  567. INSTALLTOP_QQ=$INSTALLTOP_QQ
  568. OPENSSLDIR=$OPENSSLDIR
  569. OPENSSLDIR_QQ=$OPENSSLDIR_QQ
  570. ENGINESDIR=$ENGINESDIR
  571. ENGINESDIR_QQ=$ENGINESDIR_QQ
  572. # Set your compiler options
  573. PLATFORM=$platform
  574. CC=$bin_dir${cc}
  575. CFLAG=$cflags
  576. CFLAG_Q=$cflags_q
  577. APP_CFLAG=$app_cflag
  578. LIB_CFLAG=$lib_cflag
  579. SHLIB_CFLAG=$shl_cflag
  580. APP_EX_OBJ=$app_ex_obj
  581. SHLIB_EX_OBJ=$shlib_ex_obj
  582. # add extra libraries to this define, for solaris -lsocket -lnsl would
  583. # be added
  584. EX_LIBS=$ex_libs
  585. # The OpenSSL directory
  586. SRC_D=$src_dir
  587. LINK_CMD=$link
  588. LFLAGS=$lflags
  589. RSC=$rsc
  590. FIPSLINK=\$(PERL) util${o}fipslink.pl
  591. # The output directory for everything interesting
  592. OUT_D=$out_dir
  593. # The output directory for all the temporary muck
  594. TMP_D=$tmp_dir
  595. PERL=$perl
  596. PERLASM_SCHEME=$mf_perlasm_scheme
  597. CP=$cp
  598. CP2=$cp2
  599. RM=$rm
  600. MV=$mv
  601. RANLIB=$ranlib
  602. MKDIR=$mkdir
  603. MKLIB=$bin_dir$mklib
  604. MLFLAGS=$mlflags
  605. $asm_def
  606. # FIPS validated module and support file locations
  607. E_PREMAIN_DSO=fips_premain_dso
  608. FIPSLIB_D=$fipslibdir
  609. BASEADDR=$baseaddr
  610. FIPS_PREMAIN_SRC=$fips_premain_c_path
  611. O_FIPSCANISTER=$fips_canister_path
  612. FIPS_SHA1_EXE=$fips_sha1_exe_path
  613. PREMAIN_DSO_EXE=$fips_premain_dso_exe_path
  614. ######################################################
  615. # You should not need to touch anything below this point
  616. ######################################################
  617. E_EXE=openssl
  618. SSL=$ssl
  619. CRYPTO=$crypto
  620. # BIN_D - Binary output directory
  621. # TEST_D - Binary test file output directory
  622. # LIB_D - library output directory
  623. # ENG_D - dynamic engine output directory
  624. # Note: if you change these point to different directories then uncomment out
  625. # the lines around the 'NB' comment below.
  626. #
  627. BIN_D=\$(OUT_D)
  628. TEST_D=\$(OUT_D)
  629. LIB_D=\$(OUT_D)
  630. ENG_D=\$(OUT_D)
  631. # INCL_D - local library directory
  632. # OBJ_D - temp object file directory
  633. OBJ_D=\$(TMP_D)
  634. INCL_D=\$(TMP_D)
  635. O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
  636. O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
  637. SO_SSL= $plib\$(SSL)$so_shlibp
  638. SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
  639. L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp
  640. L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp
  641. L_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs
  642. ######################################################
  643. # Don't touch anything below this point
  644. ######################################################
  645. INC=-I\$(SRC_D)${o}include -I\$(INCL_D) -I\$(SRC_D)${o}crypto${o}include
  646. APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
  647. LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
  648. SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
  649. LIBS_DEP=$libs_dep
  650. #############################################
  651. EOF
  652. $rules=<<"EOF";
  653. all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) headers \$(FIPS_SHA1_EXE) $build_targets
  654. banner:
  655. $banner
  656. \$(TMP_D):
  657. \$(MKDIR) \"\$(TMP_D)\"
  658. # NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
  659. #\$(BIN_D):
  660. # \$(MKDIR) \$(BIN_D)
  661. #
  662. #\$(TEST_D):
  663. # \$(MKDIR) \$(TEST_D)
  664. \$(LIB_D):
  665. \$(MKDIR) \"\$(LIB_D)\"
  666. # This needs to be invoked once, when the makefile is first constructed, or
  667. # after cleaning.
  668. init: \$(TMP_D) \$(LIB_D) \$(BIN_D) \$(TEST_D) headers
  669. headers: \$(HEADER)
  670. lib: \$(LIBS_DEP) \$(E_SHLIB)
  671. exe: apps tools testapps
  672. apps: \$(BIN_D)$o\$(E_EXE)$exep \$(BIN_D)${o}CA.pl
  673. testapps: \$(T_EXE)
  674. tools: \$(BIN_D)${o}c_rehash
  675. install: all
  676. \$(MKDIR) \"\$(INSTALLTOP)\"
  677. \$(MKDIR) \"\$(INSTALLTOP)${o}bin\"
  678. \$(MKDIR) \"\$(INSTALLTOP)${o}include\"
  679. \$(MKDIR) \"\$(INSTALLTOP)${o}include${o}openssl\"
  680. \$(MKDIR) \"\$(INSTALLTOP)${o}lib\"
  681. \$(MKDIR) \"\$(INSTALLTOP)${o}lib${o}engines\"
  682. $extra_install
  683. clean:
  684. \$(RM) \$(TMP_D)$o*.*
  685. vclean:
  686. \$(RM) \$(TMP_D)$o*.*
  687. \$(RM) \$(OUT_D)$o*.*
  688. reallyclean:
  689. \$(RM) -rf \$(TMP_D)
  690. \$(RM) -rf \$(BIN_D)
  691. \$(RM) -rf \$(TEST_D)
  692. \$(RM) -rf \$(LIB_D)
  693. EOF
  694. $rules .= &do_rehash_rule("rehash.time", "certs/demo apps tools");
  695. $rules .= &do_test_rule("test", "rehash.time", "run_tests.pl");
  696. $rules .= <<"EOF";
  697. crypto${o}buildinf.h : MINFO
  698. \$(PERL) util${o}mkbuildinf.pl "\$(CC) \$(CFLAG_Q)" "\$(PLATFORM)" > crypto${o}buildinf.h
  699. $(OBJ_D)${o}cversion${obj} : crypto${o}buildinf.h
  700. EOF
  701. # Strip off trailing ' '
  702. foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
  703. $test=&clean_up_ws($test);
  704. $e_exe=&clean_up_ws($e_exe);
  705. $header=&clean_up_ws($header);
  706. $defs.=&do_defs("HEADER",$header,"\$(INCL_D)","");
  707. $rules.=&do_copy_rule("\$(INCL_D)",$header,"");
  708. $defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
  709. $rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
  710. $defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
  711. $rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
  712. # Special case rules for fips_start and fips_end fips_premain_dso
  713. if ($fips)
  714. {
  715. if ($fipscanisterbuild)
  716. {
  717. $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_start$obj",
  718. "fips${o}fips_canister.c",
  719. "-DFIPS_START \$(SHLIB_CFLAGS)");
  720. $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_end$obj",
  721. "fips${o}fips_canister.c", "\$(SHLIB_CFLAGS)");
  722. }
  723. $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_standalone_sha1$obj",
  724. "fips${o}sha${o}fips_standalone_sha1.c",
  725. "\$(APP_CFLAGS)");
  726. $rules.=&cc_compile_target("\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj",
  727. "fips${o}fips_premain.c",
  728. "-DFINGERPRINT_PREMAIN_DSO_LOAD \$(APP_CFLAGS)");
  729. }
  730. sub fix_asm
  731. {
  732. my($asm, $dir) = @_;
  733. $asm = " $asm";
  734. $asm =~ s/\s+/ $dir\//g;
  735. $asm =~ s/\.o//g;
  736. $asm =~ s/^ //;
  737. return $asm . ' ';
  738. }
  739. if ($orig_platform eq 'copy') {
  740. $lib_obj{CRYPTO} .= fix_asm($mf_md5_asm, 'crypto/md5');
  741. $lib_obj{CRYPTO} .= fix_asm($mf_bn_asm, 'crypto/bn');
  742. # cpuid is included by the crypto dir
  743. #$lib_obj{CRYPTO} .= fix_asm($mf_cpuid_asm, 'crypto');
  744. # AES asm files end up included by the aes dir itself
  745. #$lib_obj{CRYPTO} .= fix_asm($mf_aes_asm, 'crypto/aes');
  746. $lib_obj{CRYPTO} .= fix_asm($mf_sha_asm, 'crypto/sha');
  747. $lib_obj{CRYPTO} .= fix_asm($mf_engines_asm, 'engines');
  748. $lib_obj{CRYPTO} .= fix_asm($mf_rc4_asm, 'crypto/rc4');
  749. $lib_obj{CRYPTO} .= fix_asm($mf_modes_asm, 'crypto/modes');
  750. $lib_obj{CRYPTO} .= fix_asm($mf_ec_asm, 'crypto/ec');
  751. }
  752. foreach (values %lib_nam)
  753. {
  754. $lib_obj=$lib_obj{$_};
  755. local($slib)=$shlib;
  756. $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
  757. $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
  758. $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
  759. }
  760. # hack to add version info on MSVC
  761. if (($platform eq "VC-WIN32") || ($platform eq "VC-WIN64A")
  762. || ($platform eq "VC-WIN64I") || ($platform eq "VC-NT")) {
  763. $rules.= <<"EOF";
  764. \$(OBJ_D)\\\$(CRYPTO).res: ms\\version32.rc
  765. \$(RSC) /fo"\$(OBJ_D)\\\$(CRYPTO).res" /d CRYPTO ms\\version32.rc
  766. \$(OBJ_D)\\\$(SSL).res: ms\\version32.rc
  767. \$(RSC) /fo"\$(OBJ_D)\\\$(SSL).res" /d SSL ms\\version32.rc
  768. EOF
  769. }
  770. $defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
  771. foreach (split(/\s+/,$test))
  772. {
  773. my $t_libs;
  774. $t=&bname($_);
  775. my $ltype;
  776. # Check to see if test program is FIPS
  777. if ($fips && /fips/)
  778. {
  779. # If fips perform static link to
  780. # $(O_FIPSCANISTER)
  781. $t_libs = "\$(O_FIPSCANISTER)";
  782. $ltype = 2;
  783. }
  784. else
  785. {
  786. $t_libs = "\$(L_LIBS)";
  787. $ltype = 0;
  788. }
  789. $tt="\$(OBJ_D)${o}$t${obj}";
  790. $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","$t_libs \$(EX_LIBS)", $ltype);
  791. }
  792. $defs.=&do_defs("E_SHLIB",$engines . $otherlibs,"\$(ENG_D)",$shlibp);
  793. foreach (split(/\s+/,$engines))
  794. {
  795. my $engine = $_;
  796. my @objs = grep {/e_$engine/} @engines_obj;
  797. $rules.=&do_compile_rule("\$(OBJ_D)",join(" ",@objs),$lib);
  798. map {$_=~s/.*\/([^\/]+)$/\$(OBJ_D)${o}$1$obj/} @objs;
  799. $rules.= &do_lib_rule(join(" ",@objs),"\$(ENG_D)$o$engine$shlibp","",$shlib,"");
  800. }
  801. $rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
  802. #$rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)");
  803. foreach (split(" ",$otherlibs))
  804. {
  805. my $uc = $_;
  806. $uc =~ tr /a-z/A-Z/;
  807. $rules.= &do_lib_rule("\$(${uc}OBJ)","\$(ENG_D)$o$_$shlibp", "", $shlib, "");
  808. }
  809. if ($fips)
  810. {
  811. if ($shlib)
  812. {
  813. $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
  814. "\$(O_CRYPTO)", "$crypto",
  815. $shlib, "\$(SO_CRYPTO)", "\$(BASEADDR)");
  816. }
  817. else
  818. {
  819. $rules.= &do_lib_rule("\$(CRYPTOOBJ)",
  820. "\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)", "");
  821. $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
  822. "\$(LIB_D)$o$crypto_compat",$crypto,$shlib,"\$(SO_CRYPTO)", "");
  823. }
  824. }
  825. else
  826. {
  827. $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
  828. "\$(SO_CRYPTO)");
  829. }
  830. if ($fips)
  831. {
  832. if ($fipscanisterbuild)
  833. {
  834. $rules.= &do_rlink_rule("\$(O_FIPSCANISTER)",
  835. "\$(OBJ_D)${o}fips_start$obj",
  836. "\$(FIPSOBJ)",
  837. "\$(OBJ_D)${o}fips_end$obj",
  838. "\$(FIPS_SHA1_EXE)", "");
  839. # FIXME
  840. $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)",
  841. "\$(OBJ_D)${o}fips_standalone_sha1$obj \$(OBJ_D)${o}sha1dgst$obj $sha1_asm_obj",
  842. "","\$(EX_LIBS)", 1);
  843. }
  844. else
  845. {
  846. $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)",
  847. "\$(OBJ_D)${o}fips_standalone_sha1$obj \$(O_FIPSCANISTER)",
  848. "","", 1);
  849. }
  850. $rules.=&do_link_rule("\$(PREMAIN_DSO_EXE)","\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj \$(CRYPTOOBJ) \$(O_FIPSCANISTER)","","\$(EX_LIBS)", 1);
  851. }
  852. $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)", ($fips && !$shlib) ? 2 : 0);
  853. $rules.=&do_dofile_rule("\$(BIN_D)","c_rehash","tools/c_rehash.in");
  854. $rules.=&do_dofile_rule("\$(BIN_D)","CA.pl","apps/CA.pl.in");
  855. print $defs;
  856. if ($platform eq "linux-elf") {
  857. print <<"EOF";
  858. # Generate perlasm output files
  859. %.cpp:
  860. (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
  861. EOF
  862. }
  863. print "###################################################################\n";
  864. print $rules;
  865. ###############################################
  866. # strip off any trailing .[och] and append the relative directory
  867. # also remembering to do nothing if we are in one of the dropped
  868. # directories
  869. sub var_add
  870. {
  871. local($dir,$val,$keepext)=@_;
  872. local(@a,$_,$ret);
  873. return("") if $no_engine && $dir =~ /\/engine/;
  874. return("") if $no_hw && $dir =~ /\/hw/;
  875. return("") if $no_idea && $dir =~ /\/idea/;
  876. return("") if $no_aes && $dir =~ /\/aes/;
  877. return("") if $no_camellia && $dir =~ /\/camellia/;
  878. return("") if $no_seed && $dir =~ /\/seed/;
  879. return("") if $no_rc2 && $dir =~ /\/rc2/;
  880. return("") if $no_rc4 && $dir =~ /\/rc4/;
  881. return("") if $no_rc5 && $dir =~ /\/rc5/;
  882. return("") if $no_rsa && $dir =~ /\/rsa/;
  883. return("") if $no_rsa && $dir =~ /^rsaref/;
  884. return("") if $no_dsa && $dir =~ /\/dsa/;
  885. return("") if $no_dh && $dir =~ /\/dh/;
  886. return("") if $no_ec && $dir =~ /\/ec/;
  887. return("") if $no_cms && $dir =~ /\/cms/;
  888. return("") if $no_jpake && $dir =~ /\/jpake/;
  889. return("") if !$fips && $dir =~ /^fips/;
  890. if ($no_des && $dir =~ /\/des/)
  891. {
  892. if ($val =~ /read_pwd/)
  893. { return("$dir/read_pwd "); }
  894. else
  895. { return(""); }
  896. }
  897. return("") if $no_mdc2 && $dir =~ /\/mdc2/;
  898. return("") if $no_sock && $dir =~ /\/proxy/;
  899. return("") if $no_bf && $dir =~ /\/bf/;
  900. return("") if $no_cast && $dir =~ /\/cast/;
  901. return("") if $no_whirlpool && $dir =~ /\/whrlpool/;
  902. $val =~ s/^\s*(.*)\s*$/$1/;
  903. @a=split(/\s+/,$val);
  904. grep(s/\.[och]$//,@a) unless $keepext;
  905. @a=grep(!/^e_.*_3d$/,@a) if $no_des;
  906. @a=grep(!/^e_.*_d$/,@a) if $no_des;
  907. @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
  908. @a=grep(!/^e_.*_i$/,@a) if $no_aes;
  909. @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
  910. @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
  911. @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
  912. @a=grep(!/^e_.*_c$/,@a) if $no_cast;
  913. @a=grep(!/^e_rc4$/,@a) if $no_rc4;
  914. @a=grep(!/^e_camellia$/,@a) if $no_camellia;
  915. @a=grep(!/^e_seed$/,@a) if $no_seed;
  916. #@a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
  917. @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
  918. @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
  919. @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
  920. @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
  921. @a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
  922. @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
  923. @a=grep(!/(^p_open$)/,@a) if $no_rsa;
  924. @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
  925. @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
  926. @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
  927. @a=grep(!/_dhp$/,@a) if $no_dh;
  928. @a=grep(!/_mdc2$/,@a) if $no_mdc2;
  929. @a=grep(!/(srp)/,@a) if $no_srp;
  930. @a=grep(!/^engine$/,@a) if $no_engine;
  931. @a=grep(!/^hw$/,@a) if $no_hw;
  932. @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
  933. @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
  934. @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
  935. grep($_="$dir/$_",@a);
  936. @a=grep(!/(^|\/)s_/,@a) if $no_sock;
  937. @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
  938. $ret=join(' ',@a)." ";
  939. return($ret);
  940. }
  941. # change things so that each 'token' is only separated by one space
  942. sub clean_up_ws
  943. {
  944. local($w)=@_;
  945. $w =~ s/^\s*(.*)\s*$/$1/;
  946. $w =~ s/\s+/ /g;
  947. return($w);
  948. }
  949. sub do_defs
  950. {
  951. local($var,$files,$location,$postfix)=@_;
  952. local($_,$ret,$pf);
  953. local(*OUT,$tmp,$t);
  954. $files =~ s/\//$o/g if $o ne '/';
  955. $ret="$var=";
  956. $n=1;
  957. $Vars{$var}.="";
  958. foreach (split(/ /,$files))
  959. {
  960. $orig=$_;
  961. $_=&bname($_) unless /^\$/;
  962. if ($n++ == 2)
  963. {
  964. $n=0;
  965. $ret.="\\\n\t";
  966. }
  967. if (($_ =~ /bss_file/) && ($postfix eq ".h"))
  968. { $pf=".c"; }
  969. else { $pf=$postfix; }
  970. if ($_ =~ /BN_ASM/) { $t="$_ "; }
  971. elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
  972. elsif ($_ =~ /AES_ASM/){ $t="$_ "; }
  973. elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
  974. elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
  975. elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
  976. elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
  977. elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
  978. elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
  979. elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
  980. elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
  981. elsif ($_ =~ /WHIRLPOOL_ASM/){ $t="$_ "; }
  982. elsif ($_ =~ /CPUID_ASM/){ $t="$_ "; }
  983. else { $t="$location${o}$_$pf "; }
  984. $Vars{$var}.="$t ";
  985. $ret.=$t;
  986. }
  987. # hack to add version info on MSVC
  988. if ($shlib && (($platform eq "VC-WIN32") || ($platfrom eq "VC-WIN64I") || ($platform eq "VC-WIN64A") || ($platform eq "VC-NT")))
  989. {
  990. if ($var eq "CRYPTOOBJ")
  991. { $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
  992. elsif ($var eq "SSLOBJ")
  993. { $ret.="\$(OBJ_D)\\\$(SSL).res "; }
  994. }
  995. chomp($ret); # Does this actually do something? /RL
  996. $ret.="\n\n";
  997. return($ret);
  998. }
  999. # return the name with the leading path removed
  1000. sub bname
  1001. {
  1002. local($ret)=@_;
  1003. $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
  1004. return($ret);
  1005. }
  1006. # return the leading path
  1007. sub dname
  1008. {
  1009. my $ret=shift;
  1010. $ret =~ s/(^.*)[\\\/][^\\\/]+$/$1/;
  1011. return($ret);
  1012. }
  1013. ##############################################################
  1014. # do a rule for each file that says 'compile' to new direcory
  1015. # compile the files in '$files' into $to
  1016. sub do_compile_rule
  1017. {
  1018. local($to,$files,$ex)=@_;
  1019. local($ret,$_,$n,$d,$s);
  1020. $files =~ s/\//$o/g if $o ne '/';
  1021. foreach (split(/\s+/,$files))
  1022. {
  1023. $n=&bname($_);
  1024. $d=&dname($_);
  1025. if (-f "${_}.c")
  1026. {
  1027. $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
  1028. }
  1029. elsif (-f ($s="${d}${o}asm${o}${n}.pl") or
  1030. ($s=~s/sha256/sha512/ and -f $s) or
  1031. -f ($s="${d}${o}${n}.pl"))
  1032. {
  1033. $ret.=&perlasm_compile_target("$to${o}$n$obj",$s,$n);
  1034. }
  1035. elsif (-f ($s="${d}${o}asm${o}${n}.S") or
  1036. -f ($s="${d}${o}${n}.S"))
  1037. {
  1038. $ret.=&Sasm_compile_target("$to${o}$n$obj",$s,$n);
  1039. }
  1040. elsif (defined &special_compile_target and
  1041. ($s=special_compile_target($_)))
  1042. {
  1043. $ret.=$s;
  1044. }
  1045. else { die "no rule for $_"; }
  1046. }
  1047. return($ret);
  1048. }
  1049. ##############################################################
  1050. # do a rule for each file that says 'compile' to new direcory
  1051. sub perlasm_compile_target
  1052. {
  1053. my($target,$source,$bname)=@_;
  1054. return platform_perlasm_compile_target($target, $source, $bname)
  1055. if defined &platform_perlasm_compile_target;
  1056. my($ret);
  1057. $bname =~ s/(.*)\.[^\.]$/$1/;
  1058. $ret ="\$(TMP_D)$o$bname$asm_suffix: $source\n";
  1059. $ret.="\t\$(PERL) $source $asmtype \$(CFLAG) >\$\@\n";
  1060. if ($fipscanisteronly)
  1061. {
  1062. $ret .= "\t\$(PERL) util$o.pl . \$@ norunasm \$(CFLAG)\n";
  1063. }
  1064. $ret .= "\n";
  1065. $ret.="$target: \$(TMP_D)$o$bname$asm_suffix\n";
  1066. $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname$asm_suffix\n\n";
  1067. return($ret);
  1068. }
  1069. sub Sasm_compile_target
  1070. {
  1071. my($target,$source,$bname)=@_;
  1072. my($ret);
  1073. $bname =~ s/(.*)\.[^\.]$/$1/;
  1074. $ret ="\$(TMP_D)$o$bname.asm: $source\n";
  1075. $ret.="\t\$(CC) -E \$(CFLAG) $source >\$\@\n";
  1076. $ret.="\t\$(PERL) util\\fipsas.pl . \$@ norunasm \$(CFLAG)\n" if $fipscanisteronly;
  1077. $ret.="\n";
  1078. $ret.="$target: \$(TMP_D)$o$bname.asm\n";
  1079. $ret.="\t\$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm\n\n";
  1080. return($ret);
  1081. }
  1082. sub cc_compile_target
  1083. {
  1084. local($target,$source,$ex_flags)=@_;
  1085. local($ret);
  1086. $target =~ s/\//$o/g if $o ne "/";
  1087. $source =~ s/\//$o/g if $o ne "/";
  1088. $ret ="$target: \$(SRC_D)$o$source\n\t";
  1089. $ret.="\$(CC)";
  1090. $ret.= " -MMD" if $orig_platform eq "copy";
  1091. $ret.= " ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
  1092. $target =~ s/\.o$/.d/;
  1093. $ret.=".sinclude \"$target\"\n\n" if $orig_platform eq "copy";
  1094. return($ret);
  1095. }
  1096. ##############################################################
  1097. sub do_asm_rule
  1098. {
  1099. local($target,$src)=@_;
  1100. local($ret,@s,@t,$i);
  1101. $target =~ s/\//$o/g if $o ne "/";
  1102. $src =~ s/\//$o/g if $o ne "/";
  1103. @t=split(/\s+/,$target);
  1104. @s=split(/\s+/,$src);
  1105. for ($i=0; $i<=$#s; $i++)
  1106. {
  1107. my $objfile = $t[$i];
  1108. my $srcfile = $s[$i];
  1109. if ($perl_asm == 1)
  1110. {
  1111. my $plasm = $objfile;
  1112. $plasm =~ s/${obj}/.pl/;
  1113. $ret.="$srcfile: $plasm\n";
  1114. $ret.="\t\$(PERL) $plasm $asmtype \$(CFLAG) >$srcfile\n\n";
  1115. }
  1116. $ret.="$objfile: $srcfile\n";
  1117. $ret.="\t\$(ASM) $afile$objfile \$(SRC_D)$o$srcfile\n\n";
  1118. }
  1119. return($ret);
  1120. }
  1121. sub do_shlib_rule
  1122. {
  1123. local($n,$def)=@_;
  1124. local($ret,$nn);
  1125. local($t);
  1126. ($nn=$n) =~ tr/a-z/A-Z/;
  1127. $ret.="$n.dll: \$(${nn}OBJ)\n";
  1128. if ($vc && $w32)
  1129. {
  1130. $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
  1131. }
  1132. $ret.="\n";
  1133. return($ret);
  1134. }
  1135. # do a rule for each file that says 'copy' to new direcory on change
  1136. sub do_copy_rule
  1137. {
  1138. local($to,$files,$p)=@_;
  1139. local($ret,$_,$n,$pp);
  1140. $files =~ s/\//$o/g if $o ne '/';
  1141. foreach (split(/\s+/,$files))
  1142. {
  1143. $n=&bname($_);
  1144. if ($n =~ /bss_file/)
  1145. { $pp=".c"; }
  1146. else { $pp=$p; }
  1147. $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(PERL) \$(SRC_D)${o}util${o}copy-if-different.pl \"\$(SRC_D)$o$_$pp\" \"$to${o}$n$pp\"\n\n";
  1148. }
  1149. return($ret);
  1150. }
  1151. sub do_dofile_rule
  1152. {
  1153. (my $to, my $file, my $tmpl) = @_;
  1154. $file =~ s|/|$o|g if $o ne '/';
  1155. return <<"EOF";
  1156. $to${o}$file: $tmpl
  1157. \$(PERL) "-I." "-Mconfigdata" util/dofile.pl "$tmpl" > "$to${o}$file.new"
  1158. \$(MV) "$to${o}$file.new" "$to${o}$file"
  1159. EOF
  1160. }
  1161. # Options picked up from the OPTIONS line in the top level Makefile
  1162. # generated by Configure.
  1163. sub read_options
  1164. {
  1165. # Many options are handled in a similar way. In particular
  1166. # no-xxx sets zero or more scalars to 1.
  1167. # Process these using the %valid_options hash containing the option
  1168. # name and reference to the scalars to set. In some cases the option
  1169. # needs no special handling and can be ignored: this is done by
  1170. # setting the value to 0.
  1171. my %valid_options = (
  1172. "no-rc2" => \$no_rc2,
  1173. "no-rc4" => \$no_rc4,
  1174. "no-rc5" => \$no_rc5,
  1175. "no-idea" => \$no_idea,
  1176. "no-aes" => \$no_aes,
  1177. "no-camellia" => \$no_camellia,
  1178. "no-seed" => \$no_seed,
  1179. "no-des" => \$no_des,
  1180. "no-bf" => \$no_bf,
  1181. "no-cast" => \$no_cast,
  1182. "no-md2" => \$no_md2,
  1183. "no-md4" => \$no_md4,
  1184. "no-md5" => \$no_md5,
  1185. "no-ripemd" => \$no_ripemd,
  1186. "no-mdc2" => \$no_mdc2,
  1187. "no-whirlpool" => \$no_whirlpool,
  1188. "no-patents" =>
  1189. [\$no_rc2, \$no_rc4, \$no_rc5, \$no_idea, \$no_rsa],
  1190. "no-rsa" => \$no_rsa,
  1191. "no-dsa" => \$no_dsa,
  1192. "no-dh" => \$no_dh,
  1193. "no-asm" => \$no_asm,
  1194. "nasm" => \$nasm,
  1195. "nw-nasm" => \$nw_nasm,
  1196. "nw-mwasm" => \$nw_mwasm,
  1197. "gaswin" => \$gaswin,
  1198. "no-ssl3" => \$no_ssl3,
  1199. "no-ssl3-method" => 0,
  1200. "no-srp" => \$no_srp,
  1201. "no-cms" => \$no_cms,
  1202. "no-jpake" => \$no_jpake,
  1203. "no-ec2m" => \$no_ec2m,
  1204. "no-ec_nistp_64_gcc_128" => 0,
  1205. "no-err" => \$no_err,
  1206. "no-sock" => \$no_sock,
  1207. "no-ec" => \$no_ec,
  1208. "no-gost" => \$no_gost,
  1209. "no-engine" => \$no_engine,
  1210. "no-egd" => 0,
  1211. "no-hw" => \$no_hw,
  1212. "no-async" => \$no_async,
  1213. "no-autoalginit" => \$no_autoalginit,
  1214. "no-autoerrinit" => \$no_autoerrinit,
  1215. "just-ssl" =>
  1216. [\$no_rc2, \$no_idea, \$no_des, \$no_bf, \$no_cast,
  1217. \$no_md2, \$no_mdc2, \$no_dsa, \$no_dh,
  1218. \$no_err, \$no_ripemd, \$no_rc5,
  1219. \$no_aes, \$no_camellia, \$no_seed, \$no_srp],
  1220. "rsaref" => 0,
  1221. "gcc" => \$gcc,
  1222. "debug" => \$debug,
  1223. "--debug" => \$debug,
  1224. "profile" => \$profile,
  1225. "shlib" => \$shlib,
  1226. "dll" => \$shlib,
  1227. "shared" => 0,
  1228. "no-sctp" => 0,
  1229. "no-srtp" => 0,
  1230. "no-gmp" => 0,
  1231. "no-rfc3779" => 0,
  1232. "no-montasm" => 0,
  1233. "no-shared" => 0,
  1234. "no-store" => 0,
  1235. "no-zlib" => 0,
  1236. "no-zlib-dynamic" => 0,
  1237. "no-ssl-trace" => 0,
  1238. "no-unit-test" => 0,
  1239. "no-deprecated" => 0,
  1240. "no-ocb" => 0,
  1241. "no-crypto-mdebug" => 0,
  1242. "fips" => \$fips,
  1243. "fipscanisterbuild" => [\$fips, \$fipscanisterbuild],
  1244. "fipscanisteronly" => [\$fips, \$fipscanisterbuild, \$fipscanisteronly],
  1245. "fipscheck" => [\$fips, \$fipscanisterbuild, \$fipscanisteronly],
  1246. );
  1247. if (exists $valid_options{$_})
  1248. {
  1249. my $r = $valid_options{$_};
  1250. if ( ref $r eq "SCALAR")
  1251. { $$r = 1;}
  1252. elsif ( ref $r eq "ARRAY")
  1253. {
  1254. my $r2;
  1255. foreach $r2 (@$r)
  1256. {
  1257. $$r2 = 1;
  1258. }
  1259. }
  1260. }
  1261. elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; }
  1262. elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
  1263. elsif (/^enable-zlib-dynamic$/)
  1264. {
  1265. $zlib_opt = 2;
  1266. }
  1267. elsif (/^no-static-engine/)
  1268. {
  1269. $no_static_engine = 1;
  1270. }
  1271. elsif (/^enable-static-engine/)
  1272. {
  1273. $no_static_engine = 0;
  1274. }
  1275. # There are also enable-xxx options which correspond to
  1276. # the no-xxx. Since the scalars are enabled by default
  1277. # these can be ignored.
  1278. elsif (/^enable-/)
  1279. {
  1280. my $t = $_;
  1281. $t =~ s/^enable/no/;
  1282. if (exists $valid_options{$t})
  1283. {return 1;}
  1284. return 0;
  1285. }
  1286. # experimental-xxx is mostly like enable-xxx, but opensslconf.v
  1287. # will still set OPENSSL_NO_xxx unless we set OPENSSL_EXPERIMENTAL_xxx.
  1288. # (No need to fail if we don't know the algorithm -- this is for adventurous users only.)
  1289. elsif (/^experimental-/)
  1290. {
  1291. my $algo, $ALGO;
  1292. ($algo = $_) =~ s/^experimental-//;
  1293. ($ALGO = $algo) =~ tr/[a-z]/[A-Z]/;
  1294. $xcflags="-DOPENSSL_EXPERIMENTAL_$ALGO $xcflags";
  1295. }
  1296. elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
  1297. elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
  1298. elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
  1299. { $c_flags.="$_ "; }
  1300. else { return(0); }
  1301. return(1);
  1302. }
  1303. sub fipslib_error
  1304. {
  1305. print STDERR "***FIPS module directory sanity check failed***\n";
  1306. print STDERR "FIPS module build failed, or was deleted\n";
  1307. print STDERR "Please rebuild FIPS module.\n";
  1308. exit 1;
  1309. }
  1310. sub fips_check_files
  1311. {
  1312. my $dir = shift @_;
  1313. my $ret = 1;
  1314. if (!-d $dir)
  1315. {
  1316. print STDERR "FIPS module directory $dir does not exist\n";
  1317. fipslib_error();
  1318. }
  1319. foreach (@_)
  1320. {
  1321. if (!-f "$dir${o}$_")
  1322. {
  1323. print STDERR "FIPS module file $_ does not exist!\n";
  1324. $ret = 0;
  1325. }
  1326. }
  1327. fipslib_error() if ($ret == 0);
  1328. }