Skip to content

Commit 0d7848e

Browse files
committed
Updated instructions for NDK r12b (issue #3)
1 parent 20cefa7 commit 0d7848e

File tree

2 files changed

+39
-76
lines changed

2 files changed

+39
-76
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.repo
12
ndk/
23
toolchain/
34
out/
5+
prebuilts

README.md

Lines changed: 37 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ and [this Google group](https://groups.google.com/forum/#!msg/android-ndk/QR1qiN
1515
## Procedure
1616

1717
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.
2019

2120
### Goals & environment
2221

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**.
2423
It has been tested on Linux x86_64, but I expect that it should work with
2524
small changes on other systems supported by the NDK.
2625

@@ -35,6 +34,7 @@ same, with a few extra steps detailed along the way.
3534
#### Requirements
3635
A few tools are required for building the toolchain, namely:
3736
- **git**
37+
- **repo**
3838
- **make**
3939
- **gcc**
4040
- **g++**
@@ -43,49 +43,28 @@ A few tools are required for building the toolchain, namely:
4343
- **bison**
4444
- **flex**
4545

46-
(I also use **wget** to download the Android NDK).
47-
4846
On Debian-based Linux, you can run:
4947
```
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
5149
```
5250

5351
**Note:** When building the toolchain for Windows, **mingw-w64** is required.
5452
For 32-bit, **gcc-multilib** and **g++-multilib** are also needed.
5553

5654
#### Android NDK
5755

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)).
6958

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:
7260
```
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
8662
```
8763

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
8968

9069
In `toolchain/gcc/build-gcc.sh`, find the line that contains:
9170
```
@@ -104,44 +83,18 @@ as_fn_append ac_func_list " ttyname_r"
10483

10584
#### Building
10685

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:
11390
```
114-
prebuilt_ndk = 'ndk'
91+
./build.py --toolchain arm-linux-androideabi
11592
```
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.
12395

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).
14598

14699
**Note:** If you want to build **standalone toolchains**
147100
(i.e. you're not using `ndk-build`), there is one extra step.
@@ -154,16 +107,24 @@ and
154107
rm -rf $TOOLCHAIN_INSTALL_PATH/sysroot
155108
```
156109

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:
159121
```
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);
161127
```
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).
167128

168129
### Deploying
169130

0 commit comments

Comments
 (0)