@@ -24,6 +24,12 @@ This tutorial aims at building the **GNU toolchain 4.9** with **Android NDK r11c
2424It has been tested on Linux x86_64, but I expect that it should work with
2525small changes on other systems supported by the NDK.
2626
27+ ### Windows
28+
29+ Although the NDK supports Windows (32-bit & 64-bit variants), the
30+ toochain can only be built from Linux. The process is the roughly the
31+ same, with a few extra steps detailed along the way.
32+
2733### Steps
2834
2935#### Requirements
@@ -44,6 +50,9 @@ On Debian-based Linux, you can run:
4450sudo apt-get install git make gcc g++ m4 texinfo bison flex wget
4551```
4652
53+ ** Note:** When building the toolchain for Windows, ** mingw-w64** is
54+ also required.
55+
4756#### Android NDK
4857
4958Download the Android NDK r11c from Google, and extract it.
@@ -62,18 +71,18 @@ The next step is to download the GNU toolchain components from Google
6271repositories. We'll clone them in a folder called ` toolchain/ ` .
6372```
6473mkdir toolchain && cd toolchain
65- git clone https://android.googlesource.com/toolchain/gcc
66- git clone https://android.googlesource.com/toolchain/build
67- git clone https://android.googlesource.com/toolchain/gmp
68- git clone https://android.googlesource.com/toolchain/gdb
69- git clone https://android.googlesource.com/toolchain/mpc
70- git clone https://android.googlesource.com/toolchain/mpfr
71- git clone https://android.googlesource.com/toolchain/expat
72- git clone https://android.googlesource.com/toolchain/ppl
73- git clone https://android.googlesource.com/toolchain/cloog
74- git clone https://android.googlesource.com/toolchain/isl
75- git clone https://android.googlesource.com/toolchain/sed
76- git clone https://android.googlesource.com/toolchain/binutils
74+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/gcc
75+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/build
76+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/gmp
77+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/gdb
78+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/mpc
79+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/mpfr
80+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/expat
81+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/ppl
82+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/cloog
83+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/isl
84+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/sed
85+ git clone -b ndk-r11c https://android.googlesource.com/toolchain/binutils
7786```
7887
7988#### Add support for Fortran
104113```
105114prebuilt_ndk = 'ndk'
106115```
107- so that the building script can find the ` ndk/platforms ` folder correctly.
116+ so that the building script can find the ` ndk/platforms ` folder
117+ correctly.
118+
119+ ** Note:** When building the toolchain for Windows,
120+ you need to change ` ndk/build/tools/prebuilt-common.sh ` for the MinGW
121+ wrapper to be found. Find the line that says:
122+ ```
123+ # generate wrappers for BUILD toolchain
124+ ```
125+ and replace the section that follows by:
126+ ```
127+ LEGACY_TOOLCHAIN_PREFIX="/usr/bin/x86_64-linux-gnu-"
128+ $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=i386-linux-gnu- \
129+ --cflags="-m32" --cxxflags="-m32" --ldflags="-m elf_i386" --asflags="--32" \
130+ --dst-prefix="$LEGACY_TOOLCHAIN_PREFIX" "$CROSS_WRAP_DIR"
131+ $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=i386-pc-linux-gnu- \
132+ --cflags="-m32" --cxxflags="-m32" --ldflags="-m elf_i386" --asflags="--32" \
133+ --dst-prefix="$LEGACY_TOOLCHAIN_PREFIX" "$CROSS_WRAP_DIR"
134+ # 64-bit BUILD toolchain. libbfd is still built in 32-bit.
135+ $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=x86_64-linux-gnu- \
136+ --dst-prefix="$LEGACY_TOOLCHAIN_PREFIX" "$CROSS_WRAP_DIR"
137+ $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=x86_64-pc-linux-gnu- \
138+ --dst-prefix="$LEGACY_TOOLCHAIN_PREFIX" "$CROSS_WRAP_DIR"
139+ ```
108140
109141** Note:** If you want to build ** standalone toolchains**
110142(i.e. you're not using ` ndk-build ` ), there is one extra step.
@@ -125,14 +157,17 @@ You can specify which toolchain to build. For instance:
125157See ` ./build.py -h ` for possible values.
126158If nothing is specified, it will build all of them.
127159
160+ ** Note:** When building the toolchain for Windows, add ` --host windows `
161+ (or ` --host windows64 ` for 64-bit).
162+
128163### Deploying
129164
130165If you built a standalone toolchain, just extract the archive. You'll probably
131166want to add ` $(TOOLCHAIN)/bin ` to your path.
132167
133168Otherwise, to allow ` ndk-build ` to use your new toolchain, extract the archive
134- under ` ndk/toolchains/$(TOOLCHAIN)/prebuilt/$(HOST_ARCH) ` . Don't forget to back
169+ under ` ndk/toolchains/$(TOOLCHAIN)/prebuilt/$(HOST_ARCH) ` . Don't forget to back up
135170the toolchain that was already packaged with the NDK.
136171
137- For instance, on Linux 64-bit for the AArch64 toolchain, unpack the archive as
172+ For instance, on Linux x86_64 for the AArch64 toolchain, unpack the archive as
138173` ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 ` .
0 commit comments