I've investigated various ways of building OpenSSL (release 0.9.8) for Win32 with gcc.
There are at least three ways to do this 1. Using mingw32 compiler (from http://www.mingw.org) 2. Using cygwin compiler with -mno-cygwin switch to create executables which do not depend on cygwin.dll 3. Using cross-compiler on some Unix system. I've used cross-compiler included in Debian GNU/Linux ver./g 3.1 (sarge) as package mingw32 Resulting libraries are in all cases compatible with Microsoft Visual C. There is common opinion that mingw32 cannot create .lib libraries. It is wrong. It just names them differently. If you feed microsoft .lib file to Unix file command on any unix system around, it would report "Current ar archive". So, if you rename libsomething.a, created by mingw32 to something.lib, MSVC would be quite happy with it, and vice versa. All three ways are quite easy to get working. 1. Using mingw32 There is a batch file ms/mingw.bat in OpenSSL distribution. As I could understand from the discussion in openssl mailing lists, it is mostly unmaintained and is somewhat behind current state of code. Although it took few minutes for me to fix it. So, I decide to use more busy road and use `perl Configure mingw shared' to do a Unix-style build. It requires minor modification of Configure script - it thinks that unix-style builds are possible for mingw only if current perl is a CYGWIN one. --- $IsMK1MF=1 if ($target eq "mingw" && $^O ne "cygwin"); --- I think that this is wrong assumption. One can use ActiveState Perl while having all the rest of necessary Cygwin utilities installed, or one can use other set of POSIX utilities available. So, I've just commented out this line. More robust test can be written. For example, we can test for SHELL environment variable matching regular expression /sh$/. Both CYGWIN and MSys shells set it, and if this test is documented, user can set it manually, if he prefers to run `perl Configure' from cmd.exe, but is sure that he has necessary POSIX utilities. This way requires some POSIX utilites (such as rm, mv and pwd) to be available. There is a collection of such utilities, available on mingw site, called MSys (Minimal SYStem). Unfortunately, version of MSys which I use doesn't include pwd as standalone utility. There is shell builtin pwd, but it seems to not be enough for OpensSSL `make links' target. I've solved this problem by creating file pwd.bat somewhere in my path, which contains just two letters: 'cd'. Of course, command.com/cmd.exe cd command would output current directory using DOSish backslashes as separator. But mingw32 utilities and make seems to be happy with it. If YOU are not so happy, you can use following small C program: ---- start pwd.c -------- #include <unistd.h> #include <stdio.h> int main(int argc,char **argv) { char buffer[4096]; char *p; if (!getcwd(buffer,4096)) { perror("pwd"); return 1; } for (p=buffer;*p;p++) { if (*p=='\\') *p='/'; } printf("%s\n",buffer); return 0; } ---- end pwd.c ---------- 2. Using CYGWIN suite. This is supported way to compile. Only problem I've encountered is that Configure expects that one would use cygwin perl for cygwin compile, and I've ActivePerl installed on the machine where I've made this compilation. Solution, described above for MSys works here too. Cygwin have more complete set of POSIX commands, so pwd hack described above is not need. 3. Using cross-compiler. GNU C cross-compilers can be invoked in two ways 1. Using -B option to gcc 2. Using name which looks like <architecture>-<system>-gcc, in this case i586-mingw32msvc-gcc. I recommend using the second way, because we need to call cross-versions of some binutils programs, such as ranlib, and they do not have -B option. Anyway in both cases we need to add additional target to Configure. I've added following elemet for Configure %table array: "mingw-cross", "i586-mingw32msvc-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:i586-mingw32msvc-ranlib", Line is split here for clarity, using correct perl syntax to concatenate it back, so it may be just cut'n'pasted from here. This solution can be further improved - here there is hardcoded architecture-system prefix for compiler and ranlib. This prefix can vary from installation to installation, so it is better to use some varible substitution. After doing this modification, I've found out that everything compiles clearly, but all the executables do not have .exe suffix. This is caused by following line in Configure: $exe_ext=".exe" if ($target eq "Cygwin" || $target eq "DJGPP" || $target eq "mingw"); I've changed the last condition to $target =~ m/^mingw/ So, it would work for any target STARTED with mingw. After this modification OpenSSL compile cleanly under Debian and after that make test runs successfully on Windows. Sincerely yours, Victor Wagner. ______________________________________________________________________ OpenSSL Project http://www.openssl.org Development Mailing List [email protected] Automated List Manager [EMAIL PROTECTED]
