The Packages
binutils
gcc
mingw32
msys
Prerequisites
sudo apt-get subversion mpc libgmp-dev libmpfr-dev libmpc-dev
Creating Directories
The build will install the programs into the /opt directory:- /opt/src - source code / compiling area
mkdir /opt
mkdir /opt/src
Downloading
binutils: ftp://sourceware.org/pub/binutils/snapshotsgcc: ftp://gcc.gnu.org/pub/gcc/snapshots
cd /opt/src
# Download Binutils
wget ftp://sourceware.org/pub/binutils/snapshots/binutils-2.24.51.tar.bz2
cat binutils-2.24.51.tar.bz2 | bunzip2 | tar xf -
# Download GCC
wget ftp://gcc.gnu.org/pub/gcc/snapshots/LATEST-4.9/gcc-4.9-20140112.tar.bz2
cat gcc-4.9-20140112.tar.bz2 | bunzip2 | tar xf -
# Download Mingw32
svn checkout svn://svn.code.sf.net/p/mingw-w64/code/trunk mingw-w64-code
Building
This guide builds the compiler and libraries to run on a Ubuntu 13.10 platform, but to generate statically linked programs which can run on a 32-bit windows platform.It is possible to produce multiple targets during the build (e.g. give the option of creating 64-bit windows applications too), but to keep this simple, the multilib features have not been described (building is also faster!).
Downloading / Installing Default MinGW Libraries / Apps
MinGW can either be built from scratch (see General GCC / Binutils / MinGW Building Procedure below), or a pre-built version can be installed via the operating system.sudo apt-get mingw-w64 bintuils-mingw-w64 g++-mingw-w64 mingw-w64-tools
General GCC / Binutils / MinGW Building Procedure
To build the MinGW tools from scratch, follow this procedure.Normally, you will do the following:
- Create a build directory, somewhere outside of the source tree
- cd into the build directory, and run configure from the source directory
- Pass options to configure to indicate what the build platform and target platforms are (i.e. cross-compile)
- Run make, then make install
Building Mingw Sequence
Because some of the programs / libraries depend on each other, it is necessary to build in a specific order:- Binutils
- Mingw Headers
- GCC core
- Mingw Libraries
- Complete GCC installation
Binutils
# With Multilib (32-bit and 64-bit support)
cd /opt/src
mkdir binutils-build
cd binutils-build
../binutils-*/configure --target=x86_64-w64-mingw32 --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32 --prefix=/opt
make
make install
Modify Path
PATH=$PATH:/opt/binMingw32 Headers
cd /opt/srcmkdir mingw32-build
cd mingw32-build
../mingw-*/mingw-w64-headers/configure --host=x86_64-w64-mingw32 --build=i686-pc-linux-gnu --prefix=/opt/x86_64-w64-mingw32
make
make install
# Create softlinks for gcc
cd /opt
ln -s x86_64-w64-mingw32 mingw
cd /opt/mingw
ln -s lib lib64
* Note the intentional addition of the host to the prefix path. This applies to version 3 of Mingw32.
GCC (Cross-Compiler)
# With Multilib (32-bit and 64-bit support)
cd /opt/src
mkdir gcc-build
cd gcc-build
../gcc-*/configure --target=x86_64-w64-mingw32 --enable-targets=all --prefix=/opt
make all-gcc
make install-gcc
Mingw32 Libraries
# With Multilib (32-bit and 64-bit support)
cd /opt/src
mkdir mingw32-build
cd mingw32-build
../mingw-*/configure --host=x86_64-w64-mingw32 --build=i686-pc-linux-gnu --prefix=/opt/x86_64-w64-mingw32 --enable-lib32 --enable-static --enable-shared
make -k
make -k install
Note: the release I used gave the error:
No rule to make target `lib64/libwmilib.a', needed by `all-am'
As I want the 32-bit libraries only, I've replaced the make with make -k to force the rest to be built, but it is not clear that this will be successful.
GCC (Cross-Compiler)
# With Multilib (32-bit and 64-bit support)
cd /opt/src/gcc-build
makemake install
Building & Cross-Compiling QT
Ensure that the downloaded / built applications are in the path.cd /opt/src/qt/tarballs
wget http://download.qt-project.org/official_releases/qt/5.2/5.2.0/single/qt-everywhere-opensource-src-5.2.0.7z