@@ -24,6 +24,12 @@ This tutorial aims at building the **GNU toolchain 4.9** with **Android NDK r11c
24
24
It has been tested on Linux x86_64, but I expect that it should work with
25
25
small changes on other systems supported by the NDK.
26
26
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
+
27
33
### Steps
28
34
29
35
#### Requirements
@@ -44,6 +50,9 @@ On Debian-based Linux, you can run:
44
50
sudo apt-get install git make gcc g++ m4 texinfo bison flex wget
45
51
```
46
52
53
+ ** Note:** When building the toolchain for Windows, ** mingw-w64** is
54
+ also required.
55
+
47
56
#### Android NDK
48
57
49
58
Download 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
62
71
repositories. We'll clone them in a folder called ` toolchain/ ` .
63
72
```
64
73
mkdir 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
77
86
```
78
87
79
88
#### Add support for Fortran
104
113
```
105
114
prebuilt_ndk = 'ndk'
106
115
```
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
+ ```
108
140
109
141
** Note:** If you want to build ** standalone toolchains**
110
142
(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:
125
157
See ` ./build.py -h ` for possible values.
126
158
If nothing is specified, it will build all of them.
127
159
160
+ ** Note:** When building the toolchain for Windows, add ` --host windows `
161
+ (or ` --host windows64 ` for 64-bit).
162
+
128
163
### Deploying
129
164
130
165
If you built a standalone toolchain, just extract the archive. You'll probably
131
166
want to add ` $(TOOLCHAIN)/bin ` to your path.
132
167
133
168
Otherwise, 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
135
170
the toolchain that was already packaged with the NDK.
136
171
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
138
173
` ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 ` .
0 commit comments