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