Cross-compiling Mono for Windows

Starting with Mono from svn revision 109671 (or version 2.2+) it is now possible to compile Mono for Windows on your Linux machine. To do it you will need to provide a MinGW (http://mingw.org/) environment for your Linux distribution and several compile and runtime dependencies for Mono. Distribution-specific instructions follow below. Once you have your MinGW environment set up, go to your Mono source directory and type:

./build-mingw32.sh

The above command assumes that your cross-compilation environment is installed in the /opt/cross directory and that the MinGW target is i386-mingw32msvc. If your environment is in another directory, you can specify it by passing the full path in the first parameter to the above script. If your MinGW uses a different target, please pass it to the script as the second parameter. Building will take some time since the mono runtime needs to be built twice (once for the target Windows platform, the second time to build the compilers and class libraries). Once the process is done, you will find a zip file in the same directory where the build script lives with the name following the pattern:

mono-win32-X.Y-BRANCH-REVISION

where:

* X.Y - major.minor Mono version
* BRANCH - Mono branch or tarball if svn branch could not have been detected
* REVISION - Mono svn revision or rUNKNOWN if it wasn't possible to determine the revision number

The zip file must be unpacked in the root directory of any Windows disk drive and you will be able to find the Mono installation in the directory whose name follows the pattern:

Z:\mono-X.Y-BRANCH-REVISION

where:

* Z - the letter identifying the Windows disk drive where you unpacked the zip
* X.Y - major.minor mono version
* BRANCH - Mono branch or tarball if svn branch could not have been detected
* REVISION - Mono svn revision or rUNKNOWN if it wasn't possible to determine the revision number

If you want to permanently put a path to the Mono bin directory from the above package in your global PATH environment variable, but you're worried you will have to update it every time you compile new package from another Mono revision, do not despair - there is a way to create symlinks on Windows 2000 onwards if your disk is formatted with the NTFS filesystem. Install this utility (http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx) and issue the following command from the cmd prompt:

junction Z:\mono-trunk Z:\mono-X.Y-BRANCH-REVISION

where the elements of the path are described above. After that you can add the z:\mono-trunk\bin path to your system PATH variable and just update the symlink every time you install new version of Mono built from trunk.

List of packages needed for cross-compiling

Not all of the packages are strictly necessary, but having them around in your mingw environment can't hurt. If you're not using any distribution-specific package, you will need to unpack the packages in the top-level directory of your MinGW installation (e.g. /opt/cross/):

* glib-2.16.5.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.16/glib-2.16.5.zip)
* glib-dev-2.16.5.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.16/glib-dev-2.16.5.zip) 
* zlib123-dll.zip (http://www.zlib.net/zlib123-dll.zip)
* pkg-config-0.23-2.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config-0.23-2.zip)
* libpng-1.2.29.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/libpng-1.2.29.zip)
* libpng-dev-1.2.29.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/libpng-dev-1.2.29.zip)
* libtiff-dev-3.8.2.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/libtiff-dev-3.8.2.zip)
* libjpeg-6b-bin.zip (http://heanet.dl.sourceforge.net/sourceforge/gnuwin32/libjpeg-6b-bin.zip)
* libjpeg-6b-lib.zip (http://heanet.dl.sourceforge.net/sourceforge/gnuwin32/libjpeg-6b-lib.zip)
* giflib-4.1.4-bin.zip (http://heanet.dl.sourceforge.net/sourceforge/gnuwin32/giflib-4.1.4-bin.zip)
* giflib-4.1.4-lib.zip (http://heanet.dl.sourceforge.net/sourceforge/gnuwin32/giflib-4.1.4-lib.zip)
* freetype-2.3.6.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/freetype-2.3.6.zip)
* freetype-dev-2.3.6.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/freetype-dev-2.3.6.zip)
* fontconfig-2.4.2-tml-20071015.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/fontconfig-2.4.2-tml-20071015.zip)
* fontconfig-dev-2.4.2-tml-20071015.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/fontconfig-dev-2.4.2-tml-20071015.zip)
* expat-2.0.0.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/expat-2.0.0.zip)
* proxy-libintl-20080612.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/proxy-libintl-20080612.zip)
* ettext-runtime-0.17-1.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime-0.17-1.zip)
* gettext-runtime-dev-0.17-1.zip (http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime-dev-0.17-1.zip)

The list is valid as of August 5th, 2008. You can substitute the above packages with newer versions (if supported by Mono).

Distribution-specific instructions

openSUSE

With openSUSE all you need to do in order to satisfy all the requirements is to add two repositories using Yast:

* http://download.opensuse.org/repositories/Mono:/Community/
* http://download.opensuse.org/repositories/CrossToolchain:/mingw/

Note that the above URLs do NOT specify the final repository - you need to visit them and pick the version of openSUSE you are using (e.g. http://download.opensuse.org/repositories/Mono:/Community/openSUSE_10.3/) After configuring and refreshing the repositories in Yast, proceed to install the following packages:

* cross-mingw-gcc
* cross-mono-build-dependencies

And that's it! You're set to compile as described above!