1 # Metrowerks Codewarrior or gcc / nlmconv for NetWare
4 $version_header = "crypto/opensslv.h";
5 open(IN, "$version_header") or die "Couldn't open $version_header: $!";
7 if (/^#define[\s\t]+OPENSSL_VERSION_NUMBER[\s\t]+0x(\d)(\d{2})(\d{2})(\d{2})/)
9 # die "OpenSSL version detected: $1.$2.$3.$4\n";
10 #$nlmvernum = "$1,$2,$3";
11 $nlmvernum = "$1,".($2*10+$3).",".($4*1);
12 #$nlmverstr = "$1.".($2*1).".".($3*1).($4?(chr(96+$4)):"");
16 close(IN) or die "Couldn't close $version_header: $!";
18 $readme_file = "README";
19 open(IN, $readme_file) or die "Couldn't open $readme_file: $!";
21 if (/^[\s\t]+OpenSSL[\s\t]+(\d)\.(\d{1,2})\.(\d{1,2})([a-z])(.*)/)
23 #$nlmvernum = "$1,$2,$3";
24 #$nlmvernum = "$1,".($2*10+$3).",".($4*1);
25 $nlmverstr = "$1.$2.$3$4$5";
27 elsif (/^[\s\t]+(Copyright \(c\) \d{4}\-\d{4} The OpenSSL Project)$/)
31 break if ($nlmvernum && $nlmcpystr);
33 close(IN) or die "Couldn't close $readme_file: $!";
35 # Define stacksize here
38 # some default settings here in case we failed to find them in README
39 $nlmvernum = "1,0,0" if (!$nlmvernum);
40 $nlmverstr = "OpenSSL" if (!$nlmverstr);
41 $nlmcpystr = "Copyright (c) 1998-now The OpenSSL Project" if (!$nlmcpystr);
43 # die "OpenSSL copyright: $nlmcpystr\nOpenSSL verstring: $nlmverstr\nOpenSSL vernumber: $nlmvernum\n";
45 # The import files and other misc imports needed to link
46 @misc_imports = ("GetProcessSwitchCount", "RunningProcess",
47 "GetSuperHighResolutionTimer");
50 @import_files = ("libc.imp");
51 @module_files = ("libc");
57 @import_files = ("clib.imp");
58 push(@import_files, "socklib.imp") if ($BSDSOCK);
59 @module_files = ("clib");
60 # push(@misc_imports, "_rt_modu64%16", "_rt_divu64%16");
70 push(@import_files, "ws2nlm.imp");
73 # The "IMPORTS" environment variable must be set and point to the location
74 # where import files (*.imp) can be found.
75 # Example: set IMPORTS=c:\ndk\nwsdk\imports
76 $import_path = $ENV{"IMPORTS"} || die ("IMPORTS environment variable not set\n");
79 # The "PRELUDE" environment variable must be set and point to the location
80 # and name of the prelude source to link with ( nwpre.obj is recommended ).
81 # Example: set PRELUDE=c:\codewar\novell support\metrowerks support\libraries\runtime\nwpre.obj
82 $prelude = $ENV{"PRELUDE"} || die ("PRELUDE environment variable not set\n");
84 # The "INCLUDES" environment variable must be set and point to the location
85 # where import files (*.imp) can be found.
86 $include_path = $ENV{"INCLUDE"} || die ("INCLUDES environment variable not set\n");
87 $include_path =~ s/\\/\//g;
88 $include_path = join(" -I", split(/;/, $include_path));
90 # check for gcc compiler
136 $asm=(`nasm -v 2>NUL` gt `nasmw -v 2>NUL`?"nasm":"nasmw");
143 $asm.=" -s -f coff -d __coff__";
146 $asm.=" -g" if $debug;
150 $asm="mwasmnlm -maxerrors 20";
152 $asm.=" -g" if $debug;
156 # masm assembly settings - it should be possible to use masm but haven't
158 # $asm='ml /Cp /coff /c /Cx';
159 # $asm.=" /Zi" if $debug;
161 die("Support for masm assembler not yet functional\n");
173 # compile flags for GNUC
174 # additional flags based upon debug | non-debug
177 $cflags="-g -DDEBUG";
183 $cflags.=" -nostdinc -I$include_path \\
184 -fno-builtin -fpcc-struct-return -fno-strict-aliasing \\
185 -funsigned-char -Wall -Wno-unused -Wno-uninitialized";
192 # compile flags for CodeWarrior
193 # additional flags based upon debug | non-debug
196 $cflags="-opt off -g -sym internal -DDEBUG";
200 # CodeWarrior compiler has a problem with optimizations for floating
201 # points - no optimizations until further investigation
202 # $cflags="-opt all";
205 # NOTES: Several c files in the crypto subdirectory include headers from
206 # their local directories. Metrowerks wouldn't find these h files
207 # without adding individual include directives as compile flags
208 # or modifying the c files. Instead of adding individual include
209 # paths for each subdirectory a recursive include directive
210 # is used ( -ir crypto ).
212 # A similar issue exists for the engines and apps subdirectories.
214 # Turned off the "possible" warnings ( -w nopossible ). Metrowerks
215 # complained a lot about various stuff. May want to turn back
216 # on for further development.
217 $cflags.=" -nostdinc -ir crypto -ir ssl -ir engines -ir apps -I$include_path \\
218 -msgstyle gcc -align 4 -processor pentium -char unsigned \\
219 -w on -w nolargeargs -w nopossible -w nounusedarg -w nounusedexpr \\
220 -w noimplicitconv -relax_pointers -nosyspath -maxerrors 20";
223 $lflags="-msgstyle gcc -zerobss -nostdlib -sym internal -commandfile";
227 $cflags.=" -DL_ENDIAN -DOPENSSL_SYS_NETWARE -U_WIN32";
229 # If LibC build add in NKS_LIBC define and set the entry/exit
230 # routines - The default entry/exit routines are for CLib and don't exist
234 $cflags.=" -DNETWARE_LIBC";
235 $nlmstart = "_LibCPrelude";
236 $nlmexit = "_LibCPostlude";
237 @nlm_flags = ("pseudopreemption", "flag_on 64");
241 $cflags.=" -DNETWARE_CLIB";
242 $nlmstart = "_Prelude";
246 # If BSD Socket support is requested, set a define for the compiler
249 $cflags.=" -DNETWARE_BSDSOCK";
252 $cflags.=" -DNETDB_USE_INTERNET";
258 # for the output directories use the mk1mf.pl values with "_nw" appended
263 $out_def.="_nw_libc_nlm";
264 $tmp_def.="_nw_libc_nlm";
265 $inc_def.="_nw_libc_nlm";
269 $out_def.="_nw_clib_nlm";
270 $tmp_def.="_nw_clib_nlm";
271 $inc_def.="_nw_clib_nlm";
276 if ($gnuc) # GNUC Tools
286 $lib_flags="-nodefaults -type library -o";
290 $out_def.="_nw_libc";
291 $tmp_def.="_nw_libc";
292 $inc_def.="_nw_libc";
296 $out_def.="_nw_clib";
297 $tmp_def.="_nw_clib";
298 $inc_def.="_nw_clib";
311 $bn_asm_obj="\$(OBJ_D)${o}bn-nw${obj}";
312 $bn_asm_src="crypto${o}bn${o}asm${o}bn-nw.asm";
313 $bnco_asm_obj="\$(OBJ_D)${o}co-nw${obj}";
314 $bnco_asm_src="crypto${o}bn${o}asm${o}co-nw.asm";
315 $aes_asm_obj="\$(OBJ_D)${o}a-nw${obj}";
316 $aes_asm_src="crypto${o}aes${o}asm${o}a-nw.asm";
317 $des_enc_obj="\$(OBJ_D)${o}d-nw${obj} \$(OBJ_D)${o}y-nw${obj}";
318 $des_enc_src="crypto${o}des${o}asm${o}d-nw.asm crypto${o}des${o}asm${o}y-nw.asm";
319 $bf_enc_obj="\$(OBJ_D)${o}b-nw${obj}";
320 $bf_enc_src="crypto${o}bf${o}asm${o}b-nw.asm";
321 $cast_enc_obj="\$(OBJ_D)${o}c-nw${obj}";
322 $cast_enc_src="crypto${o}cast${o}asm${o}c-nw.asm";
323 $rc4_enc_obj="\$(OBJ_D)${o}r4-nw${obj}";
324 $rc4_enc_src="crypto${o}rc4${o}asm${o}r4-nw.asm";
325 $rc5_enc_obj="\$(OBJ_D)${o}r5-nw${obj}";
326 $rc5_enc_src="crypto${o}rc5${o}asm${o}r5-nw.asm";
327 $md5_asm_obj="\$(OBJ_D)${o}m5-nw${obj}";
328 $md5_asm_src="crypto${o}md5${o}asm${o}m5-nw.asm";
329 $sha1_asm_obj="\$(OBJ_D)${o}s1-nw${obj} \$(OBJ_D)${o}sha256-nw${obj} \$(OBJ_D)${o}sha512-nw${obj}";
330 $sha1_asm_src="crypto${o}sha${o}asm${o}s1-nw.asm crypto${o}sha${o}asm${o}sha256-nw.asm crypto${o}sha${o}asm${o}sha512-nw.asm";
331 $rmd160_asm_obj="\$(OBJ_D)${o}rm-nw${obj}";
332 $rmd160_asm_src="crypto${o}ripemd${o}asm${o}rm-nw.asm";
333 $whirlpool_asm_obj="\$(OBJ_D)${o}wp-nw${obj}";
334 $whirlpool_asm_src="crypto${o}whrlpool${o}asm${o}wp-nw.asm";
335 $cpuid_asm_obj="\$(OBJ_D)${o}x86cpuid-nw${obj}";
336 $cpuid_asm_src="crypto${o}x86cpuid-nw.asm";
337 $cflags.=" -DOPENSSL_CPUID_OBJ -DBN_ASM -DOPENSSL_BN_ASM_PART_WORDS -DMD5_ASM -DWHIRLPOOL_ASM";
338 $cflags.=" -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM";
339 $cflags.=" -DAES_ASM -DRMD160_ASM";
365 $whirlpool_asm_obj='';
366 $whirlpool_asm_src='';
371 # create the *.def linker command files in \openssl\netware\ directory
374 # strip off the leading path
375 my($target) = bname(shift);
378 if ($target =~ /(.*).nlm/)
383 # special case for openssl - the mk1mf.pl defines E_EXE = openssl
384 if ($target =~ /E_EXE/)
386 $target =~ s/\$\(E_EXE\)/openssl/;
389 # Note: originally tried to use full path ( \openssl\netware\$target.def )
390 # Metrowerks linker choked on this with an assertion failure. bug???
392 my($def_file) = "netware${o}$target.def";
394 open(DEF_OUT, ">$def_file") || die("unable to open file $def_file\n");
396 print( DEF_OUT "# command file generated by netware.pl for NLM target.\n" );
397 print( DEF_OUT "# do not edit this file - all your changes will be lost!!\n" );
398 print( DEF_OUT "#\n");
399 print( DEF_OUT "DESCRIPTION \"$target ($libarch) - OpenSSL $nlmverstr\"\n");
400 print( DEF_OUT "COPYRIGHT \"$nlmcpystr\"\n");
401 print( DEF_OUT "VERSION $nlmvernum\n");
402 print( DEF_OUT "STACK $nlmstack\n");
403 print( DEF_OUT "START $nlmstart\n");
404 print( DEF_OUT "EXIT $nlmexit\n");
406 # special case for openssl
407 if ($target eq "openssl")
409 print( DEF_OUT "SCREENNAME \"OpenSSL $nlmverstr\"\n");
413 print( DEF_OUT "SCREENNAME \"DEFAULT\"\n");
416 foreach $i (@misc_imports)
418 print( DEF_OUT "IMPORT $i\n");
421 foreach $i (@import_files)
423 print( DEF_OUT "IMPORT \@$import_path${o}$i\n");
426 foreach $i (@module_files)
428 print( DEF_OUT "MODULE $i\n");
431 foreach $i (@nlm_flags)
433 print( DEF_OUT "$i\n");
438 if ($target =~ /openssl/)
440 print( DEF_OUT "INPUT ${tmp_def}${o}openssl${obj}\n");
441 print( DEF_OUT "INPUT ${tmp_def}${o}openssl${libp}\n");
445 print( DEF_OUT "INPUT ${tmp_def}${o}${target}${obj}\n");
447 print( DEF_OUT "INPUT $prelude\n");
448 print( DEF_OUT "INPUT ${out_def}${o}${ssl}${libp} ${out_def}${o}${crypto}${libp}\n");
449 print( DEF_OUT "OUTPUT $target.nlm\n");
458 my($objs,$target,$name,$shlib)=@_;
461 $ret.="$target: $objs\n";
464 $ret.="\t\@echo Building Lib: $name\n";
465 $ret.="\t\$(MKLIB) $lib_flags $target $objs\n";
470 die( "Building as NLM not currently supported!" );
479 my($target,$files,$dep_libs,$libs)=@_;
481 my($def_file) = do_def_file($target);
483 $ret.="$target: $files $dep_libs\n";
485 # NOTE: When building the test nlms no screen name is given
486 # which causes the console screen to be used. By using the console
487 # screen there is no "<press any key to continue>" message which
488 # requires user interaction. The test script ( do_tests.pl ) needs
489 # to be able to run the tests without requiring user interaction.
491 # However, the sample program "openssl.nlm" is used by the tests and is
492 # a interactive sample so a screen is desired when not be run by the
493 # tests. To solve the problem, two versions of the program are built:
494 # openssl2 - no screen used by tests
495 # openssl - default screen - use for normal interactive modes
498 # special case for openssl - the mk1mf.pl defines E_EXE = openssl
499 if ($target =~ /E_EXE/)
501 my($target2) = $target;
503 $target2 =~ s/\(E_EXE\)/\(E_EXE\)2/;
506 my($def_file2) = do_def_file($target2);
510 $ret.="\t\$(MKLIB) $lib_flags \$(TMP_D)${o}\$(E_EXE).a \$(filter-out \$(TMP_D)${o}\$(E_EXE)${obj},$files)\n";
511 $ret.="\t\$(LINK_CMD) \$(LFLAGS) $def_file2\n";
512 $ret.="\t\@$mv \$(E_EXE)2.nlm \$(TEST_D)\n";
516 $ret.="\t\$(LINK_CMD) \$(LFLAGS) $def_file2 $files \"$prelude\" $libs -o $target2\n";
521 $ret.="\t\$(LINK_CMD) \$(LFLAGS) $def_file\n";
522 $ret.="\t\@$mv \$(\@F) \$(TEST_D)\n";
526 $ret.="\t\$(LINK_CMD) \$(LFLAGS) $def_file $files \"$prelude\" $libs -o $target\n";