@@ -15,12 +15,11 @@ and [this Google group](https://groups.google.com/forum/#!msg/android-ndk/QR1qiN
15
15
## Procedure
16
16
17
17
The whole process has become fairly easy, thanks to the new Python building
18
- scripts Google added in NDK r11c. A few modifications are still required,
19
- and the building process takes time.
18
+ scripts. A few modifications are still required, and the building process takes time.
20
19
21
20
### Goals & environment
22
21
23
- This tutorial aims at building the ** GNU toolchain 4.9** with ** Android NDK r11c ** .
22
+ This tutorial aims at building the ** GNU toolchain 4.9** with ** Android NDK r12b ** .
24
23
It has been tested on Linux x86_64, but I expect that it should work with
25
24
small changes on other systems supported by the NDK.
26
25
@@ -35,6 +34,7 @@ same, with a few extra steps detailed along the way.
35
34
#### Requirements
36
35
A few tools are required for building the toolchain, namely:
37
36
- ** git**
37
+ - ** repo**
38
38
- ** make**
39
39
- ** gcc**
40
40
- ** g++**
@@ -43,49 +43,28 @@ A few tools are required for building the toolchain, namely:
43
43
- ** bison**
44
44
- ** flex**
45
45
46
- (I also use ** wget** to download the Android NDK).
47
-
48
46
On Debian-based Linux, you can run:
49
47
```
50
- sudo apt-get install git make gcc g++ m4 texinfo bison flex wget
48
+ sudo apt-get install git repo make gcc g++ m4 texinfo bison flex
51
49
```
52
50
53
51
** Note:** When building the toolchain for Windows, ** mingw-w64** is required.
54
52
For 32-bit, ** gcc-multilib** and ** g++-multilib** are also needed.
55
53
56
54
#### Android NDK
57
55
58
- Download the Android NDK r11c from Google, and extract it.
59
- It is best to rename the folder ` ndk/ ` for building scripts to work
60
- out-of-the-box.
61
- ```
62
- wget http://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip
63
- unzip android-ndk-r11c-linux-x86_64.zip
64
- rm android-ndk-r11c-linux-x86_64.zip
65
- mv android-ndk-r11c ndk
66
- ```
67
-
68
- #### GNU toolchain
56
+ The easiest way to setup all required sources is to follow the official steps
57
+ ([ found here] ( https://android.googlesource.com/toolchain/gcc/+/master/README.md ) ).
69
58
70
- The next step is to download the GNU toolchain components from Google
71
- repositories. We'll clone them in a folder called ` toolchain/ ` .
59
+ In this repository, call:
72
60
```
73
- mkdir toolchain && cd toolchain
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
61
+ repo init -u https://android.googlesource.com/platform/manifest -b gcc
86
62
```
87
63
88
- #### Add support for Fortran
64
+ You can then use ` repo sync ` to clone all parts of the toolchain,
65
+ and ` repo forall -c git checkout ndk-r12b ` to checkout the r12b version.
66
+
67
+ #### Adding support for Fortran
89
68
90
69
In ` toolchain/gcc/build-gcc.sh ` , find the line that contains:
91
70
```
@@ -104,44 +83,18 @@ as_fn_append ac_func_list " ttyname_r"
104
83
105
84
#### Building
106
85
107
- The last change to do before building everything is in
108
- ` ndk/build/lib/build_support.py ` . Change the line
109
- ```
110
- prebuilt_ndk = 'prebuilts/ndk/current'
111
- ```
112
- to
86
+ If you are planning to build the ARM or AArch64 toolchains for Linux 64-bit
87
+ or Windows 32-bit, that shoule be sufficient.
88
+ Simply call ` build.py ` under ` toolchain/gcc ` which will take care of everything.
89
+ You can specify which toolchain to build. For instance:
113
90
```
114
- prebuilt_ndk = 'ndk'
91
+ ./build.py --toolchain arm-linux-androideabi
115
92
```
116
- so that the building script can find the ` ndk/platforms ` folder
117
- correctly.
118
-
119
- ** Note:** When building the x86 or x86_64 toolchains, additional changes are
120
- required. There is an issue in libgfortran for the x86 and x86_64 targets
121
- (see [ this issue] ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71363 ) ) causing
122
- an error when building it. See the ` x86.diff ` .
93
+ See ` ./build.py -h ` for possible values.
94
+ If nothing is specified, it will build all of them.
123
95
124
- ** Note:** When building the toolchain for Windows,
125
- you need to change ` ndk/build/tools/prebuilt-common.sh ` for the MinGW
126
- wrapper to be found. Find the line that says:
127
- ```
128
- # generate wrappers for BUILD toolchain
129
- ```
130
- and replace the section that follows by:
131
- ```
132
- LEGACY_TOOLCHAIN_PREFIX="/usr/bin/x86_64-linux-gnu-"
133
- $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=i386-linux-gnu- \
134
- --cflags="-m32" --cxxflags="-m32" --ldflags="-m elf_i386" --asflags="--32" \
135
- --dst-prefix="$LEGACY_TOOLCHAIN_PREFIX" "$CROSS_WRAP_DIR"
136
- $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=i386-pc-linux-gnu- \
137
- --cflags="-m32" --cxxflags="-m32" --ldflags="-m elf_i386" --asflags="--32" \
138
- --dst-prefix="$LEGACY_TOOLCHAIN_PREFIX" "$CROSS_WRAP_DIR"
139
- # 64-bit BUILD toolchain. libbfd is still built in 32-bit.
140
- $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=x86_64-linux-gnu- \
141
- --dst-prefix="$LEGACY_TOOLCHAIN_PREFIX" "$CROSS_WRAP_DIR"
142
- $NDK_BUILDTOOLS_PATH/gen-toolchain-wrapper.sh --src-prefix=x86_64-pc-linux-gnu- \
143
- --dst-prefix="$LEGACY_TOOLCHAIN_PREFIX" "$CROSS_WRAP_DIR"
144
- ```
96
+ When building the toolchain for Windows, add ` --host windows `
97
+ (or ` --host windows64 ` for 64-bit).
145
98
146
99
** Note:** If you want to build ** standalone toolchains**
147
100
(i.e. you're not using ` ndk-build ` ), there is one extra step.
@@ -154,16 +107,24 @@ and
154
107
rm -rf $TOOLCHAIN_INSTALL_PATH/sysroot
155
108
```
156
109
157
- Now you can run ` build.py ` under ` toolchain/gcc ` which will take care of everything.
158
- You can specify which toolchain to build. For instance:
110
+ #### Other targets / hosts
111
+
112
+ When building the ** x86 or x86_64 toolchains** , additional changes are
113
+ required. There is an issue in libgfortran for the x86 and x86_64 targets
114
+ (see #2 and [ this issue] ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71363 ) )
115
+ causing an error when building it. See the ` x86.diff ` .
116
+
117
+ When building the toolchain for ** Windows 64-bit** ,
118
+ you need to change ` toolchain/binutils/binutils-2.25/gold/aarch64.cc `
119
+ (see #1 and [ this issue] ( https://sourceware.org/ml/binutils-cvs/2015-07/msg00148.html ) ).
120
+ Find line 2028 that says:
159
121
```
160
- ./build.py --toolchain arm-linux-androideabi
122
+ Insntype adr_insn = adrp_insn & ((1 << 31) - 1);
123
+ ```
124
+ and replace it by:
125
+ ```
126
+ Insntype adr_insn = adrp_insn & ((1u << 31) - 1);
161
127
```
162
- See ` ./build.py -h ` for possible values.
163
- If nothing is specified, it will build all of them.
164
-
165
- ** Note:** When building the toolchain for Windows, add ` --host windows `
166
- (or ` --host windows64 ` for 64-bit).
167
128
168
129
### Deploying
169
130
0 commit comments