This patch is against version openssl-1.0.0d.
Please find attached a patch that works for me. Works means it builds without error, the test.bat executes the tests ok and even the "make install" works to some degree. It has also been test built against "zlib zlib-dynamic" options. Background to this work. This work has been done to provide the QtJambi project with a MinGW based build, this project are Java bindings library for the GUI / platform toolkit Qt. Due to the nature and complexity of the resulting project (a collection of multiple open source libraries end up loaded into a Java JVM) toolchain compatibility and interoperability is critical to this project. This patch should be tested against other MinGW build environments, such as using MinGW under CYGWIN shell or MSYS shell. To make sure that process is not broken, also to see if the ms/mingw32.bat script still works for them. But I guess no one builds this way when they have a bash shell. So maybe this batch file can be exclusively for he purpose of building with MinGW from cmd.exe. $ git diff | diffstat Configure | 11 +++++++++-- INSTALL.W32 | 22 ++++++++++++++++++++++ ms/mingw32.bat | 41 ++++++++++++++++++++++++++++++++--------- ms/test.bat | 2 ++ util/mk1mf.pl | 7 +++---- util/pl/Mingw32.pl | 10 ++++++---- 6 files changed, 74 insertions(+), 19 deletions(-) File Notes: Configure - This includes MinGW64 additions but another patch/ticket will be opened for that target. I have used the term "native-mingw" to mean from cmd.exe and without access to any Unix like shell. Compile options brought roughly info line with those in util/pl/Mingw32.pl however they are on the new target "native-mingw" so should not affect anyone else. INSTALL.W32 - Tried to update some documentation about mingw to clarify builds with Unix like shell (CYGWIN/MSYS) to those without. ms/mingw32.bat - This tries to detect if a bash.exe is present to setup the correct argument to "perl Configure ..." this needs proper testing with MinGW builds under CYGWIN/MSYS. There is provision for manually setting up debug builds by editing the top of the mingw32.bat file, see the comments. Additional errorlevel checks are put in place to fail upon any error with any part of the process. It does not seem necessary at all to perform any of the ASM generation since the mk1mf.pl has been fixed to do the correct thing now. ms/test.bat - This has been updated to allow optional first argument as the directory to change into before executing the test EXE files. util/mk1mf.pl - Multiple fixes here. Fix the "test" target to not execute a "cd out" as one command and then run "..\ms\test" as another command. I don't think this even works on Unix shell systems, you'd need to put them on the same line with a semicolon for it to work. But on Windows it is more complicated so to make the "make test" work out-the-box the directory to change into is now passed as the first argument to the test.bat file. Fix the "install" target to not have the shell glob pattern *.[ch] for installing the include files. There are no *.c file to install. The Windows "copy" command does not understand the *.[ch] glob syntax. The Windows "copy" command returns error status of no files were found to copy. So the *.c has been removed, with just *.h remaining. util/pl/Mingw32.pl - Compile options tweaked. Missing $asmtype='gaswin', maybe this is the reason why ms/mingw32.bat manually generated the ASM, since the resulting ms/mingw32a.mak Makefile is broken with working out-the-box without $asmtype being set. Added $exep='.exe' since the "make install" breaks without it and the linker auto-corrects the resulting exe name so doesn't care either way. Darryl
diff --git a/Configure b/Configure index 429ab2e..ccfa30c 100755 --- a/Configure +++ b/Configure @@ -506,6 +506,9 @@ my %table=( # MinGW "mingw", "gcc:-mno-cygwin -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -fomit-frame-pointer -O3 -march=i486 -Wall::-D_MT:MINGW32:-lws2_32 -lgdi32 -lcrypt32:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts} EXPORT_VAR_AS_FN:${x86_asm}:coff:win32:cygwin-shared:-D_WINDLL -DOPENSSL_USE_APPLINK:-mno-cygwin:.dll.a", +# *-native-mingw means without Bash (no CYGWIN, no MSYS, no bash, no sh), see ms/mingw32.bat +"debug-native-mingw", "gcc:-mno-cygwin -DL_ENDIAN -DDSO_WIN32 -DWIN32_LEAN_AND_MEAN -g2 -ggdb -march=i486 -Wall::-D_MT:MINGW32:-lws2_32 -lgdi32 -lcrypt32:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts} EXPORT_VAR_AS_FN:${x86_asm}:coff:win32:cygwin-shared:-D_WINDLL -DOPENSSL_USE_APPLINK:-mno-cygwin:.dll.a", +"native-mingw", "gcc:-mno-cygwin -DL_ENDIAN -DDSO_WIN32 -DWIN32_LEAN_AND_MEAN -fomit-frame-pointer -O3 -march=i486 -Wall::-D_MT:MINGW32:-lws2_32 -lgdi32 -lcrypt32:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts} EXPORT_VAR_AS_FN:${x86_asm}:coff:win32:cygwin-shared:-D_WINDLL -DOPENSSL_USE_APPLINK:-mno-cygwin:.dll.a", # As for OPENSSL_USE_APPLINK. Applink makes it possible to use .dll # compiled with one compiler with application compiled with another # compiler. It's possible to engage Applink support in mingw64 build, @@ -514,6 +517,8 @@ my %table=( # non-mingw64 run-time environment. And as mingw64 is always consistent # with itself, Applink is never engaged and can as well be omitted. "mingw64", "gcc:-mno-cygwin -DL_ENDIAN -O3 -Wall -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE::-D_MT:MINGW64:-lws2_32 -lgdi32 -lcrypt32:SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:${x86_64_asm}:mingw64:win32:cygwin-shared:-D_WINDLL:-mno-cygwin:.dll.a", +"debug-native-mingw64", "gcc:-mno-cygwin -DL_ENDIAN -DDSO_WIN32 -DWIN32_LEAN_AND_MEAN -g2 -ggdb -Wall -DUNICODE -D_UNICODE::-D_MT:MINGW64:-lws2_32 -lgdi32 -lcrypt32:SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:${x86_64_asm}:mingw64:win32:cygwin-shared:-D_WINDLL:-mno-cygwin:.dll.a", +"native-mingw64", "gcc:-mno-cygwin -DL_ENDIAN -DDSO_WIN32 -DWIN32_LEAN_AND_MEAN -fomit-frame-pointer -O3 -Wall -DUNICODE -D_UNICODE::-D_MT:MINGW64:-lws2_32 -lgdi32 -lcrypt32:SIXTY_FOUR_BIT RC4_CHUNK_LL DES_INT EXPORT_VAR_AS_FN:${x86_64_asm}:mingw64:win32:cygwin-shared:-D_WINDLL:-mno-cygwin:.dll.a", # UWIN "UWIN", "cc:-DTERMIOS -DL_ENDIAN -O -Wall:::UWIN::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${no_asm}:win32", @@ -588,6 +593,8 @@ my @MK1MF_Builds=qw(VC-WIN64I VC-WIN64A debug-VC-WIN64I debug-VC-WIN64A VC-NT VC-CE VC-WIN32 debug-VC-WIN32 BC-32 + debug-native-mingw native-mingw + debug-native-mingw64 native-mingw64 netware-clib netware-clib-bsdsock netware-libc netware-libc-bsdsock); @@ -1038,7 +1045,7 @@ foreach (sort @experimental) my $IsMK1MF=scalar grep /^$target$/,@MK1MF_Builds; -$exe_ext=".exe" if ($target eq "Cygwin" || $target eq "DJGPP" || $target =~ /^mingw/); +$exe_ext=".exe" if ($target eq "Cygwin" || $target eq "DJGPP" || $target =~ /^(native-mingw|mingw)/); $exe_ext=".nlm" if ($target =~ /netware/); $exe_ext=".pm" if ($target =~ /vos/); $openssldir="/usr/local/ssl" if ($openssldir eq "" and $prefix eq ""); @@ -1111,7 +1118,7 @@ my ($prelflags,$postlflags)=split('%',$lflags); if (defined($postlflags)) { $lflags=$postlflags; } else { $lflags=$prelflags; undef $prelflags; } -if ($target =~ /^mingw/ && `$cc --target-help 2>&1` !~ m/\-mno\-cygwin/m) +if ($target =~ /^(native-mingw|mingw)/ && `$cc --target-help 2>&1` !~ m/\-mno\-cygwin/m) { $cflags =~ s/\-mno\-cygwin\s*//; $shared_ldflag =~ s/\-mno\-cygwin\s*//; diff --git a/INSTALL.W32 b/INSTALL.W32 index d23c4ba..a54a5d8 100644 --- a/INSTALL.W32 +++ b/INSTALL.W32 @@ -165,6 +165,17 @@ $ make test $ make install + To build the MinGW version (native Windows) without Cygwin from cmd.exe: + + $ set MAKE=mingw32-make + $ ms\mingw32.bat + [...] + $ mingw32-make + [...] + $ mingw32-make -f ms\mingw32a.mak test + [...the install below may not install *.dll...] + $ mingw32-make -f ms\mingw32a.mak install + Cygwin Notes: "make test" and normal file operations may fail in directories @@ -176,6 +187,17 @@ non-fatal error in "make test" but is otherwise harmless. If desired and needed, GNU bc can be built with Cygwin without change. + MinGW Notes: + + There are two types of MinGW builds: + * those with a Unix like shell available. These builds are much like + all Unix builds and are expected to happen under a CYGWIN/MSYS shell. + * those without a Unix like shell available. *-native-mingw but with + the MinGW toolchain available on the %PATH%, as well as perl.exe. + These builds use the batch file ms\mingw32.bat. + It is possible to build debug versions by editing the top of + mingw32.bat as per the instructions in there. + GNU C (MinGW/MSYS) ------------- diff --git a/ms/mingw32.bat b/ms/mingw32.bat index 06b5733..295c114 100644 --- a/ms/mingw32.bat +++ b/ms/mingw32.bat @@ -1,12 +1,33 @@ @rem OpenSSL with Mingw32+GNU as @rem --------------------------- -perl Configure mingw %1 %2 %3 %4 %5 %6 %7 %8 +@rem Swap these 2 settings below for a debuging build +set build_debug= +set build_dirext= +@rem set build_debug=debug- +@rem set build_dirext=.dbg + +@rem we try to detect if we are mingw or native-mingw by the presence of bash.exe on the PATH +bash -c "exit 0" 2>NUL: +@if errorlevel 1 goto native-mingw +set build_flavour=%build_debug%mingw +goto configure + +:native-mingw +set build_flavour=%build_debug%native-mingw + +:configure +echo BUILD_FLAVOR=%build_flavour% +perl Configure %build_flavour% %1 %2 %3 %4 %5 %6 %7 %8 +@if errorlevel 1 goto end @echo off perl -e "exit 1 if '%1' eq 'no-asm'" -if errorlevel 1 goto noasm +@if errorlevel 1 goto noasm +@rem always skip ASM generation here for native-mingw since the makefile knows how to build them +if "%build_flavour%"=="native-mingw" goto noasm +if "%build_flavour%"=="debug-native-mingw" goto noasm echo Generating x86 for GNU assember @@ -65,24 +86,26 @@ cd ..\..\.. echo Generating makefile perl util\mkfiles.pl >MINFO +@if errorlevel 1 goto end perl util\mk1mf.pl gaswin Mingw32 >ms\mingw32a.mak +@if errorlevel 1 goto end echo Generating DLL definition files perl util\mkdef.pl 32 libeay >ms\libeay32.def -if errorlevel 1 goto end +@if errorlevel 1 goto end perl util\mkdef.pl 32 ssleay >ms\ssleay32.def -if errorlevel 1 goto end +@if errorlevel 1 goto end rem copy ms\tlhelp32.h outinc echo Building the libraries mingw32-make -f ms/mingw32a.mak -if errorlevel 1 goto end +@if errorlevel 1 goto end echo Generating the DLLs and input libraries -dllwrap --dllname libeay32.dll --output-lib out/libeay32.a --def ms/libeay32.def out/libcrypto.a -lws2_32 -lgdi32 -if errorlevel 1 goto end -dllwrap --dllname libssl32.dll --output-lib out/libssl32.a --def ms/ssleay32.def out/libssl.a out/libeay32.a -if errorlevel 1 goto end +dllwrap --dllname libeay32.dll --output-lib out%build_dirext%/libeay32.a --def ms/libeay32.def out%build_dirext%/libcrypto.a -lws2_32 -lgdi32 -lcrypt32 +@if errorlevel 1 goto end +dllwrap --dllname libssl32.dll --output-lib out%build_dirext%/libssl32.a --def ms/ssleay32.def out%build_dirext%/libssl.a out%build_dirext%/libeay32.a +@if errorlevel 1 goto end echo Done compiling OpenSSL diff --git a/ms/test.bat b/ms/test.bat index f490546..b48cff0 100755 --- a/ms/test.bat +++ b/ms/test.bat @@ -1,5 +1,7 @@ @echo off +if not "%1"=="" cd "%1" + set test=..\ms set opath=%PATH% PATH=..\ms;%PATH% diff --git a/util/mk1mf.pl b/util/mk1mf.pl index afe8c73..4ab01e0 100755 --- a/util/mk1mf.pl +++ b/util/mk1mf.pl @@ -549,16 +549,15 @@ install: all \$(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) \"\$(INCO_D)${o}*.h\" \"\$(INSTALLTOP)${o}include${o}openssl\" + \$(CP) \"\$(BIN_D)$o\$(E_EXE)$exep\" \"\$(INSTALLTOP)${o}bin\" \$(MKDIR) \"\$(OPENSSLDIR)\" \$(CP) apps${o}openssl.cnf \"\$(OPENSSLDIR)\" $extra_install test: \$(T_EXE) - cd \$(BIN_D) - ..${o}ms${o}test + ms${o}test \$(BIN_D) clean: \$(RM) \$(TMP_D)$o*.* diff --git a/util/pl/Mingw32.pl b/util/pl/Mingw32.pl index fe3fb27..613cff7 100644 --- a/util/pl/Mingw32.pl +++ b/util/pl/Mingw32.pl @@ -17,9 +17,9 @@ $mkdir='mkdir'; $cc='gcc'; if ($debug) - { $cflags="-DL_ENDIAN -DDSO_WIN32 -g2 -ggdb"; } + { $cflags="-DL_ENDIAN -DDSO_WIN32 -DWIN32_LEAN_AND_MEAN -g2 -ggdb -march=i486 -Wall"; } else - { $cflags="-DL_ENDIAN -DDSO_WIN32 -fomit-frame-pointer -O3 -mcpu=i486 -Wall"; } + { $cflags="-DL_ENDIAN -DDSO_WIN32 -DWIN32_LEAN_AND_MEAN -fomit-frame-pointer -O3 -march=i486 -Wall"; } if ($gaswin and !$no_asm) { @@ -46,6 +46,7 @@ if ($gaswin and !$no_asm) $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DOPENSSL_BN_ASM_PART_WORDS"; } +$asmtype='gaswin' if($gaswin); $obj='.o'; $ofile='-o '; @@ -54,8 +55,9 @@ $ofile='-o '; $link='${CC}'; $lflags='${CFLAGS}'; $efile='-o '; -$exep=''; -$ex_libs="-lws2_32 -lgdi32"; +$exep='.exe'; +# -lcrypt32 added due to engines/e_capi.c +$ex_libs="-lws2_32 -lgdi32 -lcrypt32"; # static library stuff $mklib='ar r';