# In a msys2/mingw64 command prompt: mkdir -p /c/code/gcc-bootstrap cd /c/code/gcc-bootstrap # Building the new gcc and its sysroot using the existing msys2/mingw64 # gcc installation: # $ which gcc # /mingw64/bin/gcc # $ gcc --version # gcc.exe (Rev2, Built by MSYS2 project) 7.3.0 export TOOLCHAIN_PREFIX=/c/code/mingw-native export TARGET_TRIPLET=x86_64-w64-mingw32 # Build libraries that GCC needs. These can also potentially be found # from the msys2/mingw64 installation, and that should probably also # work just as well. If omitted, leave out the --with-gmp=$DEPENDS_PREFIX # from the gcc configure command. export DEPENDS_PREFIX=/c/code/gcc-depends wget http://ftp.funet.fi/pub/gnu/gnu/gmp/gmp-6.1.2.tar.bz2 tar -jxvf gmp-6.1.2.tar.bz2 cd gmp-6.1.2 ./configure --prefix=$DEPENDS_PREFIX --disable-shared make -j$(nproc) make install cd .. wget http://ftp.funet.fi/pub/gnu/gnu/mpfr/mpfr-4.0.2.tar.bz2 tar -jxvf mpfr-4.0.2.tar.bz2 cd mpfr-4.0.2 ./configure --prefix=$DEPENDS_PREFIX --with-gmp=$DEPENDS_PREFIX --disable-shared make -j$(nproc) make install cd .. wget http://www.multiprecision.org/downloads/mpc-1.1.0.tar.gz tar -zxvf mpc-1.1.0.tar.gz cd mpc-1.1.0 ./configure --prefix=$DEPENDS_PREFIX --with-gmp=$DEPENDS_PREFIX --disable-shared make -j$(nproc) make install cd .. # End of optional section. wget http://ftp.funet.fi/pub/gnu/gnu/binutils/binutils-2.32.tar.bz2 tar -jxvf binutils-2.32.tar.bz2 cd binutils-2.32 mkdir build cd build ../configure --prefix=$TOOLCHAIN_PREFIX --disable-werror --disable-multilib make -j$(nproc) make install-strip cd ../.. # Clone mingw-w64; using a recent known-good version from the master branch. # The v6.x branch should also probably be good for ucrt, but the master branch # is certainly good at least. git clone git://git.code.sf.net/p/mingw-w64/mingw-w64 cd mingw-w64 git checkout 69af6ee195e65a29acc02a49119a833606424a1b cd mingw-w64-headers mkdir build cd build ../configure --prefix=$TOOLCHAIN_PREFIX/$TARGET_TRIPLET --with-default-msvcrt=ucrt make install cd ../../.. # Build GCC; build the compiler itself and all tools, using the existing # msys2/mingw64 compiler, having that compiler itself link against the # CRT that it defaults to. This compiler will be set up that the code # it produces uses UCRT though. # Build the same version of gcc as in the surrounding host environment. # This seems to be necessary for building the Ada tools this particular # way (a single-stage, non-bootstrap build), as the Ada tools are built # with the existing host Ada compiler, and the GCC Ada sources are picky # about being built with the exact right version of the compiler. wget http://ftp.funet.fi/pub/gnu/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.xz tar -Jxvf gcc-7.3.0.tar.xz cd gcc-7.3.0 && \ mkdir build cd build ../configure --prefix=$TOOLCHAIN_PREFIX --enable-languages=c,c++,ada --disable-multilib --with-gmp=$DEPENDS_PREFIX --with-native-system-header-dir=$TOOLCHAIN_PREFIX/$TARGET_TRIPLET/include --disable-bootstrap CXXFLAGS="-O2" make -j$(nproc) all-gcc make install-strip-gcc cd ../.. # Now build the CRT runtimes using the newly built C/C++ compiler. # Add the new toolchain/compiler to the PATH. export PATH=$TOOLCHAIN_PREFIX/bin:$PATH # $ which gcc # /c/code/mingw-native/bin/gcc # $ gcc --version # gcc.exe (GCC) 7.3.0 cd mingw-w64/mingw-w64-crt mkdir build cd build ../configure --prefix=$TOOLCHAIN_PREFIX/$TARGET_TRIPLET --disable-lib32 --enable-lib64 --with-default-msvcrt=ucrt make -j$(nproc) make install cd ../../.. # Build the libgcc/libstdc++ runtimes, with the new toolchain and its # new sysroot (defaulting to UCRT). cd gcc-7.3.0/build make -j$(nproc) all-target make install-target # Build the rest of the gnat frontend tools using the old host ada compiler: export PATH=/mingw64/bin:$PATH make configure-gnattools cd gnattools make -j$(nproc) gnattools-cross cd .. make install-strip-gcc cd ../../.. # Copy a few runtime dlls that the compiler ended up requiring. cp /mingw64/bin/libiconv-2.dll $TOOLCHAIN_PREFIX/bin cp /mingw64/bin/libwinpthread-1.dll $TOOLCHAIN_PREFIX/bin cp /mingw64/bin/libgmp-10.dll $TOOLCHAIN_PREFIX/bin