2
0

mk1mf.pl 35 KB

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