Building your own GNU toolchains

If you want to build your own GNU toolchain for Windows instead of downloading prebuilt ones, follow the steps described in this page.

In this example we will build GCC for embedded ARM (arm-eabi). You can alternatively use any other target supported by GCC.

1. Download MinGW and MSys packages.

2. Create a directory for building the toolchains. E.g. c:\gnu. In MinGW notation this will be /c/gnu.

3. Create a directory where the built toolchain will be installed. E.g. c:\gnu\out

4. Download a recent binutils source package from http://ftp.gnu.org/gnu/binutils/ and save it to c:\gnu.

5. Start MinGW shell from Start Menu.

6. Go to the directory with the binutils by running the following command:

cd /c/gnu

7. Extract the binutils package 

tar xjf binutils-<version>.tar.bz2

8. Create a build directory for binutils:

mkdir binutils-<version>-build

9. Go to the binutils directory

cd binutils-<version>-build

10. Configure binutils

../binutils-<version>/configure --target arm-eabi --enable-win32-registry=MyToolchainName --prefix /c/gnu/out

Change MyToolchainName to any name you want to associate with your toolchain. If you move the toolchain to a different location you'll need to specify the new location in the registry:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Free Software Foundation\MyToolchainName]
"GCC"="C:\\New-Location"
"BINUTILS"="C:\\New-Location"
"G++"="C:\\New-Location"

11. Build binutils

make

If you have a multi-core machine, you can speed up the build process by running several parallel build jobs. To do so, instead of "make" type:

make -j16

Replace 16 with the amount of parallel jobs you want to have.

12. Install binutils to the output directory

make install-strip

The "install-strip" option is similar to "install", but it will remove debugging information from the binaries. Unless you want to debug the toolchain itself, always use it to save disk space.

13. Download GCC source from http://ftp.gnu.org/gnu/gcc/ and unpack it.

14. If you are building the "barebone" toolchain, you will most likely need newlib library. Download and unpack it from ftp://sources.redhat.com/pub/newlib/

15. Create a build directory for gcc and enter it

16. Configure GCC:

../gcc-<version>/configure --target arm-eabi --enable-win32-registry=MyToolchainName --prefix /c/gnu/out/ --enable-languages=c,c++ --disable-nls --disable-shared --with-newlib --with-headers=../newlib-<version>/newlib/libc/include

17. Build GCC:

make -j16

18. Install GCC:

make install-strip

19. Create a build directory for newlib and enter it

20. Configure newlib

../newlib-<version>/configure --target arm-eabi --prefix /c/gnu/out

21. Build  newlib:

make

22. Install newlib

make install

23. Download GDB sources from ftp://sourceware.org/pub/gdb/releases/

24. Unpack GDB, create a build directory for it and enter it.

25. Configure GDB 

../gdb-<version>/configure --target arm-eabi --prefix /c/gnu/out

26. Build GDB

make -j16

27. Install GDB

make install