VC-32.pl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. #!/usr/local/bin/perl
  2. # VC-32.pl - unified script for Microsoft Visual C++, covering Win32,
  3. # Win64 and WinCE [follow $FLAVOR variable to trace the differences].
  4. #
  5. $ssl= "ssleay32";
  6. $crypto="libeay32";
  7. if ($fips && !$shlib)
  8. {
  9. $crypto="libeayfips32";
  10. $crypto_compat = "libeaycompat32.lib";
  11. }
  12. else
  13. {
  14. $crypto="libeay32";
  15. }
  16. if ($fipscanisterbuild)
  17. {
  18. $fips_canister_path = "\$(LIB_D)\\fipscanister.lib";
  19. }
  20. $o='\\';
  21. $cp='$(PERL) util/copy.pl';
  22. $cp2='$(PERL) util/copy.pl -stripcr';
  23. $mkdir='$(PERL) util/mkdir-p.pl';
  24. $rm='del /Q';
  25. $zlib_lib="zlib1.lib";
  26. # Santize -L options for ms link
  27. $l_flags =~ s/-L("\[^"]+")/\/libpath:$1/g;
  28. $l_flags =~ s/-L(\S+)/\/libpath:$1/g;
  29. # C compiler stuff
  30. $cc='cl';
  31. if ($FLAVOR =~ /WIN64/)
  32. {
  33. # Note that we currently don't have /WX on Win64! There is a lot of
  34. # warnings, but only of two types:
  35. #
  36. # C4344: conversion from '__int64' to 'int/long', possible loss of data
  37. # C4267: conversion from 'size_t' to 'int/long', possible loss of data
  38. #
  39. # Amount of latter type is minimized by aliasing strlen to function of
  40. # own desing and limiting its return value to 2GB-1 (see e_os.h). As
  41. # per 0.9.8 release remaining warnings were explicitly examined and
  42. # considered safe to ignore.
  43. #
  44. $base_cflags= " $mf_cflag";
  45. my $f = ($shlib and !$fipscanisterbuild)?' /MD':' /MT';
  46. $opt_cflags=$f.' /Ox';
  47. $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
  48. $lflags="/nologo /subsystem:console /opt:ref";
  49. *::perlasm_compile_target = sub {
  50. my ($target,$source,$bname)=@_;
  51. my $ret;
  52. $bname =~ s/(.*)\.[^\.]$/$1/;
  53. $ret=<<___;
  54. \$(TMP_D)$o$bname.asm: $source
  55. set ASM=\$(ASM)
  56. \$(PERL) $source \$\@
  57. ___
  58. $ret .= "\t\$(PERL) util\\fipsas.pl . \$@ norunasm \$(CFLAG)\n" if $fipscanisterbuild;
  59. $ret.=<<___;
  60. $target: \$(TMP_D)$o$bname.asm
  61. \$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm
  62. ___
  63. }
  64. }
  65. elsif ($FLAVOR =~ /CE/)
  66. {
  67. # sanity check
  68. die '%OSVERSION% is not defined' if (!defined($ENV{'OSVERSION'}));
  69. die '%PLATFORM% is not defined' if (!defined($ENV{'PLATFORM'}));
  70. die '%TARGETCPU% is not defined' if (!defined($ENV{'TARGETCPU'}));
  71. #
  72. # Idea behind this is to mimic flags set by eVC++ IDE...
  73. #
  74. $wcevers = $ENV{'OSVERSION'}; # WCENNN
  75. die '%OSVERSION% value is insane' if ($wcevers !~ /^WCE([1-9])([0-9]{2})$/);
  76. $wcecdefs = "-D_WIN32_WCE=$1$2 -DUNDER_CE=$1$2"; # -D_WIN32_WCE=NNN
  77. $wcelflag = "/subsystem:windowsce,$1.$2"; # ...,N.NN
  78. $wceplatf = $ENV{'PLATFORM'};
  79. $wceplatf =~ tr/a-z0-9 /A-Z0-9_/d;
  80. $wcecdefs .= " -DWCE_PLATFORM_$wceplatf";
  81. $wcetgt = $ENV{'TARGETCPU'}; # just shorter name...
  82. SWITCH: for($wcetgt) {
  83. /^X86/ && do { $wcecdefs.=" -Dx86 -D_X86_ -D_i386_ -Di_386_";
  84. $wcelflag.=" /machine:X86"; last; };
  85. /^ARMV4[IT]/ && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
  86. $wcecdefs.=" -DTHUMB -D_THUMB_" if($wcetgt=~/T$/);
  87. $wcecdefs.=" -QRarch4T -QRinterwork-return";
  88. $wcelflag.=" /machine:THUMB"; last; };
  89. /^ARM/ && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
  90. $wcelflag.=" /machine:ARM"; last; };
  91. /^MIPSIV/ && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
  92. $wcecdefs.=" -D_MIPS64 -QMmips4 -QMn32";
  93. $wcelflag.=" /machine:MIPSFPU"; last; };
  94. /^MIPS16/ && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
  95. $wcecdefs.=" -DMIPSII -QMmips16";
  96. $wcelflag.=" /machine:MIPS16"; last; };
  97. /^MIPSII/ && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
  98. $wcecdefs.=" -QMmips2";
  99. $wcelflag.=" /machine:MIPS"; last; };
  100. /^R4[0-9]{3}/ && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000";
  101. $wcelflag.=" /machine:MIPS"; last; };
  102. /^SH[0-9]/ && do { $wcecdefs.=" -D$wcetgt -D_$wcetgt_ -DSHx";
  103. $wcecdefs.=" -Qsh4" if ($wcetgt =~ /^SH4/);
  104. $wcelflag.=" /machine:$wcetgt"; last; };
  105. { $wcecdefs.=" -D$wcetgt -D_$wcetgt_";
  106. $wcelflag.=" /machine:$wcetgt"; last; };
  107. }
  108. $cc=($ENV{CC} or "cl");
  109. $base_cflags=' /W3 /WX /GF /Gy /nologo -DUNICODE -D_UNICODE -DOPENSSL_SYS_WINCE -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD -DOPENSSL_SMALL_FOOTPRINT';
  110. $base_cflags.=" $wcecdefs";
  111. $base_cflags.=' -I$(WCECOMPAT)/include' if (defined($ENV{'WCECOMPAT'}));
  112. $base_cflags.=' -I$(PORTSDK_LIBPATH)/../../include' if (defined($ENV{'PORTSDK_LIBPATH'}));
  113. if (`$cc 2>&1` =~ /Version ([0-9]+)\./ && $1>=14) {
  114. $base_cflags.=($shlib and !$fipscanisterbuild)?' /MD':' /MT';
  115. } else {
  116. $base_cflags.=' /MC';
  117. }
  118. $opt_cflags=' /O1i'; # optimize for space, but with intrinsics...
  119. $dbg_cflags=' /Od -DDEBUG -D_DEBUG';
  120. $lflags="/nologo /opt:ref $wcelflag";
  121. }
  122. else # Win32
  123. {
  124. $base_cflags= " $mf_cflag";
  125. my $f = ($shlib and !$fipscanisterbuild)?' /MD':' /MT';
  126. $opt_cflags=$f.' /Ox /O2 /Ob2';
  127. $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
  128. $lflags="/nologo /subsystem:console /opt:ref";
  129. }
  130. $lib_cflag='/Zl' if (!$shlib or $fipscanisterbuild); # remove /DEFAULTLIBs
  131. $mlflags='';
  132. $out_def ="out32"; $out_def.="dll" if ($shlib);
  133. $out_def.='_$(TARGETCPU)' if ($FLAVOR =~ /CE/);
  134. $tmp_def ="tmp32"; $tmp_def.="dll" if ($shlib);
  135. $tmp_def.='_$(TARGETCPU)' if ($FLAVOR =~ /CE/);
  136. $inc_def="inc32";
  137. if ($debug)
  138. {
  139. $cflags=$dbg_cflags.$base_cflags;
  140. }
  141. else
  142. {
  143. $cflags=$opt_cflags.$base_cflags;
  144. }
  145. # generate symbols.pdb unconditionally
  146. $app_cflag.=" /Zi /Fd\$(TMP_D)/app";
  147. $lib_cflag.=" /Zi /Fd\$(TMP_D)/lib";
  148. $lflags.=" /debug";
  149. $lflags.=" /fixed" if ($fips && $FLAVOR !~ /WIN64/);
  150. $obj='.obj';
  151. $asm_suffix='.asm';
  152. $ofile="/Fo";
  153. # EXE linking stuff
  154. $link="link";
  155. $rsc="rc";
  156. $efile="/out:";
  157. $exep='.exe';
  158. if ($no_sock) { $ex_libs=''; }
  159. elsif ($FLAVOR =~ /CE/) { $ex_libs='ws2.lib'; }
  160. else { $ex_libs='ws2_32.lib'; }
  161. if ($FLAVOR =~ /CE/)
  162. {
  163. $ex_libs.=' crypt32.lib'; # for e_capi.c
  164. if (defined($ENV{WCECOMPAT}))
  165. {
  166. $ex_libs.= ' $(WCECOMPAT)/lib';
  167. if (-f "$ENV{WCECOMPAT}/lib/$ENV{TARGETCPU}/wcecompatex.lib")
  168. {
  169. $ex_libs.='/$(TARGETCPU)/wcecompatex.lib';
  170. }
  171. else
  172. {
  173. $ex_libs.='/wcecompatex.lib';
  174. }
  175. }
  176. $ex_libs.=' $(PORTSDK_LIBPATH)/portlib.lib' if (defined($ENV{'PORTSDK_LIBPATH'}));
  177. $ex_libs.=' /nodefaultlib coredll.lib corelibc.lib' if ($ENV{'TARGETCPU'} eq "X86");
  178. }
  179. else
  180. {
  181. $ex_libs.=' gdi32.lib advapi32.lib crypt32.lib user32.lib';
  182. $ex_libs.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/ and `cl 2>&1` =~ /14\.00\.4[0-9]{4}\./);
  183. # WIN32 UNICODE build gets linked with unicows.lib for
  184. # backward compatibility with Win9x.
  185. $ex_libs="unicows.lib $ex_libs" if ($FLAVOR =~ /WIN32/ and $cflags =~ /\-DUNICODE/);
  186. }
  187. # static library stuff
  188. $mklib='lib /nologo';
  189. $ranlib='';
  190. $plib="";
  191. $libp=".lib";
  192. $shlibp=($shlib)?".dll":".lib";
  193. $lfile='/out:';
  194. $shlib_ex_obj="";
  195. $app_ex_obj="setargv.obj" if ($FLAVOR !~ /CE/);
  196. if ($FLAVOR =~ /WIN64A/) {
  197. if (`nasm -v 2>NUL` =~ /NASM version ([0-9]+\.[0-9]+)/ && $1 >= 2.0) {
  198. $asm='nasm -f win64 -DNEAR -Ox -g';
  199. $afile='-o ';
  200. } else {
  201. $asm='ml64 /c /Cp /Cx /Zi';
  202. $afile='/Fo';
  203. }
  204. } elsif ($FLAVOR =~ /WIN64I/) {
  205. $asm='ias -d debug';
  206. $afile="-o ";
  207. } elsif ($nasm) {
  208. my $ver=`nasm -v 2>NUL`;
  209. my $vew=`nasmw -v 2>NUL`;
  210. # pick newest version
  211. $asm=($ver ge $vew?"nasm":"nasmw")." -f win32";
  212. $asmtype="win32n";
  213. $afile='-o ';
  214. } else {
  215. $asm='ml /nologo /Cp /coff /c /Cx /Zi';
  216. $afile='/Fo';
  217. $asmtype="win32";
  218. }
  219. $bn_asm_obj='';
  220. $bn_asm_src='';
  221. $des_enc_obj='';
  222. $des_enc_src='';
  223. $bf_enc_obj='';
  224. $bf_enc_src='';
  225. if (!$no_asm)
  226. {
  227. win32_import_asm($mf_bn_asm, "bn", \$bn_asm_obj, \$bn_asm_src);
  228. win32_import_asm($mf_aes_asm, "aes", \$aes_asm_obj, \$aes_asm_src);
  229. win32_import_asm($mf_des_asm, "des", \$des_enc_obj, \$des_enc_src);
  230. win32_import_asm($mf_bf_asm, "bf", \$bf_enc_obj, \$bf_enc_src);
  231. win32_import_asm($mf_cast_asm, "cast", \$cast_enc_obj, \$cast_enc_src);
  232. win32_import_asm($mf_rc4_asm, "rc4", \$rc4_enc_obj, \$rc4_enc_src);
  233. win32_import_asm($mf_rc5_asm, "rc5", \$rc5_enc_obj, \$rc5_enc_src);
  234. win32_import_asm($mf_md5_asm, "md5", \$md5_asm_obj, \$md5_asm_src);
  235. win32_import_asm($mf_sha_asm, "sha", \$sha1_asm_obj, \$sha1_asm_src);
  236. win32_import_asm($mf_rmd_asm, "ripemd", \$rmd160_asm_obj, \$rmd160_asm_src);
  237. win32_import_asm($mf_wp_asm, "whrlpool", \$whirlpool_asm_obj, \$whirlpool_asm_src);
  238. win32_import_asm($mf_modes_asm, "modes", \$modes_asm_obj, \$modes_asm_src);
  239. win32_import_asm($mf_cpuid_asm, "", \$cpuid_asm_obj, \$cpuid_asm_src);
  240. $perl_asm = 1;
  241. }
  242. if ($shlib && $FLAVOR !~ /CE/)
  243. {
  244. $mlflags.=" $lflags /dll";
  245. $lib_cflag.=" -D_WINDLL";
  246. #
  247. # Engage Applink...
  248. #
  249. $app_ex_obj.=" \$(OBJ_D)\\applink.obj /implib:\$(TMP_D)\\junk.lib";
  250. $cflags.=" -DOPENSSL_USE_APPLINK -I.";
  251. # I'm open for better suggestions than overriding $banner...
  252. $banner=<<'___';
  253. @echo Building OpenSSL
  254. $(OBJ_D)\applink.obj: ms\applink.c
  255. $(CC) /Fo$(OBJ_D)\applink.obj $(APP_CFLAGS) -c ms\applink.c
  256. $(OBJ_D)\uplink.obj: ms\uplink.c ms\applink.c
  257. $(CC) /Fo$(OBJ_D)\uplink.obj $(SHLIB_CFLAGS) -c ms\uplink.c
  258. LIBS_DEP=$(LIBS_DEP) $(OBJ_D)\applink.obj
  259. CRYPTOOBJ=$(OBJ_D)\uplink.obj $(CRYPTOOBJ)
  260. ___
  261. $banner.=<<'___' if ($FLAVOR =~ /WIN64/);
  262. CRYPTOOBJ=ms\uptable.obj $(CRYPTOOBJ)
  263. ___
  264. }
  265. elsif ($shlib && $FLAVOR =~ /CE/)
  266. {
  267. $mlflags.=" $lflags /dll";
  268. $lflags.=' /entry:mainCRTstartup' if(defined($ENV{'PORTSDK_LIBPATH'}));
  269. $lib_cflag.=" -D_WINDLL";
  270. $lib_cflag.=" -D_DLL" if (!$fipscanisterbuild);
  271. }
  272. sub do_lib_rule
  273. {
  274. my($objs,$target,$name,$shlib,$ign,$base_addr) = @_;
  275. local($ret);
  276. $taget =~ s/\//$o/g if $o ne '/';
  277. my $base_arg;
  278. if ($base_addr ne "")
  279. {
  280. $base_arg= " /base:$base_addr";
  281. }
  282. else
  283. {
  284. $base_arg = "";
  285. }
  286. if ($name ne "")
  287. {
  288. $name =~ tr/a-z/A-Z/;
  289. $name = "/def:ms/${name}.def";
  290. }
  291. # $target="\$(LIB_D)$o$target";
  292. # $ret.="$target: $objs\n";
  293. if (!$shlib)
  294. {
  295. # $ret.="\t\$(RM) \$(O_$Name)\n";
  296. $ret.="$target: $objs\n";
  297. $ret.="\t\$(MKLIB) $lfile$target @<<\n $objs\n<<\n";
  298. }
  299. else
  300. {
  301. local($ex)=($target =~ /O_CRYPTO/)?'':' $(L_CRYPTO)';
  302. $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
  303. if ($fips && $target =~ /O_CRYPTO/)
  304. {
  305. $ret.="$target: $objs \$(PREMAIN_DSO_EXE)";
  306. $ret.="\n\tSET FIPS_LINK=\$(LINK)\n";
  307. $ret.="\tSET FIPS_CC=\$(CC)\n";
  308. $ret.="\tSET FIPS_CC_ARGS=/Fo\$(OBJ_D)${o}fips_premain.obj \$(SHLIB_CFLAGS) -c\n";
  309. $ret.="\tSET PREMAIN_DSO_EXE=\$(PREMAIN_DSO_EXE)\n";
  310. $ret.="\tSET FIPS_SHA1_EXE=\$(FIPS_SHA1_EXE)\n";
  311. $ret.="\tSET FIPS_TARGET=$target\n";
  312. $ret.="\tSET FIPSLIB_D=\$(FIPSLIB_D)\n";
  313. $ret.="\t\$(FIPSLINK) \$(MLFLAGS) /map $base_arg $efile$target ";
  314. $ret.="$name @<<\n \$(SHLIB_EX_OBJ) $objs \$(EX_LIBS) ";
  315. $ret.="\$(OBJ_D)${o}fips_premain.obj $ex\n<<\n";
  316. }
  317. else
  318. {
  319. $ret.="$target: $objs";
  320. $ret.="\n\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n \$(SHLIB_EX_OBJ) $objs $ex \$(EX_LIBS)\n<<\n";
  321. }
  322. $ret.="\tIF EXIST \$@.manifest mt -nologo -manifest \$@.manifest -outputresource:\$@;2\n\n";
  323. }
  324. $ret.="\n";
  325. return($ret);
  326. }
  327. sub do_link_rule
  328. {
  329. my($target,$files,$dep_libs,$libs,$standalone)=@_;
  330. local($ret,$_);
  331. $file =~ s/\//$o/g if $o ne '/';
  332. $n=&bname($target);
  333. $ret.="$target: $files $dep_libs\n";
  334. if ($standalone == 1)
  335. {
  336. $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n\t";
  337. $ret.= "\$(EX_LIBS) " if ($files =~ /O_FIPSCANISTER/ && !$fipscanisterbuild);
  338. $ret.="$files $libs\n<<\n";
  339. }
  340. elsif ($standalone == 2)
  341. {
  342. $ret.="\tSET FIPS_LINK=\$(LINK)\n";
  343. $ret.="\tSET FIPS_CC=\$(CC)\n";
  344. $ret.="\tSET FIPS_CC_ARGS=/Fo\$(OBJ_D)${o}fips_premain.obj \$(SHLIB_CFLAGS) -c\n";
  345. $ret.="\tSET PREMAIN_DSO_EXE=\n";
  346. $ret.="\tSET FIPS_TARGET=$target\n";
  347. $ret.="\tSET FIPS_SHA1_EXE=\$(FIPS_SHA1_EXE)\n";
  348. $ret.="\tSET FIPSLIB_D=\$(FIPSLIB_D)\n";
  349. $ret.="\t\$(FIPSLINK) \$(LFLAGS) /map $efile$target @<<\n";
  350. $ret.="\t\$(APP_EX_OBJ) $files \$(OBJ_D)${o}fips_premain.obj $libs\n<<\n";
  351. }
  352. else
  353. {
  354. $ret.="\t\$(LINK) \$(LFLAGS) $efile$target @<<\n";
  355. $ret.="\t\$(APP_EX_OBJ) $files $libs\n<<\n";
  356. }
  357. $ret.="\tIF EXIST \$@.manifest mt -nologo -manifest \$@.manifest -outputresource:\$@;1\n\n";
  358. return($ret);
  359. }
  360. sub do_rlink_rule
  361. {
  362. local($target,$rl_start, $rl_mid, $rl_end,$dep_libs,$libs)=@_;
  363. local($ret,$_);
  364. my $files = "$rl_start $rl_mid $rl_end";
  365. $file =~ s/\//$o/g if $o ne '/';
  366. $n=&bname($target);
  367. $ret.="$target: $files $dep_libs \$(FIPS_SHA1_EXE)\n";
  368. $ret.="\t\$(PERL) ms\\segrenam.pl \$\$a $rl_start\n";
  369. $ret.="\t\$(PERL) ms\\segrenam.pl \$\$b $rl_mid\n";
  370. $ret.="\t\$(PERL) ms\\segrenam.pl \$\$c $rl_end\n";
  371. $ret.="\t\$(MKLIB) $lfile$target @<<\n\t$files\n<<\n";
  372. $ret.="\t\$(FIPS_SHA1_EXE) $target > ${target}.sha1\n";
  373. $ret.="\t\$(PERL) util${o}copy.pl -stripcr fips${o}fips_premain.c \$(LIB_D)${o}fips_premain.c\n";
  374. $ret.="\t\$(CP) fips${o}fips_premain.c.sha1 \$(LIB_D)${o}fips_premain.c.sha1\n";
  375. $ret.="\n";
  376. return($ret);
  377. }
  378. sub win32_import_asm
  379. {
  380. my ($mf_var, $asm_name, $oref, $sref) = @_;
  381. my $asm_dir;
  382. if ($asm_name eq "")
  383. {
  384. $asm_dir = "crypto\\";
  385. }
  386. else
  387. {
  388. $asm_dir = "crypto\\$asm_name\\asm\\";
  389. }
  390. $$oref = "";
  391. $$sref = "";
  392. $mf_var =~ s/\.o//g;
  393. foreach (split(/ /, $mf_var))
  394. {
  395. $$sref .= $asm_dir . $_ . ".asm ";
  396. }
  397. foreach (split(/ /, $mf_var))
  398. {
  399. $$oref .= "\$(TMP_D)\\" . $_ . ".obj ";
  400. }
  401. $$oref =~ s/ $//;
  402. $$sref =~ s/ $//;
  403. }
  404. 1;