Difference between revisions of "Building MINGW-w64"

From ReactOS Wiki
Jump to: navigation, search
(Setting up the build environment)
 
(120 intermediate revisions by 6 users not shown)
Line 2: Line 2:
 
This guide is provided for those who have no clue how to compile gcc, but still want to do it. It's a reference, just follow the steps and you get what you want. There's no support for special wishes ;-)
 
This guide is provided for those who have no clue how to compile gcc, but still want to do it. It's a reference, just follow the steps and you get what you want. There's no support for special wishes ;-)
  
= Setting up the build environment =
+
== Setting up the build environment ==
Download and install MSYS. You will need the following packages:
+
Download and install MSYS2. You will need the following packages:
  
* msysCORE-1.0.14-1-msys-1.0.14-bin.tar.lzma
+
* MSYS2 (version [http://repo.msys2.org/distrib/i686/msys2-i686-20180531.exe 20180531])
* coreutils-5.97-2-msys-1.0.11-bin.tar.lzma
+
* Recent mingw-w64 32 bit Toolchain ([https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/7.3.0/threads-win32/dwarf/ here])
* bash-3.1.17-2-msys-1.0.11-bin.tar.lzma
 
* bison-2.4.1-1-msys-1.0.11-bin.tar.lzma
 
* flex-2.5.35-1-msys-1.0.11-bin.tar.lzma
 
* gawk-3.1.7-1-msys-1.0.11-bin.tar.lzma
 
* grep-2.5.4-1-msys-1.0.11-bin.tar.lzma
 
* sed-4.2.1-1-msys-1.0.11-bin.tar.lzma
 
* make-3.81-2-msys-1.0.11-bin.tar.lzma
 
* m4-1.4.13-1-msys-1.0.11-bin.tar.lzma
 
* gcc-core-3.4.5-20060117-3.tar.gz
 
* gcc-g++-3.4.5-20060117-3.tar.gz
 
* binutils-2.20.1-2-mingw32-bin.tar.gz
 
* mingwrt-3.18-mingw32-dev.tar.gz
 
* w32api-3.14-mingw32-dev.tar.gz
 
* libregex-1.20090805-1-msys-1.0.11-dll-1.tar.lzma
 
* tar-1.22-1-msys-1.0.11-bin.tar.lzma
 
* diffutils-2.8.7.20071206cvs-2-msys-1.0.11-bin.tar.lzma
 
* gettext-0.17-1-msys-1.0.11-dev.tar.lzma
 
* libiconv-1.13.1-1-mingw32-dev.tar.lzma
 
  
Download all packages and extract them into c:\MSYS (or similar).
+
Download all packages and install them into c:\MSYS32. Extract Toolchain to the /mingw32/ folder inside.
You can unpack the .tar.lzma files using the latest version of 7zip.
 
  
Extract libiconv-1.13.1-1-mingw32-dev.tar.lzma into the mingw subfolder of the MSYS root (Why? Because!)
+
pacman -Syu
  
= Getting the sources =
+
pacman -Su
  
Download all the sources into subfolders of /home/YourName/src
+
pacman -S --needed make texinfo diffutils
  
* binutils (version [ftp://sourceware.org/pub/binutils/snapshots/binutils-2.20.51.tar.bz2 2.20.51] or [ftp://sourceware.org/pub/binutils/snapshots/ newer]) -> home/YourName/src/binutils
+
(If installing make makes problems, remove the files it laments about already being existent)
* gcc-core (version [ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.5.0/gcc-core-4.5.0.tar.bz2 4.5.0] or [ftp://ftp.fu-berlin.de/unix/languages/gcc/snapshots/LATEST-4.6/ newer]) -> home/YourName/src/gcc
 
* gcc-g++ (version [ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.5.0/gcc-g++-4.5.0.tar.bz2 4.5.0] or [ftp://ftp.fu-berlin.de/unix/languages/gcc/snapshots/LATEST-4.6/ newer]) -> home/YourName/src/gcc
 
* mingw-w64 [http://sourceforge.net/projects/mingw-w64/files/] -> home/YourName/src/mingw-w64
 
  
* MPFR (version [http://www.mpfr.org/mpfr-current/mpfr-2.4.2.tar.bz2 2.4.2]) -> home/YourName/src/mpfr
+
== Getting the sources ==
* GMP (version [ftp://ftp.gmplib.org/pub/gmp-5.0.1/gmp-5.0.1.tar.bz2 5.0.1]) -> home/YourName/src/gmp
 
* MPC (version [http://www.multiprecision.org/mpc/download/mpc-0.8.1.tar.gz 0.8.1]) -> home/YourName/src/mpc
 
  
= Note =
+
Download all the sources into subfolders of /src
  
Copy the src/mingw-w64/mingw-w64-headers/include directory to /RosBE64/mingw and to /RosBE64/x86_64-w64-mingw32 (64 bit) or /RosBE64/i686-w64-mingw32 (32 bit).
+
* binutils (version [ftp://sourceware.org/pub/binutils/releases/binutils-2.32.tar.xz 2.32]) -> /src/binutils
 +
* gcc (version [ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-8.3.0/gcc-8.3.0.tar.xz 8.3.0]) -> /src/gcc
 +
* mingw-w64 v6.0.0 ([https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/ here]) -> /src/mingw-w64
  
== Patching the sources ==
+
* MPFR (version [https://www.mpfr.org/mpfr-current/mpfr-4.0.2.tar.xz 4.0.2]) -> /src/gcc/mpfr
 +
* GMP (version [ftp://ftp.gmplib.org/pub/gmp-6.1.2/gmp-6.1.2.tar.xz 6.1.2]) -> /src/gcc/gmp
 +
* MPC (version [https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz 1.1.0]) -> /src/gcc/mpc
  
You need to apply 2 patches (Kudos go to Kai Tietz from mingw-w64):
+
= Building =
* [http://dreimer.bplaced.net/rosbe/patches/x86_64_bin_underscore.diff Patch for binutils] (Obsolete with recent Nightlies)
 
* [http://dreimer.bplaced.net/rosbe/patches/x86_64_gcc_underscore.diff Patch for gcc] (Obsolete with gcc 4.6.0 Tree)
 
  
= Building =
+
* USE THE MINGW32.EXE!!! Otherwise the host= and build= parameters are set to some msys2 environment and not the one we expect.
 +
* the -jX parameter added to make speeds up the build processes by using mutiple threads to build on more than one CPU core. Use your amout of cores + 1 as number instead of the X.
  
 
Optionally set buildflags:
 
Optionally set buildflags:
export CFLAGS="-O2 -pipe -fomit-frame-pointer"
 
export CXXFLAGS="-O2 -pipe -fomit-frame-pointer"
 
export LDFLAGS=-s
 
  
== Building GMP ==
+
64 bit:
 +
export CFLAGS="-g0 -O2 -pipe -Wl,-S"
 +
export CXXFLAGS="-g0 -O2 -pipe -Wl,-S"
  
Create a build subdirectory for gmp:
+
32 bit:
  cd build
+
  export CFLAGS="-g0 -O2 -pipe -Wl,-S -march=pentium -mtune=i686"
  mkdir gmp
+
  export CXXFLAGS="-g0 -O2 -pipe -Wl,-S -march=pentium -march=i686"
cd gmp
 
  
From the build directory run the gmp configure script:
+
=== Building binutils ===
  
  ../../src/gmp/configure --prefix=/support --host=i686-w64-mingw32 --build=i686-w64-mingw32 --disable-shared
+
Create a build subdirectory for binutils:
 +
  cd build
 +
mkdir binutils
 +
cd binutils
  
Now build the whole stuff.
+
From the build directory run the binutils configure script:
make
 
  
Finally install it into the designated directory.
+
64 bit:
  make install
+
  ../../src/binutils/configure --prefix=/RosBE --with-sysroot=/RosBE --target=x86_64-w64-mingw32 --disable-multilib --disable-werror --enable-lto --enable-plugins --with-zlib=yes --disable-nls
  
== Building MPFR ==
+
32 bit:
 
+
  ../../src/binutils/configure --prefix=/RosBE --with-sysroot=/RosBE --target=i686-w64-mingw32 --disable-multilib --disable-werror --enable-lto --enable-plugins --with-zlib=yes --disable-nls
Create a build subdirectory for mpfr:
 
cd build
 
mkdir mpfr
 
cd mpfr
 
 
 
From the build directory run the mpfr configure script:
 
 
 
  ../../src/mpfr/configure --prefix=/support --host=i686-w64-mingw32 --build=i686-w64-mingw32 --with-gmp=/support --disable-shared
 
  
 
Now build the whole stuff.
 
Now build the whole stuff.
  make
+
  make -jX
  
 
Finally install it into the designated directory.
 
Finally install it into the designated directory.
 
  make install
 
  make install
  
== Building MPC ==
+
=== Building the mingw-w64 headers ===
  
Create a build subdirectory for mpc:
+
Create a build directory.
  cd build
+
  cd ..
  mkdir mpc
+
  mkdir mingw-w64-headers
  cd mpc
+
  cd mingw-w64-headers
  
From the build directory run the mpc configure script:
+
Run the configure script
  
  ../../src/mpc/configure --prefix=/support --host=i686-w64-mingw32 --build=i686-w64-mingw32 --with-gmp=/support --with-mpfr=/support
+
64 bit:
  --disable-shared
+
  ../../src/mingw-w64/mingw-w64-headers/configure --prefix=/RosBE/x86_64-w64-mingw32 --host=x86_64-w64-mingw32
  
Now build the whole stuff.
+
32 bit:
  make
+
  ../../src/mingw-w64/mingw-w64-headers/configure --prefix=/RosBE/i686-w64-mingw32 --host=i686-w64-mingw32
  
Finally install it into the designated directory.
+
Install
 
  make install
 
  make install
  
== Building binutils ==
+
=== Note ===
 
 
Create a build subdirectory for binutils:
 
cd build
 
mkdir binutils
 
cd binutils
 
  
From the build directory run the binutils configure script:
+
Copy the /RosBE/x86_64-w64-mingw32 (64 bit) or /RosBE/i686-w64-mingw32 (32 bit) directory to /RosBE/mingw.
  
64 bit:
+
Add it to the PATH variable.
  ../../src/binutils/configure --prefix=/RosBE64 --target=x86_64-w64-mingw32 --disable-nls --disable-werror --disable-multilib
+
  export PATH="$PATH:/RosBE/bin"
  --with-sysroot=/RosBE64
 
  
32 bit:
+
=== Building gcc-core ===
../../src/binutils/configure --prefix=/RosBE64 --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32
 
  --disable-nls --disable-werror --disable-multilib --with-sysroot=/RosBE64
 
  
Now build the whole stuff.
+
Enter into the build directory:
make
 
 
 
Finally install it into the designated directory.
 
make install
 
 
 
== Building gcc-core ==
 
Emter into the build directory:
 
 
  cd ..
 
  cd ..
 
  mkdir gcc
 
  mkdir gcc
Line 145: Line 101:
  
 
64 bit:
 
64 bit:
  ../../src/gcc/configure --prefix=/RosBE64 --target=x86_64-w64-mingw32 --with-gmp=/support --with-mpfr=/support --with-mpc=/support
+
  ../../src/gcc/configure --target=x86_64-w64-mingw32 --prefix=/RosBE --with-sysroot=/RosBE --with-pkgversion="RosBE-Windows" --enable-languages=c,c++ --enable-fully-dynamic-string --enable-checking=release --enable-version-specific-runtime-libs --enable-plugins --disable-shared --disable-multilib --disable-nls --disable-werror --disable-win32-registry --disable-sjlj-exceptions --disable-libstdcxx-verbose
  --with-pkgversion="RosBE-Windows" --enable-languages=c,c++ --enable-checking=release --enable-version-specific-runtime-libs
 
  --disable-win32-registry --disable-shared --disable-nls --disable-werror --disable-multilib --with-sysroot=/RosBE64
 
  
 
32 bit:
 
32 bit:
  ../../src/gcc/configure --prefix=/RosBE64 --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32
+
  ../../src/gcc/configure --target=i686-w64-mingw32 --prefix=/RosBE --with-sysroot=/RosBE --with-pkgversion="RosBE-Windows" --enable-languages=c,c++ --enable-fully-dynamic-string --enable-checking=release --enable-version-specific-runtime-libs --enable-plugins --disable-shared --disable-multilib --disable-nls --disable-werror --disable-win32-registry --disable-sjlj-exceptions --disable-libstdcxx-verbose
  --with-gmp=/support --with-mpfr=/support --with-mpc=/support --with-pkgversion="RosBE-Windows" --enable-languages=c,c++
 
  --enable-checking=release --enable-version-specific-runtime-libs --disable-win32-registry --disable-shared --disable-nls
 
  --disable-werror --disable-multilib --with-sysroot=/RosBE64
 
  
 
Compile the gcc-core
 
Compile the gcc-core
  make all-gcc
+
  make all-gcc -jX
  
 
And install it
 
And install it
 
  make install-gcc
 
  make install-gcc
 +
make install-lto-plugin
  
Finally add it to the PATH variable.
+
=== Building the crt ===
PATH=$PATH:/RosBE64/bin ; export PATH
 
 
 
== Building the crt ==
 
  
 
Create a build directory.
 
Create a build directory.
Line 174: Line 123:
  
 
64 bit:
 
64 bit:
  ../../src/mingw-w64/mingw-w64-crt/configure --prefix=/RosBE64 --host=x86_64-w64-mingw32 --with-sysroot=/RosBE64
+
  ../../src/mingw-w64/mingw-w64-crt/configure --prefix=/RosBE/x86_64-w64-mingw32 --with-sysroot=/RosBE/x86_64-w64-mingw32 --host=x86_64-w64-mingw32
  
 
32 bit:
 
32 bit:
  ../../src/mingw-w64/mingw-w64-crt/configure --prefix=/RosBE64 --host=i686-w64-mingw32 --build=i686-w64-mingw32 --with-sysroot=/RosBE64
+
  ../../src/mingw-w64/mingw-w64-crt/configure --prefix=/RosBE/i686-w64-mingw32 --with-sysroot=/RosBE/i686-w64-mingw32 --host=i686-w64-mingw32
  
 
Compile
 
Compile
  make
+
  make -jX
  
 
And install
 
And install
 
  make install
 
  make install
  
Copy the /RosBE64/x86_64-w64-mingw32 (64 bit) or /RosBE64/i686-w64-mingw32 (32 bit) directory to /RosBE64/mingw.
+
=== Note ===
 +
 
 +
Copy the /RosBE/x86_64-w64-mingw32 (64 bit) or /RosBE/i686-w64-mingw32 (32 bit) directory to /RosBE/mingw.
 +
 
 +
=== Building the rest of gcc ===
  
== Building the rest of gcc ==
 
 
Enter into the gcc build directory.
 
Enter into the gcc build directory.
 
  cd ..
 
  cd ..
Line 193: Line 145:
  
 
And compile the rest.
 
And compile the rest.
  make
+
  make -jX
 
  make install
 
  make install
 +
 +
=== Stripping the binaries ===
 +
 +
CD to the RosBE directory and execute these
 +
 +
find -executable -type f -exec strip -s {} ";" >& /dev/null
 +
find -name "*.a" -type f -exec strip -d {} ";" >& /dev/null
 +
find -name "*.o" -type f -exec strip -d {} ";" >& /dev/null
  
 
= Common errors =
 
= Common errors =
  
When compiling crt:
+
* Check if you have copied the /RosBE/x86_64-w64-mingw32 (64 bit) or /RosBE/i686-w64-mingw32 (32 bit) directory to /RosBE/mingw anytime you have to do something with GCC building.
configure: error: Please check if the mingw-w64 header set and the build/host option are set properly.
+
* Check if you have set the PATH variable to the new compiler correctly.
 +
* Check if you have installed the new compiler correctly ("make install-gcc").
 +
* If you wanna make a new ninja. "configure.py --platform=mingw --host=mingw --bootstrap"
  
* Check if you have copied the mingw-headers/include directory to both /RosBE64/x86_64-w64-mingw32 and /RosBE64/mingw
+
[[Category:Building]]
* Check if you have set the PATH variable to the new compiler correctly
+
[[Category:amd64]]
* Check if you have installed the new compiler correctly ("make install-gcc")
+
[[Category:Tutorial]]
(--enable-leading-mingw64-underscores)
 

Latest revision as of 20:31, 19 August 2019

... for idiots. This guide is provided for those who have no clue how to compile gcc, but still want to do it. It's a reference, just follow the steps and you get what you want. There's no support for special wishes ;-)

Setting up the build environment

Download and install MSYS2. You will need the following packages:

  • MSYS2 (version 20180531)
  • Recent mingw-w64 32 bit Toolchain (here)

Download all packages and install them into c:\MSYS32. Extract Toolchain to the /mingw32/ folder inside.

pacman -Syu

pacman -Su

pacman -S --needed make texinfo diffutils

(If installing make makes problems, remove the files it laments about already being existent)

Getting the sources

Download all the sources into subfolders of /src

  • binutils (version 2.32) -> /src/binutils
  • gcc (version 8.3.0) -> /src/gcc
  • mingw-w64 v6.0.0 (here) -> /src/mingw-w64
  • MPFR (version 4.0.2) -> /src/gcc/mpfr
  • GMP (version 6.1.2) -> /src/gcc/gmp
  • MPC (version 1.1.0) -> /src/gcc/mpc

Building

  • USE THE MINGW32.EXE!!! Otherwise the host= and build= parameters are set to some msys2 environment and not the one we expect.
  • the -jX parameter added to make speeds up the build processes by using mutiple threads to build on more than one CPU core. Use your amout of cores + 1 as number instead of the X.

Optionally set buildflags:

64 bit:

export CFLAGS="-g0 -O2 -pipe -Wl,-S"
export CXXFLAGS="-g0 -O2 -pipe -Wl,-S"

32 bit:

export CFLAGS="-g0 -O2 -pipe -Wl,-S -march=pentium -mtune=i686"
export CXXFLAGS="-g0 -O2 -pipe -Wl,-S -march=pentium -march=i686"

Building binutils

Create a build subdirectory for binutils:

cd build
mkdir binutils
cd binutils

From the build directory run the binutils configure script:

64 bit:

../../src/binutils/configure --prefix=/RosBE --with-sysroot=/RosBE --target=x86_64-w64-mingw32 --disable-multilib --disable-werror --enable-lto --enable-plugins --with-zlib=yes --disable-nls

32 bit:

../../src/binutils/configure --prefix=/RosBE --with-sysroot=/RosBE --target=i686-w64-mingw32 --disable-multilib --disable-werror --enable-lto --enable-plugins --with-zlib=yes --disable-nls

Now build the whole stuff.

make -jX

Finally install it into the designated directory.

make install

Building the mingw-w64 headers

Create a build directory.

cd ..
mkdir mingw-w64-headers
cd mingw-w64-headers

Run the configure script

64 bit:

../../src/mingw-w64/mingw-w64-headers/configure --prefix=/RosBE/x86_64-w64-mingw32 --host=x86_64-w64-mingw32

32 bit:

../../src/mingw-w64/mingw-w64-headers/configure --prefix=/RosBE/i686-w64-mingw32 --host=i686-w64-mingw32

Install

make install

Note

Copy the /RosBE/x86_64-w64-mingw32 (64 bit) or /RosBE/i686-w64-mingw32 (32 bit) directory to /RosBE/mingw.

Add it to the PATH variable.

export PATH="$PATH:/RosBE/bin"

Building gcc-core

Enter into the build directory:

cd ..
mkdir gcc
cd gcc

Now run the configure script:

64 bit:

../../src/gcc/configure --target=x86_64-w64-mingw32 --prefix=/RosBE --with-sysroot=/RosBE --with-pkgversion="RosBE-Windows" --enable-languages=c,c++ --enable-fully-dynamic-string --enable-checking=release --enable-version-specific-runtime-libs --enable-plugins --disable-shared --disable-multilib --disable-nls --disable-werror --disable-win32-registry --disable-sjlj-exceptions --disable-libstdcxx-verbose

32 bit:

../../src/gcc/configure --target=i686-w64-mingw32 --prefix=/RosBE --with-sysroot=/RosBE --with-pkgversion="RosBE-Windows" --enable-languages=c,c++ --enable-fully-dynamic-string --enable-checking=release --enable-version-specific-runtime-libs --enable-plugins --disable-shared --disable-multilib --disable-nls --disable-werror --disable-win32-registry --disable-sjlj-exceptions --disable-libstdcxx-verbose

Compile the gcc-core

make all-gcc -jX

And install it

make install-gcc
make install-lto-plugin

Building the crt

Create a build directory.

cd ..
mkdir mingw-w64-crt
cd mingw-w64-crt

Run the configure script

64 bit:

../../src/mingw-w64/mingw-w64-crt/configure --prefix=/RosBE/x86_64-w64-mingw32 --with-sysroot=/RosBE/x86_64-w64-mingw32 --host=x86_64-w64-mingw32

32 bit:

../../src/mingw-w64/mingw-w64-crt/configure --prefix=/RosBE/i686-w64-mingw32 --with-sysroot=/RosBE/i686-w64-mingw32 --host=i686-w64-mingw32

Compile

make -jX

And install

make install

Note

Copy the /RosBE/x86_64-w64-mingw32 (64 bit) or /RosBE/i686-w64-mingw32 (32 bit) directory to /RosBE/mingw.

Building the rest of gcc

Enter into the gcc build directory.

cd ..
cd gcc

And compile the rest.

make -jX
make install

Stripping the binaries

CD to the RosBE directory and execute these

find -executable -type f -exec strip -s {} ";" >& /dev/null
find -name "*.a" -type f -exec strip -d {} ";" >& /dev/null
find -name "*.o" -type f -exec strip -d {} ";" >& /dev/null

Common errors

  • Check if you have copied the /RosBE/x86_64-w64-mingw32 (64 bit) or /RosBE/i686-w64-mingw32 (32 bit) directory to /RosBE/mingw anytime you have to do something with GCC building.
  • Check if you have set the PATH variable to the new compiler correctly.
  • Check if you have installed the new compiler correctly ("make install-gcc").
  • If you wanna make a new ninja. "configure.py --platform=mingw --host=mingw --bootstrap"