mk1mf.pl 35 KB

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