Project

General

Profile

NDKBuild » History » Version 2

Beuc Beuc, 07/24/2015 09:53 PM
GNU/Linux build

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
These tools download various upstream imports from https://android.googlesource.com/toolchain/XXX/ with optional commit date (no branches or tags), apply patches, and build them.
7
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
h2. Ubuntu 10.04 build environment with LXC
11
12
Replicant 4.2 is based on CyanogenMod 10.1 which is based on AOSP 4.2.2 (2013-02).
13
The build environment used by Google should be Ubuntu LTS 12.04.
14
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
</pre>
35
36
h2. Build dependencies
37
38
<pre>
39
# Base Android build dependencies (from https://source.android.com/source/initializing.html, section "Installing required packages (Ubuntu 12.04)")
40
# Dropping mingw to skip windows builds for now.
41
# Installing g++-multilib first otherwise apt-get complains.
42
apt-get install build-essential g++-multilib
43
apt-get install git gnupg flex bison gperf \
44
  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
45
  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
46
  libgl1-mesa-dev \
47
  python-markdown libxml2-utils xsltproc zlib1g-dev:i386
48
49
# Additional NDK build dependencies (completed from https://android.googlesource.com/platform/ndk/+/master/README.md)
50
apt-get install curl texinfo bison flex libtool pbzip2 groff
51
52
# Make 'bash' the default shell otherwise 'build-gabi++.sh' will fail
53
dpkg-reconfigure dash
54
</pre>
55
56
h2. Preparing the sources
57
58
Based on [[ReplicantSourceCode]] with additional configuration.
59
60
<pre>
61
mkdir ~/tools/
62
cd ~/tools/
63
wget http://commondatastorage.googleapis.com/git-repo-downloads/repo
64
chmod a+x repo
65
cd ~
66
67
cat <<EOF >> ~/.bashrc
68
export USE_CCACHE=1
69
EOF
70
71
# Avoid prompts
72
git config --global user.email "you@example.com"
73
git config --global user.name "Your Name"
74
git config --global color.ui true
75
76
mkdir replicant-4.2/
77
cd replicant-4.2/
78
../tools/repo init -u git://git.replicant.us/manifest.git -b replicant-4.2
79
../tools/repo sync -j4 
80
# > 1h, 27GB (inc. 17GB .repo)
81
</pre>
82
83
h2. Determining the checkout date
84
85
Since there's no NDK release tag for the AOSP @toolchain/@ checkouts, we need to find the right date.
86
87
@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).
88
Checking @build/tools/toolchain-patches/@ in the NDKs shows r8c has matching patches.
89
90
Also NDKs from google contain several @SOURCES@ files listing Git repos and commit IDs.
91
With r8c's release date (@ls --full-time RELEASE.TXT@), @build/tools/download-toolchain-sources.sh@ checkouts the same Git commit IDs, and the patches apply.
92
Only, r8c references a LLVM Git repo, while our scripts download a tarball.
93
So our scripts match a NDK version between r8b and r8c, and can almost exactly reproduce r8c. Let's call it r8b2.
94
95
h2. Building the SDK
96
97
Based on @ndk/docs/DEVELOPMENT.html@, with much improvement :)
98
99
<pre>
100
export NDK=~/replicant-4.2/ndk
101
cd $NDK
102
103
# Allow checking build errors
104
export NDK_LOGFILE=$HOME/ndk.log
105
106
# Follow Python download redirection
107
sed -i -e 's/curl -S/curl -L -S/' build/tools/download-toolchain-sources.sh
108
109
# Get the sources from toolchain/ repos, with r8c release date:
110
bash $NDK/build/tools/download-toolchain-sources.sh --git-date='2012-10-22T07:59:40+0200' ~/ndk-dl
111
# ndk-dl: 2.5GB
112
113
# Define NDK_TMPDIR and and use --incremental so the build can be resumed on error
114
export NDK_TMPDIR=~/ndk-tmp
115
mkdir -p $NDK_TMPDIR/release-r8b2/
116
117
# Build the release
118
bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental
119
# 30mn with 4 cores, 28GB (inc. 17GB .repo), 2.5GB ndk-dl, 1GB /tmp
120
</pre>
121
122
The GNU/Linux NDK release is in @/tmp/ndk-replicant/release/android-ndk-r8b2-linux-x86.tar.bz2@ :)