mk1mf.pl 35 KB

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