Netware-specific changes,
[openssl.git] / util / pl / netware.pl
1 # Metrowerks Codewarrior for NetWare
2 #
3
4 # The import files and other misc imports needed to link
5 if ($LIBC)
6 {
7    @import_files = ("libc.imp", "ws2nlm.imp");
8    @module_files = ("libc");
9 }
10 else
11 {
12    # clib build
13    @import_files = ("clib.imp", "ws2nlm.imp");
14    @module_files = ("clib");
15 }
16 @misc_imports = ("GetProcessSwitchCount", "RunningProcess",  
17                  "GetSuperHighResolutionTimer" );
18
19 # The "IMPORTS" environment variable must be set and point to the location
20 # where import files (*.imp) can be found.
21 # Example:  set IMPORTS=c:\ndk\nwsdk\imports
22 $import_path = $ENV{"IMPORTS"} || die ("IMPORTS environment variable not set\n");
23
24
25 # The "PRELUDE" environment variable must be set and point to the location
26 # and name of the prelude source to link with ( nwpre.obj is recommended ).
27 # Example: set PRELUDE=c:\codewar\novell support\metrowerks support\libraries\runtime\nwpre.obj
28 $prelude = $ENV{"PRELUDE"} || die ("PRELUDE environment variable not set\n");
29
30 #$ssl=   "ssleay32";
31 #$crypto="libeay32";
32
33 $o='\\\\';
34 $cp='copy >nul:';
35 $rm='del';
36
37 # C compiler
38 $cc="mwccnlm";
39
40 # Linker
41 $link="mwldnlm";
42
43 # librarian
44 $mklib="mwldnlm";
45
46 # assembler 
47 if ($nw_nasm) 
48 {
49    $asm="nasmw -s -f coff";
50    $afile="-o ";
51    $asm.=" -g" if $debug;
52 }
53 elsif ($nw_mwasm) 
54 {
55    $asm="mwasmnlm -maxerrors 20";
56    $afile="-o ";
57    $asm.=" -g" if $debug;
58 }
59 elsif ($nw_masm)
60 {
61 # masm assembly settings - it should be possible to use masm but haven't 
62 # got it working.
63 # $asm='ml /Cp /coff /c /Cx';
64 # $asm.=" /Zi" if $debug;
65 # $afile='/Fo';
66    die("Support for masm assembler not yet functional\n");
67 }
68 else 
69 {
70    $asm="";
71    $afile="";
72 }
73
74
75
76 # compile flags
77 #
78 # NOTES: Several c files in the crypto subdirectory include headers from
79 #        their local directories.  Metrowerks wouldn't find these h files
80 #        without adding individual include directives as compile flags
81 #        or modifying the c files.  Instead of adding individual include
82 #        paths for each subdirectory a recursive include directive
83 #        is used ( -ir crypto ).
84 #
85 #        Turned off the "possible" warnings ( -w nopossible ).  Metrowerks
86 #        complained a lot about various stuff.  May want to turn back
87 #        on for further development.
88 $cflags="-ir crypto -msgstyle gcc -align 4 -processor pentium \\
89          -char unsigned -w on -w nolargeargs -w nopossible -w nounusedarg \\
90          -w noimplicitconv -relax_pointers -nosyspath -DL_ENDIAN \\
91          -DOPENSSL_SYSNAME_NETWARE -U_WIN32 -maxerrors 20 ";
92
93 # link flags
94 $lflags="-msgstyle gcc -zerobss -stacksize 32768 -nostdlib -sym internal ";
95
96
97 # additional flags based upon debug | non-debug
98 if ($debug)
99 {
100    $cflags.=" -opt off -g -sym internal -DDEBUG";
101 }
102 else
103 {
104 # CodeWarrior compiler has a problem with optimizations for floating
105 # points - no optimizations until further investigation
106 #   $cflags.=" -opt all";
107 }
108
109 # If LibC build add in NKS_LIBC define and set the entry/exit
110 # routines - The default entry/exit routines are for CLib and don't exist
111 # in LibC
112 if ($LIBC)
113 {
114    $cflags.=" -DNETWARE_LIBC";
115    $lflags.=" -entry _LibCPrelude -exit _LibCPostlude -flags pseudopreemption";
116 }
117 else
118 {
119    $cflags.=" -DNETWARE_CLIB";
120    $lflags.=" -entry _Prelude -exit _Stop";
121 }
122
123
124 # linking stuff
125 # for the output directories use the mk1mf.pl values with "_nw" appended
126 if ($shlib)
127 {
128    if ($LIBC)
129    {
130       $out_def.="_nw_libc_nlm";
131       $tmp_def.="_nw_libc_nlm";
132       $inc_def.="_nw_libc_nlm";
133    }
134    else  # NETWARE_CLIB
135    {
136       $out_def.="_nw_clib_nlm";
137       $tmp_def.="_nw_clib_nlm";
138       $inc_def.="_nw_clib_nlm";
139    }
140 }
141 else
142 {
143    $libp=".lib";
144    $shlibp=".lib";
145    $lib_flags="-nodefaults -type library";
146    if ($LIBC)
147    {
148       $out_def.="_nw_libc";
149       $tmp_def.="_nw_libc";
150       $inc_def.="_nw_libc";
151    }
152    else  # NETWARE_CLIB 
153    {
154       $out_def.="_nw_clib";
155       $tmp_def.="_nw_clib";
156       $inc_def.="_nw_clib";
157    }
158 }
159
160 # used by mk1mf.pl
161 $obj='.obj';
162 $ofile='-o ';
163 $efile='';
164 $exep='.nlm';
165 $ex_libs='';
166
167 if (!$no_asm)
168 {
169    $bn_asm_obj="crypto${o}bn${o}asm${o}bn-nw.obj";
170    $bn_asm_src="crypto${o}bn${o}asm${o}bn-nw.asm";
171    $des_enc_obj="crypto${o}des${o}asm${o}d-nw.obj crypto${o}des${o}asm${o}y-nw.obj";
172    $des_enc_src="crypto${o}des${o}asm${o}d-nw.asm crypto${o}des${o}asm${o}y-nw.asm";
173    $bf_enc_obj="crypto${o}bf${o}asm${o}b-nw.obj";
174    $bf_enc_src="crypto${o}bf${o}asm${o}b-nw.asm";
175    $cast_enc_obj="crypto${o}cast${o}asm${o}c-nw.obj";
176    $cast_enc_src="crypto${o}cast${o}asm${o}c-nw.asm";
177    $rc4_enc_obj="crypto${o}rc4${o}asm${o}r4-nw.obj";
178    $rc4_enc_src="crypto${o}rc4${o}asm${o}r4-nw.asm";
179    $rc5_enc_obj="crypto${o}rc5${o}asm${o}r5-nw.obj";
180    $rc5_enc_src="crypto${o}rc5${o}asm${o}r5-nw.asm";
181    $md5_asm_obj="crypto${o}md5${o}asm${o}m5-nw.obj";
182    $md5_asm_src="crypto${o}md5${o}asm${o}m5-nw.asm";
183    $sha1_asm_obj="crypto${o}sha${o}asm${o}s1-nw.obj";
184    $sha1_asm_src="crypto${o}sha${o}asm${o}s1-nw.asm";
185    $rmd160_asm_obj="crypto${o}ripemd${o}asm${o}rm-nw.obj";
186    $rmd160_asm_src="crypto${o}ripemd${o}asm${o}rm-nw.asm";
187    $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
188 }
189 else
190 {
191    $bn_asm_obj='';
192    $bn_asm_src='';
193    $des_enc_obj='';
194    $des_enc_src='';
195    $bf_enc_obj='';
196    $bf_enc_src='';
197    $cast_enc_obj='';
198    $cast_enc_src='';
199    $rc4_enc_obj='';
200    $rc4_enc_src='';
201    $rc5_enc_obj='';
202    $rc5_enc_src='';
203    $md5_asm_obj='';
204    $md5_asm_src='';
205    $sha1_asm_obj='';
206    $sha1_asm_src='';
207    $rmd160_asm_obj='';
208    $rmd160_asm_src='';
209 }
210
211 # create the *.def linker command files in \openssl\netware\ directory
212 sub do_def_file
213 {
214    # strip off the leading path
215    my($target) = bname(@_);
216    my($def_file);
217    my($mod_file);
218    my($i);
219
220    if ($target =~ /(.*).nlm/)
221    {
222       $target = $1;
223    }
224
225    # special case for openssl - the mk1mf.pl defines E_EXE = openssl
226    if ($target =~ /E_EXE/)
227    {
228       $target = "openssl";
229    }
230
231    # Note: originally tried to use full path ( \openssl\netware\$target.def )
232    # Metrowerks linker choked on this with an assertion failure. bug???
233    #
234    $def_file = "netware\\$target.def";
235
236    open(DEF_OUT, ">$def_file") || die("unable to open file $def_file\n");
237
238    print( DEF_OUT "# command file generated by netware.pl for Metrowerks build\n" );
239    print( DEF_OUT "#\n");
240    print( DEF_OUT "DESCRIPTION \"$target\"\n");
241    
242    foreach $i (@misc_imports)
243    {
244       print( DEF_OUT "IMPORT $i\n");
245    }
246    
247    foreach $i (@import_files)
248    {
249       print( DEF_OUT "IMPORT \@$import_path\\$i\n");
250    }
251    
252    foreach $i (@module_files)
253    {
254       print( DEF_OUT "MODULE $i\n");
255    }
256
257    close(DEF_OUT);
258    return($def_file);
259 }
260
261 sub do_lib_rule
262 {
263    my($objs,$target,$name,$shlib)=@_;
264    my($ret);
265
266    $ret.="$target: $objs\n";
267    if (!$shlib)
268    {
269       $ret.="\t\@echo Building Lib: $name\n";
270       $ret.="\t\$(MKLIB) $lib_flags -o $target $objs\n";
271       $ret.="\t\@echo .\n"
272    }
273    else
274    {
275       die( "Building as NLM not currently supported!" );
276    }
277
278    $ret.="\n";
279    return($ret);
280 }
281
282 sub do_link_rule
283 {
284    my($target,$files,$dep_libs,$libs)=@_;
285    my($ret);
286    my($def_file);
287
288    $def_file = do_def_file($target);
289
290    # special case for openssl - the mk1mf.pl defines E_EXE = openssl
291
292    # NOTE:  When building the test nlms no screen name is given
293    #  which causes the console screen to be used.  By using the console
294    #  screen there is no "<press any key to continue>" message which
295    #  requires user interaction.  The test script ( tests.pl ) needs to be
296    #  able to run the tests without requiring user interaction.
297    #
298    #  However, the sample program "openssl.nlm" is used by the tests and is
299    #  a interactive sample so a screen is desired when not be run by the
300    #  tests.  To solve the problem, two versions of the program are built:
301    #    openssl2 - no screen used by tests
302    #    openssl - default screen - use for normal interactive modes
303    #
304    if ($target =~ /E_EXE/)
305    {
306       my($target2) = $target;
307
308       $target2 =~ s/\(E_EXE\)/\(E_EXE\)2/;
309
310       $ret.="$target: $files $dep_libs\n";
311
312          # openssl
313       $ret.="\t\$(LINK) \$(LFLAGS) -screenname openssl -commandfile $def_file $files \"$prelude\" $libs -o $target\n";
314          # openssl2
315       $ret.="\t\$(LINK) \$(LFLAGS) -commandfile $def_file $files \"$prelude\" $libs -o $target2\n";
316    }
317    else
318    {
319       $ret.="$target: $files $dep_libs\n";
320       $ret.="\t\$(LINK) \$(LFLAGS) -commandfile $def_file $files \"$prelude\" $libs -o $target\n";
321    }
322
323    $ret.="\n";
324    return($ret);
325 }
326
327 1;