This is a patch against openssl-0.9.7-stable-SNAP-20021203 to enable building with the Watcom compiler. I've tested this on Win2k with Watcom C/C++ 11.0c, and the library produced passes all tests (except the verify one, since the Watcom clib doesn't do file globbing - I intend to submit another patch for this. Running the test by hand passes.).

So far, the patch only produces a static library without the optimized assembly. I've taken a guess at which options to use (e.g. DES_PTR) on the basis of past experience, but I aim to run some tests to check they're the best.

The patch changes no core files, so should be safe to add to the 0.9.7 branch. In case it isn't obvious, WAT-32.pl lives in util\pl, and do_wat.bat lives in ms.

I aim to get Watcom to build with the assembly, both as a static library and a DLL, shortly.

Regards,

Charles

p.s. The motivation behind this patch is that it was less effort to get OpenSSL to compile with Watcom than it was to get Watcom to link the VC.Net-produced library with my project. Strange, but true.
#!/usr/local/bin/perl
# WAT-32.pl - the file for Watcom 11.0c windows NT, static libraries
#

$ssl=   "ssleay32";
$crypto="libeay32";
$RSAref="RSAref32";

$o='\\';
$cp='copy nul+';        # Timestamps get stuffed otherwise
$rm='del';

# C compiler stuff
$cc='wcc386';
$cflags=' -zq -we -oneatx -oh -oi -ei -zp8 -6 -fpi87 -fp6 -bm -bt=nt -ef -DWIN32 
-DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32';
$lflags="sys nt op q";
$mlflags='-q';

$out_def="out32";
$tmp_def="tmp32";
$inc_def="inc32";

if ($debug)
        {
        $cflags=" -we -zq -ei -d2 -bm -6r -bt=mt -ef -DWIN32 -D_DEBUG -DL_ENDIAN 
-DWIN32_LEAN_AND_MEAN -DDEBUG -DDSO_WIN32";
        $lflags.=" /debug";
        $mlflags.=' /debug';
        }
$cflags .= " -DWINNT" if $NT == 1;

$obj='.obj';
$ofile="-fo=";

# EXE linking stuff
$link="wlink";
$efile="";
$exep='.exe';
if ($no_sock)
        { $ex_libs=""; }
else    { $ex_libs="wsock32.lib user32.lib gdi32.lib"; }

# static library stuff
$mklib='wlib -n -q';
$ranlib='';
$plib="";
$libp=".lib";
$shlibp=($shlib)?".dll":".lib";
$lfile='';

$shlib_ex_obj="";
$app_ex_obj="";
$asm='wasm -q';
$asm.=" /Zi" if $debug;
$afile='';

$bn_asm_obj='';
$bn_asm_src='';
$des_enc_obj='';
$des_enc_src='';
$bf_enc_obj='';
$bf_enc_src='';

if (!$no_asm)
        {
        $bn_asm_obj='crypto\bn\asm\bn_win32.obj';
        $bn_asm_src='crypto\bn\asm\bn_win32.asm';
        $des_enc_obj='crypto\des\asm\d_win32.obj crypto\des\asm\y_win32.obj';
        $des_enc_src='crypto\des\asm\d_win32.asm crypto\des\asm\y_win32.asm';
        $bf_enc_obj='crypto\bf\asm\b_win32.obj';
        $bf_enc_src='crypto\bf\asm\b_win32.asm';
        $cast_enc_obj='crypto\cast\asm\c_win32.obj';
        $cast_enc_src='crypto\cast\asm\c_win32.asm';
        $rc4_enc_obj='crypto\rc4\asm\r4_win32.obj';
        $rc4_enc_src='crypto\rc4\asm\r4_win32.asm';
        $rc5_enc_obj='crypto\rc5\asm\r5_win32.obj';
        $rc5_enc_src='crypto\rc5\asm\r5_win32.asm';
        $md5_asm_obj='crypto\md5\asm\m5_win32.obj';
        $md5_asm_src='crypto\md5\asm\m5_win32.asm';
        $sha1_asm_obj='crypto\sha\asm\s1_win32.obj';
        $sha1_asm_src='crypto\sha\asm\s1_win32.asm';
        $rmd160_asm_obj='crypto\ripemd\asm\rm_win32.obj';
        $rmd160_asm_src='crypto\ripemd\asm\rm_win32.asm';
        $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
        }

if ($shlib)
        {
        $mlflags.=" $lflags /dll";
#       $cflags =~ s| /MD| /MT|;
        $lib_cflag=" /GD -D_WINDLL -D_DLL";
        $out_def="out32dll";
        $tmp_def="tmp32dll";
        }

sub do_lib_rule
        {
        local($objs,$target,$name,$shlib)=@_;
        local($ret,$Name);

        $taget =~ s/\//$o/g if $o ne '/';
        ($Name=$name) =~ tr/a-z/A-Z/;

#       $target="\$(LIB_D)$o$target";
        $ret.="$target: $objs\n";
        if (!$shlib)
                {
                $ex =' advapi32.lib';
                $ret.="\t@%create \$(OBJ_D)\\$Name.lnk\n";
                $ret.="\tfor %i in ($objs) do %append \$(OBJ_D)\\$Name.lnk +%i\n";
                $ret.="\t\$(MKLIB) $lfile$target @\$(OBJ_D)\\$Name.lnk\n";
                }
        else
                {
                local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
                $ex.=' wsock32.lib gdi32.lib advapi32.lib';
                $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n  
\$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
                }
        $ret.="\n";
        return($ret);
        }

sub do_link_rule
        {
        local($target,$files,$dep_libs,$libs)=@_;
        local($ret,$_);
        
        $file =~ s/\//$o/g if $o ne '/';
        $n=&bname($targer);
        $ret.="$target: $files $dep_libs\n";
        $ret.="\t@%create \$\^*.lnk\n";
        $ret.="\tfor %i in ($files) do %append \$\^*.lnk FIL %i\n";
        $ret.="\tfor %i in ($libs) do %append \$\^*.lnk LIBR %i\n";
        $ret.="\t\$(LINK) \$(LFLAGS) name \$\^\@ \@\$\^*.lnk\n\n";
        
#       $ret.="  \$(LINK) \$(LFLAGS) $efile$target @<<\n";
#       $ret.="  \$(APP_EX_OBJ) $files $libs\n<<\n\n";
        return($ret);
        }

1;
diff -ur openssl-0.9.7-stable-SNAP-20021203\Configure 
openssl-0.9.7-stable-SNAP-20021203-work\Configure
--- openssl-0.9.7-stable-SNAP-20021203\Configure        Tue Nov 26 16:02:12 2002
+++ openssl-0.9.7-stable-SNAP-20021203-work\Configure   Wed Dec 04 23:23:44 2002
@@ -516,6 +516,10 @@
 # and its library files in util/pl/*)
 "Mingw32", "gcc:-DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall:::::BN_LLONG 
${x86_gcc_des} ${x86_gcc_opts}::::::::::win32",
 
+# WATCOM C/C++ 11/Open Watcom, from Charles Lecklider <[EMAIL PROTECTED]>
+"WAT-NT","wcc386::::WINNT::DES_PTR DES_UNROLL RC4_CHUNK::::::::::win32",
+"WAT-WIN32","wcc386::::WIN32::DES_PTR DES_UNROLL RC4_CHUNK::::::::::win32",
+
 # UWIN 
 "UWIN", "cc:-DTERMIOS -DL_ENDIAN -O -Wall:::UWIN::BN_LLONG ${x86_gcc_des} 
${x86_gcc_opts}::::::::::win32",
 
@@ -573,7 +577,7 @@
 );
 
 my @WinTargets=qw(VC-NT VC-CE VC-WIN32 VC-WIN16 VC-W31-16 VC-W31-32 VC-MSDOS
-       BC-32 BC-16 Mingw32 OS2-EMX);
+       BC-32 BC-16 Mingw32 WAT-NT WAT-WIN32 OS2-EMX);
 
 my $idx = 0;
 my $idx_cc = $idx++;
diff -ur openssl-0.9.7-stable-SNAP-20021203\e_os.h 
openssl-0.9.7-stable-SNAP-20021203-work\e_os.h
--- openssl-0.9.7-stable-SNAP-20021203\e_os.h   Tue Dec 03 17:02:34 2002
+++ openssl-0.9.7-stable-SNAP-20021203-work\e_os.h      Wed Dec 04 19:36:09 2002
@@ -206,12 +206,14 @@
 #    define _O_BINARY O_BINARY
 #  endif /* __DJGPP__ */
 
-#  ifndef S_IFDIR
-#    define S_IFDIR    _S_IFDIR
-#  endif
-
-#  ifndef S_IFMT
-#    define S_IFMT     _S_IFMT
+#  ifndef __WATCOMC__
+#    ifndef S_IFDIR
+#      define S_IFDIR  _S_IFDIR
+#    endif
+
+#    ifndef S_IFMT
+#      define S_IFMT   _S_IFMT
+#    endif
 #  endif
 
 #  if !defined(WINNT) && !defined(__DJGPP__)
@@ -239,6 +241,12 @@
 #    define _setmode setmode
 #    define _O_TEXT O_TEXT
 #    define _O_BINARY O_BINARY
+#    define _int64 __int64
+#    define _kbhit kbhit
+#  endif
+
+#  if defined (__WATCOMC__)
+#    define _setmode setmode
 #    define _int64 __int64
 #    define _kbhit kbhit
 #  endif
diff -ur openssl-0.9.7-stable-SNAP-20021203\INSTALL.W32 
openssl-0.9.7-stable-SNAP-20021203-work\INSTALL.W32
--- openssl-0.9.7-stable-SNAP-20021203\INSTALL.W32      Fri Nov 15 23:07:30 2002
+++ openssl-0.9.7-stable-SNAP-20021203-work\INSTALL.W32 Wed Dec 04 23:37:42 2002
@@ -17,6 +17,7 @@
   * Visual C++
   * Borland C
   * GNU C (Mingw32 or Cygwin)
+  * WATCOM C/C++ 11.0 or Open Watcom 1.0
 
  If you want to compile in the assembly language routines with Visual C++ then
  you will need an assembler. This is worth doing because it will result in
@@ -25,6 +26,7 @@
 
   * Microsoft MASM (aka "ml")
   * Free Netwide Assembler NASM.
+  * WASM
 
  MASM was at one point distributed with VC++. It is now distributed with some
  Microsoft DDKs, for example the Windows NT 4.0 DDK and the Windows 98 DDK. If
@@ -37,6 +39,8 @@
  may also work. It is available from many places, see for example:
  http://www.kernel.org/pub/software/devel/nasm/binaries/win32/
  The NASM binary nasmw.exe needs to be installed anywhere on your PATH.
+ 
+ WASM is part of WATCOM and Open Watcom.
 
  If you are compiling from a tarball or a CVS snapshot then the Win32 files
  may well be not up to date. This may mean that some "tweaking" is required to
@@ -194,6 +198,24 @@
  "bc" is not provided in older Cygwin distribution.  This causes a
  non-fatal error in "make test" but is otherwise harmless.  If
  desired and needed, GNU bc can be built with Cygwin without change.
+
+ WATCOM C/C++ 11.0 and Open Watcom 1.0
+ -------------------------------------
+
+ Currently, OpenSSL will only compile to a static library with Watcom.
+
+ * Configure for building with Watcom:
+   > perl Configure WAT-WIN32
+
+   or WAT-NT for the NT-only features.
+
+ * Create the appropriate makefile
+   > ms\do_wat
+
+ * Build
+   > wmake -f ms\wat32-lib.mak
+   
+   or watnt-lib.mak for NT.
 
 
  Installation
diff -ur openssl-0.9.7-stable-SNAP-20021203\util\mk1mf.pl 
openssl-0.9.7-stable-SNAP-20021203-work\util\mk1mf.pl
--- openssl-0.9.7-stable-SNAP-20021203\util\mk1mf.pl    Tue Dec 03 15:03:04 2002
+++ openssl-0.9.7-stable-SNAP-20021203-work\util\mk1mf.pl       Wed Dec 04 21:46:17 
+2002
@@ -35,6 +35,8 @@
        "BC-NT",   "Borland C++ 4.5 - Windows NT",
        "BC-W31",  "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING",
        "BC-MSDOS","Borland C++ 4.5 - MSDOS",
+       "WAT-NT",  "Watcom C/C++ 11.0/Open Watcom - Windows NT ONLY",
+       "WAT-WIN32",  "Watcom C/C++ 11.0/Open Watcom - Windows NT or 9x",
        "linux-elf","Linux elf",
        "ultrix-mips","DEC mips ultrix",
        "FreeBSD","FreeBSD distribution",
@@ -172,6 +174,12 @@
        $msdos=1;
        require 'BC-16.pl';
        }
+elsif (($platform eq "WAT-WIN32") || ($platform eq "WAT-NT"))
+       {
+       $watcom=1;
+       $NT = 1 if $platform eq "WAT-NT";
+       require 'WAT-32.pl';
+       }
 elsif ($platform eq "FreeBSD")
        {
        require 'unix.pl';
@@ -385,6 +393,63 @@
 #############################################
 EOF
 
+if ($watcom)
+       {
+       $rules=<<"EOF";
+all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe
+
+banner: .SYMBOLIC
+$banner
+
+\$(TMP_D): .SYMBOLIC
+       \$(MKDIR) \$(TMP_D)
+# NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
+#\$(BIN_D): .SYMBOLIC
+#      \$(MKDIR) \$(BIN_D)
+#
+#\$(TEST_D): .SYMBOLIC
+#      \$(MKDIR) \$(TEST_D)
+
+\$(LIB_D): .SYMBOLIC
+       \$(MKDIR) \$(LIB_D)
+
+\$(INCO_D): \$(INC_D)
+       \$(MKDIR) \$(INCO_D)
+
+\$(INC_D): .SYMBOLIC
+       \$(MKDIR) \$(INC_D)
+
+headers: \$(HEADER) \$(EXHEADER) .SYMBOLIC
+       %null
+
+lib: \$(LIBS_DEP) .SYMBOLIC
+       %null
+
+exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep .SYMBOLIC
+       %null
+
+install: .SYMBOLIC
+       \$(MKDIR) \$(INSTALLTOP)
+       \$(MKDIR) \$(INSTALLTOP)${o}bin
+       \$(MKDIR) \$(INSTALLTOP)${o}include
+       \$(MKDIR) \$(INSTALLTOP)${o}include${o}openssl
+       \$(MKDIR) \$(INSTALLTOP)${o}lib
+       \$(CP) \$(INCO_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include${o}openssl
+       \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin
+       \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib
+       \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib
+
+clean: .SYMBOLIC
+       \$(RM) \$(TMP_D)$o*.*
+
+vclean: .SYMBOLIC
+       \$(RM) \$(TMP_D)$o*.*
+       \$(RM) \$(OUT_D)$o*.*
+
+EOF
+       }
+else
+       {
 $rules=<<"EOF";
 all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe
 
@@ -435,6 +500,7 @@
        \$(RM) \$(OUT_D)$o*.*
 
 EOF
+       }
     
 my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
 $platform_cpp_symbol =~ s/-/_/g;
@@ -749,7 +815,7 @@
                if ($n++ == 2)
                        {
                        $n=0;
-                       $ret.="\\\n\t";
+                       $ret.=($watcom) ? "\&\n\t" : "\\\n\t";
                        }
                if (($_ =~ /bss_file/) && ($postfix eq ".h"))
                        { $pf=".c"; }
@@ -811,7 +877,12 @@
        $target =~ s/\//$o/g if $o ne "/";
        $source =~ s/\//$o/g if $o ne "/";
        $ret ="$target: \$(SRC_D)$o$source\n\t";
-       $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
+       $ret.="\$(CC) ${ofile}$target $ex_flags ";
+       if (!$watcom)
+               {
+               $ret.="-c ";
+               }
+       $ret.="\$(SRC_D)$o$source\n\n";
        return($ret);
        }
 
perl util\mkfiles.pl >MINFO
rem perl util\mk1mf.pl WAT-MSDOS no-sock >ms\msdos.mak
rem perl util\mk1mf.pl WAT-W31-32 >ms\w31.mak
rem perl util\mk1mf.pl dll WAT-W31-32 >ms\w31dll.mak
perl util\mk1mf.pl no-asm WAT-WIN32 >ms\wat32-lib.mak
perl util\mk1mf.pl no-asm WAT-NT >ms\watnt-lib.mak
rem perl util\mk1mf.pl dll no-asm WAT-WIN32 >ms\ntdll.mak
rem perl util\mk1mf.pl no-asm WAT-CE >ms\ce.mak
rem perl util\mk1mf.pl dll no-asm WAT-CE >ms\cedll.mak

rem rem perl util\mkdef.pl 16 libeay > ms\libeay16.def
rem perl util\mkdef.pl 32 libeay > ms\libeay32.def
rem rem perl util\mkdef.pl 16 ssleay > ms\ssleay16.def
rem perl util\mkdef.pl 32 ssleay > ms\ssleay32.def

Reply via email to