It is not too difficult to find mingw cross compiler to produce windows binaries from linux, except that it does not include the fortran part (g77, or gfortran for 4.*). Here is a relatively simple script which can build gcc, g77 (and other compilers as well, I guess: the difficult part is to build the bootstrap gcc + system headers/libs; once you get this right, all the other parts are much easier).
The script has the following characteristics:
- It needs the tarballs in the archives directory
- It will build everything in the build directory
- It will install everything in the install directory
- By default, the above directories are created in the directory of the script
- It does not build gcc in the sources, but in separate build directories, which is the advised way to do it
It is not too difficult to do it by hand once you know exactly what to do. The basic scheme is the following:
- Build the binutils with target mingw32 and install it in $PREFIX (e.g. –prefix=$PREFIX –target=mingw32).
- Add $PREFIX in your path.
- Copy the include path content of both w32api and mingw32-runtime in $PREFIX/mingw32/include
- Create an empty build directory for the bootstrap gcc, and inside it, build a minimal gcc (e.g. –enable-languages=c) with the same options than binutils for target and prefix.
- The tricky part: once the bootstrapped gcc is built, go back into w32api directory, and configure it with *host* as mingw32 and prefix as $PREFIX/mingw32: configure –prefix=$PREFIX/mingw32 –host=mingw32. Build and install it
- In the parent directory of w32api build directory, make a soft link from the w32api build directory and w32api (e.g. ln -s w32api-3.11 w32api). I think that this is a bug, but wo doing this, mingw32 won’t pick up the w32api headers (it does not look in $PREFIX/target/include).
- Make sure that the extracted archive of mingw runtime is in the parent directory of w32api
- configure, build and install mingw runtime the exact same way as w32api (same host, same prefix)
- now, you can build the final gcc, g77, etc… by just using –target=mingw32.
I managed to build both gcc 3.* and 4.* series for C and fortran using the sources provided on mingw website. I have not extensively tested the built compilers, but I managed to compile non trivial programs with both g77 and gfortran (blas, lapack). The only thing not working properly is dlltool, to produce the .lib from the dll: using the import library with visual studio will crash, but this does not seem to work with mingw32 on windows either (e.g. this is a bug in mingw).