Project

General

Profile

NDKBuild » History » Version 11

Beuc Beuc, 07/25/2015 09:58 AM
Note where to login as non-priv user

1 1 Beuc Beuc
h1. Build a Native Developement Kit (NDK) with Replicant 4.2
2
3
h2. Principle of operation
4
5
The [[ReplicantSourceCode|Android 4.2 source code]] ships a @ndk@ directory with NDK build scripts.
6 9 Beuc Beuc
These tools download various upstream imports from https://git.androidproject.xxx/toolchain/XXX/ with optional commit date (no branches or tags), apply patches, and build them.
7 1 Beuc Beuc
8 2 Beuc Beuc
Note: as of 2015-07, the upcoming Android version moved to a different build system, and will populate $topdir/toolchain/ through @repo@ instead of invoking git in a temporary directory (i.e. ditched @download-toolchain-sources.sh@).
9
10 3 Beuc Beuc
h2. Ubuntu 12.04 build environment with LXC
11 2 Beuc Beuc
12
Replicant 4.2 is based on CyanogenMod 10.1 which is based on AOSP 4.2.2 (2013-02).
13 5 Beuc Beuc
The build environment used by NDK release managers should be Ubuntu LTS 12.04.
14 2 Beuc Beuc
We recreate it through LXC.  If you know how to use Triskel 6 instead, please contribute the instructions.
15
16
<pre>
17
lxc-create -n replicant -t download -- -d ubuntu -r precise -a amd64
18
# Note: or Triskel 6, if you know how to configure LXC/debootstrap for it
19
lxc-start -n replicant -d
20
lxc-attach -n replicant
21
22
# clean-up non-free sources
23
sed -i -e 's/ restricted//' -e 's/ multiverse//' /etc/apt/sources.list
24
apt-get update
25
26
# prepare build user
27
apt-get install openssh-server
28
useradd replicant --shell /bin/bash --create-home
29
mkdir -p -m 700 ~replicant/.ssh
30
cat <<EOF >> ~replicant/.ssh/authorized_keys
31
your public key
32
EOF
33
chown -R replicant: ~replicant
34 1 Beuc Beuc
</pre>
35 3 Beuc Beuc
36
Note: compiling from Debian 8 will yield errors from texinfo (doc in binutils) and Perl (POD in LLVM) due to more recent, stricter versions of these.
37 2 Beuc Beuc
38
h2. Build dependencies
39
40
<pre>
41
# Base Android build dependencies (from https://source.android.com/source/initializing.html, section "Installing required packages (Ubuntu 12.04)")
42
# Dropping mingw to skip windows builds for now.
43
# Installing g++-multilib first otherwise apt-get complains.
44
apt-get install build-essential g++-multilib
45
apt-get install git gnupg flex bison gperf \
46
  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
47
  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
48
  libgl1-mesa-dev \
49
  python-markdown libxml2-utils xsltproc zlib1g-dev:i386
50
51
# Additional NDK build dependencies (completed from https://android.googlesource.com/platform/ndk/+/master/README.md)
52
apt-get install curl texinfo bison flex libtool pbzip2 groff
53
54
# Make 'bash' the default shell otherwise 'build-gabi++.sh' will fail
55
dpkg-reconfigure dash
56
</pre>
57
58
h2. Preparing the sources
59
60
Based on [[ReplicantSourceCode]] with additional configuration.
61 11 Beuc Beuc
Login as user @replicant@ and:
62 2 Beuc Beuc
63
<pre>
64
mkdir ~/tools/
65
cd ~/tools/
66
wget http://commondatastorage.googleapis.com/git-repo-downloads/repo
67
chmod a+x repo
68
cd ~
69
70
cat <<EOF >> ~/.bashrc
71
export USE_CCACHE=1
72
EOF
73
74
# Avoid prompts
75
git config --global user.email "you@example.com"
76
git config --global user.name "Your Name"
77
git config --global color.ui true
78
79
mkdir replicant-4.2/
80
cd replicant-4.2/
81
../tools/repo init -u git://git.replicant.us/manifest.git -b replicant-4.2
82
../tools/repo sync -j4 
83
# > 1h, 27GB (inc. 17GB .repo)
84
</pre>
85
86
h2. Determining the checkout date
87
88 7 Beuc Beuc
Since there's no NDK release tag for the @toolchain/@ Git checkouts, we need to find the right date.
89 2 Beuc Beuc
90
@cd ndk/ && git log@ says the last commit is 2012-10-05, so it's around NDK r8b (2012-07) and NDK r8c (2012-11).
91
Checking @build/tools/toolchain-patches/@ in the NDKs shows r8c has matching patches.
92
93
Also NDKs from google contain several @SOURCES@ files listing Git repos and commit IDs.
94 10 Beuc Beuc
With r8c's release date (@ls --full-time RELEASE.TXT@ => 2012-10-22 05:59), @build/tools/download-toolchain-sources.sh@ checkouts the same Git commit IDs, and the patches apply.
95 2 Beuc Beuc
Only, r8c references a LLVM Git repo, while our scripts download a tarball.
96
So our scripts match a NDK version between r8b and r8c, and can almost exactly reproduce r8c. Let's call it r8b2.
97
98
h2. Building the SDK
99
100
Based on @ndk/docs/DEVELOPMENT.html@, with much improvement :)
101
102
<pre>
103
export NDK=~/replicant-4.2/ndk
104
cd $NDK
105
106
# Allow checking build errors
107
export NDK_LOGFILE=$HOME/ndk.log
108
109
# Follow Python download redirection
110
sed -i -e 's/curl -S/curl -L -S/' build/tools/download-toolchain-sources.sh
111
112
# Get the sources from toolchain/ repos, with r8c release date:
113 10 Beuc Beuc
bash $NDK/build/tools/download-toolchain-sources.sh --git-date='2012-10-22T05:59:40Z' ~/ndk-dl
114 2 Beuc Beuc
# ndk-dl: 2.5GB
115
116
# Define NDK_TMPDIR and and use --incremental so the build can be resumed on error
117
export NDK_TMPDIR=~/ndk-tmp
118
mkdir -p $NDK_TMPDIR/release-r8b2/
119
120
# Build the release
121
bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental
122
# 30mn with 4 cores, 28GB (inc. 17GB .repo), 2.5GB ndk-dl, 1GB /tmp
123
</pre>
124
125
The GNU/Linux NDK release is in @/tmp/ndk-replicant/release/android-ndk-r8b2-linux-x86.tar.bz2@ :)
126 4 Beuc Beuc
127
128
h2. TODOs
129 1 Beuc Beuc
130 7 Beuc Beuc
h3. Mirror @toolchain/@ repos
131
132
@download-toolchain-sources.sh@'s default is @--git-base=https://android.googlesource.com/toolchain@.
133
Should we use a git.replicant.us repo? (note: there's no 'toolchain' there yet)
134
135 4 Beuc Beuc
h3. Windows build
136
137
Build deps:
138
<pre>
139
# windows build is triggered by the presence of mingw32
140
apt-get install mingw32 tofrodos
141
# and requires running maketab.exe
142
apt-get install wine
143
# I had troubles in LXC registering direct .exe execution:
144
# $ /tmp/ndk-replicant/tmp/build-3038/maketab.exe 
145
# run-detectors: unable to find an interpreter for /tmp/ndk-replicant/tmp/build-3038/maketab.exe
146
# Work-around:
147
update-binfmts --disable
148
dpkg-reconfigure wine1.4 --pri=high
149
</pre>
150
151
Code fixes:
152
<pre>
153
# build-ndk-stack/elff/ produces a warning with mingw32, and uses -Werror
154
# cf. https://android.googlesource.com/platform/ndk/+/32e74f3f1b969ff65f037e1ee89e21a5cbc0ecf0
155
sed -i -e 's/-Werror//' sources/host-tools/ndk-stack/GNUMakefile
156
# TODO: maybe 'export EXTRA_CFLAGS=-Wall' would be enough?
157
# TODO: does this mean google was rebuilding from Ubuntu 10.04 instead of 12.04?
158
</pre>
159
160
...
161
162
<pre>
163
bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental
164
# /home/replicant/ndk-dl/build/../binutils/binutils-2.21/gold/arm.cc:2171: internal compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:4971
165
# => let's disable the windows build for now.. maybe better with 10.04? or a later ndk.git revision?
166
</pre>
167
168 6 Beuc Beuc
h3. Use of prebuilts
169
170
Check how much of $topdir/prebuilts/ is used to compile the NDK. We shouldn't rely on untrusted binaries.
171 4 Beuc Beuc
172 1 Beuc Beuc
h3. Other build method
173 4 Beuc Beuc
174 7 Beuc Beuc
Attempt to rebuild r8e with the same build environment, but checkout-ing precise .git revisions from ndk.git and development.git:
175 4 Beuc Beuc
less patches + local LLVM repo + precise control over the ndk scripts revision
176
177
According to @ndk/docs/DEVELOPMENT.html@ one only needs:
178 9 Beuc Beuc
  git clone https://git.androidproject.xxx/platform/ndk.git ndk
179
  git clone https://git.androidproject.xxx/platform/development.git development
180 4 Beuc Beuc
181 7 Beuc Beuc
This means we wouldn't rely on exactly the build scripts shipped in Replicant 4.2.
182 6 Beuc Beuc
183
h4. Yet another build method
184
185
@ndk/docs/DEVELOPMENT.html@ references using an existing (trusted) NDK to build the next one.