NDKBuild » History » Version 19
Wolfgang Wiedmeyer, 05/02/2017 10:33 PM
only link to source code page (information needs to be consolidated, so it's less likely to be outdated as in this case)
1 | 1 | Beuc Beuc | h1. Build a Native Developement Kit (NDK) with Replicant 4.2 |
---|---|---|---|
2 | |||
3 | 18 | Wolfgang Wiedmeyer | See feature #837 for the discussion about a NDK for Replicant and this page. |
4 | |||
5 | 1 | Beuc Beuc | h2. Principle of operation |
6 | |||
7 | The [[ReplicantSourceCode|Android 4.2 source code]] ships a @ndk@ directory with NDK build scripts. |
||
8 | 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. |
9 | 1 | Beuc Beuc | |
10 | 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@). |
11 | |||
12 | 12 | Beuc Beuc | h2. Recreate matching build environment |
13 | 1 | Beuc Beuc | |
14 | 12 | Beuc Beuc | Replicant 4.2 is based on CyanogenMod 10.1 which is based on AOSP 4.2.2, released 2013-02. |
15 | The build environment used by NDK release managers should be Ubuntu LTS 12.04 (or maybe Ubuntu LTS 10.04). |
||
16 | 2 | Beuc Beuc | |
17 | 12 | Beuc Beuc | To recreate it easily with LXC, follow: |
18 | * [[BuildEnvironments#Ubuntu-1204-Precise-with-LXC|Ubuntu 12.04 Precise with LXC]] (Trisquel support in progress) |
||
19 | * [[BuildEnvironments#Non-privileged-user-setup|Non-privileged user setup]] |
||
20 | 3 | Beuc Beuc | |
21 | 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. |
||
22 | 2 | Beuc Beuc | |
23 | h2. Build dependencies |
||
24 | |||
25 | <pre> |
||
26 | # Base Android build dependencies (from https://source.android.com/source/initializing.html, section "Installing required packages (Ubuntu 12.04)") |
||
27 | # Dropping mingw to skip windows builds for now. |
||
28 | # Installing g++-multilib first otherwise apt-get complains. |
||
29 | apt-get install build-essential g++-multilib |
||
30 | 13 | Beuc Beuc | apt-get install wget git gnupg flex bison gperf \ |
31 | 2 | Beuc Beuc | zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \ |
32 | libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \ |
||
33 | libgl1-mesa-dev \ |
||
34 | python-markdown libxml2-utils xsltproc zlib1g-dev:i386 |
||
35 | |||
36 | # Additional NDK build dependencies (completed from https://android.googlesource.com/platform/ndk/+/master/README.md) |
||
37 | apt-get install curl texinfo bison flex libtool pbzip2 groff |
||
38 | |||
39 | # Make 'bash' the default shell otherwise 'build-gabi++.sh' will fail |
||
40 | dpkg-reconfigure dash |
||
41 | </pre> |
||
42 | |||
43 | h2. Preparing the sources |
||
44 | |||
45 | 19 | Wolfgang Wiedmeyer | Login as user @replicant@ and prepare the Replicant 4.2 source code as described in [[ReplicantSourceCode]]. |
46 | 11 | Beuc Beuc | |
47 | 19 | Wolfgang Wiedmeyer | Optionally configure ccache: |
48 | 2 | Beuc Beuc | <pre> |
49 | cat <<EOF >> ~/.bashrc |
||
50 | export USE_CCACHE=1 |
||
51 | EOF |
||
52 | exec bash |
||
53 | |||
54 | 14 | Beuc Beuc | prebuilts/misc/linux-x86/ccache/ccache -M 10G # unused in Trisquel 4.1? |
55 | 2 | Beuc Beuc | </pre> |
56 | |||
57 | h2. Determining the checkout date |
||
58 | |||
59 | 7 | Beuc Beuc | Since there's no NDK release tag for the @toolchain/@ Git checkouts, we need to find the right date. |
60 | 2 | Beuc Beuc | |
61 | @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). |
||
62 | Checking @build/tools/toolchain-patches/@ in the NDKs shows r8c has matching patches. |
||
63 | |||
64 | Also NDKs from google contain several @SOURCES@ files listing Git repos and commit IDs. |
||
65 | 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. |
66 | 2 | Beuc Beuc | Only, r8c references a LLVM Git repo, while our scripts download a tarball. |
67 | So our scripts match a NDK version between r8b and r8c, and can almost exactly reproduce r8c. Let's call it r8b2. |
||
68 | |||
69 | 17 | Wolfgang Wiedmeyer | h2. Building the NDK |
70 | 2 | Beuc Beuc | |
71 | Based on @ndk/docs/DEVELOPMENT.html@, with much improvement :) |
||
72 | |||
73 | <pre> |
||
74 | export NDK=~/replicant-4.2/ndk |
||
75 | cd $NDK |
||
76 | |||
77 | # Allow checking build errors |
||
78 | export NDK_LOGFILE=$HOME/ndk.log |
||
79 | |||
80 | # Follow Python download redirection |
||
81 | sed -i -e 's/curl -S/curl -L -S/' build/tools/download-toolchain-sources.sh |
||
82 | |||
83 | 10 | Beuc Beuc | # Get the sources from toolchain/ repos, with r8c release date: |
84 | 1 | Beuc Beuc | bash $NDK/build/tools/download-toolchain-sources.sh --git-date='2012-10-22T05:59:40Z' ~/ndk-dl |
85 | 14 | Beuc Beuc | # ~5mn with good network, ndk-dl: 2.5GB |
86 | 2 | Beuc Beuc | |
87 | # Define NDK_TMPDIR and and use --incremental so the build can be resumed on error |
||
88 | export NDK_TMPDIR=~/ndk-tmp |
||
89 | mkdir -p $NDK_TMPDIR/release-r8b2/ |
||
90 | |||
91 | 1 | Beuc Beuc | # Build the release |
92 | 2 | Beuc Beuc | bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental |
93 | 14 | Beuc Beuc | # 30mn with 4 cores, 28GB (inc. 17GB .repo), 2.5GB ndk-dl, ?GB ndk-tmp, 1GB /tmp |
94 | 2 | Beuc Beuc | </pre> |
95 | |||
96 | 4 | Beuc Beuc | The GNU/Linux NDK release is in @/tmp/ndk-replicant/release/android-ndk-r8b2-linux-x86.tar.bz2@ :) |
97 | |||
98 | h2. TODOs |
||
99 | 1 | Beuc Beuc | |
100 | 7 | Beuc Beuc | h3. Mirror @toolchain/@ repos |
101 | |||
102 | @download-toolchain-sources.sh@'s default is @--git-base=https://android.googlesource.com/toolchain@. |
||
103 | Should we use a git.replicant.us repo? (note: there's no 'toolchain' there yet) |
||
104 | |||
105 | 4 | Beuc Beuc | h3. Windows build |
106 | |||
107 | Build deps: |
||
108 | <pre> |
||
109 | # windows build is triggered by the presence of mingw32 |
||
110 | apt-get install mingw32 tofrodos |
||
111 | # and requires running maketab.exe |
||
112 | apt-get install wine |
||
113 | # I had troubles in LXC registering direct .exe execution: |
||
114 | # $ /tmp/ndk-replicant/tmp/build-3038/maketab.exe |
||
115 | 1 | Beuc Beuc | # run-detectors: unable to find an interpreter for /tmp/ndk-replicant/tmp/build-3038/maketab.exe |
116 | 4 | Beuc Beuc | # Work-around: |
117 | update-binfmts --disable |
||
118 | 14 | Beuc Beuc | dpkg-reconfigure wine1.4 --pri=high # or wine1.2 for Trisquel 4.1 |
119 | 4 | Beuc Beuc | </pre> |
120 | |||
121 | Code fixes: |
||
122 | <pre> |
||
123 | # build-ndk-stack/elff/ produces a warning with mingw32, and uses -Werror |
||
124 | # cf. https://android.googlesource.com/platform/ndk/+/32e74f3f1b969ff65f037e1ee89e21a5cbc0ecf0 |
||
125 | sed -i -e 's/-Werror//' sources/host-tools/ndk-stack/GNUMakefile |
||
126 | # TODO: maybe 'export EXTRA_CFLAGS=-Wall' would be enough? |
||
127 | </pre> |
||
128 | |||
129 | ... |
||
130 | 1 | Beuc Beuc | |
131 | <pre> |
||
132 | bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental |
||
133 | # /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 |
||
134 | </pre> |
||
135 | 14 | Beuc Beuc | |
136 | Exact same errors with Trisquel 4.1 (Ubuntu 10.04). For reference, the build dependencies: |
||
137 | <pre> |
||
138 | # Based on https://web.archive.org/web/20121201011547/http://source.android.com/source/initializing.html |
||
139 | apt-get install gnupg flex bison gperf build-essential \ |
||
140 | zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \ |
||
141 | x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \ |
||
142 | libgl1-mesa-dev g++-multilib python-markdown \ |
||
143 | libxml2-utils xsltproc |
||
144 | </pre> |
||
145 | |||
146 | No idea how google made the windows build for r8c. Maybe a later ndk.git has fixes? |
||
147 | |||
148 | 4 | Beuc Beuc | |
149 | 6 | Beuc Beuc | h3. Use of prebuilts |
150 | |||
151 | Check how much of $topdir/prebuilts/ is used to compile the NDK. We shouldn't rely on untrusted binaries. |
||
152 | 4 | Beuc Beuc | |
153 | 15 | Beuc Beuc | |
154 | 16 | Beuc Beuc | h3. Other build method : directly use ndk.git and development.git |
155 | 4 | Beuc Beuc | |
156 | 7 | Beuc Beuc | Attempt to rebuild r8e with the same build environment, but checkout-ing precise .git revisions from ndk.git and development.git: |
157 | 4 | Beuc Beuc | less patches + local LLVM repo + precise control over the ndk scripts revision |
158 | |||
159 | According to @ndk/docs/DEVELOPMENT.html@ one only needs: |
||
160 | 9 | Beuc Beuc | git clone https://git.androidproject.xxx/platform/ndk.git ndk |
161 | git clone https://git.androidproject.xxx/platform/development.git development |
||
162 | 1 | Beuc Beuc | |
163 | 16 | Beuc Beuc | We wouldn't rely on exactly the build scripts shipped in Replicant 4.2, but official NDK releases are not sync'd with an Android release either. |
164 | This would allow us to reproduce an existing NDK release precisely. |
||
165 | 15 | Beuc Beuc | |
166 | 16 | Beuc Beuc | h4. Other build method : rely on previously built NDK |
167 | 6 | Beuc Beuc | |
168 | 1 | Beuc Beuc | @ndk/docs/DEVELOPMENT.html@ references using an existing (trusted) NDK to build the next one. |
169 | 15 | Beuc Beuc | Maybe this is how the NDK release team worked around the windows build errors (by not recompiling everything)? |