My goal: compile opensc, openssl and putty for windows, but using linux and mingw (on i686 machine, debian sarge). that way opensc could build nightly binary pacakges for windows.
so, here is a patch for openssl, so it can be compiled with mingw under linux. no big changes, mostly using the existing code, changed paths from \ to / and used the i586-mingw32msvc-* tools (thats how they are called on debian gnu/linux). install procedure: wget http://www.openssl.org/source/openssl-0.9.8-beta5.tar.gz tar xfvz openssl-0.9.8-beta5.tar.gz cd openssl-0.9.8-beta5 patch -p1 < ../diff5 sh -x ms/mingw32.sh mkdir -p /opt/win32/openssl mkdir /opt/win32/openssl/bin mkdir /opt/win32/openssl/lib mkdir /opt/win32/openssl/include mkdir /opt/win32/openssl/include/openssl cp outinc/openssl/* /opt/win32/openssl/include/openssl cp out/*.lib /opt/win32/openssl/lib cp *.dll /opt/win32/openssl/bin cp out/openssl.exe /opt/win32/openssl/bin I can't test the result well today (no windows here),but will do so tomorrow. the resulting binaries are located at http://www.opensc.org/files/testing/openssl-0.9.8-beta5-win32.tar.gz I don't know the openssl build system well, so please help me to fix any bugs I might have in this patch. (it doesn't change any existing code, only adds new files and a mingwx option.) Thanks, Andreas
diff -udrNP openssl-0.9.8-beta4.orig/Configure openssl-0.9.8-beta4/Configure --- openssl-0.9.8-beta4.orig/Configure 2005-06-06 00:19:34.000000000 +0200 +++ openssl-0.9.8-beta4/Configure 2005-06-19 18:38:18.195835720 +0200 @@ -474,6 +474,9 @@ # MinGW "mingw", "gcc:-mno-cygwin -DL_ENDIAN -fomit-frame-pointer -O3 -march=i486 -Wall -D_WIN32_WINNT=0x333:::MINGW32:-lwsock32 -lgdi32:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts} EXPORT_VAR_AS_FN:${x86_coff_asm}:win32:cygwin-shared:-D_WINDLL -DOPENSSL_USE_APPLINK:-mno-cygwin -shared:.dll.a", +# MinGW cross compile +"mingwx", "i586-mingw32msvc-cc:-mno-cygwin -DL_ENDIAN -fomit-frame-pointer -O3 -march=i486 -Wall -D_WIN32_WINNT=0x333:::MINGW32:-lwsock32 -lgdi32:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts} EXPORT_VAR_AS_FN:${x86_coff_asm}:win32:cygwin-shared:-D_WINDLL -DOPENSSL_USE_APPLINK:-mno-cygwin -shared:.dll.a", + # UWIN "UWIN", "cc:-DTERMIOS -DL_ENDIAN -O -Wall:::UWIN::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${no_asm}:win32", @@ -908,9 +911,9 @@ my $IsMK1MF=scalar grep /^$target$/,@MK1MF_Builds; -$IsMK1MF=1 if ($target eq "mingw" && $^O ne "cygwin"); +$IsMK1MF=1 if ($target eq "mingw" && $^O ne "mingwx" && $^O ne "cygwin"); -$exe_ext=".exe" if ($target eq "Cygwin" || $target eq "DJGPP" || $target eq "mingw"); +$exe_ext=".exe" if ($target eq "Cygwin" || $target eq "DJGPP" || $target eq "mingw" || $target eq "mingwx"); $exe_ext=".pm" if ($target =~ /vos/); $openssldir="/usr/local/ssl" if ($openssldir eq "" and $prefix eq ""); $prefix=$openssldir if $prefix eq ""; diff -udrNP openssl-0.9.8-beta4.orig/Makefile openssl-0.9.8-beta4/Makefile --- openssl-0.9.8-beta4.orig/Makefile 2005-06-06 02:51:46.000000000 +0200 +++ openssl-0.9.8-beta4/Makefile 2005-06-19 18:38:24.904815800 +0200 @@ -11,11 +11,11 @@ SHLIB_VERSION_HISTORY= SHLIB_MAJOR=0 SHLIB_MINOR=9.8 -SHLIB_EXT= -PLATFORM=dist -OPTIONS= no-gmp no-krb5 no-mdc2 no-rc5 no-shared no-zlib no-zlib-dynamic -CONFIGURE_ARGS=dist -SHLIB_TARGET= +SHLIB_EXT=.dll.a +PLATFORM=mingwx +OPTIONS=386 no-gmp no-krb5 no-mdc2 no-rc5 no-shared no-sse2 no-zlib no-zlib-dynamic +CONFIGURE_ARGS=386 mingwx +SHLIB_TARGET=cygwin-shared # HERE indicates where this Makefile lives. This can be used to indicate # where sub-Makefiles are expected to be. Currently has very limited usage, @@ -59,16 +59,16 @@ # equal 4. # PKCS1_CHECK - pkcs1 tests. -CC= cc -CFLAG= -O +CC= i586-mingw32msvc-cc +CFLAG= -DOPENSSL_THREADS -DDSO_WIN32 -mno-cygwin -DL_ENDIAN -fomit-frame-pointer -O3 -march=i486 -Wall -D_WIN32_WINNT=0x333 -DOPENSSL_BN_ASM_PART_WORDS -DSHA1_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM DEPFLAG= -DOPENSSL_NO_GMP -DOPENSSL_NO_MDC2 -DOPENSSL_NO_RC5 PEX_LIBS= -EX_LIBS= -EXE_EXT= +EX_LIBS= -lwsock32 -lgdi32 +EXE_EXT= .exe ARFLAGS= AR=ar $(ARFLAGS) r -RANLIB= /usr/bin/ranlib -PERL= /usr/bin/perl +RANLIB= true +PERL= perl TAR= tar TARFLAGS= --no-recursion MAKEDEPPROG=makedepend @@ -83,20 +83,20 @@ # For x86 assembler: Set PROCESSOR to 386 if you want to support # the 80386. -PROCESSOR= +PROCESSOR= 386 # CPUID module collects small commonly used assembler snippets CPUID_OBJ= -BN_ASM= bn_asm.o -DES_ENC= des_enc.o fcrypt_b.o -AES_ASM_OBJ= aes_core.o aes_cbc.o -BF_ENC= bf_enc.o -CAST_ENC= c_enc.o -RC4_ENC= rc4_enc.o -RC5_ENC= rc5_enc.o -MD5_ASM_OBJ= -SHA1_ASM_OBJ= -RMD160_ASM_OBJ= +BN_ASM= bn86-cof.o co86-cof.o +DES_ENC= dx86-cof.o yx86-cof.o +AES_ASM_OBJ= ax86-cof.o +BF_ENC= bx86-cof.o +CAST_ENC= cx86-cof.o +RC4_ENC= rx86-cof.o +RC5_ENC= r586-cof.o +MD5_ASM_OBJ= mx86-cof.o +SHA1_ASM_OBJ= sx86-cof.o +RMD160_ASM_OBJ= rm86-cof.o # KRB5 stuff KRB5_INCLUDES= @@ -136,7 +136,7 @@ SHARED_SSL=libssl$(SHLIB_EXT) SHARED_LIBS= SHARED_LIBS_LINK_EXTS= -SHARED_LDFLAGS= +SHARED_LDFLAGS=-mno-cygwin -shared GENERAL= Makefile BASENAME= openssl diff -udrNP openssl-0.9.8-beta4.orig/crypto/opensslconf.h openssl-0.9.8-beta4/crypto/opensslconf.h --- openssl-0.9.8-beta4.orig/crypto/opensslconf.h 2005-06-06 02:51:46.000000000 +0200 +++ openssl-0.9.8-beta4/crypto/opensslconf.h 2005-06-19 18:38:24.960807288 +0200 @@ -2,6 +2,9 @@ /* WARNING: Generated automatically from opensslconf.h.in by Configure. */ /* OpenSSL was configured with the following options: */ +#ifndef OPENSSL_SYSNAME_MINGW32 +# define OPENSSL_SYSNAME_MINGW32 +#endif #ifndef OPENSSL_DOING_MAKEDEPEND #ifndef OPENSSL_NO_GMP @@ -18,6 +21,9 @@ #endif #endif /* OPENSSL_DOING_MAKEDEPEND */ +#ifndef OPENSSL_THREADS +# define OPENSSL_THREADS +#endif #ifndef OPENSSL_NO_DYNAMIC_ENGINE # define OPENSSL_NO_DYNAMIC_ENGINE #endif @@ -44,7 +50,7 @@ /* crypto/opensslconf.h.in */ /* Generate 80386 code? */ -#undef I386_ONLY +#define I386_ONLY #if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */ #if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR) @@ -57,6 +63,7 @@ #define OPENSSL_UNISTD <unistd.h> #undef OPENSSL_EXPORT_VAR_AS_FUNCTION +#define OPENSSL_EXPORT_VAR_AS_FUNCTION #if defined(HEADER_IDEA_H) && !defined(IDEA_INT) #define IDEA_INT unsigned int @@ -101,7 +108,7 @@ #if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H) #define CONFIG_HEADER_BN_H -#undef BN_LLONG +#define BN_LLONG /* Should we define BN_DIV2W here? */ @@ -120,7 +127,7 @@ #define CONFIG_HEADER_RC4_LOCL_H /* if this is defined data[i] is used instead of *data, this is a %20 * speedup on x86 */ -#undef RC4_INDEX +#define RC4_INDEX #endif #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) @@ -134,14 +141,14 @@ /* the following is tweaked from a config script, that is why it is a * protected undef/define */ #ifndef DES_PTR -#undef DES_PTR +#define DES_PTR #endif /* This helps C compiler generate the correct code for multiple functional * units. It reduces register dependancies at the expense of 2 more * registers */ #ifndef DES_RISC1 -#undef DES_RISC1 +#define DES_RISC1 #endif #ifndef DES_RISC2 @@ -155,7 +162,7 @@ /* Unroll the inner loop, this sometimes helps, sometimes hinders. * Very mucy CPU dependant */ #ifndef DES_UNROLL -#undef DES_UNROLL +#define DES_UNROLL #endif /* These default values were supplied by diff -udrNP openssl-0.9.8-beta4.orig/ms/mingw32.sh openssl-0.9.8-beta4/ms/mingw32.sh --- openssl-0.9.8-beta4.orig/ms/mingw32.sh 1970-01-01 01:00:00.000000000 +0100 +++ openssl-0.9.8-beta4/ms/mingw32.sh 2005-06-19 19:58:04.709175088 +0200 @@ -0,0 +1,98 @@ +#!/bin/sh + +# OpenSSL with Mingw32+GNU as +# --------------------------- + +set -e + +perl Configure 386 mingwx + +if test "$1" != "no-asm" +then + echo Generating x86 for GNU assember + + echo Bignum + cd crypto/bn/asm + perl bn-586.pl gaswin > bn-win32.s + perl co-586.pl gaswin > co-win32.s + cd ../../.. + + echo DES + cd crypto/des/asm + perl des-586.pl gaswin > d-win32.s + cd ../../.. + + echo crypt + cd crypto/des/asm + perl crypt586.pl gaswin > y-win32.s + cd ../../.. + + echo Blowfish + cd crypto/bf/asm + perl bf-586.pl gaswin > b-win32.s + cd ../../.. + + echo CAST5 + cd crypto/cast/asm + perl cast-586.pl gaswin > c-win32.s + cd ../../.. + + echo RC4 + cd crypto/rc4/asm + perl rc4-586.pl gaswin > r4-win32.s + cd ../../.. + + echo MD5 + cd crypto/md5/asm + perl md5-586.pl gaswin > m5-win32.s + cd ../../.. + + echo SHA1 + cd crypto/sha/asm + perl sha1-586.pl gaswin > s1-win32.s + cd ../../.. + + echo RIPEMD160 + cd crypto/ripemd/asm + perl rmd-586.pl gaswin > rm-win32.s + cd ../../.. + + echo RC5/32 + cd crypto/rc5/asm + perl rc5-586.pl gaswin > r5-win32.s + cd ../../.. + + echo CPUID + cd crypto/ + perl x86cpuid.pl gaswin > x86cpuid.s + cd .. + +fi + +echo Generating makefile +perl util/mkfiles.pl >MINFO +perl util/mk1mf.pl gaswin Mingw32-sh >ms/mingw32a.mak + +echo Generating DLL definition files +perl util/mkdef.pl 32 libeay >ms/libeay32.def +perl util/mkdef.pl 32 ssleay >ms/ssleay32.def + +# copy ms/tlhelp32.h outinc + +echo Building the libraries +make -f ms/mingw32a.mak + +echo Generating the DLLs and input libraries +i586-mingw32msvc-dlltool -d ms/libeay32.def -e out/libeay32.lib \ + -l libeay32.dll out/libcrypto.a +i586-mingw32msvc-cc -shared -o libeay32.dll out/libeay32.lib out/libcrypto.a \ + /usr/i586-mingw32msvc/lib/libwsock32.a \ + /usr/i586-mingw32msvc/lib/libgdi32.a +#dllwrap --dllname libeay32.dll --output-lib out/libeay32.a --def ms/libeay32.def out/libcrypto.a -lwsock32 -lgdi32 + +i586-mingw32msvc-dlltool -d ms/ssleay32.def -e out/libssl32.lib -l libssl32.dll out/libssl.a +i586-mingw32msvc-cc -shared -o libssl32.dll libeay32.dll out/libssl32.lib out/libssl.a +#dllwrap --dllname libssl32.dll --output-lib out/libssl32.a --def ms/ssleay32.def out/libssl.a out/libeay32.a + +echo Done compiling OpenSSL + diff -udrNP openssl-0.9.8-beta4.orig/util/mk1mf.pl openssl-0.9.8-beta4/util/mk1mf.pl --- openssl-0.9.8-beta4.orig/util/mk1mf.pl 2005-05-17 15:51:35.000000000 +0200 +++ openssl-0.9.8-beta4/util/mk1mf.pl 2005-06-19 18:38:18.204834352 +0200 @@ -27,6 +27,7 @@ "VC-CE", "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY", "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY", "Mingw32", "GNU C++ - Windows NT or 9x", + "Mingw32-sh", "GNU C++ - for Windows, but crosscompile from unix", "Mingw32-files", "Create files with DOS copy ...", "BC-NT", "Borland C++ 4.5 - Windows NT", "linux-elf","Linux elf", @@ -132,6 +133,10 @@ { require 'Mingw32.pl'; } +elsif ($platform eq "Mingw32-sh") + { + require 'Mingw32x.pl'; + } elsif ($platform eq "Mingw32-files") { require 'Mingw32f.pl'; @@ -598,6 +603,11 @@ $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/; $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src); } + if (($cpuid_asm_obj ne "") && ($_ eq "CRYPTO")) + { + $lib_obj =~ s/\s(\S*\/cpuid\S*)/ $1 \$(CPUID_OBJ)/; + $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src); + } $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj); $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)"; $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib); diff -udrNP openssl-0.9.8-beta4.orig/util/pl/Mingw32x.pl openssl-0.9.8-beta4/util/pl/Mingw32x.pl --- openssl-0.9.8-beta4.orig/util/pl/Mingw32x.pl 1970-01-01 01:00:00.000000000 +0100 +++ openssl-0.9.8-beta4/util/pl/Mingw32x.pl 2005-06-19 18:38:18.209833592 +0200 @@ -0,0 +1,104 @@ +#!/usr/local/bin/perl +# +# Mingw32x.pl -- Mingw cross compile from unix. +# + +$o='/'; +$cp='cp'; +$rm='rm -f'; +$mkdir='gmkdir'; + +$o='/'; +$cp='cp'; +$rm='rm'; +$mkdir='mkdir'; + +# C compiler stuff + +$cc='i586-mingw32msvc-cc'; +if ($debug) + { $cflags="-DL_ENDIAN -DDSO_WIN32 -g2 -ggdb"; } +else + { $cflags="-DL_ENDIAN -DDSO_WIN32 -fomit-frame-pointer -O3 -mtune=i486 -Wall"; } + +if ($gaswin and !$no_asm) + { + $bn_asm_obj='$(OBJ_D)/bn-win32.o'; + $bn_asm_src='crypto/bn/asm/bn-win32.s'; + $bnco_asm_obj='$(OBJ_D)/co-win32.o'; + $bnco_asm_src='crypto/bn/asm/co-win32.s'; + $des_enc_obj='$(OBJ_D)/d-win32.o $(OBJ_D)/y-win32.o'; + $des_enc_src='crypto/des/asm/d-win32.s crypto/des/asm/y-win32.s'; + $bf_enc_obj='$(OBJ_D)/b-win32.o'; + $bf_enc_src='crypto/bf/asm/b-win32.s'; +# $cast_enc_obj='$(OBJ_D)/c-win32.o'; +# $cast_enc_src='crypto/cast/asm/c-win32.s'; + $rc4_enc_obj='$(OBJ_D)/r4-win32.o'; + $rc4_enc_src='crypto/rc4/asm/r4-win32.s'; + $rc5_enc_obj='$(OBJ_D)/r5-win32.o'; + $rc5_enc_src='crypto/rc5/asm/r5-win32.s'; + $md5_asm_obj='$(OBJ_D)/m5-win32.o'; + $md5_asm_src='crypto/md5/asm/m5-win32.s'; + $rmd160_asm_obj='$(OBJ_D)/rm-win32.o'; + $rmd160_asm_src='crypto/ripemd/asm/rm-win32.s'; + $sha1_asm_obj='$(OBJ_D)/s1-win32.o'; + $sha1_asm_src='crypto/sha/asm/s1-win32.s'; + $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DOPENSSL_BN_ASM_PART_WORDS"; + } + + +$obj='.o'; +$ofile='-o '; + +# EXE linking stuff +$link='i586-mingw32msvc-cc'; +$lflags='${CFLAGS}'; +$efile='-o '; +$exep='.exe'; +$ex_libs="/usr/i586-mingw32msvc/lib/libwsock32.a /usr/i586-mingw32msvc/lib/libgdi32.a"; + +# static library stuff +$mklib='ar r'; +$mlflags=''; +$ranlib='i586-mingw32msvc-ranlib'; +$plib='lib'; +$libp=".a"; +$shlibp=".a"; +$lfile=''; + +$asm='i586-mingw32msvc-as'; +$afile='-o '; +#$bn_asm_obj=""; +#$bn_asm_src=""; +#$des_enc_obj=""; +#$des_enc_src=""; +#$bf_enc_obj=""; +#$bf_enc_src=""; + +sub do_lib_rule + { + local($obj,$target,$name,$shlib)[EMAIL PROTECTED]; + local($ret,$_,$Name); + + $target =~ s/\//$o/g if $o ne '/'; + $target="$target"; + ($Name=$name) =~ tr/a-z/A-Z/; + + $ret.="$target: \$(${Name}OBJ)\n"; + $ret.="\t\$(RM) -f $target\n"; + $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n"; + $ret.="\t\$(RANLIB) $target\n\n"; + } + +sub do_link_rule + { + local($target,$files,$dep_libs,$libs)[EMAIL PROTECTED]; + local($ret,$_); + + $file =~ s/\//$o/g if $o ne '/'; + $n=&bname($target); + $ret.="$target: $files $dep_libs\n"; + $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n"; + return($ret); + } +1;