2 # VC-32.pl - unified script for Microsoft Visual C++, covering Win32,
3 # Win64 and WinCE [follow $FLAVOR variable to trace the differences].
10 $cp='$(PERL) util/copy.pl';
11 $mkdir='$(PERL) util/mkdir-p.pl';
14 $zlib_lib="zlib1.lib";
18 if ($FLAVOR =~ /WIN64/)
20 # Note that we currently don't have /WX on Win64! There is a lot of
21 # warnings, but only of two types:
23 # C4344: conversion from '__int64' to 'int/long', possible loss of data
24 # C4267: conversion from 'size_t' to 'int/long', possible loss of data
26 # Amount of latter type is minimized by aliasing strlen to function of
27 # own desing and limiting its return value to 2GB-1 (see e_os.h). As
28 # per 0.9.8 release remaining warnings were explicitly examined and
29 # considered safe to ignore.
31 $base_cflags= " $mf_cflag";
32 my $f = $shlib?' /MD':' /MT';
33 $lib_cflag='/Zl' if (!$shlib); # remove /DEFAULTLIBs from static lib
34 $opt_cflags=$f.' /Ox';
35 $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
36 $lflags="/nologo /subsystem:console /opt:ref";
38 *::perlasm_compile_target = sub {
39 my ($target,$source,$bname)=@_;
42 $bname =~ s/(.*)\.[^\.]$/$1/;
44 \$(TMP_D)$o$bname.asm: $source
48 $target: \$(TMP_D)$o$bname.asm
49 \$(ASM) $afile\$\@ \$(TMP_D)$o$bname.asm
54 elsif ($FLAVOR =~ /CE/)
57 die '%OSVERSION% is not defined' if (!defined($ENV{'OSVERSION'}));
58 die '%PLATFORM% is not defined' if (!defined($ENV{'PLATFORM'}));
59 die '%TARGETCPU% is not defined' if (!defined($ENV{'TARGETCPU'}));
62 # Idea behind this is to mimic flags set by eVC++ IDE...
64 $wcevers = $ENV{'OSVERSION'}; # WCENNN
65 die '%OSVERSION% value is insane' if ($wcevers !~ /^WCE([1-9])([0-9]{2})$/);
66 $wcecdefs = "-D_WIN32_WCE=$1$2 -DUNDER_CE=$1$2"; # -D_WIN32_WCE=NNN
67 $wcelflag = "/subsystem:windowsce,$1.$2"; # ...,N.NN
69 $wceplatf = $ENV{'PLATFORM'};
70 $wceplatf =~ tr/a-z0-9 /A-Z0-9_/d;
71 $wcecdefs .= " -DWCE_PLATFORM_$wceplatf";
73 $wcetgt = $ENV{'TARGETCPU'}; # just shorter name...
74 SWITCH: for($wcetgt) {
75 /^X86/ && do { $wcecdefs.=" -Dx86 -D_X86_ -D_i386_ -Di_386_";
76 $wcelflag.=" /machine:IX86"; last; };
77 /^ARMV4[IT]/ && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
78 $wcecdefs.=" -DTHUMB -D_THUMB_" if($wcetgt=~/T$/);
79 $wcecdefs.=" -QRarch4T -QRinterwork-return";
80 $wcelflag.=" /machine:THUMB"; last; };
81 /^ARM/ && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
82 $wcelflag.=" /machine:ARM"; last; };
83 /^MIPSIV/ && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
84 $wcecdefs.=" -D_MIPS64 -QMmips4 -QMn32";
85 $wcelflag.=" /machine:MIPSFPU"; last; };
86 /^MIPS16/ && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
87 $wcecdefs.=" -DMIPSII -QMmips16";
88 $wcelflag.=" /machine:MIPS16"; last; };
89 /^MIPSII/ && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
90 $wcecdefs.=" -QMmips2";
91 $wcelflag.=" /machine:MIPS"; last; };
92 /^R4[0-9]{3}/ && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000";
93 $wcelflag.=" /machine:MIPS"; last; };
94 /^SH[0-9]/ && do { $wcecdefs.=" -D$wcetgt -D_$wcetgt_ -DSHx";
95 $wcecdefs.=" -Qsh4" if ($wcetgt =~ /^SH4/);
96 $wcelflag.=" /machine:$wcetgt"; last; };
97 { $wcecdefs.=" -D$wcetgt -D_$wcetgt_";
98 $wcelflag.=" /machine:$wcetgt"; last; };
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 $opt_cflags=' /MC /O1i'; # optimize for space, but with intrinsics...
107 $dbg_clfags=' /MC /Od -DDEBUG -D_DEBUG';
108 $lflags="/nologo /opt:ref $wcelflag";
112 $base_cflags= " $mf_cflag";
113 my $f = $shlib?' /MD':' /MT';
114 $lib_cflag='/Zl' if (!$shlib); # remove /DEFAULTLIBs from static lib
115 $opt_cflags=$f.' /Ox /O2 /Ob2';
116 $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
117 $lflags="/nologo /subsystem:console /opt:ref";
121 $out_def="out32"; $out_def.='_$(TARGETCPU)' if ($FLAVOR =~ /CE/);
122 $tmp_def="tmp32"; $tmp_def.='_$(TARGETCPU)' if ($FLAVOR =~ /CE/);
127 $cflags=$dbg_cflags.$base_cflags;
133 $cflags=$opt_cflags.$base_cflags;
145 if ($no_sock) { $ex_libs=''; }
146 elsif ($FLAVOR =~ /CE/) { $ex_libs='winsock.lib'; }
147 else { $ex_libs='ws2_32.lib'; }
151 $ex_libs.=' $(WCECOMPAT)/lib/wcecompatex.lib' if (defined($ENV{'WCECOMPAT'}));
152 $ex_libs.=' $(PORTSDK_LIBPATH)/portlib.lib' if (defined($ENV{'PORTSDK_LIBPATH'}));
153 $ex_libs.=' /nodefaultlib:oldnames.lib coredll.lib corelibc.lib' if ($ENV{'TARGETCPU'} eq "X86");
157 $ex_libs.=' gdi32.lib advapi32.lib user32.lib';
158 $ex_libs.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/);
159 # WIN32 UNICODE build gets linked with unicows.lib for
160 # backward compatibility with Win9x.
161 $ex_libs="unicows.lib $ex_libs" if ($FLAVOR =~ /WIN32/ and $cflags =~ /\-DUNICODE/);
164 # static library stuff
169 $shlibp=($shlib)?".dll":".lib";
173 $app_ex_obj="setargv.obj" if ($FLAVOR !~ /CE/);
174 if ($FLAVOR =~ /WIN64A/) {
175 if (`nasm -v` =~ /NASM version ([0-9]+\.[0-9]+)/ && $1 >= 2.0) {
176 $asm='nasm -f win64';
177 $asm.=' -g' if $debug;
180 $asm='ml64 /c /Cp /Cx';
181 $asm.=" /Zi" if $debug;
184 } elsif ($FLAVOR =~ /WIN64I/) {
186 $asm.=" -d debug" if $debug;
189 my $ver=`nasm -v 2>NUL`;
190 my $vew=`nasmw -v 2>NUL`;
191 # pick newest version
192 $asm=($ver gt $vew?"nasm":"nasmw")." -f win32";
196 $asm='ml /Cp /coff /c /Cx';
197 $asm.=" /Zi" if $debug;
211 win32_import_asm($mf_bn_asm, "bn", \$bn_asm_obj, \$bn_asm_src);
212 win32_import_asm($mf_aes_asm, "aes", \$aes_asm_obj, \$aes_asm_src);
213 win32_import_asm($mf_des_asm, "des", \$des_enc_obj, \$des_enc_src);
214 win32_import_asm($mf_bf_asm, "bf", \$bf_enc_obj, \$bf_enc_src);
215 win32_import_asm($mf_cast_asm, "cast", \$cast_enc_obj, \$cast_enc_src);
216 win32_import_asm($mf_rc4_asm, "rc4", \$rc4_enc_obj, \$rc4_enc_src);
217 win32_import_asm($mf_rc5_asm, "rc5", \$rc5_enc_obj, \$rc5_enc_src);
218 win32_import_asm($mf_md5_asm, "md5", \$md5_asm_obj, \$md5_asm_src);
219 win32_import_asm($mf_sha_asm, "sha", \$sha1_asm_obj, \$sha1_asm_src);
220 win32_import_asm($mf_rmd_asm, "ripemd", \$rmd160_asm_obj, \$rmd160_asm_src);
221 win32_import_asm($mf_wp_asm, "whrlpool", \$whirlpool_asm_obj, \$whirlpool_asm_src);
222 win32_import_asm($mf_cpuid_asm, "", \$cpuid_asm_obj, \$cpuid_asm_src);
226 if ($shlib && $FLAVOR !~ /CE/)
228 $mlflags.=" $lflags /dll";
229 $lib_cflag=" -D_WINDLL";
235 $app_ex_obj.=" \$(OBJ_D)\\applink.obj /implib:\$(TMP_D)\\junk.lib";
236 $cflags.=" -DOPENSSL_USE_APPLINK -I.";
237 # I'm open for better suggestions than overriding $banner...
239 @echo Building OpenSSL
241 $(OBJ_D)\applink.obj: ms\applink.c
242 $(CC) /Fo$(OBJ_D)\applink.obj $(APP_CFLAGS) -c ms\applink.c
243 $(OBJ_D)\uplink.obj: ms\uplink.c ms\applink.c
244 $(CC) /Fo$(OBJ_D)\uplink.obj $(SHLIB_CFLAGS) -c ms\uplink.c
245 $(INCO_D)\applink.c: ms\applink.c
246 $(CP) ms\applink.c $(INCO_D)\applink.c
248 EXHEADER= $(EXHEADER) $(INCO_D)\applink.c
250 LIBS_DEP=$(LIBS_DEP) $(OBJ_D)\applink.obj
251 CRYPTOOBJ=$(OBJ_D)\uplink.obj $(CRYPTOOBJ)
253 $banner.=<<'___' if ($FLAVOR =~ /WIN64/);
254 CRYPTOOBJ=ms\uptable.obj $(CRYPTOOBJ)
257 elsif ($shlib && $FLAVOR =~ /CE/)
259 $mlflags.=" $lflags /dll";
260 $lflags.=' /entry:mainCRTstartup' if(defined($ENV{'PORTSDK_LIBPATH'}));
261 $lib_cflag=" -D_WINDLL -D_DLL";
262 $out_def='out32dll_$(TARGETCPU)';
263 $tmp_def='tmp32dll_$(TARGETCPU)';
266 $cflags.=" /Fd$out_def";
270 local($objs,$target,$name,$shlib)=@_;
273 $taget =~ s/\//$o/g if $o ne '/';
276 $name =~ tr/a-z/A-Z/;
277 $name = "/def:ms/${name}.def";
280 # $target="\$(LIB_D)$o$target";
281 $ret.="$target: $objs\n";
284 # $ret.="\t\$(RM) \$(O_$Name)\n";
286 $ret.="\t\$(MKLIB) $lfile$target @<<\n $objs $ex\n<<\n";
290 local($ex)=($target =~ /O_CRYPTO/)?'':' $(L_CRYPTO)';
293 $ex.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/);
295 elsif ($FLAVOR =~ /CE/)
298 $ex.=' $(WCECOMPAT)/lib/wcecompatex.lib' if (defined($ENV{'WCECOMPAT'}));
299 $ex.=' $(PORTSDK_LIBPATH)/portlib.lib' if (defined($ENV{'PORTSDK_LIBPATH'}));
303 $ex.=' unicows.lib' if ($FLAVOR =~ /NT/);
304 $ex.=' ws2_32.lib gdi32.lib advapi32.lib user32.lib';
305 $ex.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/);
307 $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
308 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
309 $ret.="\tIF EXIST \$@.manifest mt -nologo -manifest \$@.manifest -outputresource:\$@;2\n\n";
317 local($target,$files,$dep_libs,$libs)=@_;
320 $file =~ s/\//$o/g if $o ne '/';
322 $ret.="$target: $files $dep_libs\n";
323 $ret.="\t\$(LINK) \$(LFLAGS) $efile$target @<<\n";
324 $ret.=" \$(APP_EX_OBJ) $files $libs\n<<\n";
325 $ret.="\tIF EXIST \$@.manifest mt -nologo -manifest \$@.manifest -outputresource:\$@;1\n\n";
331 my ($mf_var, $asm_name, $oref, $sref) = @_;
335 $asm_dir = "crypto\\";
339 $asm_dir = "crypto\\$asm_name\\asm\\";
343 $mf_var =~ s/\.o$/.obj/g;
345 foreach (split(/ /, $mf_var))
347 $$oref .= $asm_dir . $_ . " ";
351 $$sref =~ s/\.obj/.asm/g;