2
0

VC-32.pl 12 KB

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