HowTo build x86_64-pc-mingw32 cross-compiler<br>
<br>
Date /		Version /	Author<br>
2007-07-31  	1.0		Kai Tietz &lt;Kai.Tietz at onevision.com&gt;<br>
2007-08-20	1.1		Kai Tietz &lt;Kai.Tietz at onevision.com&gt;<br>
2007-08-21	1.2		NightStrike &lt;nightstrike at gmail.com&gt;<br>
<br>
This document describes how to build the amd64 mingw32 gcc toolchain as a cross-compiler on cygwin and unix shells.<br>
<br>
1. Download packages<br>
The following packages you need to download<br>
	- binutils 2.17.50 snapshot released after or equal to the 1st of July 2007.<br>
	- gcc version 4.3 snapshort released after or equal to the 1st of July 2007.<br>
	- current mingw-w64-snapshot available at https://sourceforge.net/projects/mingw-w64<br>
<br>
Now extract these tarballs to a temporary folder. E.g. use ~/w64src. For the tarballs with<br>
extension .tar.gz or .tgz use the following command to extract : tar -xzf &lt;tarball&gt;'.  For<br>
tarballs with extension .tar.bz2 or .tbz2 use the command 'tar -xjf &lt;tarball&gt;'.<br>
There are now three folders within you temporary folder: trunk, binutils, and gcc.<br>
<br>
<br>
<br>
2. Build type options<br>
<br>
You have at least two different choices to build the crosscompiler toolchain:<br>
 I)  Using standard settings of configure.<br>
 II) Using --prefix and --with-sysroot configuration<br>
<br>
  I assume that '/usr/local/' is the &lt;install-root&gt; for build type I, the path specified using --with-sysroot is <br>
  the root for type II.  For this example, it will be set to '/mypath'.<br>
<br>
<br>
<br>
3. Building binutils cross toolchain:<br>
  Step 1) Enter into the binutils root folder and generate a folder within (e.g.<br>
	'build'). Then enter into it.<br>
  Step 2 for I) Type '../configure --target=x86_64-pc-mingw32'<br>
  Step 2 for II) Type '../configure --target=x86_64-pc-mingw32 --prefix=/mypath --with-sysroot=/mypath'.<br>
  Step 3) Type 'make'<br>
  Step 4) Type 'make install'<br>
<br>
  Now copy the content of the folder 'trunk/mingw-w64-headers/include' into your '&lt;install-root&gt;/x86_64-pc-mingw32/include'<br>
  folder. If you choose the configuration variant II create in /mypath a symbolic link named<br>
  'mingw' pointing to the directory 'x86_64-pc-mingw32'.  For instance:<br>
    $ cd /mypath<br>
    $ ln -s x86_64-pc-mingw32 mingw<br>
<br>
<br>
<br>
4. Building the gcc core cross-compiler(s):<br>
  Step 0) If you have to patch gcc, may do this here. There are some patches necessary, if you want<br>
  	to cross compile libiberty with early header sets, or if you want to use gfortran. These patches<br>
  	are available by the 'gcc-patches' mailing list at 'gcc.gnu.org' or by taking a look at mingw.org<br>
  	or mingw-w64 sites.<br>
  Step 1) Enter into the gcc root folder and generate a folder within (e.g. 'build'). Then you may<br>
	apply optional patches to gcc (currently there is a patch file for gcc needed to fix some<br>
	problems about autoimported variables, libiberty and the fortan compiler).  Enter into the<br>
	build directory when finished.<br>
  Step 2 for I) Type: '../configure --target=x86_64-pc-mingw32'.<br>
  Step 2 for II) Type: '../configure --target=x86_64-pc-mingw32 --prefix=/mypath --with-sysroot=/mypath'.<br>
  Step 3) Type 'make all-gcc'<br>
  Step 4) Type 'make install-gcc'<br>
<br>
  Now the core stuff of gcc is present and we can build the crt itself.<br>
<br>
<br>
<br>
5. Building the crt:<br>
  Step 0) If you are using variant II, may you need to adjust the 'prefix' value in Makefiles.<br>
  Step 1) Enter into the trunk/mingw-w64-crt root directory.<br>
  Step 2 for I) Type 'make'<br>
  Step 2 for II) Type 'make prefix=/mypath'<br>
	(Note: If building the cross compiler on a system where the default executable extension is not .exe, override<br>
	the EXEEXT variable on the make commandline by adding &quote;EXEEXT=&quote;.)<br>
  Step 3) Copy all generated *.a files out of the 'mklibs' folder into the<br>
	'&lt;install-root&gt;/x86_64-pc-mingw32/lib' folder.<br>
  Step 4) Copy out of the root folder to the '&lt;install-root&gt;/x86_64-pc-mingw32/lib' folder the files<br>
	crt1.o, crt2.o, lib*.a, *.dll, crtbegin.o, crtend.o, dllcrt1.o, dllcrt2.o, binmode.o, txtmode.o,<br>
	CRT_fp8.o, and the CRT_fp10.o.<br>
<br>
<br>
<br>
6. Now you are ready to build the rest of gcc:<br>
  Step 1) Enter into your generated folder within your gcc root source folder.<br>
  Step 2) Type 'make'<br>
  Step 3) Type 'make install'<br>
<br>
<br>