netware.pl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. # Metrowerks Codewarrior or gcc / nlmconv for NetWare
  2. #
  3. $version_header = "crypto/opensslv.h";
  4. open(IN, "$version_header") or die "Couldn't open $version_header: $!";
  5. while (<IN>) {
  6. if (/^#define[\s\t]+OPENSSL_VERSION_NUMBER[\s\t]+0x(\d)(\d{2})(\d{2})(\d{2})/)
  7. {
  8. # die "OpenSSL version detected: $1.$2.$3.$4\n";
  9. #$nlmvernum = "$1,$2,$3";
  10. $nlmvernum = "$1,".($2*10+$3).",".($4*1);
  11. #$nlmverstr = "$1.".($2*1).".".($3*1).($4?(chr(96+$4)):"");
  12. break;
  13. }
  14. }
  15. close(IN) or die "Couldn't close $version_header: $!";
  16. $readme_file = "README";
  17. open(IN, $readme_file) or die "Couldn't open $readme_file: $!";
  18. while (<IN>) {
  19. if (/^[\s\t]+OpenSSL[\s\t]+(\d)\.(\d{1,2})\.(\d{1,2})([a-z])(.*)/)
  20. {
  21. #$nlmvernum = "$1,$2,$3";
  22. #$nlmvernum = "$1,".($2*10+$3).",".($4*1);
  23. $nlmverstr = "$1.$2.$3$4$5";
  24. }
  25. elsif (/^[\s\t]+(Copyright \(c\) \d{4}\-\d{4} The OpenSSL Project)$/)
  26. {
  27. $nlmcpystr = $1;
  28. }
  29. break if ($nlmvernum && $nlmcpystr);
  30. }
  31. close(IN) or die "Couldn't close $readme_file: $!";
  32. # Define stacksize here
  33. $nlmstack = "32768";
  34. # some default settings here in case we failed to find them in README
  35. $nlmvernum = "1,0,0" if (!$nlmvernum);
  36. $nlmverstr = "OpenSSL" if (!$nlmverstr);
  37. $nlmcpystr = "Copyright (c) 1998-now The OpenSSL Project" if (!$nlmcpystr);
  38. # die "OpenSSL copyright: $nlmcpystr\nOpenSSL verstring: $nlmverstr\nOpenSSL vernumber: $nlmvernum\n";
  39. # The import files and other misc imports needed to link
  40. @misc_imports = ("GetProcessSwitchCount", "RunningProcess",
  41. "GetSuperHighResolutionTimer");
  42. if ($LIBC)
  43. {
  44. @import_files = ("libc.imp");
  45. @module_files = ("libc");
  46. $libarch = "LIBC";
  47. }
  48. else
  49. {
  50. # clib build
  51. @import_files = ("clib.imp");
  52. push(@import_files, "socklib.imp") if ($BSDSOCK);
  53. @module_files = ("clib");
  54. # push(@misc_imports, "_rt_modu64%16", "_rt_divu64%16");
  55. $libarch = "CLIB";
  56. }
  57. if ($BSDSOCK)
  58. {
  59. $libarch .= "-BSD";
  60. }
  61. else
  62. {
  63. $libarch .= "-WS2";
  64. push(@import_files, "ws2nlm.imp");
  65. }
  66. # The "IMPORTS" environment variable must be set and point to the location
  67. # where import files (*.imp) can be found.
  68. # Example: set IMPORTS=c:\ndk\nwsdk\imports
  69. $import_path = $ENV{"IMPORTS"} || die ("IMPORTS environment variable not set\n");
  70. # The "PRELUDE" environment variable must be set and point to the location
  71. # and name of the prelude source to link with ( nwpre.obj is recommended ).
  72. # Example: set PRELUDE=c:\codewar\novell support\metrowerks support\libraries\runtime\nwpre.obj
  73. $prelude = $ENV{"PRELUDE"} || die ("PRELUDE environment variable not set\n");
  74. # The "INCLUDES" environment variable must be set and point to the location
  75. # where import files (*.imp) can be found.
  76. $include_path = $ENV{"INCLUDE"} || die ("INCLUDES environment variable not set\n");
  77. $include_path =~ s/\\/\//g;
  78. $include_path = join(" -I", split(/;/, $include_path));
  79. # check for gcc compiler
  80. $gnuc = $ENV{"GNUC"};
  81. #$ssl= "ssleay32";
  82. #$crypto="libeay32";
  83. if ($gnuc)
  84. {
  85. # C compiler
  86. $cc='gcc';
  87. # Linker
  88. $link='nlmconv';
  89. # librarian
  90. $mklib='ar';
  91. $o='/';
  92. # cp command
  93. $cp='cp -af';
  94. # rm command
  95. $rm='rm -f';
  96. # mv command
  97. $mv='mv -f';
  98. # mkdir command
  99. $mkdir='gmkdir';
  100. #$ranlib='ranlib';
  101. }
  102. else
  103. {
  104. # C compiler
  105. $cc='mwccnlm';
  106. # Linker
  107. $link='mwldnlm';
  108. # librarian
  109. $mklib='mwldnlm';
  110. # Path separator
  111. $o='\\';
  112. # cp command
  113. $cp='copy >nul:';
  114. # rm command
  115. $rm='del /f /q';
  116. }
  117. # assembler
  118. if ($nw_nasm)
  119. {
  120. $asm=(`nasm -v 2>NUL` gt `nasmw -v 2>NUL`?"nasm":"nasmw");
  121. if ($gnuc)
  122. {
  123. $asm.=" -s -f elf";
  124. }
  125. else
  126. {
  127. $asm.=" -s -f coff -d __coff__";
  128. }
  129. $afile="-o ";
  130. $asm.=" -g" if $debug;
  131. }
  132. elsif ($nw_mwasm)
  133. {
  134. $asm="mwasmnlm -maxerrors 20";
  135. $afile="-o ";
  136. $asm.=" -g" if $debug;
  137. }
  138. elsif ($nw_masm)
  139. {
  140. # masm assembly settings - it should be possible to use masm but haven't
  141. # got it working.
  142. # $asm='ml /Cp /coff /c /Cx';
  143. # $asm.=" /Zi" if $debug;
  144. # $afile='/Fo';
  145. die("Support for masm assembler not yet functional\n");
  146. }
  147. else
  148. {
  149. $asm="";
  150. $afile="";
  151. }
  152. if ($gnuc)
  153. {
  154. # compile flags for GNUC
  155. # additional flags based upon debug | non-debug
  156. if ($debug)
  157. {
  158. $cflags="-g -DDEBUG";
  159. }
  160. else
  161. {
  162. $cflags="-O2";
  163. }
  164. $cflags.=" -nostdinc -I$include_path \\
  165. -fno-builtin -fpcc-struct-return -fno-strict-aliasing \\
  166. -funsigned-char -Wall -Wno-unused -Wno-uninitialized";
  167. # link flags
  168. $lflags="-T";
  169. }
  170. else
  171. {
  172. # compile flags for CodeWarrior
  173. # additional flags based upon debug | non-debug
  174. if ($debug)
  175. {
  176. $cflags="-opt off -g -sym internal -DDEBUG";
  177. }
  178. else
  179. {
  180. # CodeWarrior compiler has a problem with optimizations for floating
  181. # points - no optimizations until further investigation
  182. # $cflags="-opt all";
  183. }
  184. # NOTES: Several c files in the crypto subdirectory include headers from
  185. # their local directories. Metrowerks wouldn't find these h files
  186. # without adding individual include directives as compile flags
  187. # or modifying the c files. Instead of adding individual include
  188. # paths for each subdirectory a recursive include directive
  189. # is used ( -ir crypto ).
  190. #
  191. # A similar issue exists for the engines and apps subdirectories.
  192. #
  193. # Turned off the "possible" warnings ( -w nopossible ). Metrowerks
  194. # complained a lot about various stuff. May want to turn back
  195. # on for further development.
  196. $cflags.=" -nostdinc -ir crypto -ir engines -ir apps -I$include_path \\
  197. -msgstyle gcc -align 4 -processor pentium -char unsigned \\
  198. -w on -w nolargeargs -w nopossible -w nounusedarg -w nounusedexpr \\
  199. -w noimplicitconv -relax_pointers -nosyspath -maxerrors 20";
  200. # link flags
  201. $lflags="-msgstyle gcc -zerobss -nostdlib -sym internal -commandfile";
  202. }
  203. # common defines
  204. $cflags.=" -DL_ENDIAN -DOPENSSL_SYSNAME_NETWARE -U_WIN32";
  205. # If LibC build add in NKS_LIBC define and set the entry/exit
  206. # routines - The default entry/exit routines are for CLib and don't exist
  207. # in LibC
  208. if ($LIBC)
  209. {
  210. $cflags.=" -DNETWARE_LIBC";
  211. $nlmstart = "_LibCPrelude";
  212. $nlmexit = "_LibCPostlude";
  213. @nlm_flags = ("pseudopreemption", "flag_on 64");
  214. }
  215. else
  216. {
  217. $cflags.=" -DNETWARE_CLIB";
  218. $nlmstart = "_Prelude";
  219. $nlmexit = "_Stop";
  220. }
  221. # If BSD Socket support is requested, set a define for the compiler
  222. if ($BSDSOCK)
  223. {
  224. $cflags.=" -DNETWARE_BSDSOCK";
  225. if (!$LIBC)
  226. {
  227. $cflags.=" -DNETDB_USE_INTERNET";
  228. }
  229. }
  230. # linking stuff
  231. # for the output directories use the mk1mf.pl values with "_nw" appended
  232. if ($shlib)
  233. {
  234. if ($LIBC)
  235. {
  236. $out_def.="_nw_libc_nlm";
  237. $tmp_def.="_nw_libc_nlm";
  238. $inc_def.="_nw_libc_nlm";
  239. }
  240. else # NETWARE_CLIB
  241. {
  242. $out_def.="_nw_clib_nlm";
  243. $tmp_def.="_nw_clib_nlm";
  244. $inc_def.="_nw_clib_nlm";
  245. }
  246. }
  247. else
  248. {
  249. if ($gnuc) # GNUC Tools
  250. {
  251. $libp=".a";
  252. $shlibp=".a";
  253. $lib_flags="-cr";
  254. }
  255. else # CodeWarrior
  256. {
  257. $libp=".lib";
  258. $shlibp=".lib";
  259. $lib_flags="-nodefaults -type library -o";
  260. }
  261. if ($LIBC)
  262. {
  263. $out_def.="_nw_libc";
  264. $tmp_def.="_nw_libc";
  265. $inc_def.="_nw_libc";
  266. }
  267. else # NETWARE_CLIB
  268. {
  269. $out_def.="_nw_clib";
  270. $tmp_def.="_nw_clib";
  271. $inc_def.="_nw_clib";
  272. }
  273. }
  274. # used by mk1mf.pl
  275. $obj='.o';
  276. $ofile='-o ';
  277. $efile='';
  278. $exep='.nlm';
  279. $ex_libs='';
  280. if (!$no_asm)
  281. {
  282. $bn_asm_obj="\$(OBJ_D)${o}bn-nw${obj}";
  283. $bn_asm_src="crypto${o}bn${o}asm${o}bn-nw.asm";
  284. $bnco_asm_obj="\$(OBJ_D)${o}co-nw${obj}";
  285. $bnco_asm_src="crypto${o}bn${o}asm${o}co-nw.asm";
  286. $aes_asm_obj="\$(OBJ_D)${o}a-nw${obj}";
  287. $aes_asm_src="crypto${o}aes${o}asm${o}a-nw.asm";
  288. $des_enc_obj="\$(OBJ_D)${o}d-nw${obj} \$(OBJ_D)${o}y-nw${obj}";
  289. $des_enc_src="crypto${o}des${o}asm${o}d-nw.asm crypto${o}des${o}asm${o}y-nw.asm";
  290. $bf_enc_obj="\$(OBJ_D)${o}b-nw${obj}";
  291. $bf_enc_src="crypto${o}bf${o}asm${o}b-nw.asm";
  292. $cast_enc_obj="\$(OBJ_D)${o}c-nw${obj}";
  293. $cast_enc_src="crypto${o}cast${o}asm${o}c-nw.asm";
  294. $rc4_enc_obj="\$(OBJ_D)${o}r4-nw${obj}";
  295. $rc4_enc_src="crypto${o}rc4${o}asm${o}r4-nw.asm";
  296. $rc5_enc_obj="\$(OBJ_D)${o}r5-nw${obj}";
  297. $rc5_enc_src="crypto${o}rc5${o}asm${o}r5-nw.asm";
  298. $md5_asm_obj="\$(OBJ_D)${o}m5-nw${obj}";
  299. $md5_asm_src="crypto${o}md5${o}asm${o}m5-nw.asm";
  300. $sha1_asm_obj="\$(OBJ_D)${o}s1-nw${obj} \$(OBJ_D)${o}sha256-nw${obj} \$(OBJ_D)${o}sha512-nw${obj}";
  301. $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";
  302. $rmd160_asm_obj="\$(OBJ_D)${o}rm-nw${obj}";
  303. $rmd160_asm_src="crypto${o}ripemd${o}asm${o}rm-nw.asm";
  304. $whirlpool_asm_obj="\$(OBJ_D)${o}wp-nw${obj}";
  305. $whirlpool_asm_src="crypto${o}whrlpool${o}asm${o}wp-nw.asm";
  306. $cpuid_asm_obj="\$(OBJ_D)${o}x86cpuid-nw${obj}";
  307. $cpuid_asm_src="crypto${o}x86cpuid-nw.asm";
  308. $cflags.=" -DOPENSSL_CPUID_OBJ -DBN_ASM -DOPENSSL_BN_ASM_PART_WORDS -DMD5_ASM -DWHIRLPOOL_ASM";
  309. $cflags.=" -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM";
  310. $cflags.=" -DAES_ASM -DRMD160_ASM";
  311. }
  312. else
  313. {
  314. $bn_asm_obj='';
  315. $bn_asm_src='';
  316. $bnco_asm_obj='';
  317. $bnco_asm_src='';
  318. $aes_asm_obj='';
  319. $aes_asm_src='';
  320. $des_enc_obj='';
  321. $des_enc_src='';
  322. $bf_enc_obj='';
  323. $bf_enc_src='';
  324. $cast_enc_obj='';
  325. $cast_enc_src='';
  326. $rc4_enc_obj='';
  327. $rc4_enc_src='';
  328. $rc5_enc_obj='';
  329. $rc5_enc_src='';
  330. $md5_asm_obj='';
  331. $md5_asm_src='';
  332. $sha1_asm_obj='';
  333. $sha1_asm_src='';
  334. $rmd160_asm_obj='';
  335. $rmd160_asm_src='';
  336. $whirlpool_asm_obj='';
  337. $whirlpool_asm_src='';
  338. $cpuid_asm_obj='';
  339. $cpuid_asm_src='';
  340. }
  341. # create the *.def linker command files in \openssl\netware\ directory
  342. sub do_def_file
  343. {
  344. # strip off the leading path
  345. my($target) = bname(shift);
  346. my($i);
  347. if ($target =~ /(.*).nlm/)
  348. {
  349. $target = $1;
  350. }
  351. # special case for openssl - the mk1mf.pl defines E_EXE = openssl
  352. if ($target =~ /E_EXE/)
  353. {
  354. $target =~ s/\$\(E_EXE\)/openssl/;
  355. }
  356. # Note: originally tried to use full path ( \openssl\netware\$target.def )
  357. # Metrowerks linker choked on this with an assertion failure. bug???
  358. #
  359. my($def_file) = "netware${o}$target.def";
  360. open(DEF_OUT, ">$def_file") || die("unable to open file $def_file\n");
  361. print( DEF_OUT "# command file generated by netware.pl for NLM target.\n" );
  362. print( DEF_OUT "# do not edit this file - all your changes will be lost!!\n" );
  363. print( DEF_OUT "#\n");
  364. print( DEF_OUT "DESCRIPTION \"$target ($libarch) - OpenSSL $nlmverstr\"\n");
  365. print( DEF_OUT "COPYRIGHT \"$nlmcpystr\"\n");
  366. print( DEF_OUT "VERSION $nlmvernum\n");
  367. print( DEF_OUT "STACK $nlmstack\n");
  368. print( DEF_OUT "START $nlmstart\n");
  369. print( DEF_OUT "EXIT $nlmexit\n");
  370. # special case for openssl
  371. if ($target eq "openssl")
  372. {
  373. print( DEF_OUT "SCREENNAME \"OpenSSL $nlmverstr\"\n");
  374. }
  375. else
  376. {
  377. print( DEF_OUT "SCREENNAME \"DEFAULT\"\n");
  378. }
  379. foreach $i (@misc_imports)
  380. {
  381. print( DEF_OUT "IMPORT $i\n");
  382. }
  383. foreach $i (@import_files)
  384. {
  385. print( DEF_OUT "IMPORT \@$import_path${o}$i\n");
  386. }
  387. foreach $i (@module_files)
  388. {
  389. print( DEF_OUT "MODULE $i\n");
  390. }
  391. foreach $i (@nlm_flags)
  392. {
  393. print( DEF_OUT "$i\n");
  394. }
  395. if ($gnuc)
  396. {
  397. if ($target =~ /openssl/)
  398. {
  399. print( DEF_OUT "INPUT ${tmp_def}${o}openssl${obj}\n");
  400. print( DEF_OUT "INPUT ${tmp_def}${o}openssl${libp}\n");
  401. }
  402. else
  403. {
  404. print( DEF_OUT "INPUT ${tmp_def}${o}${target}${obj}\n");
  405. }
  406. print( DEF_OUT "INPUT $prelude\n");
  407. print( DEF_OUT "INPUT ${out_def}${o}${ssl}${libp} ${out_def}${o}${crypto}${libp}\n");
  408. print( DEF_OUT "OUTPUT $target.nlm\n");
  409. }
  410. close(DEF_OUT);
  411. return($def_file);
  412. }
  413. sub do_lib_rule
  414. {
  415. my($objs,$target,$name,$shlib)=@_;
  416. my($ret);
  417. $ret.="$target: $objs\n";
  418. if (!$shlib)
  419. {
  420. $ret.="\t\@echo Building Lib: $name\n";
  421. $ret.="\t\$(MKLIB) $lib_flags $target $objs\n";
  422. $ret.="\t\@echo .\n"
  423. }
  424. else
  425. {
  426. die( "Building as NLM not currently supported!" );
  427. }
  428. $ret.="\n";
  429. return($ret);
  430. }
  431. sub do_link_rule
  432. {
  433. my($target,$files,$dep_libs,$libs)=@_;
  434. my($ret);
  435. my($def_file) = do_def_file($target);
  436. $ret.="$target: $files $dep_libs\n";
  437. # NOTE: When building the test nlms no screen name is given
  438. # which causes the console screen to be used. By using the console
  439. # screen there is no "<press any key to continue>" message which
  440. # requires user interaction. The test script ( do_tests.pl ) needs
  441. # to be able to run the tests without requiring user interaction.
  442. #
  443. # However, the sample program "openssl.nlm" is used by the tests and is
  444. # a interactive sample so a screen is desired when not be run by the
  445. # tests. To solve the problem, two versions of the program are built:
  446. # openssl2 - no screen used by tests
  447. # openssl - default screen - use for normal interactive modes
  448. #
  449. # special case for openssl - the mk1mf.pl defines E_EXE = openssl
  450. if ($target =~ /E_EXE/)
  451. {
  452. my($target2) = $target;
  453. $target2 =~ s/\(E_EXE\)/\(E_EXE\)2/;
  454. # openssl2
  455. my($def_file2) = do_def_file($target2);
  456. if ($gnuc)
  457. {
  458. $ret.="\t\$(MKLIB) $lib_flags \$(TMP_D)${o}\$(E_EXE).a \$(filter-out \$(TMP_D)${o}\$(E_EXE)${obj},$files)\n";
  459. $ret.="\t\$(LINK) \$(LFLAGS) $def_file2\n";
  460. $ret.="\t\@$mv \$(E_EXE)2.nlm \$(TEST_D)\n";
  461. }
  462. else
  463. {
  464. $ret.="\t\$(LINK) \$(LFLAGS) $def_file2 $files \"$prelude\" $libs -o $target2\n";
  465. }
  466. }
  467. if ($gnuc)
  468. {
  469. $ret.="\t\$(LINK) \$(LFLAGS) $def_file\n";
  470. $ret.="\t\@$mv \$(\@F) \$(TEST_D)\n";
  471. }
  472. else
  473. {
  474. $ret.="\t\$(LINK) \$(LFLAGS) $def_file $files \"$prelude\" $libs -o $target\n";
  475. }
  476. $ret.="\n";
  477. return($ret);
  478. }
  479. 1;