First draft for WCE PortSDK support. Once again! It's *draft* which requires
[openssl.git] / util / pl / VC-32.pl
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
6 $ssl=   "ssleay32";
7 $crypto="libeay32";
8
9 $o='\\';
10 $cp='copy nul+';        # Timestamps get stuffed otherwise
11 $rm='del';
12
13 # C compiler stuff
14 $cc='cl';
15 if ($FLAVOR =~ /WIN64/)
16     {
17     # Note that we currently don't have /WX on Win64! There is a lot of
18     # warnings, but only of two types:
19     #
20     # C4344: conversion from '__int64' to 'int/long', possible loss of data
21     # C4267: conversion from 'size_t' to 'int/long', possible loss of data
22     #
23     # Amount of latter type is minimized by aliasing strlen to function of
24     # own desing and limiting its return value to 2GB-1 (see e_os.h). As
25     # per 0.9.8 release remaining warnings were explicitly examined and
26     # considered safe to ignore.
27     # 
28     $base_cflags=' /W3 /Gs0 /GF /Gy /nologo -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DOPENSSL_SYSNAME_WIN32 -DOPENSSL_SYSNAME_WINNT -DUNICODE -D_UNICODE';
29     $base_cflags.=' -D_CRT_SECURE_NO_DEPRECATE'; # shut up VC8
30     $opt_cflags=' /MD /Ox';
31     $dbg_cflags=' /MDd /Od -DDEBUG -D_DEBUG';
32     $lflags="/nologo /subsystem:console /opt:ref";
33     }
34 elsif ($FLAVOR =~ /CE/)
35     {
36     # sanity check
37     die '%OSVERSION% is not defined'    if (!defined($ENV{'OSVERSION'}));
38     die '%PLATFORM% is not defined'     if (!defined($ENV{'PLATFORM'}));
39     die '%TARGETCPU% is not defined'    if (!defined($ENV{'TARGETCPU'}));
40
41     #
42     # Idea behind this is to mimic flags set by eVC++ IDE...
43     #
44     $wcevers = $ENV{'OSVERSION'};                       # WCENNN
45     die '%OSVERSION% value is insane'   if ($wcevers !~ /^WCE([1-9])([0-9]{2})$/);
46     $wcecdefs = "-D_WIN32_WCE=$1$2 -DUNDER_CE=$1$2";    # -D_WIN32_WCE=NNN
47     $wcelflag = "/subsystem:windowsce,$1.$2";           # ...,N.NN
48
49     $wceplatf =  $ENV{'PLATFORM'};
50     $wceplatf =~ tr/a-z0-9 /A-Z0-9_/d;
51     $wcecdefs .= " -DWCE_PLATFORM_$wceplatf";
52
53     $wcetgt = $ENV{'TARGETCPU'};        # just shorter name...
54     SWITCH: for($wcetgt) {
55         /^X86/          && do { $wcecdefs.=" -Dx86 -D_X86_ -D_i386_ -Di_386_";
56                                 $wcelflag.=" /machine:IX86";    last; };
57         /^ARMV4[IT]/    && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
58                                 $wcecdefs.=" -DTHUMB -D_THUMB_" if($wcetgt=~/T$/);
59                                 $wcecdefs.=" -QRarch4T -QRinterwork-return";
60                                 $wcelflag.=" /machine:THUMB";   last; };
61         /^ARM/          && do { $wcecdefs.=" -DARM -D_ARM_ -D$wcetgt";
62                                 $wcelflag.=" /machine:ARM";     last; };
63         /^MIPSIV/       && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
64                                 $wcecdefs.=" -D_MIPS64 -QMmips4 -QMn32";
65                                 $wcelflag.=" /machine:MIPSFPU"; last; };
66         /^MIPS16/       && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
67                                 $wcecdefs.=" -DMIPSII -QMmips16";
68                                 $wcelflag.=" /machine:MIPS16";  last; };
69         /^MIPSII/       && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000 -D$wcetgt";
70                                 $wcecdefs.=" -QMmips2";
71                                 $wcelflag.=" /machine:MIPS";    last; };
72         /^R4[0-9]{3}/   && do { $wcecdefs.=" -DMIPS -D_MIPS_ -DR4000";
73                                 $wcelflag.=" /machine:MIPS";    last; };
74         /^SH[0-9]/      && do { $wcecdefs.=" -D$wcetgt -D_$wcetgt_ -DSHx";
75                                 $wcecdefs.=" -Qsh4" if ($wcetgt =~ /^SH4/);
76                                 $wcelflag.=" /machine:$wcetgt"; last; };
77         { $wcecdefs.=" -D$wcetgt -D_$wcetgt_";
78           $wcelflag.=" /machine:$wcetgt";                       last; };
79     }
80
81     $cc='$(CC)';
82     $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';
83     $base_cflags.=" $wcecdefs";
84     $base_cflags.=' $(WCECOMPAT)/include'               if (defined($ENV{'WCECOMPAT'}));
85     $base_cflags.=' $(PORTSDK_LIBPATH)/../../include'   if (defined($ENV{'PORTSDK_LIBPATH'}));
86     $opt_cflags=' /MC /O1i';    # optimize for space, but with intrinsics...
87     $dbg_clfags=' /MC /Od -DDEBUG -D_DEBUG';
88     $lflags="/nologo /opt:ref $wcelflag";
89     }
90 else    # Win32
91     {
92     $base_cflags=' /W3 /WX /Gs0 /GF /Gy /nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32';
93     $base_cflags.=' -D_CRT_SECURE_NO_DEPRECATE';        # shut up VC8
94     $opt_cflags=' /MD /Ox /O2 /Ob2';
95     $dbg_cflags=' /MDd /Od -DDEBUG -D_DEBUG';
96     $lflags="/nologo /subsystem:console /machine:I386 /opt:ref";
97     }
98 $mlflags='';
99
100 $out_def="out32"; $out_def.='_$(TARGETCPU)' if ($FLAVOR =~ /CE/);
101 $tmp_def="tmp32"; $tmp_def.='_$(TARGETCPU)' if ($FLAVOR =~ /CE/);
102 $inc_def="inc32";
103
104 if ($debug)
105         {
106         $cflags=$dbg_cflags.$base_cflags;
107         $lflags.=" /debug";
108         $mlflags.=' /debug';
109         }
110 else
111         {
112         $cflags=$opt_cflags.$base_cflags;
113         }
114
115 $obj='.obj';
116 $ofile="/Fo";
117
118 # EXE linking stuff
119 $link="link";
120 $rsc="rc";
121 $efile="/out:";
122 $exep='.exe';
123 if ($no_sock)           { $ex_libs=''; }
124 elsif ($FLAVOR =~ /CE/) { $ex_libs='winsock.lib'; }
125 else                    { $ex_libs='wsock32.lib'; }
126
127 if ($FLAVOR =~ /CE/)
128         {
129         $ex_libs.=' $(WCECOMPAT)/lib/wcecompatex.lib'   if (defined($ENV{'WCECOMPAT'}));
130         $ex_libs.=' $(PORTSDK_LIBPATH)/portlib.lib'     if (defined($ENV{'PORTSDK_LIBPATH'}));
131         $ex_libs.=' /nodefaultlib:oldnames.lib coredll.lib corelibc.lib' if ($ENV{'TARGETCPU'} eq "X86");
132         }
133 else
134         {
135         $ex_libs.=' gdi32.lib advapi32.lib user32.lib';
136         $ex_libs.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/);
137         }
138
139 # As native NT API is pure UNICODE, our WIN-NT build defaults to UNICODE,
140 # but gets linked with unicows.lib to ensure backward compatibility.
141 if ($FLAVOR =~ /NT/)
142         {
143         $cflags.=" -DOPENSSL_SYSNAME_WINNT -DUNICODE -D_UNICODE";
144         $ex_libs="unicows.lib $ex_libs";
145         }
146
147 # static library stuff
148 $mklib='lib';
149 $ranlib='';
150 $plib="";
151 $libp=".lib";
152 $shlibp=($shlib)?".dll":".lib";
153 $lfile='/out:';
154
155 $shlib_ex_obj="";
156 $app_ex_obj="setargv.obj" if ($FLAVOR !~ /CE/);
157 if ($nasm) {
158         $asm='nasmw -f win32';
159         $afile='-o ';
160 } else {
161         $asm='ml /Cp /coff /c /Cx';
162         $asm.=" /Zi" if $debug;
163         $afile='/Fo';
164 }
165
166 $bn_asm_obj='';
167 $bn_asm_src='';
168 $des_enc_obj='';
169 $des_enc_src='';
170 $bf_enc_obj='';
171 $bf_enc_src='';
172
173 if (!$no_asm)
174         {
175         $bn_asm_obj='crypto\bn\asm\bn_win32.obj';
176         $bn_asm_src='crypto\bn\asm\bn_win32.asm';
177         $des_enc_obj='crypto\des\asm\d_win32.obj crypto\des\asm\y_win32.obj';
178         $des_enc_src='crypto\des\asm\d_win32.asm crypto\des\asm\y_win32.asm';
179         $bf_enc_obj='crypto\bf\asm\b_win32.obj';
180         $bf_enc_src='crypto\bf\asm\b_win32.asm';
181         $cast_enc_obj='crypto\cast\asm\c_win32.obj';
182         $cast_enc_src='crypto\cast\asm\c_win32.asm';
183         $rc4_enc_obj='crypto\rc4\asm\r4_win32.obj';
184         $rc4_enc_src='crypto\rc4\asm\r4_win32.asm';
185         $rc5_enc_obj='crypto\rc5\asm\r5_win32.obj';
186         $rc5_enc_src='crypto\rc5\asm\r5_win32.asm';
187         $md5_asm_obj='crypto\md5\asm\m5_win32.obj';
188         $md5_asm_src='crypto\md5\asm\m5_win32.asm';
189         $sha1_asm_obj='crypto\sha\asm\s1_win32.obj';
190         $sha1_asm_src='crypto\sha\asm\s1_win32.asm';
191         $rmd160_asm_obj='crypto\ripemd\asm\rm_win32.obj';
192         $rmd160_asm_src='crypto\ripemd\asm\rm_win32.asm';
193         $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
194         }
195
196 if ($shlib && $FLAVOR !~ /CE/)
197         {
198         $mlflags.=" $lflags /dll";
199 #       $cflags =~ s| /MD| /MT|;
200         $lib_cflag=" -D_WINDLL";
201         $out_def="out32dll";
202         $tmp_def="tmp32dll";
203         #
204         # Engage Applink...
205         #
206         $app_ex_obj.=" \$(OBJ_D)\\applink.obj /implib:\$(TMP_D)\\junk.lib";
207         $cflags.=" -DOPENSSL_USE_APPLINK -I.";
208         # I'm open for better suggestions than overriding $banner...
209         $banner=<<'___';
210         @echo Building OpenSSL
211
212 $(OBJ_D)\applink.obj:   ms\applink.c
213         $(CC) /Fo$(OBJ_D)\applink.obj $(APP_CFLAGS) -c ms\applink.c
214 $(OBJ_D)\uplink.obj:    ms\uplink.c ms\applink.c
215         $(CC) /Fo$(OBJ_D)\uplink.obj $(SHLIB_CFLAGS) -c ms\uplink.c
216 $(INCO_D)\applink.c:    ms\applink.c
217         $(CP) ms\applink.c $(INCO_D)\applink.c
218
219 EXHEADER= $(EXHEADER) $(INCO_D)\applink.c
220
221 LIBS_DEP=$(LIBS_DEP) $(OBJ_D)\applink.obj
222 CRYPTOOBJ=$(OBJ_D)\uplink.obj $(CRYPTOOBJ)
223 ___
224         $banner.=<<'___' if ($FLAVOR =~ /WIN64/);
225 CRYPTOOBJ=ms\uptable.obj $(CRYPTOOBJ)
226 ___
227         }
228 elsif ($shlib && $FLAVOR =~ /CE/)
229         {
230         $mlflags.=" $lflags /dll";
231         $lflags.=' /entry:mainCRTstartup' if(defined($ENV{'PORTSDK_LIBPATH'}));
232         $lib_cflag=" -D_WINDLL -D_DLL";
233         $out_def='out32dll_$(TARGETCPU)';
234         $tmp_def='tmp32dll_$(TARGETCPU)';
235         }
236
237 $cflags.=" /Fd$out_def";
238
239 sub do_lib_rule
240         {
241         local($objs,$target,$name,$shlib)=@_;
242         local($ret);
243
244         $taget =~ s/\//$o/g if $o ne '/';
245         if ($name ne "")
246                 {
247                 $name =~ tr/a-z/A-Z/;
248                 $name = "/def:ms/${name}.def";
249                 }
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                 elsif ($FLAVOR =~ /CE/)
265                         {
266                         $ex.=' winsock.lib';
267                         $ex.=' $(WCECOMPAT)/lib/wcecompatex.lib' if (defined($ENV{'WCECOMPAT'}));
268                         $ex.=' $(PORTSDK_LIBPATH)/portlib.lib'   if (defined($ENV{'PORTSDK_LIBPATH'}));
269                         }
270                 else
271                         {
272                         $ex.=' unicows.lib' if ($FLAVOR =~ /NT/);
273                         $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib';
274                         $ex.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/);
275                         }
276                 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n  \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
277                 }
278         $ret.="\n";
279         return($ret);
280         }
281
282 sub do_link_rule
283         {
284         local($target,$files,$dep_libs,$libs)=@_;
285         local($ret,$_);
286         
287         $file =~ s/\//$o/g if $o ne '/';
288         $n=&bname($targer);
289         $ret.="$target: $files $dep_libs\n";
290         $ret.="  \$(LINK) \$(LFLAGS) $efile$target @<<\n";
291         $ret.="  \$(APP_EX_OBJ) $files $libs\n<<\n\n";
292         return($ret);
293         }
294
295 1;