netware.pl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. if ($gnuc)
  121. {
  122. $asm="nasmw -s -f elf";
  123. }
  124. else
  125. {
  126. $asm="nasmw -s -f coff";
  127. }
  128. $afile="-o ";
  129. $asm.=" -g" if $debug;
  130. }
  131. elsif ($nw_mwasm)
  132. {
  133. $asm="mwasmnlm -maxerrors 20";
  134. $afile="-o ";
  135. $asm.=" -g" if $debug;
  136. }
  137. elsif ($nw_masm)
  138. {
  139. # masm assembly settings - it should be possible to use masm but haven't
  140. # got it working.
  141. # $asm='ml /Cp /coff /c /Cx';
  142. # $asm.=" /Zi" if $debug;
  143. # $afile='/Fo';
  144. die("Support for masm assembler not yet functional\n");
  145. }
  146. else
  147. {
  148. $asm="";
  149. $afile="";
  150. }
  151. if ($gnuc)
  152. {
  153. # compile flags for GNUC
  154. # additional flags based upon debug | non-debug
  155. if ($debug)
  156. {
  157. $cflags="-g -DDEBUG";
  158. }
  159. else
  160. {
  161. $cflags="-O2";
  162. }
  163. $cflags.=" -nostdinc -I$include_path \\
  164. -fno-builtin -fpcc-struct-return -fno-strict-aliasing \\
  165. -funsigned-char -Wall -Wno-unused -Wno-uninitialized";
  166. # link flags
  167. $lflags="-T";
  168. }
  169. else
  170. {
  171. # compile flags for CodeWarrior
  172. # additional flags based upon debug | non-debug
  173. if ($debug)
  174. {
  175. $cflags="-opt off -g -sym internal -DDEBUG";
  176. }
  177. else
  178. {
  179. # CodeWarrior compiler has a problem with optimizations for floating
  180. # points - no optimizations until further investigation
  181. # $cflags="-opt all";
  182. }
  183. # NOTES: Several c files in the crypto subdirectory include headers from
  184. # their local directories. Metrowerks wouldn't find these h files
  185. # without adding individual include directives as compile flags
  186. # or modifying the c files. Instead of adding individual include
  187. # paths for each subdirectory a recursive include directive
  188. # is used ( -ir crypto ).
  189. #
  190. # A similar issue exists for the engines and apps subdirectories.
  191. #
  192. # Turned off the "possible" warnings ( -w nopossible ). Metrowerks
  193. # complained a lot about various stuff. May want to turn back
  194. # on for further development.
  195. $cflags.=" -nostdinc -ir crypto -ir engines -ir apps -I$include_path \\
  196. -msgstyle gcc -align 4 -processor pentium -char unsigned \\
  197. -w on -w nolargeargs -w nopossible -w nounusedarg -w nounusedexpr \\
  198. -w noimplicitconv -relax_pointers -nosyspath -maxerrors 20";
  199. # link flags
  200. $lflags="-msgstyle gcc -zerobss -nostdlib -sym internal -commandfile";
  201. }
  202. # common defines
  203. $cflags.=" -DL_ENDIAN -DOPENSSL_SYSNAME_NETWARE -U_WIN32";
  204. # If LibC build add in NKS_LIBC define and set the entry/exit
  205. # routines - The default entry/exit routines are for CLib and don't exist
  206. # in LibC
  207. if ($LIBC)
  208. {
  209. $cflags.=" -DNETWARE_LIBC";
  210. $nlmstart = "_LibCPrelude";
  211. $nlmexit = "_LibCPostlude";
  212. @nlm_flags = ("pseudopreemption", "flag_on 64");
  213. }
  214. else
  215. {
  216. $cflags.=" -DNETWARE_CLIB";
  217. $nlmstart = "_Prelude";
  218. $nlmexit = "_Stop";
  219. }
  220. # If BSD Socket support is requested, set a define for the compiler
  221. if ($BSDSOCK)
  222. {
  223. $cflags.=" -DNETWARE_BSDSOCK";
  224. if (!$LIBC)
  225. {
  226. $cflags.=" -DNETDB_USE_INTERNET";
  227. }
  228. }
  229. # linking stuff
  230. # for the output directories use the mk1mf.pl values with "_nw" appended
  231. if ($shlib)
  232. {
  233. if ($LIBC)
  234. {
  235. $out_def.="_nw_libc_nlm";
  236. $tmp_def.="_nw_libc_nlm";
  237. $inc_def.="_nw_libc_nlm";
  238. }
  239. else # NETWARE_CLIB
  240. {
  241. $out_def.="_nw_clib_nlm";
  242. $tmp_def.="_nw_clib_nlm";
  243. $inc_def.="_nw_clib_nlm";
  244. }
  245. }
  246. else
  247. {
  248. if ($gnuc) # GNUC Tools
  249. {
  250. $libp=".a";
  251. $shlibp=".a";
  252. $lib_flags="-cr";
  253. }
  254. else # CodeWarrior
  255. {
  256. $libp=".lib";
  257. $shlibp=".lib";
  258. $lib_flags="-nodefaults -type library -o";
  259. }
  260. if ($LIBC)
  261. {
  262. $out_def.="_nw_libc";
  263. $tmp_def.="_nw_libc";
  264. $inc_def.="_nw_libc";
  265. }
  266. else # NETWARE_CLIB
  267. {
  268. $out_def.="_nw_clib";
  269. $tmp_def.="_nw_clib";
  270. $inc_def.="_nw_clib";
  271. }
  272. }
  273. # used by mk1mf.pl
  274. $obj='.o';
  275. $ofile='-o ';
  276. $efile='';
  277. $exep='.nlm';
  278. $ex_libs='';
  279. if (!$no_asm)
  280. {
  281. $bn_asm_obj="\$(OBJ_D)${o}bn-nw${obj}";
  282. $bn_asm_src="crypto${o}bn${o}asm${o}bn-nw.asm";
  283. $bnco_asm_obj="\$(OBJ_D)${o}co-nw${obj}";
  284. $bnco_asm_src="crypto${o}bn${o}asm${o}co-nw.asm";
  285. $aes_asm_obj="\$(OBJ_D)${o}a-nw${obj}";
  286. $aes_asm_src="crypto${o}aes${o}asm${o}a-nw.asm";
  287. $des_enc_obj="\$(OBJ_D)${o}d-nw${obj} \$(OBJ_D)${o}y-nw${obj}";
  288. $des_enc_src="crypto${o}des${o}asm${o}d-nw.asm crypto${o}des${o}asm${o}y-nw.asm";
  289. $bf_enc_obj="\$(OBJ_D)${o}b-nw${obj}";
  290. $bf_enc_src="crypto${o}bf${o}asm${o}b-nw.asm";
  291. $cast_enc_obj="\$(OBJ_D)${o}c-nw${obj}";
  292. $cast_enc_src="crypto${o}cast${o}asm${o}c-nw.asm";
  293. $rc4_enc_obj="\$(OBJ_D)${o}r4-nw${obj}";
  294. $rc4_enc_src="crypto${o}rc4${o}asm${o}r4-nw.asm";
  295. $rc5_enc_obj="\$(OBJ_D)${o}r5-nw${obj}";
  296. $rc5_enc_src="crypto${o}rc5${o}asm${o}r5-nw.asm";
  297. $md5_asm_obj="\$(OBJ_D)${o}m5-nw${obj}";
  298. $md5_asm_src="crypto${o}md5${o}asm${o}m5-nw.asm";
  299. $sha1_asm_obj="\$(OBJ_D)${o}s1-nw${obj}";
  300. $sha1_asm_src="crypto${o}sha${o}asm${o}s1-nw.asm";
  301. $rmd160_asm_obj="\$(OBJ_D)${o}rm-nw${obj}";
  302. $rmd160_asm_src="crypto${o}ripemd${o}asm${o}rm-nw.asm";
  303. $cpuid_asm_obj="\$(OBJ_D)${o}x86cpuid-nw${obj}";
  304. $cpuid_asm_src="crypto${o}x86cpuid-nw.asm";
  305. $cflags.=" -DOPENSSL_CPUID_OBJ -DBN_ASM -DOPENSSL_BN_ASM_PART_WORDS -DMD5_ASM -DSHA1_ASM";
  306. $cflags.=" -DAES_ASM -DRMD160_ASM";
  307. }
  308. else
  309. {
  310. $bn_asm_obj='';
  311. $bn_asm_src='';
  312. $bnco_asm_obj='';
  313. $bnco_asm_src='';
  314. $aes_asm_obj='';
  315. $aes_asm_src='';
  316. $des_enc_obj='';
  317. $des_enc_src='';
  318. $bf_enc_obj='';
  319. $bf_enc_src='';
  320. $cast_enc_obj='';
  321. $cast_enc_src='';
  322. $rc4_enc_obj='';
  323. $rc4_enc_src='';
  324. $rc5_enc_obj='';
  325. $rc5_enc_src='';
  326. $md5_asm_obj='';
  327. $md5_asm_src='';
  328. $sha1_asm_obj='';
  329. $sha1_asm_src='';
  330. $rmd160_asm_obj='';
  331. $rmd160_asm_src='';
  332. $cpuid_asm_obj='';
  333. $cpuid_asm_src='';
  334. }
  335. # create the *.def linker command files in \openssl\netware\ directory
  336. sub do_def_file
  337. {
  338. # strip off the leading path
  339. my($target) = bname(shift);
  340. my($i);
  341. if ($target =~ /(.*).nlm/)
  342. {
  343. $target = $1;
  344. }
  345. # special case for openssl - the mk1mf.pl defines E_EXE = openssl
  346. if ($target =~ /E_EXE/)
  347. {
  348. $target =~ s/\$\(E_EXE\)/openssl/;
  349. }
  350. # Note: originally tried to use full path ( \openssl\netware\$target.def )
  351. # Metrowerks linker choked on this with an assertion failure. bug???
  352. #
  353. my($def_file) = "netware${o}$target.def";
  354. open(DEF_OUT, ">$def_file") || die("unable to open file $def_file\n");
  355. print( DEF_OUT "# command file generated by netware.pl for NLM target.\n" );
  356. print( DEF_OUT "# do not edit this file - all your changes will be lost!!\n" );
  357. print( DEF_OUT "#\n");
  358. print( DEF_OUT "DESCRIPTION \"$target ($libarch) - OpenSSL $nlmverstr\"\n");
  359. print( DEF_OUT "COPYRIGHT \"$nlmcpystr\"\n");
  360. print( DEF_OUT "VERSION $nlmvernum\n");
  361. print( DEF_OUT "STACK $nlmstack\n");
  362. print( DEF_OUT "START $nlmstart\n");
  363. print( DEF_OUT "EXIT $nlmexit\n");
  364. # special case for openssl
  365. if ($target eq "openssl")
  366. {
  367. print( DEF_OUT "SCREENNAME \"OpenSSL $nlmverstr\"\n");
  368. }
  369. else
  370. {
  371. print( DEF_OUT "SCREENNAME \"DEFAULT\"\n");
  372. }
  373. foreach $i (@misc_imports)
  374. {
  375. print( DEF_OUT "IMPORT $i\n");
  376. }
  377. foreach $i (@import_files)
  378. {
  379. print( DEF_OUT "IMPORT \@$import_path${o}$i\n");
  380. }
  381. foreach $i (@module_files)
  382. {
  383. print( DEF_OUT "MODULE $i\n");
  384. }
  385. foreach $i (@nlm_flags)
  386. {
  387. print( DEF_OUT "$i\n");
  388. }
  389. if ($gnuc)
  390. {
  391. if ($target =~ /openssl/)
  392. {
  393. print( DEF_OUT "INPUT ${tmp_def}${o}openssl${obj}\n");
  394. print( DEF_OUT "INPUT ${tmp_def}${o}openssl${libp}\n");
  395. }
  396. else
  397. {
  398. print( DEF_OUT "INPUT ${tmp_def}${o}${target}${obj}\n");
  399. }
  400. print( DEF_OUT "INPUT $prelude\n");
  401. print( DEF_OUT "INPUT ${out_def}${o}${ssl}${libp} ${out_def}${o}${crypto}${libp}\n");
  402. print( DEF_OUT "OUTPUT $target.nlm\n");
  403. }
  404. close(DEF_OUT);
  405. return($def_file);
  406. }
  407. sub do_lib_rule
  408. {
  409. my($objs,$target,$name,$shlib)=@_;
  410. my($ret);
  411. $ret.="$target: $objs\n";
  412. if (!$shlib)
  413. {
  414. $ret.="\t\@echo Building Lib: $name\n";
  415. $ret.="\t\$(MKLIB) $lib_flags $target $objs\n";
  416. $ret.="\t\@echo .\n"
  417. }
  418. else
  419. {
  420. die( "Building as NLM not currently supported!" );
  421. }
  422. $ret.="\n";
  423. return($ret);
  424. }
  425. sub do_link_rule
  426. {
  427. my($target,$files,$dep_libs,$libs)=@_;
  428. my($ret);
  429. my($def_file) = do_def_file($target);
  430. $ret.="$target: $files $dep_libs\n";
  431. # NOTE: When building the test nlms no screen name is given
  432. # which causes the console screen to be used. By using the console
  433. # screen there is no "<press any key to continue>" message which
  434. # requires user interaction. The test script ( do_tests.pl ) needs
  435. # to be able to run the tests without requiring user interaction.
  436. #
  437. # However, the sample program "openssl.nlm" is used by the tests and is
  438. # a interactive sample so a screen is desired when not be run by the
  439. # tests. To solve the problem, two versions of the program are built:
  440. # openssl2 - no screen used by tests
  441. # openssl - default screen - use for normal interactive modes
  442. #
  443. # special case for openssl - the mk1mf.pl defines E_EXE = openssl
  444. if ($target =~ /E_EXE/)
  445. {
  446. my($target2) = $target;
  447. $target2 =~ s/\(E_EXE\)/\(E_EXE\)2/;
  448. # openssl2
  449. my($def_file2) = do_def_file($target2);
  450. if ($gnuc)
  451. {
  452. $ret.="\t\$(MKLIB) $lib_flags \$(TMP_D)${o}\$(E_EXE).a \$(filter-out \$(TMP_D)${o}\$(E_EXE)${obj},$files)\n";
  453. $ret.="\t\$(LINK) \$(LFLAGS) $def_file2\n";
  454. $ret.="\t\@$mv \$(E_EXE)2.nlm \$(TEST_D)\n";
  455. }
  456. else
  457. {
  458. $ret.="\t\$(LINK) \$(LFLAGS) $def_file2 $files \"$prelude\" $libs -o $target2\n";
  459. }
  460. }
  461. if ($gnuc)
  462. {
  463. $ret.="\t\$(LINK) \$(LFLAGS) $def_file\n";
  464. $ret.="\t\@$mv \$(\@F) \$(TEST_D)\n";
  465. }
  466. else
  467. {
  468. $ret.="\t\$(LINK) \$(LFLAGS) $def_file $files \"$prelude\" $libs -o $target\n";
  469. }
  470. $ret.="\n";
  471. return($ret);
  472. }
  473. 1;