NDKBuild » History » Version 3
Beuc Beuc, 07/24/2015 09:56 PM
Additional build environment notes
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 | 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 | 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 | 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 | |||
62 | <pre> |
||
63 | mkdir ~/tools/ |
||
64 | cd ~/tools/ |
||
65 | wget http://commondatastorage.googleapis.com/git-repo-downloads/repo |
||
66 | chmod a+x repo |
||
67 | cd ~ |
||
68 | |||
69 | cat <<EOF >> ~/.bashrc |
||
70 | export USE_CCACHE=1 |
||
71 | EOF |
||
72 | |||
73 | # Avoid prompts |
||
74 | git config --global user.email "you@example.com" |
||
75 | git config --global user.name "Your Name" |
||
76 | git config --global color.ui true |
||
77 | |||
78 | mkdir replicant-4.2/ |
||
79 | cd replicant-4.2/ |
||
80 | ../tools/repo init -u git://git.replicant.us/manifest.git -b replicant-4.2 |
||
81 | ../tools/repo sync -j4 |
||
82 | # > 1h, 27GB (inc. 17GB .repo) |
||
83 | </pre> |
||
84 | |||
85 | h2. Determining the checkout date |
||
86 | |||
87 | Since there's no NDK release tag for the AOSP @toolchain/@ checkouts, we need to find the right date. |
||
88 | |||
89 | @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). |
||
90 | Checking @build/tools/toolchain-patches/@ in the NDKs shows r8c has matching patches. |
||
91 | |||
92 | Also NDKs from google contain several @SOURCES@ files listing Git repos and commit IDs. |
||
93 | 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. |
||
94 | Only, r8c references a LLVM Git repo, while our scripts download a tarball. |
||
95 | So our scripts match a NDK version between r8b and r8c, and can almost exactly reproduce r8c. Let's call it r8b2. |
||
96 | |||
97 | h2. Building the SDK |
||
98 | |||
99 | Based on @ndk/docs/DEVELOPMENT.html@, with much improvement :) |
||
100 | |||
101 | <pre> |
||
102 | export NDK=~/replicant-4.2/ndk |
||
103 | cd $NDK |
||
104 | |||
105 | # Allow checking build errors |
||
106 | export NDK_LOGFILE=$HOME/ndk.log |
||
107 | |||
108 | # Follow Python download redirection |
||
109 | sed -i -e 's/curl -S/curl -L -S/' build/tools/download-toolchain-sources.sh |
||
110 | |||
111 | # Get the sources from toolchain/ repos, with r8c release date: |
||
112 | bash $NDK/build/tools/download-toolchain-sources.sh --git-date='2012-10-22T07:59:40+0200' ~/ndk-dl |
||
113 | # ndk-dl: 2.5GB |
||
114 | |||
115 | # Define NDK_TMPDIR and and use --incremental so the build can be resumed on error |
||
116 | export NDK_TMPDIR=~/ndk-tmp |
||
117 | mkdir -p $NDK_TMPDIR/release-r8b2/ |
||
118 | |||
119 | # Build the release |
||
120 | bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental |
||
121 | # 30mn with 4 cores, 28GB (inc. 17GB .repo), 2.5GB ndk-dl, 1GB /tmp |
||
122 | </pre> |
||
123 | |||
124 | The GNU/Linux NDK release is in @/tmp/ndk-replicant/release/android-ndk-r8b2-linux-x86.tar.bz2@ :) |