User:Max/Preparing Windows as a build environment

From OSDev Wiki
Jump to navigation Jump to search

IMPORTANT: Since Windows Subsystem for Linux is here, I highly recommend using it instead of Cygwin. It makes your life much easier. Simply follow the tutorials for building a toolchain and do so under WSL.



This page explains how to prepare your Windows system to be ready to act as a build environment for building an OS specific toolchain or a cross compiler on.

The goal is to set up a Cygwin environment that is capable of building binutils and gcc for your target system, as this usually seems to be the hardest part when Windows users try to create a cross compiler. This page does not cover building the actual toolchain, but how to prepare your system to be able to do so.

To compile binutils and gcc for a target system, the host system must have:

  • gcc
  • make
  • autoconf
  • automake
  • gmp
  • mpc
  • mpfr

The explanations on this page assume that your PATH is not polluted by other toolchains (remove MinGW etc.). A basic understanding of how to build software with configure scripts and makefiles is also assumed.

Reference system

The steps explained here should work on any Windows version starting from 7. The reference system for this is a fresh Windows 10 installation.

Installing Cygwin

In this most basic step we will set up Cygwin and create the pre-requisites for building autoconf and automake in the next steps.

1. Download the Cygwin setup file and start it

2. Select gcc-core, gcc-g++, make, m4, perl

3. Perform installation

Now you have clean setup of Cygwin with only the absolutely required tools. There will now be the Cygwin Terminal installed on your system which you use for the following steps.

Compiling autoconf & automake

Specific versions of GCC depend on specific versions of autoconf/automake/aclocal on your host system. To build gcc 4.9 for example, you need exactly autoconf 2.64 and automake 1.11.1. Adapt the following steps to match the compiler version you want to build later.

1. Download the archives of autoconf 2.64 and automake 1.11.1.

2. Build autoconf from within a separate build directory using:

../autoconf-2.64/configure --prefix=/versions/autoconf-2.64
make && make install

3. Create a symbolic link to make autoconf available on the path:

ln -s /versions/autoconf-2.64/bin/autoconf /bin/autoconf

4. Build automake from within a separate build directory using:

../automake-1.11.1/configure --prefix=/versions/automake-1.11.1
make && make install

5. Create symbolic links to make automake available, too:

ln -s /versions/automake-1.11.1/bin/automake /bin/automake
ln -s /versions/automake-1.11.1/bin/aclocal /bin/aclocal

With this approach the specific versions of a tool are installed into a "/versions/tool-x.y.z" directory. The binary of the version that should be used is then simply linked into the "/bin" directory.

Installing GMP, MPFR, MPC

For GCC 4.9, the versions mentioned in these points should be suitable. For other versions, consider the respective readmes.

1. Download gmp-6.0.0a, mpfr-3.1.2 and mpc-1.0.3

2. Build gmp from within a separate build directory using:

../gmp-6.0.0/configure --prefix=/usr/local
make && make install

3. Build mpfr from within a separate build directory using:

../mpfr-3.1.2/configure --prefix=/usr/local --with-gmp=/usr/local
make && make install

4. Build mpc from within a separate build directory using:

../mpc-1.0.3/configure --prefix=/usr/local --with-gmp=/usr/local --with-mpfr=/usr/local --enable-static --disable-shared
make && make install

Notes for building your toolchain

Now you are prepared to build binutils and gcc on your system. The required build tools autoconf, aclocal and automake are in your path, and the required libraries are installed to /usr/local.

Few points to notice:

  • When building gcc, it will likely not find the locations of gmp/mpfr/mpc: use --with-*=/usr/local to tell it where each library is