2
0

VC-32.pl 10 KB

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