Commit | Line | Data |
---|---|---|
59f0d218 FF |
1 | #!/bin/bash |
2 | ||
59f0d218 FF |
3 | set -e -o pipefail -u |
4 | ||
7b1f1bd3 FF |
5 | # Utility function to log an error message and exit with an error code. |
6 | termux_error_exit() { | |
7 | echo "ERROR: $*" 1>&2 | |
a0057943 | 8 | exit 1 |
7b1f1bd3 | 9 | } |
2c1aa558 | 10 | |
bd2f734a FF |
11 | if [ `uname -o` = Android ]; then |
12 | termux_error_exit "On-device builds are not supported - see README.md" | |
13 | fi | |
14 | ||
7b1f1bd3 | 15 | # Utility function to download a resource, optionally checking against a checksum. |
19fb617a | 16 | termux_download() { |
7b1f1bd3 FF |
17 | local URL="$1" |
18 | local DESTINATION="$2" | |
c9d4e74f FF |
19 | |
20 | if [ -f "$DESTINATION" ] && [ $# = 3 ] && [ -n "$3" ]; then | |
21 | # Keep existing file if checksum matches. | |
22 | local EXISTING_CHECKSUM | |
23 | EXISTING_CHECKSUM=$(sha256sum "$DESTINATION" | cut -f 1 -d ' ') | |
24 | if [ "$EXISTING_CHECKSUM" = "$3" ]; then return; fi | |
25 | fi | |
26 | ||
7b1f1bd3 FF |
27 | local TMPFILE |
28 | TMPFILE=$(mktemp "$TERMUX_PKG_TMPDIR/download.$TERMUX_PKG_NAME.XXXXXXXXX") | |
e239964b | 29 | echo "Downloading ${URL}" |
7b1f1bd3 | 30 | local TRYMAX=6 |
6ad2991c | 31 | for try in $(seq 1 $TRYMAX); do |
e239964b | 32 | if curl -L --fail --retry 2 -o "$TMPFILE" "$URL"; then |
7b1f1bd3 FF |
33 | local ACTUAL_CHECKSUM |
34 | ACTUAL_CHECKSUM=$(sha256sum "$TMPFILE" | cut -f 1 -d ' ') | |
35 | if [ $# = 3 ] && [ -n "$3" ]; then | |
e239964b | 36 | # Optional checksum argument: |
aea30235 | 37 | local EXPECTED=$3 |
7b1f1bd3 | 38 | if [ "$EXPECTED" != "$ACTUAL_CHECKSUM" ]; then |
a75313ee FF |
39 | >&2 printf "Wrong checksum for %s:\nExpected: %s\nActual: %s\n" \ |
40 | "$URL" "$EXPECTED" "$ACTUAL_CHECKSUM" | |
aea30235 FF |
41 | exit 1 |
42 | fi | |
e239964b | 43 | else |
a75313ee FF |
44 | printf "No validation of checksum for %s:\nActual: %s\n" \ |
45 | "$URL" "$ACTUAL_CHECKSUM" | |
e239964b FF |
46 | fi |
47 | mv "$TMPFILE" "$DESTINATION" | |
48 | return | |
49 | else | |
7b1f1bd3 | 50 | echo "Download of $URL failed (attempt $try/$TRYMAX)" 1>&2 |
e239964b FF |
51 | sleep 45 |
52 | fi | |
53 | done | |
54 | ||
7b1f1bd3 FF |
55 | termux_error_exit "Failed to download $URL" |
56 | } | |
57 | ||
58 | # Utility function for golang-using packages to setup a go toolchain. | |
01e699d9 | 59 | termux_setup_golang() { |
7b1f1bd3 FF |
60 | export GOOS=android |
61 | export CGO_ENABLED=1 | |
62 | export GO_LDFLAGS="-extldflags=-pie" | |
63 | if [ "$TERMUX_ARCH" = "arm" ]; then | |
64 | export GOARCH=arm | |
65 | export GOARM=7 | |
66 | elif [ "$TERMUX_ARCH" = "i686" ]; then | |
67 | export GOARCH=386 | |
68 | export GO386=sse2 | |
69 | elif [ "$TERMUX_ARCH" = "aarch64" ]; then | |
70 | export GOARCH=arm64 | |
71 | elif [ "$TERMUX_ARCH" = "x86_64" ]; then | |
72 | export GOARCH=amd64 | |
73 | else | |
74 | termux_error_exit "Unsupported arch: $TERMUX_ARCH" | |
75 | fi | |
76 | ||
c451d911 | 77 | local TERMUX_GO_VERSION=go1.10.2 |
7b1f1bd3 | 78 | local TERMUX_GO_PLATFORM=linux-amd64 |
7b1f1bd3 | 79 | |
538812ae | 80 | local TERMUX_BUILDGO_FOLDER=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION} |
7b1f1bd3 FF |
81 | export GOROOT=$TERMUX_BUILDGO_FOLDER |
82 | export PATH=$GOROOT/bin:$PATH | |
83 | ||
84 | if [ -d "$TERMUX_BUILDGO_FOLDER" ]; then return; fi | |
85 | ||
86 | local TERMUX_BUILDGO_TAR=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz | |
87 | rm -Rf "$TERMUX_COMMON_CACHEDIR/go" "$TERMUX_BUILDGO_FOLDER" | |
88 | termux_download https://storage.googleapis.com/golang/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz \ | |
926a7bf3 | 89 | "$TERMUX_BUILDGO_TAR" \ |
c451d911 | 90 | 4b677d698c65370afa33757b6954ade60347aaca310ea92a63ed717d7cb0c2ff |
36c4069c | 91 | |
7b1f1bd3 FF |
92 | ( cd "$TERMUX_COMMON_CACHEDIR"; tar xf "$TERMUX_BUILDGO_TAR"; mv go "$TERMUX_BUILDGO_FOLDER"; rm "$TERMUX_BUILDGO_TAR" ) |
93 | } | |
94 | ||
9683c971 | 95 | # Utility function to setup a current ninja build system. |
f0c1439b | 96 | termux_setup_ninja() { |
5f03e364 | 97 | local NINJA_VERSION=1.8.2 |
f0c1439b FF |
98 | local NINJA_FOLDER=$TERMUX_COMMON_CACHEDIR/ninja-$NINJA_VERSION |
99 | if [ ! -x $NINJA_FOLDER/ninja ]; then | |
100 | mkdir -p $NINJA_FOLDER | |
101 | local NINJA_ZIP_FILE=$TERMUX_PKG_TMPDIR/ninja-$NINJA_VERSION.zip | |
102 | termux_download https://github.com/ninja-build/ninja/releases/download/v$NINJA_VERSION/ninja-linux.zip \ | |
103 | $NINJA_ZIP_FILE \ | |
5f03e364 | 104 | d2fea9ff33b3ef353161ed906f260d565ca55b8ca0568fa07b1d2cab90a84a07 |
f0c1439b FF |
105 | unzip $NINJA_ZIP_FILE -d $NINJA_FOLDER |
106 | fi | |
107 | export PATH=$NINJA_FOLDER:$PATH | |
108 | } | |
109 | ||
9683c971 | 110 | # Utility function to setup a current meson build system. |
f0c1439b FF |
111 | termux_setup_meson() { |
112 | termux_setup_ninja | |
8e60e2ea | 113 | local MESON_VERSION=0.45.1 |
490a9b18 | 114 | local MESON_FOLDER=$TERMUX_COMMON_CACHEDIR/meson-$MESON_VERSION-v1 |
f0c1439b FF |
115 | if [ ! -d "$MESON_FOLDER" ]; then |
116 | local MESON_TAR_NAME=meson-$MESON_VERSION.tar.gz | |
117 | local MESON_TAR_FILE=$TERMUX_PKG_TMPDIR/$MESON_TAR_NAME | |
490a9b18 | 118 | local MESON_TMP_FOLDER=$TERMUX_PKG_TMPDIR/meson-$MESON_VERSION |
f0c1439b FF |
119 | termux_download \ |
120 | https://github.com/mesonbuild/meson/releases/download/$MESON_VERSION/meson-$MESON_VERSION.tar.gz \ | |
121 | $MESON_TAR_FILE \ | |
8e60e2ea | 122 | 4d0bb0dbb1bb556cb7a4092fdfea3d6e76606bd739a4bc97481c2d7bc6200afb |
490a9b18 | 123 | tar xf "$MESON_TAR_FILE" -C "$TERMUX_PKG_TMPDIR" |
490a9b18 | 124 | mv $MESON_TMP_FOLDER $MESON_FOLDER |
f0c1439b FF |
125 | fi |
126 | TERMUX_MESON="$MESON_FOLDER/meson.py" | |
f2d612ab | 127 | TERMUX_MESON_CROSSFILE=$TERMUX_COMMON_CACHEDIR/meson-crossfile-$TERMUX_ARCH-v2.txt |
f0c1439b FF |
128 | if [ ! -f $TERMUX_MESON_CROSSFILE ]; then |
129 | local MESON_CPU MESON_CPU_FAMILY | |
130 | if [ $TERMUX_ARCH = "arm" ]; then | |
131 | MESON_CPU_FAMILY="arm" | |
132 | MESON_CPU="armv7" | |
133 | elif [ $TERMUX_ARCH = "i686" ]; then | |
134 | MESON_CPU_FAMILY="x86" | |
135 | MESON_CPU="i686" | |
136 | elif [ $TERMUX_ARCH = "x86_64" ]; then | |
137 | MESON_CPU_FAMILY="x86_64" | |
138 | MESON_CPU="x86_64" | |
139 | elif [ $TERMUX_ARCH = "aarch64" ]; then | |
140 | MESON_CPU_FAMILY="arm" | |
141 | MESON_CPU="aarch64" | |
142 | else | |
143 | termux_error_exit "Unsupported arch: $TERMUX_ARCH" | |
144 | fi | |
145 | ||
146 | cat > $TERMUX_MESON_CROSSFILE <<-HERE | |
147 | [binaries] | |
148 | ar = '$AR' | |
149 | c = '$CC' | |
150 | cpp = '$CXX' | |
151 | ld = '$LD' | |
f2d612ab | 152 | pkgconfig = '$PKG_CONFIG' |
f0c1439b FF |
153 | strip = '$STRIP' |
154 | [properties] | |
155 | needs_exe_wrapper = true | |
156 | [host_machine] | |
157 | cpu_family = '$MESON_CPU_FAMILY' | |
158 | cpu = '$MESON_CPU' | |
159 | endian = 'little' | |
160 | system = 'android' | |
161 | HERE | |
162 | fi | |
163 | } | |
164 | ||
9683c971 | 165 | # Utility function to setup a current cmake build system |
bb8baaa2 | 166 | termux_setup_cmake() { |
7ddd5140 | 167 | local TERMUX_CMAKE_MAJORVESION=3.11 |
1f46ae15 | 168 | local TERMUX_CMAKE_MINORVERSION=1 |
bb8baaa2 FF |
169 | local TERMUX_CMAKE_VERSION=$TERMUX_CMAKE_MAJORVESION.$TERMUX_CMAKE_MINORVERSION |
170 | local TERMUX_CMAKE_TARNAME=cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64.tar.gz | |
171 | local TERMUX_CMAKE_TARFILE=$TERMUX_PKG_TMPDIR/$TERMUX_CMAKE_TARNAME | |
172 | local TERMUX_CMAKE_FOLDER=$TERMUX_COMMON_CACHEDIR/cmake-$TERMUX_CMAKE_VERSION | |
7048a1f2 | 173 | if [ ! -d "$TERMUX_CMAKE_FOLDER" ]; then |
bb8baaa2 | 174 | termux_download https://cmake.org/files/v$TERMUX_CMAKE_MAJORVESION/$TERMUX_CMAKE_TARNAME \ |
7048a1f2 | 175 | "$TERMUX_CMAKE_TARFILE" \ |
1f46ae15 | 176 | 3aa8d3b53903563bdc13dfec80716c286b2228db36ef65c23bc616f9bb930367 |
7048a1f2 FF |
177 | rm -Rf "$TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64" |
178 | tar xf "$TERMUX_CMAKE_TARFILE" -C "$TERMUX_PKG_TMPDIR" | |
179 | mv "$TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64" \ | |
180 | "$TERMUX_CMAKE_FOLDER" | |
bb8baaa2 FF |
181 | fi |
182 | export PATH=$TERMUX_CMAKE_FOLDER/bin:$PATH | |
16087461 | 183 | export CMAKE_INSTALL_ALWAYS=1 |
bb8baaa2 FF |
184 | } |
185 | ||
7b1f1bd3 FF |
186 | # First step is to handle command-line arguments. Not to be overridden by packages. |
187 | termux_step_handle_arguments() { | |
188 | # shellcheck source=/dev/null | |
189 | test -f "$HOME/.termuxrc" && source "$HOME/.termuxrc" | |
190 | ||
191 | # Handle command-line arguments: | |
192 | _show_usage () { | |
cf575909 | 193 | echo "Usage: ./build-package.sh [-a ARCH] [-d] [-D] [-f] [-q] [-s] PACKAGE" |
7b1f1bd3 FF |
194 | echo "Build a package by creating a .deb file in the debs/ folder." |
195 | echo " -a The architecture to build for: aarch64(default), arm, i686, x86_64 or all." | |
196 | echo " -d Build with debug symbols." | |
197 | echo " -D Build a disabled package in disabled-packages/." | |
bc0560aa | 198 | echo " -f Force build even if package has already been built." |
cf575909 | 199 | echo " -q Quiet build" |
7b1f1bd3 FF |
200 | echo " -s Skip dependency check." |
201 | exit 1 | |
202 | } | |
cf575909 | 203 | while getopts :a:hdDfqs option; do |
7b1f1bd3 FF |
204 | case "$option" in |
205 | a) TERMUX_ARCH="$OPTARG";; | |
206 | h) _show_usage;; | |
207 | d) TERMUX_DEBUG=true;; | |
208 | D) local TERMUX_IS_DISABLED=true;; | |
bc0560aa | 209 | f) TERMUX_FORCE_BUILD=true;; |
cf575909 | 210 | q) export TERMUX_QUIET_BUILD=true;; |
7b1f1bd3 FF |
211 | s) export TERMUX_SKIP_DEPCHECK=true;; |
212 | ?) termux_error_exit "./build-package.sh: illegal option -$OPTARG";; | |
213 | esac | |
214 | done | |
215 | shift $((OPTIND-1)) | |
216 | ||
217 | if [ "$#" -ne 1 ]; then _show_usage; fi | |
218 | unset -f _show_usage | |
219 | ||
220 | # Handle 'all' arch: | |
221 | if [ -n "${TERMUX_ARCH+x}" ] && [ "${TERMUX_ARCH}" = 'all' ]; then | |
adc0d548 | 222 | for arch in 'aarch64' 'arm' 'i686' 'x86_64'; do |
bc0560aa | 223 | ./build-package.sh ${TERMUX_FORCE_BUILD+-f} -a $arch "$1" |
7b1f1bd3 FF |
224 | done |
225 | exit | |
226 | fi | |
227 | ||
228 | # Check the package to build: | |
229 | TERMUX_PKG_NAME=$(basename "$1") | |
230 | export TERMUX_SCRIPTDIR | |
231 | TERMUX_SCRIPTDIR=$(cd "$(dirname "$0")"; pwd) | |
232 | if [[ $1 == *"/"* ]]; then | |
233 | # Path to directory which may be outside this repo: | |
234 | if [ ! -d "$1" ]; then termux_error_exit "'$1' seems to be a path but is not a directory"; fi | |
235 | export TERMUX_PKG_BUILDER_DIR | |
236 | TERMUX_PKG_BUILDER_DIR=$(realpath "$1") | |
237 | else | |
238 | # Package name: | |
239 | if [ -n "${TERMUX_IS_DISABLED=""}" ]; then | |
240 | export TERMUX_PKG_BUILDER_DIR=$TERMUX_SCRIPTDIR/disabled-packages/$TERMUX_PKG_NAME | |
241 | else | |
242 | export TERMUX_PKG_BUILDER_DIR=$TERMUX_SCRIPTDIR/packages/$TERMUX_PKG_NAME | |
243 | fi | |
244 | fi | |
245 | TERMUX_PKG_BUILDER_SCRIPT=$TERMUX_PKG_BUILDER_DIR/build.sh | |
246 | if test ! -f "$TERMUX_PKG_BUILDER_SCRIPT"; then | |
247 | termux_error_exit "No build.sh script at package dir $TERMUX_PKG_BUILDER_DIR!" | |
248 | fi | |
249 | } | |
250 | ||
251 | # Setup variables used by the build. Not to be overridden by packages. | |
252 | termux_step_setup_variables() { | |
253 | : "${ANDROID_HOME:="${HOME}/lib/android-sdk"}" | |
254 | : "${NDK:="${HOME}/lib/android-ndk"}" | |
4428ae3c | 255 | : "${TERMUX_MAKE_PROCESSES:="$(nproc)"}" |
7b1f1bd3 FF |
256 | : "${TERMUX_TOPDIR:="$HOME/.termux-build"}" |
257 | : "${TERMUX_ARCH:="aarch64"}" # arm, aarch64, i686 or x86_64. | |
258 | : "${TERMUX_PREFIX:="/data/data/com.termux/files/usr"}" | |
259 | : "${TERMUX_ANDROID_HOME:="/data/data/com.termux/files/home"}" | |
260 | : "${TERMUX_DEBUG:=""}" | |
272404e1 | 261 | : "${TERMUX_PKG_API_LEVEL:="21"}" |
452ca55f | 262 | : "${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="27.0.3"}" |
392b4b6b | 263 | : "${TERMUX_NDK_VERSION:="16"}" |
7b1f1bd3 | 264 | |
10b023b8 | 265 | if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then |
7b1f1bd3 FF |
266 | TERMUX_ARCH_BITS=64 |
267 | else | |
268 | TERMUX_ARCH_BITS=32 | |
269 | fi | |
270 | ||
271 | TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-android" | |
272 | if [ "$TERMUX_ARCH" = "arm" ]; then TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}eabi"; fi | |
273 | ||
274 | if [ ! -d "$NDK" ]; then | |
275 | termux_error_exit 'NDK not pointing at a directory!' | |
276 | fi | |
277 | if ! grep -s -q "Pkg.Revision = $TERMUX_NDK_VERSION" "$NDK/source.properties"; then | |
278 | termux_error_exit "Wrong NDK version - we need $TERMUX_NDK_VERSION" | |
279 | fi | |
280 | ||
2b0e9dc9 FF |
281 | # The build tuple that may be given to --build configure flag: |
282 | TERMUX_BUILD_TUPLE=$(sh "$TERMUX_SCRIPTDIR/scripts/config.guess") | |
283 | ||
7b1f1bd3 FF |
284 | # We do not put all of build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/ into PATH |
285 | # to avoid stuff like arm-linux-androideabi-ld there to conflict with ones from | |
286 | # the standalone toolchain. | |
287 | TERMUX_DX=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/dx | |
7b1f1bd3 FF |
288 | |
289 | TERMUX_COMMON_CACHEDIR="$TERMUX_TOPDIR/_cache" | |
290 | TERMUX_DEBDIR="$TERMUX_SCRIPTDIR/debs" | |
291 | TERMUX_ELF_CLEANER=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner | |
292 | ||
7b1f1bd3 FF |
293 | export prefix=${TERMUX_PREFIX} |
294 | export PREFIX=${TERMUX_PREFIX} | |
7b1f1bd3 FF |
295 | |
296 | TERMUX_PKG_BUILDDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/build | |
297 | TERMUX_PKG_CACHEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/cache | |
298 | TERMUX_PKG_MASSAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/massage | |
299 | TERMUX_PKG_PACKAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/package | |
300 | TERMUX_PKG_SRCDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/src | |
301 | TERMUX_PKG_SHA256="" | |
302 | TERMUX_PKG_TMPDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/tmp | |
303 | TERMUX_PKG_HOSTBUILD_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/host-build | |
304 | TERMUX_PKG_PLATFORM_INDEPENDENT="" | |
305 | TERMUX_PKG_NO_DEVELSPLIT="" | |
af4dc416 | 306 | TERMUX_PKG_REVISION="0" # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version |
7b1f1bd3 FF |
307 | TERMUX_PKG_EXTRA_CONFIGURE_ARGS="" |
308 | TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS="" | |
309 | TERMUX_PKG_EXTRA_MAKE_ARGS="" | |
310 | TERMUX_PKG_BUILD_IN_SRC="" | |
311 | TERMUX_PKG_RM_AFTER_INSTALL="" | |
9ec05091 | 312 | TERMUX_PKG_BREAKS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps |
7b1f1bd3 | 313 | TERMUX_PKG_DEPENDS="" |
45d85e7f | 314 | TERMUX_PKG_BUILD_DEPENDS="" |
7b1f1bd3 FF |
315 | TERMUX_PKG_HOMEPAGE="" |
316 | TERMUX_PKG_DESCRIPTION="FIXME:Add description" | |
7b1f1bd3 FF |
317 | TERMUX_PKG_KEEP_STATIC_LIBRARIES="false" |
318 | TERMUX_PKG_ESSENTIAL="" | |
319 | TERMUX_PKG_CONFLICTS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts | |
5f217847 | 320 | TERMUX_PKG_RECOMMENDS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps |
7b1f1bd3 FF |
321 | TERMUX_PKG_REPLACES="" |
322 | TERMUX_PKG_CONFFILES="" | |
323 | TERMUX_PKG_INCLUDE_IN_DEVPACKAGE="" | |
324 | TERMUX_PKG_DEVPACKAGE_DEPENDS="" | |
325 | # Set if a host build should be done in TERMUX_PKG_HOSTBUILD_DIR: | |
326 | TERMUX_PKG_HOSTBUILD="" | |
327 | TERMUX_PKG_MAINTAINER="Fredrik Fornwall @fornwall" | |
2f0de587 | 328 | TERMUX_PKG_CLANG=yes # does nothing for cmake based packages. clang is chosen by cmake |
58f7a21c | 329 | TERMUX_PKG_FORCE_CMAKE=no # if the package has autotools as well as cmake, then set this to prefer cmake |
7b1f1bd3 FF |
330 | |
331 | unset CFLAGS CPPFLAGS LDFLAGS CXXFLAGS | |
332 | } | |
333 | ||
334 | # Save away and restore build setups which may change between builds. | |
335 | termux_step_handle_buildarch() { | |
336 | # If $TERMUX_PREFIX already exists, it may have been built for a different arch | |
337 | local TERMUX_ARCH_FILE=/data/TERMUX_ARCH | |
338 | if [ -f "${TERMUX_ARCH_FILE}" ]; then | |
339 | local TERMUX_PREVIOUS_ARCH | |
340 | TERMUX_PREVIOUS_ARCH=$(cat $TERMUX_ARCH_FILE) | |
341 | if [ "$TERMUX_PREVIOUS_ARCH" != "$TERMUX_ARCH" ]; then | |
342 | local TERMUX_DATA_BACKUPDIRS=$TERMUX_TOPDIR/_databackups | |
343 | mkdir -p "$TERMUX_DATA_BACKUPDIRS" | |
344 | local TERMUX_DATA_PREVIOUS_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_PREVIOUS_ARCH | |
345 | local TERMUX_DATA_CURRENT_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_ARCH | |
346 | # Save current /data (removing old backup if any) | |
347 | if test -e "$TERMUX_DATA_PREVIOUS_BACKUPDIR"; then | |
348 | termux_error_exit "Directory already exists" | |
349 | fi | |
d7310004 FF |
350 | if [ -d /data/data ]; then |
351 | mv /data/data "$TERMUX_DATA_PREVIOUS_BACKUPDIR" | |
352 | fi | |
7b1f1bd3 FF |
353 | # Restore new one (if any) |
354 | if [ -d "$TERMUX_DATA_CURRENT_BACKUPDIR" ]; then | |
355 | mv "$TERMUX_DATA_CURRENT_BACKUPDIR" /data/data | |
356 | fi | |
357 | fi | |
358 | fi | |
359 | ||
360 | # Keep track of current arch we are building for. | |
361 | echo "$TERMUX_ARCH" > $TERMUX_ARCH_FILE | |
19fb617a FF |
362 | } |
363 | ||
7b1f1bd3 FF |
364 | # Source the package build script and start building. No to be overridden by packages. |
365 | termux_step_start_build() { | |
366 | # shellcheck source=/dev/null | |
367 | source "$TERMUX_PKG_BUILDER_SCRIPT" | |
19fb617a | 368 | |
1d1a41b0 | 369 | TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/${TERMUX_NDK_VERSION}-${TERMUX_ARCH}-${TERMUX_PKG_API_LEVEL}" |
28c3a74a FF |
370 | # Bump the below version if a change is made in toolchain setup to ensure |
371 | # that everyone gets an updated toolchain: | |
1d1a41b0 | 372 | TERMUX_STANDALONE_TOOLCHAIN+="-v3" |
28c3a74a | 373 | |
7b1f1bd3 FF |
374 | if [ -n "${TERMUX_PKG_BLACKLISTED_ARCHES:=""}" ] && [ "$TERMUX_PKG_BLACKLISTED_ARCHES" != "${TERMUX_PKG_BLACKLISTED_ARCHES/$TERMUX_ARCH/}" ]; then |
375 | echo "Skipping building $TERMUX_PKG_NAME for arch $TERMUX_ARCH" | |
376 | exit 0 | |
377 | fi | |
378 | ||
379 | if [ -z "${TERMUX_SKIP_DEPCHECK:=""}" ]; then | |
93ae139b | 380 | local p TERMUX_ALL_DEPS |
02764a91 | 381 | TERMUX_ALL_DEPS=$(./scripts/buildorder.py "$TERMUX_PKG_BUILDER_DIR") |
93ae139b | 382 | for p in $TERMUX_ALL_DEPS; do |
02764a91 FF |
383 | echo "Building dependency $p if necessary..." |
384 | ./build-package.sh -a $TERMUX_ARCH -s "$p" | |
7b1f1bd3 FF |
385 | done |
386 | fi | |
2c1aa558 | 387 | |
7b1f1bd3 | 388 | TERMUX_PKG_FULLVERSION=$TERMUX_PKG_VERSION |
af4dc416 | 389 | if [ "$TERMUX_PKG_REVISION" != "0" ] || [ "$TERMUX_PKG_FULLVERSION" != "${TERMUX_PKG_FULLVERSION/-/}" ]; then |
7b1f1bd3 | 390 | # "0" is the default revision, so only include it if the upstream versions contains "-" itself |
af4dc416 | 391 | TERMUX_PKG_FULLVERSION+="-$TERMUX_PKG_REVISION" |
7b1f1bd3 | 392 | fi |
59f0d218 | 393 | |
9b2f3b62 HG |
394 | if [ "$TERMUX_DEBUG" == "true" ]; then |
395 | DEBUG="-dbg" | |
396 | else | |
397 | DEBUG="" | |
398 | fi | |
399 | ||
bc0560aa FF |
400 | if [ -z "$TERMUX_DEBUG" ] && |
401 | [ -z "${TERMUX_FORCE_BUILD+x}" ] && | |
402 | [ -e "/data/data/.built-packages/$TERMUX_PKG_NAME" ]; then | |
7b1f1bd3 FF |
403 | if [ "$(cat "/data/data/.built-packages/$TERMUX_PKG_NAME")" = "$TERMUX_PKG_FULLVERSION" ]; then |
404 | echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION built - skipping (rm /data/data/.built-packages/$TERMUX_PKG_NAME to force rebuild)" | |
405 | exit 0 | |
406 | fi | |
407 | fi | |
408 | ||
409 | # Cleanup old state: | |
410 | rm -Rf "$TERMUX_PKG_BUILDDIR" \ | |
411 | "$TERMUX_PKG_PACKAGEDIR" \ | |
412 | "$TERMUX_PKG_SRCDIR" \ | |
413 | "$TERMUX_PKG_TMPDIR" \ | |
414 | "$TERMUX_PKG_MASSAGEDIR" | |
415 | ||
416 | # Ensure folders present (but not $TERMUX_PKG_SRCDIR, it will be created in build) | |
417 | mkdir -p "$TERMUX_COMMON_CACHEDIR" \ | |
418 | "$TERMUX_DEBDIR" \ | |
419 | "$TERMUX_PKG_BUILDDIR" \ | |
420 | "$TERMUX_PKG_PACKAGEDIR" \ | |
421 | "$TERMUX_PKG_TMPDIR" \ | |
422 | "$TERMUX_PKG_CACHEDIR" \ | |
423 | "$TERMUX_PKG_MASSAGEDIR" \ | |
7b1f1bd3 FF |
424 | $TERMUX_PREFIX/{bin,etc,lib,libexec,share,tmp,include} |
425 | ||
426 | # Make $TERMUX_PREFIX/bin/sh executable on the builder, so that build | |
427 | # scripts can assume that it works on both builder and host later on: | |
428 | ln -f -s /bin/sh "$TERMUX_PREFIX/bin/sh" | |
429 | ||
bd54a46a FF |
430 | local TERMUX_ELF_CLEANER_SRC=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner.cpp |
431 | local TERMUX_ELF_CLEANER_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/termux-elf-cleaner/build.sh; echo \$TERMUX_PKG_VERSION") | |
432 | termux_download \ | |
433 | https://raw.githubusercontent.com/termux/termux-elf-cleaner/v$TERMUX_ELF_CLEANER_VERSION/termux-elf-cleaner.cpp \ | |
434 | $TERMUX_ELF_CLEANER_SRC \ | |
0c3e72d6 | 435 | 62c3cf9813756a1b262108fbc39684c5cfd3f9a69b376276bb1ac6af138f5fa2 |
7b1f1bd3 FF |
436 | if [ "$TERMUX_ELF_CLEANER_SRC" -nt "$TERMUX_ELF_CLEANER" ]; then |
437 | g++ -std=c++11 -Wall -Wextra -pedantic -Os "$TERMUX_ELF_CLEANER_SRC" -o "$TERMUX_ELF_CLEANER" | |
438 | fi | |
439 | ||
440 | if [ -n "$TERMUX_PKG_BUILD_IN_SRC" ]; then | |
441 | echo "Building in src due to TERMUX_PKG_BUILD_IN_SRC being set" > "$TERMUX_PKG_BUILDDIR/BUILDING_IN_SRC.txt" | |
442 | TERMUX_PKG_BUILDDIR=$TERMUX_PKG_SRCDIR | |
443 | fi | |
444 | ||
445 | echo "termux - building $TERMUX_PKG_NAME for arch $TERMUX_ARCH..." | |
446 | test -t 1 && printf "\033]0;%s...\007" "$TERMUX_PKG_NAME" | |
447 | ||
0dc0e842 FF |
448 | # Avoid exporting PKG_CONFIG_LIBDIR until after termux_step_host_build. |
449 | export TERMUX_PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig | |
450 | # Add a pkg-config file for the system zlib. | |
b833ad7a | 451 | mkdir -p "$TERMUX_PKG_CONFIG_LIBDIR" |
0dc0e842 | 452 | cat > "$TERMUX_PKG_CONFIG_LIBDIR/zlib.pc" <<-HERE |
7b1f1bd3 FF |
453 | Name: zlib |
454 | Description: zlib compression library | |
455 | Version: 1.2.8 | |
456 | Requires: | |
457 | Libs: -lz | |
458 | HERE | |
459 | ||
460 | # Keep track of when build started so we can see what files have been created. | |
461 | # We start by sleeping so that any generated files above (such as zlib.pc) get | |
462 | # an older timestamp than the TERMUX_BUILD_TS_FILE. | |
463 | sleep 1 | |
464 | TERMUX_BUILD_TS_FILE=$TERMUX_PKG_TMPDIR/timestamp_$TERMUX_PKG_NAME | |
465 | touch "$TERMUX_BUILD_TS_FILE" | |
466 | } | |
467 | ||
468 | # Run just after sourcing $TERMUX_PKG_BUILDER_SCRIPT. May be overridden by packages. | |
01e699d9 | 469 | termux_step_extract_package() { |
7b1f1bd3 FF |
470 | if [ -z "${TERMUX_PKG_SRCURL:=""}" ]; then |
471 | mkdir -p "$TERMUX_PKG_SRCDIR" | |
472 | return | |
473 | fi | |
474 | cd "$TERMUX_PKG_TMPDIR" | |
475 | local filename | |
476 | filename=$(basename "$TERMUX_PKG_SRCURL") | |
477 | local file="$TERMUX_PKG_CACHEDIR/$filename" | |
c9d4e74f | 478 | termux_download "$TERMUX_PKG_SRCURL" "$file" "$TERMUX_PKG_SHA256" |
e239964b | 479 | |
1b3f3ebd FF |
480 | local folder |
481 | set +o pipefail | |
7b1f1bd3 | 482 | if [ "${file##*.}" = zip ]; then |
1b3f3ebd FF |
483 | folder=`unzip -qql "$file" | head -n1 | tr -s ' ' | cut -d' ' -f5-` |
484 | rm -Rf $folder | |
7b1f1bd3 | 485 | unzip -q "$file" |
e1163ab5 | 486 | mv $folder "$TERMUX_PKG_SRCDIR" |
59f0d218 | 487 | else |
e1163ab5 S |
488 | mkdir "$TERMUX_PKG_SRCDIR" |
489 | tar xf "$file" -C "$TERMUX_PKG_SRCDIR" --strip-components=1 | |
59f0d218 | 490 | fi |
1b3f3ebd | 491 | set -o pipefail |
59f0d218 FF |
492 | } |
493 | ||
7b1f1bd3 | 494 | # Hook for packages to act just after the package has been extracted. |
508fa73c | 495 | # Invoked in $TERMUX_PKG_SRCDIR. |
01e699d9 | 496 | termux_step_post_extract_package() { |
59f0d218 FF |
497 | return |
498 | } | |
499 | ||
7b1f1bd3 FF |
500 | # Optional host build. Not to be overridden by packages. |
501 | termux_step_handle_hostbuild() { | |
502 | if [ "x$TERMUX_PKG_HOSTBUILD" = "x" ]; then return; fi | |
93ae139b | 503 | |
7b1f1bd3 FF |
504 | cd "$TERMUX_PKG_SRCDIR" |
505 | for patch in $TERMUX_PKG_BUILDER_DIR/*.patch.beforehostbuild; do | |
506 | test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | patch --silent -p1 | |
507 | done | |
93ae139b FF |
508 | |
509 | local TERMUX_HOSTBUILD_MARKER="$TERMUX_PKG_HOSTBUILD_DIR/TERMUX_BUILT_FOR_$TERMUX_PKG_VERSION" | |
510 | if [ ! -f "$TERMUX_HOSTBUILD_MARKER" ]; then | |
511 | rm -Rf "$TERMUX_PKG_HOSTBUILD_DIR" | |
512 | mkdir -p "$TERMUX_PKG_HOSTBUILD_DIR" | |
7b1f1bd3 FF |
513 | cd "$TERMUX_PKG_HOSTBUILD_DIR" |
514 | termux_step_host_build | |
93ae139b | 515 | touch "$TERMUX_HOSTBUILD_MARKER" |
7b1f1bd3 FF |
516 | fi |
517 | } | |
518 | ||
59f0d218 FF |
519 | # Perform a host build. Will be called in $TERMUX_PKG_HOSTBUILD_DIR. |
520 | # After termux_step_post_extract_package() and before termux_step_patch_package() | |
01e699d9 | 521 | termux_step_host_build() { |
7b1f1bd3 | 522 | "$TERMUX_PKG_SRCDIR/configure" ${TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS} |
4663ac70 | 523 | make -j $TERMUX_MAKE_PROCESSES |
59f0d218 FF |
524 | } |
525 | ||
7b1f1bd3 FF |
526 | # Setup a standalone Android NDK toolchain. Not to be overridden by packages. |
527 | termux_step_setup_toolchain() { | |
528 | # We put this after system PATH to avoid picking up toolchain stripped python | |
529 | export PATH=$PATH:$TERMUX_STANDALONE_TOOLCHAIN/bin | |
530 | ||
272404e1 | 531 | export CFLAGS="" |
619b9664 FF |
532 | export LDFLAGS="-L${TERMUX_PREFIX}/lib" |
533 | ||
7b1f1bd3 FF |
534 | if [ "$TERMUX_PKG_CLANG" = "no" ]; then |
535 | export AS=${TERMUX_HOST_PLATFORM}-gcc | |
536 | export CC=$TERMUX_HOST_PLATFORM-gcc | |
537 | export CXX=$TERMUX_HOST_PLATFORM-g++ | |
619b9664 FF |
538 | LDFLAGS+=" -specs=$TERMUX_SCRIPTDIR/termux.spec" |
539 | CFLAGS+=" -specs=$TERMUX_SCRIPTDIR/termux.spec" | |
7b1f1bd3 | 540 | else |
2f0de587 | 541 | export AS=${TERMUX_HOST_PLATFORM}-clang |
7b1f1bd3 FF |
542 | export CC=$TERMUX_HOST_PLATFORM-clang |
543 | export CXX=$TERMUX_HOST_PLATFORM-clang++ | |
7b1f1bd3 | 544 | fi |
619b9664 FF |
545 | |
546 | export AR=$TERMUX_HOST_PLATFORM-ar | |
7b1f1bd3 FF |
547 | export CPP=${TERMUX_HOST_PLATFORM}-cpp |
548 | export CC_FOR_BUILD=gcc | |
549 | export LD=$TERMUX_HOST_PLATFORM-ld | |
550 | export OBJDUMP=$TERMUX_HOST_PLATFORM-objdump | |
551 | # Setup pkg-config for cross-compiling: | |
552 | export PKG_CONFIG=$TERMUX_STANDALONE_TOOLCHAIN/bin/${TERMUX_HOST_PLATFORM}-pkg-config | |
553 | export RANLIB=$TERMUX_HOST_PLATFORM-ranlib | |
554 | export READELF=$TERMUX_HOST_PLATFORM-readelf | |
555 | export STRIP=$TERMUX_HOST_PLATFORM-strip | |
556 | ||
7b1f1bd3 FF |
557 | # Android 7 started to support DT_RUNPATH (but not DT_RPATH), so we may want |
558 | # LDFLAGS+="-Wl,-rpath=$TERMUX_PREFIX/lib -Wl,--enable-new-dtags" | |
559 | # and no longer remove DT_RUNPATH in termux-elf-cleaner. | |
560 | ||
561 | if [ "$TERMUX_ARCH" = "arm" ]; then | |
c9e68e0d FF |
562 | # https://developer.android.com/ndk/guides/standalone_toolchain.html#abi_compatibility: |
563 | # "We recommend using the -mthumb compiler flag to force the generation of 16-bit Thumb-2 instructions". | |
564 | # With r13 of the ndk ruby 2.4.0 segfaults when built on arm with clang without -mthumb. | |
565 | CFLAGS+=" -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb" | |
a5cdd56d | 566 | LDFLAGS+=" -march=armv7-a" |
7b1f1bd3 FF |
567 | elif [ "$TERMUX_ARCH" = "i686" ]; then |
568 | # From $NDK/docs/CPU-ARCH-ABIS.html: | |
569 | CFLAGS+=" -march=i686 -msse3 -mstackrealign -mfpmath=sse" | |
570 | elif [ "$TERMUX_ARCH" = "aarch64" ]; then | |
0d1dde5f | 571 | : |
7b1f1bd3 FF |
572 | elif [ "$TERMUX_ARCH" = "x86_64" ]; then |
573 | : | |
574 | else | |
575 | termux_error_exit "Invalid arch '$TERMUX_ARCH' - support arches are 'arm', 'i686', 'aarch64', 'x86_64'" | |
576 | fi | |
577 | ||
578 | if [ -n "$TERMUX_DEBUG" ]; then | |
579 | CFLAGS+=" -g3 -O1 -fstack-protector --param ssp-buffer-size=4 -D_FORTIFY_SOURCE=2" | |
580 | else | |
fbf60305 | 581 | if [ "$TERMUX_PKG_CLANG" = "no" ]; then |
430eef3b FF |
582 | CFLAGS+=" -Os" |
583 | else | |
49c62a86 FF |
584 | # -Oz seems good for clang, see https://github.com/android-ndk/ndk/issues/133. |
585 | # However, on arm it has a lot of issues such as #1520, #1680, #1765 and | |
586 | # https://bugs.llvm.org/show_bug.cgi?id=35379, so use so use -Os there for now: | |
587 | if [ $TERMUX_ARCH = arm ]; then | |
588 | CFLAGS+=" -Os" | |
589 | else | |
590 | CFLAGS+=" -Oz" | |
591 | fi | |
430eef3b | 592 | fi |
7b1f1bd3 FF |
593 | fi |
594 | ||
595 | export CXXFLAGS="$CFLAGS" | |
596 | export CPPFLAGS="-I${TERMUX_PREFIX}/include" | |
597 | ||
598 | if [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libandroid-support/}" ]; then | |
599 | # If using the android support library, link to it and include its headers as system headers: | |
600 | CPPFLAGS+=" -isystem $TERMUX_PREFIX/include/libandroid-support" | |
601 | LDFLAGS+=" -landroid-support" | |
602 | fi | |
603 | ||
604 | export ac_cv_func_getpwent=no | |
605 | export ac_cv_func_getpwnam=no | |
606 | export ac_cv_func_getpwuid=no | |
2173f730 | 607 | export ac_cv_func_sigsetmask=no |
7b1f1bd3 FF |
608 | |
609 | if [ ! -d $TERMUX_STANDALONE_TOOLCHAIN ]; then | |
610 | # Do not put toolchain in place until we are done with setup, to avoid having a half setup | |
611 | # toolchain left in place if something goes wrong (or process is just aborted): | |
2f0de587 | 612 | local _TERMUX_TOOLCHAIN_TMPDIR=${TERMUX_STANDALONE_TOOLCHAIN}-tmp |
7b1f1bd3 FF |
613 | rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR |
614 | ||
615 | local _NDK_ARCHNAME=$TERMUX_ARCH | |
616 | if [ "$TERMUX_ARCH" = "aarch64" ]; then | |
617 | _NDK_ARCHNAME=arm64 | |
618 | elif [ "$TERMUX_ARCH" = "i686" ]; then | |
619 | _NDK_ARCHNAME=x86 | |
620 | fi | |
2f0de587 | 621 | |
7b1f1bd3 | 622 | "$NDK/build/tools/make_standalone_toolchain.py" \ |
272404e1 | 623 | --api "$TERMUX_PKG_API_LEVEL" \ |
7b1f1bd3 | 624 | --arch $_NDK_ARCHNAME \ |
d946e67c | 625 | --stl=libc++ \ |
7b1f1bd3 FF |
626 | --install-dir $_TERMUX_TOOLCHAIN_TMPDIR |
627 | ||
d946e67c FF |
628 | # Remove android-support header wrapping not needed on android-21: |
629 | rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/local | |
630 | ||
07884eae FF |
631 | local wrapped plusplus CLANG_TARGET=$TERMUX_HOST_PLATFORM |
632 | if [ $TERMUX_ARCH = arm ]; then CLANG_TARGET=${CLANG_TARGET/arm-/armv7a-}; fi | |
633 | for wrapped in ${TERMUX_HOST_PLATFORM}-clang clang; do | |
634 | for plusplus in "" "++"; do | |
635 | local FILE_TO_REPLACE=$_TERMUX_TOOLCHAIN_TMPDIR/bin/${wrapped}${plusplus} | |
636 | if [ ! -f $FILE_TO_REPLACE ]; then | |
637 | termux_error_exit "No toolchain file to override: $FILE_TO_REPLACE" | |
638 | fi | |
7048a1f2 | 639 | cp "$TERMUX_SCRIPTDIR/scripts/clang-pie-wrapper" $FILE_TO_REPLACE |
58e38b47 | 640 | sed -i "s/COMPILER/clang50$plusplus/" $FILE_TO_REPLACE |
07884eae FF |
641 | sed -i "s/CLANG_TARGET/$CLANG_TARGET/" $FILE_TO_REPLACE |
642 | done | |
2f0de587 FF |
643 | done |
644 | ||
d946e67c | 645 | if [ "$TERMUX_ARCH" = "aarch64" ]; then |
0d1dde5f FF |
646 | # Use gold by default to work around https://github.com/android-ndk/ndk/issues/148 |
647 | cp $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld.gold \ | |
648 | $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld | |
c8d1a650 FF |
649 | cp $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld.gold \ |
650 | $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld | |
7b1f1bd3 FF |
651 | fi |
652 | ||
d1f566f7 FF |
653 | if [ "$TERMUX_ARCH" = "arm" ]; then |
654 | # Linker wrapper script to add '--exclude-libs libgcc.a', see | |
655 | # https://github.com/android-ndk/ndk/issues/379 | |
656 | # https://android-review.googlesource.com/#/c/389852/ | |
657 | local linker | |
658 | for linker in ld ld.bfd ld.gold; do | |
659 | local wrap_linker=$_TERMUX_TOOLCHAIN_TMPDIR/$TERMUX_HOST_PLATFORM/bin/$linker | |
660 | local real_linker=$_TERMUX_TOOLCHAIN_TMPDIR/$TERMUX_HOST_PLATFORM/bin/$linker.real | |
661 | cp $wrap_linker $real_linker | |
662 | echo '#!/bin/bash' > $wrap_linker | |
663 | echo -n '`dirname $0`/' >> $wrap_linker | |
664 | echo -n $linker.real >> $wrap_linker | |
665 | echo ' --exclude-libs libgcc.a "$@"' >> $wrap_linker | |
666 | done | |
667 | fi | |
668 | ||
7b1f1bd3 FF |
669 | cd $_TERMUX_TOOLCHAIN_TMPDIR/sysroot |
670 | ||
d3e5452e | 671 | for f in $TERMUX_SCRIPTDIR/ndk-patches/*.patch; do |
7b1f1bd3 FF |
672 | sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$f" | \ |
673 | sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ | |
674 | patch --silent -p1; | |
675 | done | |
42562d13 | 676 | # elf.h: Taken from glibc since the elf.h in the NDK is lacking. |
42562d13 | 677 | # ifaddrs.h: Added in android-24 unified headers, use a inline implementation for now. |
7de09d9f | 678 | cp "$TERMUX_SCRIPTDIR"/ndk-patches/{elf.h,ifaddrs.h,libintl.h} usr/include |
7b1f1bd3 | 679 | |
67d2d615 | 680 | # Remove <sys/shm.h> from the NDK in favour of that from the libandroid-shmem. |
392b4b6b FF |
681 | # Remove <sys/sem.h> as it doesn't work for non-root. |
682 | # Remove <iconv.h> as we currently provide it from libandroid-support. | |
683 | # Remove <glob.h> as we currently provide it from libandroid-glob. | |
3c8a8000 FF |
684 | # Remove <spawn.h> as it's only for future (later than android-27). |
685 | rm usr/include/sys/{shm.h,sem.h} usr/include/{iconv.h,glob.h,spawn.h} | |
d04dc139 | 686 | |
272404e1 | 687 | sed -i "s/define __ANDROID_API__ __ANDROID_API_FUTURE__/define __ANDROID_API__ $TERMUX_PKG_API_LEVEL/" \ |
d04dc139 | 688 | usr/include/android/api-level.h |
f39b87c2 | 689 | |
b26283d4 FF |
690 | local _LIBDIR=usr/lib |
691 | if [ $TERMUX_ARCH = x86_64 ]; then _LIBDIR+=64; fi | |
692 | $TERMUX_ELF_CLEANER $_LIBDIR/*.so | |
7b1f1bd3 FF |
693 | |
694 | # zlib is really version 1.2.8 in the Android platform (at least | |
695 | # starting from Android 5), not older as the NDK headers claim. | |
696 | for file in zconf.h zlib.h; do | |
d04dc139 | 697 | curl -o usr/include/$file \ |
7b1f1bd3 FF |
698 | https://raw.githubusercontent.com/madler/zlib/v1.2.8/$file |
699 | done | |
700 | unset file | |
aa1865fe | 701 | cd $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x |
702 | sed "s%\@TERMUX_HOST_PLATFORM\@%${TERMUX_HOST_PLATFORM}%g" $TERMUX_SCRIPTDIR/ndk-patches/*.cpppatch | patch -p1 | |
7b1f1bd3 FF |
703 | mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN |
704 | fi | |
705 | ||
d946e67c | 706 | local _STL_LIBFILE_NAME=libc++_shared.so |
d1f566f7 | 707 | if [ ! -f $TERMUX_PREFIX/lib/libstdc++.so ]; then |
2f6e1c12 | 708 | # Setup libc++_shared.so in $PREFIX/lib and libstdc++.so as a link to it, |
7b1f1bd3 FF |
709 | # so that other C++ using packages links to it instead of the default android |
710 | # C++ library which does not support exceptions or STL: | |
711 | # https://developer.android.com/ndk/guides/cpp-support.html | |
712 | # We do however want to avoid installing this, to avoid problems where e.g. | |
713 | # libm.so on some i686 devices links against libstdc++.so. | |
2f6e1c12 | 714 | # The libc++_shared.so library will be packaged in the libc++ package |
7b1f1bd3 FF |
715 | # which is part of the base Termux installation. |
716 | mkdir -p "$TERMUX_PREFIX/lib" | |
717 | cd "$TERMUX_PREFIX/lib" | |
d946e67c FF |
718 | |
719 | local _STL_LIBFILE= | |
7b1f1bd3 | 720 | if [ "$TERMUX_ARCH" = arm ]; then |
d946e67c | 721 | local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/armv7-a/$_STL_LIBFILE_NAME |
7b1f1bd3 | 722 | elif [ "$TERMUX_ARCH" = x86_64 ]; then |
d946e67c FF |
723 | local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib64/$_STL_LIBFILE_NAME |
724 | else | |
725 | local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/$_STL_LIBFILE_NAME | |
7b1f1bd3 | 726 | fi |
d946e67c | 727 | |
7b1f1bd3 | 728 | cp "$_STL_LIBFILE" . |
d946e67c FF |
729 | $STRIP --strip-unneeded $_STL_LIBFILE_NAME |
730 | $TERMUX_ELF_CLEANER $_STL_LIBFILE_NAME | |
d1f566f7 FF |
731 | if [ $TERMUX_ARCH = "arm" ]; then |
732 | # Use a linker script to get libunwind.a. | |
733 | echo 'INPUT(-lunwind -lc++_shared)' > libstdc++.so | |
734 | else | |
735 | ln -f $_STL_LIBFILE_NAME libstdc++.so | |
736 | fi | |
7b1f1bd3 FF |
737 | fi |
738 | ||
0dc0e842 | 739 | export PKG_CONFIG_LIBDIR="$TERMUX_PKG_CONFIG_LIBDIR" |
7b1f1bd3 FF |
740 | # Create a pkg-config wrapper. We use path to host pkg-config to |
741 | # avoid picking up a cross-compiled pkg-config later on. | |
742 | local _HOST_PKGCONFIG | |
743 | _HOST_PKGCONFIG=$(which pkg-config) | |
744 | mkdir -p $TERMUX_STANDALONE_TOOLCHAIN/bin "$PKG_CONFIG_LIBDIR" | |
745 | cat > "$PKG_CONFIG" <<-HERE | |
746 | #!/bin/sh | |
747 | export PKG_CONFIG_DIR= | |
748 | export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR | |
749 | exec $_HOST_PKGCONFIG "\$@" | |
750 | HERE | |
751 | chmod +x "$PKG_CONFIG" | |
752 | } | |
753 | ||
2b0e9dc9 | 754 | # Apply all *.patch files for the package. Not to be overridden by packages. |
01e699d9 | 755 | termux_step_patch_package() { |
7b1f1bd3 | 756 | cd "$TERMUX_PKG_SRCDIR" |
8f7dda83 | 757 | # Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses: |
7106823d | 758 | shopt -s nullglob |
8f7dda83 | 759 | for patch in $TERMUX_PKG_BUILDER_DIR/*.patch{$TERMUX_ARCH_BITS,}; do |
7b1f1bd3 | 760 | test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | \ |
dc6476e9 | 761 | sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ |
a0057943 | 762 | patch --silent -p1 |
59f0d218 | 763 | done |
a599e41a | 764 | shopt -u nullglob |
7106823d | 765 | } |
59f0d218 | 766 | |
7106823d VB |
767 | # Replace autotools build-aux/config.{sub,guess} with ours to add android targets. |
768 | termux_step_replace_guess_scripts () { | |
769 | cd "$TERMUX_PKG_SRCDIR" | |
7b1f1bd3 FF |
770 | find . -name config.sub -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.sub" '{}' \; |
771 | find . -name config.guess -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.guess" '{}' \; | |
59f0d218 FF |
772 | } |
773 | ||
7b1f1bd3 | 774 | # For package scripts to override. Called in $TERMUX_PKG_BUILDDIR. |
01e699d9 | 775 | termux_step_pre_configure() { |
7b1f1bd3 | 776 | return |
59f0d218 FF |
777 | } |
778 | ||
58f7a21c | 779 | termux_step_configure_autotools () { |
7b1f1bd3 | 780 | if [ ! -e "$TERMUX_PKG_SRCDIR/configure" ]; then return; fi |
59f0d218 | 781 | |
79739535 | 782 | local DISABLE_STATIC="--disable-static" |
59f0d218 FF |
783 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-static/}" ]; then |
784 | # Do not --disable-static if package explicitly enables it (e.g. gdb needs enable-static to build) | |
785 | DISABLE_STATIC="" | |
786 | fi | |
787 | ||
79739535 | 788 | local DISABLE_NLS="--disable-nls" |
59f0d218 FF |
789 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-nls/}" ]; then |
790 | # Do not --disable-nls if package explicitly enables it (for gettext itself) | |
791 | DISABLE_NLS="" | |
792 | fi | |
793 | ||
79739535 | 794 | local ENABLE_SHARED="--enable-shared" |
59f0d218 FF |
795 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--disable-shared/}" ]; then |
796 | ENABLE_SHARED="" | |
797 | fi | |
79739535 FF |
798 | |
799 | local HOST_FLAG="--host=$TERMUX_HOST_PLATFORM" | |
59f0d218 FF |
800 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--host=/}" ]; then |
801 | HOST_FLAG="" | |
802 | fi | |
79739535 FF |
803 | |
804 | local LIBEXEC_FLAG="--libexecdir=$TERMUX_PREFIX/libexec" | |
805 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--libexecdir=/}" ]; then | |
806 | LIBEXEC_FLAG="" | |
807 | fi | |
808 | ||
809 | local QUIET_BUILD= | |
cf575909 | 810 | if [ ! -z ${TERMUX_QUIET_BUILD+x} ]; then |
e36a2902 | 811 | QUIET_BUILD="--enable-silent-rules --silent --quiet" |
cf575909 | 812 | fi |
59f0d218 FF |
813 | |
814 | # Some packages provides a $PKG-config script which some configure scripts pickup instead of pkg-config: | |
7b1f1bd3 | 815 | mkdir "$TERMUX_PKG_TMPDIR/config-scripts" |
59f0d218 | 816 | for f in $TERMUX_PREFIX/bin/*config; do |
7b1f1bd3 | 817 | test -f "$f" && cp "$f" "$TERMUX_PKG_TMPDIR/config-scripts" |
59f0d218 | 818 | done |
59f0d218 FF |
819 | export PATH=$TERMUX_PKG_TMPDIR/config-scripts:$PATH |
820 | ||
00d9769e FF |
821 | # Avoid gnulib wrapping of functions when cross compiling. See |
822 | # http://wiki.osdev.org/Cross-Porting_Software#Gnulib | |
823 | # https://gitlab.com/sortix/sortix/wikis/Gnulib | |
824 | # https://github.com/termux/termux-packages/issues/76 | |
825 | local AVOID_GNULIB="" | |
0dc0e842 FF |
826 | AVOID_GNULIB+=" ac_cv_func_calloc_0_nonnull=yes" |
827 | AVOID_GNULIB+=" ac_cv_func_chown_works=yes" | |
828 | AVOID_GNULIB+=" ac_cv_func_getgroups_works=yes" | |
00d9769e FF |
829 | AVOID_GNULIB+=" ac_cv_func_malloc_0_nonnull=yes" |
830 | AVOID_GNULIB+=" ac_cv_func_realloc_0_nonnull=yes" | |
831 | AVOID_GNULIB+=" am_cv_func_working_getline=yes" | |
832 | AVOID_GNULIB+=" gl_cv_func_dup2_works=yes" | |
833 | AVOID_GNULIB+=" gl_cv_func_fcntl_f_dupfd_cloexec=yes" | |
834 | AVOID_GNULIB+=" gl_cv_func_fcntl_f_dupfd_works=yes" | |
542aab6b | 835 | AVOID_GNULIB+=" gl_cv_func_fnmatch_posix=yes" |
00d9769e FF |
836 | AVOID_GNULIB+=" gl_cv_func_getcwd_abort_bug=no" |
837 | AVOID_GNULIB+=" gl_cv_func_getcwd_null=yes" | |
838 | AVOID_GNULIB+=" gl_cv_func_getcwd_path_max=yes" | |
839 | AVOID_GNULIB+=" gl_cv_func_getcwd_posix_signature=yes" | |
840 | AVOID_GNULIB+=" gl_cv_func_gettimeofday_clobber=no" | |
841 | AVOID_GNULIB+=" gl_cv_func_gettimeofday_posix_signature=yes" | |
842 | AVOID_GNULIB+=" gl_cv_func_link_works=yes" | |
843 | AVOID_GNULIB+=" gl_cv_func_lstat_dereferences_slashed_symlink=yes" | |
542aab6b | 844 | AVOID_GNULIB+=" gl_cv_func_malloc_0_nonnull=yes" |
00d9769e FF |
845 | AVOID_GNULIB+=" gl_cv_func_memchr_works=yes" |
846 | AVOID_GNULIB+=" gl_cv_func_mkdir_trailing_dot_works=yes" | |
847 | AVOID_GNULIB+=" gl_cv_func_mkdir_trailing_slash_works=yes" | |
0dc0e842 | 848 | AVOID_GNULIB+=" gl_cv_func_mkfifo_works=yes" |
d4de1b23 | 849 | AVOID_GNULIB+=" gl_cv_func_mknod_works=yes" |
ea41b461 | 850 | AVOID_GNULIB+=" gl_cv_func_realpath_works=yes" |
00d9769e | 851 | AVOID_GNULIB+=" gl_cv_func_select_detects_ebadf=yes" |
542aab6b | 852 | AVOID_GNULIB+=" gl_cv_func_snprintf_posix=yes" |
00d9769e | 853 | AVOID_GNULIB+=" gl_cv_func_snprintf_retval_c99=yes" |
542aab6b | 854 | AVOID_GNULIB+=" gl_cv_func_snprintf_truncation_c99=yes" |
00d9769e FF |
855 | AVOID_GNULIB+=" gl_cv_func_stat_dir_slash=yes" |
856 | AVOID_GNULIB+=" gl_cv_func_stat_file_slash=yes" | |
857 | AVOID_GNULIB+=" gl_cv_func_strerror_0_works=yes" | |
858 | AVOID_GNULIB+=" gl_cv_func_symlink_works=yes" | |
859 | AVOID_GNULIB+=" gl_cv_func_tzset_clobber=no" | |
860 | AVOID_GNULIB+=" gl_cv_func_unlink_honors_slashes=yes" | |
861 | AVOID_GNULIB+=" gl_cv_func_unlink_honors_slashes=yes" | |
542aab6b FF |
862 | AVOID_GNULIB+=" gl_cv_func_vsnprintf_posix=yes" |
863 | AVOID_GNULIB+=" gl_cv_func_vsnprintf_zerosize_c99=yes" | |
00d9769e FF |
864 | AVOID_GNULIB+=" gl_cv_func_wcwidth_works=yes" |
865 | AVOID_GNULIB+=" gl_cv_func_working_getdelim=yes" | |
866 | AVOID_GNULIB+=" gl_cv_func_working_mkstemp=yes" | |
867 | AVOID_GNULIB+=" gl_cv_func_working_mktime=yes" | |
868 | AVOID_GNULIB+=" gl_cv_func_working_strerror=yes" | |
869 | AVOID_GNULIB+=" gl_cv_header_working_fcntl_h=yes" | |
f7d044c2 | 870 | AVOID_GNULIB+=" gl_cv_C_locale_sans_EILSEQ=yes" |
00d9769e FF |
871 | |
872 | # NOTE: We do not want to quote AVOID_GNULIB as we want word expansion. | |
873 | env $AVOID_GNULIB "$TERMUX_PKG_SRCDIR/configure" \ | |
59f0d218 FF |
874 | --disable-dependency-tracking \ |
875 | --prefix=$TERMUX_PREFIX \ | |
7b1f1bd3 | 876 | --disable-rpath --disable-rpath-hack \ |
59f0d218 FF |
877 | $HOST_FLAG \ |
878 | $TERMUX_PKG_EXTRA_CONFIGURE_ARGS \ | |
879 | $DISABLE_NLS \ | |
880 | $ENABLE_SHARED \ | |
881 | $DISABLE_STATIC \ | |
cf575909 S |
882 | $LIBEXEC_FLAG \ |
883 | $QUIET_BUILD | |
59f0d218 FF |
884 | } |
885 | ||
58f7a21c VB |
886 | termux_step_configure_cmake () { |
887 | termux_setup_cmake | |
888 | ||
58f7a21c VB |
889 | local TOOLCHAIN_ARGS="-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=$TERMUX_STANDALONE_TOOLCHAIN" |
890 | local BUILD_TYPE=MinSizeRel | |
891 | test -n "$TERMUX_DEBUG" && BUILD_TYPE=Debug | |
892 | ||
893 | local CMAKE_PROC=$TERMUX_ARCH | |
894 | test $CMAKE_PROC == "arm" && CMAKE_PROC='armv7-a' | |
895 | ||
2f0de587 FF |
896 | # XXX: CMAKE_{AR,RANLIB} needed for at least jsoncpp build to not |
897 | # pick up cross compiled binutils tool in $PREFIX/bin: | |
7048a1f2 FF |
898 | cmake -G 'Unix Makefiles' "$TERMUX_PKG_SRCDIR" \ |
899 | -DCMAKE_AR="$(which $AR)" \ | |
d946e67c | 900 | -DCMAKE_UNAME="$(which uname)" \ |
7048a1f2 | 901 | -DCMAKE_RANLIB="$(which $RANLIB)" \ |
58f7a21c VB |
902 | -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ |
903 | -DCMAKE_CROSSCOMPILING=True \ | |
904 | -DCMAKE_C_FLAGS="$CFLAGS $CPPFLAGS" \ | |
2f0de587 | 905 | -DCMAKE_CXX_FLAGS="$CXXFLAGS $CPPFLAGS" \ |
58f7a21c VB |
906 | -DCMAKE_LINKER="$TERMUX_STANDALONE_TOOLCHAIN/bin/$LD $LDFLAGS" \ |
907 | -DCMAKE_FIND_ROOT_PATH=$TERMUX_PREFIX \ | |
908 | -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ | |
909 | -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ | |
910 | -DCMAKE_INSTALL_PREFIX=$TERMUX_PREFIX \ | |
911 | -DCMAKE_MAKE_PROGRAM=`which make` \ | |
912 | -DCMAKE_SYSTEM_PROCESSOR=$CMAKE_PROC \ | |
913 | -DCMAKE_SYSTEM_NAME=Android \ | |
914 | -DCMAKE_SYSTEM_VERSION=21 \ | |
915 | -DCMAKE_SKIP_INSTALL_RPATH=ON \ | |
916 | -DCMAKE_USE_SYSTEM_LIBRARIES=True \ | |
917 | -DBUILD_TESTING=OFF \ | |
918 | $TERMUX_PKG_EXTRA_CONFIGURE_ARGS $TOOLCHAIN_ARGS | |
919 | } | |
920 | ||
f0c1439b FF |
921 | termux_step_configure_meson () { |
922 | termux_setup_meson | |
923 | CC=gcc CXX=g++ $TERMUX_MESON \ | |
924 | $TERMUX_PKG_SRCDIR \ | |
925 | $TERMUX_PKG_BUILDDIR \ | |
926 | --cross-file $TERMUX_MESON_CROSSFILE \ | |
927 | --prefix $TERMUX_PREFIX \ | |
928 | --libdir lib \ | |
929 | --buildtype minsize \ | |
930 | --strip \ | |
931 | $TERMUX_PKG_EXTRA_CONFIGURE_ARGS | |
932 | } | |
933 | ||
58f7a21c | 934 | termux_step_configure () { |
2f0de587 | 935 | if [ "$TERMUX_PKG_FORCE_CMAKE" == 'no' ] && [ -f "$TERMUX_PKG_SRCDIR/configure" ]; then |
58f7a21c VB |
936 | termux_step_configure_autotools |
937 | elif [ -f "$TERMUX_PKG_SRCDIR/CMakeLists.txt" ]; then | |
938 | termux_step_configure_cmake | |
f0c1439b FF |
939 | elif [ -f "$TERMUX_PKG_SRCDIR/meson.build" ]; then |
940 | termux_step_configure_meson | |
58f7a21c VB |
941 | fi |
942 | } | |
943 | ||
944 | termux_step_post_configure () { | |
7b1f1bd3 | 945 | return |
59f0d218 FF |
946 | } |
947 | ||
01e699d9 | 948 | termux_step_make() { |
79739535 | 949 | local QUIET_BUILD= |
79deb17c W |
950 | if [ ! -z ${TERMUX_QUIET_BUILD+x} ]; then |
951 | QUIET_BUILD="-s" | |
952 | fi | |
953 | ||
caf5d0df | 954 | if ls ./*akefile &> /dev/null; then |
7b1f1bd3 | 955 | if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then |
79deb17c | 956 | make -j $TERMUX_MAKE_PROCESSES $QUIET_BUILD |
7b1f1bd3 | 957 | else |
79deb17c | 958 | make -j $TERMUX_MAKE_PROCESSES $QUIET_BUILD ${TERMUX_PKG_EXTRA_MAKE_ARGS} |
7b1f1bd3 FF |
959 | fi |
960 | fi | |
59f0d218 FF |
961 | } |
962 | ||
01e699d9 | 963 | termux_step_make_install() { |
caf5d0df | 964 | if ls ./*akefile &> /dev/null; then |
dd54dd13 | 965 | : "${TERMUX_PKG_MAKE_INSTALL_TARGET:="install"}" |
7b1f1bd3 FF |
966 | # Some packages have problem with parallell install, and it does not buy much, so use -j 1. |
967 | if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then | |
968 | make -j 1 ${TERMUX_PKG_MAKE_INSTALL_TARGET} | |
969 | else | |
970 | make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET} | |
971 | fi | |
f0c1439b | 972 | elif test -f build.ninja; then |
b0ea9e23 | 973 | ninja -j $TERMUX_MAKE_PROCESSES install |
7b1f1bd3 | 974 | fi |
59f0d218 FF |
975 | } |
976 | ||
7b1f1bd3 | 977 | # Hook function for package scripts to override. |
01e699d9 | 978 | termux_step_post_make_install() { |
7b1f1bd3 | 979 | return |
59f0d218 FF |
980 | } |
981 | ||
01e699d9 | 982 | termux_step_extract_into_massagedir() { |
7b1f1bd3 | 983 | local TARBALL_ORIG=$TERMUX_PKG_PACKAGEDIR/${TERMUX_PKG_NAME}_orig.tar.gz |
59f0d218 FF |
984 | |
985 | # Build diff tar with what has changed during the build: | |
986 | cd $TERMUX_PREFIX | |
6b884285 FF |
987 | tar -N "$TERMUX_BUILD_TS_FILE" \ |
988 | --exclude='lib/libc++_shared.so' --exclude='lib/libstdc++.so' \ | |
989 | -czf "$TARBALL_ORIG" . | |
59f0d218 FF |
990 | |
991 | # Extract tar in order to massage it | |
7b1f1bd3 FF |
992 | mkdir -p "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
993 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" | |
2f122eed | 994 | tar xf "$TARBALL_ORIG" |
7b1f1bd3 | 995 | rm "$TARBALL_ORIG" |
59f0d218 FF |
996 | } |
997 | ||
01e699d9 | 998 | termux_step_massage() { |
7b1f1bd3 | 999 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
59f0d218 FF |
1000 | |
1001 | # Remove lib/charset.alias which is installed by gettext-using packages: | |
1002 | rm -f lib/charset.alias | |
a0c80d57 | 1003 | |
59f0d218 FF |
1004 | # Remove non-english man pages: |
1005 | test -d share/man && (cd share/man; for f in `ls | grep -v man`; do rm -Rf $f; done ) | |
a0c80d57 | 1006 | |
7b1f1bd3 | 1007 | if [ -z "${TERMUX_PKG_KEEP_INFOPAGES+x}" ]; then |
a0c80d57 FF |
1008 | # Remove info pages: |
1009 | rm -Rf share/info | |
1010 | fi | |
1011 | ||
9db621c0 FF |
1012 | # Remove locale files we're not interested in:: |
1013 | rm -Rf share/locale | |
7b1f1bd3 | 1014 | if [ -z "${TERMUX_PKG_KEEP_SHARE_DOC+x}" ]; then |
9db621c0 FF |
1015 | # Remove info pages: |
1016 | rm -Rf share/doc | |
1017 | fi | |
a0c80d57 | 1018 | |
59f0d218 FF |
1019 | # Remove old kept libraries (readline): |
1020 | find . -name '*.old' -delete | |
a0c80d57 FF |
1021 | |
1022 | # Remove static libraries: | |
59f0d218 FF |
1023 | if [ $TERMUX_PKG_KEEP_STATIC_LIBRARIES = "false" ]; then |
1024 | find . -name '*.a' -delete | |
1025 | find . -name '*.la' -delete | |
1026 | fi | |
1027 | ||
1d678bce | 1028 | # Move over sbin to bin: |
7b1f1bd3 | 1029 | for file in sbin/*; do if test -f "$file"; then mv "$file" bin/; fi; done |
59f0d218 | 1030 | |
174285d9 | 1031 | # Remove world permissions and add write permissions. |
40534bae FF |
1032 | # The -f flag is used to suppress warnings about dangling symlinks (such |
1033 | # as ones to /system/... which may not exist on the build machine): | |
174285d9 FF |
1034 | find . -exec chmod -f u+w,g-rwx,o-rwx \{\} \; |
1035 | ||
59f0d218 | 1036 | if [ "$TERMUX_DEBUG" = "" ]; then |
e5b151a0 FF |
1037 | # Strip binaries. file(1) may fail for certain unusual files, so disable pipefail. |
1038 | set +e +o pipefail | |
1039 | find . -type f | xargs -r file | grep -E "(executable|shared object)" | grep ELF | cut -f 1 -d : | \ | |
7b1f1bd3 | 1040 | xargs -r "$STRIP" --strip-unneeded --preserve-dates |
e5b151a0 | 1041 | set -e -o pipefail |
59f0d218 | 1042 | fi |
1d678bce | 1043 | # Remove DT_ entries which the android 5.1 linker warns about: |
7b1f1bd3 | 1044 | find . -type f -print0 | xargs -r -0 "$TERMUX_ELF_CLEANER" |
1d678bce FF |
1045 | |
1046 | # Fix shebang paths: | |
6b56911d FF |
1047 | while IFS= read -r -d '' file |
1048 | do | |
1049 | head -c 100 "$file" | grep -E "^#\!.*\\/bin\\/.*" | grep -q -E -v "^#\! ?\\/system" && sed --follow-symlinks -i -E "1 s@^#\!(.*)/bin/(.*)@#\!$TERMUX_PREFIX/bin/\2@" "$file" | |
1050 | done < <(find -L . -type f -print0) | |
59f0d218 FF |
1051 | |
1052 | test ! -z "$TERMUX_PKG_RM_AFTER_INSTALL" && rm -Rf $TERMUX_PKG_RM_AFTER_INSTALL | |
1053 | ||
1054 | find . -type d -empty -delete # Remove empty directories | |
1055 | ||
7b1f1bd3 FF |
1056 | # Sub packages: |
1057 | if [ -d include ] && [ -z "${TERMUX_PKG_NO_DEVELSPLIT}" ]; then | |
1058 | # Add virtual -dev sub package if there are include files: | |
1059 | local _DEVEL_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-dev.subpackage.sh | |
38a5614f | 1060 | echo TERMUX_SUBPKG_INCLUDE=\"include share/vala share/man/man3 lib/pkgconfig share/aclocal lib/cmake $TERMUX_PKG_INCLUDE_IN_DEVPACKAGE\" > "$_DEVEL_SUBPACKAGE_FILE" |
dd54dd13 | 1061 | echo "TERMUX_SUBPKG_DESCRIPTION=\"Development files for ${TERMUX_PKG_NAME}\"" >> "$_DEVEL_SUBPACKAGE_FILE" |
28dc0ace | 1062 | if [ -n "$TERMUX_PKG_DEVPACKAGE_DEPENDS" ]; then |
6b56911d | 1063 | echo "TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME,$TERMUX_PKG_DEVPACKAGE_DEPENDS\"" >> "$_DEVEL_SUBPACKAGE_FILE" |
28dc0ace | 1064 | else |
01e699d9 | 1065 | echo "TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME\"" >> "$_DEVEL_SUBPACKAGE_FILE" |
28dc0ace | 1066 | fi |
7b1f1bd3 FF |
1067 | fi |
1068 | # Now build all sub packages | |
1069 | rm -Rf "$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages" | |
59f0d218 | 1070 | for subpackage in $TERMUX_PKG_BUILDER_DIR/*.subpackage.sh $TERMUX_PKG_TMPDIR/*subpackage.sh; do |
7b1f1bd3 FF |
1071 | test ! -f "$subpackage" && continue |
1072 | local SUB_PKG_NAME | |
1073 | SUB_PKG_NAME=$(basename "$subpackage" .subpackage.sh) | |
1074 | # Default value is same as main package, but sub package may override: | |
1075 | local TERMUX_SUBPKG_PLATFORM_INDEPENDENT=$TERMUX_PKG_PLATFORM_INDEPENDENT | |
1076 | local SUB_PKG_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages/$SUB_PKG_NAME | |
1077 | local TERMUX_SUBPKG_DEPENDS="" | |
1078 | local TERMUX_SUBPKG_CONFLICTS="" | |
4f85432b | 1079 | local TERMUX_SUBPKG_REPLACES="" |
0d1a1c8e | 1080 | local TERMUX_SUBPKG_CONFFILES="" |
7b1f1bd3 FF |
1081 | local SUB_PKG_MASSAGE_DIR=$SUB_PKG_DIR/massage/$TERMUX_PREFIX |
1082 | local SUB_PKG_PACKAGE_DIR=$SUB_PKG_DIR/package | |
1083 | mkdir -p "$SUB_PKG_MASSAGE_DIR" "$SUB_PKG_PACKAGE_DIR" | |
1084 | ||
1085 | # shellcheck source=/dev/null | |
1086 | source $subpackage | |
1087 | ||
1088 | for includeset in $TERMUX_SUBPKG_INCLUDE; do | |
1089 | local _INCLUDE_DIRSET | |
1090 | _INCLUDE_DIRSET=$(dirname "$includeset") | |
1091 | test "$_INCLUDE_DIRSET" = "." && _INCLUDE_DIRSET="" | |
1092 | if [ -e "$includeset" ] || [ -L "$includeset" ]; then | |
4432ca97 | 1093 | # Add the -L clause to handle relative symbolic links: |
7b1f1bd3 FF |
1094 | mkdir -p "$SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET" |
1095 | mv "$includeset" "$SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET" | |
1096 | fi | |
1097 | done | |
59f0d218 | 1098 | |
7b1f1bd3 FF |
1099 | local SUB_PKG_ARCH=$TERMUX_ARCH |
1100 | test -n "$TERMUX_SUBPKG_PLATFORM_INDEPENDENT" && SUB_PKG_ARCH=all | |
59f0d218 | 1101 | |
7b1f1bd3 FF |
1102 | cd "$SUB_PKG_DIR/massage" |
1103 | local SUB_PKG_INSTALLSIZE | |
1104 | SUB_PKG_INSTALLSIZE=$(du -sk . | cut -f 1) | |
2f122eed | 1105 | tar -cJf "$SUB_PKG_PACKAGE_DIR/data.tar.xz" . |
59f0d218 | 1106 | |
7b1f1bd3 | 1107 | mkdir -p DEBIAN |
59f0d218 | 1108 | cd DEBIAN |
7b1f1bd3 | 1109 | cat > control <<-HERE |
9b2f3b62 | 1110 | Package: $SUB_PKG_NAME$DEBUG |
7b1f1bd3 FF |
1111 | Architecture: ${SUB_PKG_ARCH} |
1112 | Installed-Size: ${SUB_PKG_INSTALLSIZE} | |
1113 | Maintainer: $TERMUX_PKG_MAINTAINER | |
1114 | Version: $TERMUX_PKG_FULLVERSION | |
1115 | Description: $TERMUX_SUBPKG_DESCRIPTION | |
1116 | Homepage: $TERMUX_PKG_HOMEPAGE | |
1117 | HERE | |
1118 | test ! -z "$TERMUX_SUBPKG_DEPENDS" && echo "Depends: $TERMUX_SUBPKG_DEPENDS" >> control | |
1119 | test ! -z "$TERMUX_SUBPKG_CONFLICTS" && echo "Conflicts: $TERMUX_SUBPKG_CONFLICTS" >> control | |
4f85432b | 1120 | test ! -z "$TERMUX_SUBPKG_REPLACES" && echo "Replaces: $TERMUX_SUBPKG_REPLACES" >> control |
2f122eed | 1121 | tar -cJf "$SUB_PKG_PACKAGE_DIR/control.tar.xz" . |
7b1f1bd3 | 1122 | |
cc7bcfa2 VB |
1123 | for f in $TERMUX_SUBPKG_CONFFILES; do echo "$TERMUX_PREFIX/$f" >> conffiles; done |
1124 | ||
7b1f1bd3 | 1125 | # Create the actual .deb file: |
9b2f3b62 | 1126 | TERMUX_SUBPKG_DEBFILE=$TERMUX_DEBDIR/${SUB_PKG_NAME}${DEBUG}_${TERMUX_PKG_FULLVERSION}_${SUB_PKG_ARCH}.deb |
7b1f1bd3 FF |
1127 | test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary" |
1128 | ar cr "$TERMUX_SUBPKG_DEBFILE" \ | |
1129 | "$TERMUX_COMMON_CACHEDIR/debian-binary" \ | |
1130 | "$SUB_PKG_PACKAGE_DIR/control.tar.xz" \ | |
1131 | "$SUB_PKG_PACKAGE_DIR/data.tar.xz" | |
1132 | ||
1133 | # Go back to main package: | |
1134 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" | |
59f0d218 FF |
1135 | done |
1136 | ||
1137 | # .. remove empty directories (NOTE: keep this last): | |
1138 | find . -type d -empty -delete | |
7b1f1bd3 FF |
1139 | # Make sure user can read and write all files (problem with dpkg otherwise): |
1140 | chmod -R u+rw . | |
59f0d218 FF |
1141 | } |
1142 | ||
01e699d9 | 1143 | termux_step_post_massage() { |
7b1f1bd3 | 1144 | return |
59f0d218 FF |
1145 | } |
1146 | ||
7b1f1bd3 FF |
1147 | # Create data.tar.gz with files to package. Not to be overridden by package scripts. |
1148 | termux_step_create_datatar() { | |
1149 | # Create data tarball containing files to package: | |
1150 | cd "$TERMUX_PKG_MASSAGEDIR" | |
46fe48b3 FF |
1151 | |
1152 | local HARDLINKS="$(find . -type f -links +1)" | |
1153 | if [ -n "$HARDLINKS" ]; then | |
1154 | termux_error_exit "Package contains hard links: $HARDLINKS" | |
1155 | fi | |
1156 | ||
7b1f1bd3 FF |
1157 | if [ -z "${TERMUX_PKG_METAPACKAGE+x}" ] && [ "$(find . -type f)" = "" ]; then |
1158 | termux_error_exit "No files in package" | |
f6a56287 | 1159 | fi |
2f122eed | 1160 | tar -cJf "$TERMUX_PKG_PACKAGEDIR/data.tar.xz" . |
7b1f1bd3 | 1161 | } |
f6a56287 | 1162 | |
01e699d9 | 1163 | termux_step_create_debscripts() { |
7b1f1bd3 | 1164 | return |
3a189d89 FF |
1165 | } |
1166 | ||
7b1f1bd3 FF |
1167 | # Create the build deb file. Not to be overridden by package scripts. |
1168 | termux_step_create_debfile() { | |
1169 | # Get install size. This will be written as the "Installed-Size" deb field so is measured in 1024-byte blocks: | |
1170 | local TERMUX_PKG_INSTALLSIZE | |
1171 | TERMUX_PKG_INSTALLSIZE=$(du -sk . | cut -f 1) | |
1172 | ||
1173 | # From here on TERMUX_ARCH is set to "all" if TERMUX_PKG_PLATFORM_INDEPENDENT is set by the package | |
1174 | test -n "$TERMUX_PKG_PLATFORM_INDEPENDENT" && TERMUX_ARCH=all | |
1175 | ||
1176 | mkdir -p DEBIAN | |
1177 | cat > DEBIAN/control <<-HERE | |
9b2f3b62 | 1178 | Package: $TERMUX_PKG_NAME$DEBUG |
7b1f1bd3 FF |
1179 | Architecture: ${TERMUX_ARCH} |
1180 | Installed-Size: ${TERMUX_PKG_INSTALLSIZE} | |
1181 | Maintainer: $TERMUX_PKG_MAINTAINER | |
1182 | Version: $TERMUX_PKG_FULLVERSION | |
1183 | Description: $TERMUX_PKG_DESCRIPTION | |
1184 | Homepage: $TERMUX_PKG_HOMEPAGE | |
1185 | HERE | |
9ec05091 | 1186 | test ! -z "$TERMUX_PKG_BREAKS" && echo "Breaks: $TERMUX_PKG_BREAKS" >> DEBIAN/control |
7b1f1bd3 FF |
1187 | test ! -z "$TERMUX_PKG_DEPENDS" && echo "Depends: $TERMUX_PKG_DEPENDS" >> DEBIAN/control |
1188 | test ! -z "$TERMUX_PKG_ESSENTIAL" && echo "Essential: yes" >> DEBIAN/control | |
1189 | test ! -z "$TERMUX_PKG_CONFLICTS" && echo "Conflicts: $TERMUX_PKG_CONFLICTS" >> DEBIAN/control | |
5f217847 | 1190 | test ! -z "$TERMUX_PKG_RECOMMENDS" && echo "Recommends: $TERMUX_PKG_RECOMMENDS" >> DEBIAN/control |
7b1f1bd3 FF |
1191 | test ! -z "$TERMUX_PKG_REPLACES" && echo "Replaces: $TERMUX_PKG_REPLACES" >> DEBIAN/control |
1192 | ||
1193 | # Create DEBIAN/conffiles (see https://www.debian.org/doc/debian-policy/ap-pkg-conffiles.html): | |
1194 | for f in $TERMUX_PKG_CONFFILES; do echo "$TERMUX_PREFIX/$f" >> DEBIAN/conffiles; done | |
1195 | ||
1196 | # Allow packages to create arbitrary control files. | |
1197 | # XXX: Should be done in a better way without a function? | |
1198 | cd DEBIAN | |
1199 | termux_step_create_debscripts | |
1200 | ||
1201 | # Create control.tar.xz | |
2f122eed | 1202 | tar -cJf "$TERMUX_PKG_PACKAGEDIR/control.tar.xz" . |
7b1f1bd3 FF |
1203 | |
1204 | test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary" | |
9b2f3b62 | 1205 | TERMUX_PKG_DEBFILE=$TERMUX_DEBDIR/${TERMUX_PKG_NAME}${DEBUG}_${TERMUX_PKG_FULLVERSION}_${TERMUX_ARCH}.deb |
7b1f1bd3 FF |
1206 | # Create the actual .deb file: |
1207 | ar cr "$TERMUX_PKG_DEBFILE" \ | |
1208 | "$TERMUX_COMMON_CACHEDIR/debian-binary" \ | |
1209 | "$TERMUX_PKG_PACKAGEDIR/control.tar.xz" \ | |
1210 | "$TERMUX_PKG_PACKAGEDIR/data.tar.xz" | |
1211 | } | |
59f0d218 | 1212 | |
7b1f1bd3 FF |
1213 | # Finish the build. Not to be overridden by package scripts. |
1214 | termux_step_finish_build() { | |
1215 | echo "termux - build of '$TERMUX_PKG_NAME' done" | |
1216 | test -t 1 && printf "\033]0;%s - DONE\007" "$TERMUX_PKG_NAME" | |
1217 | mkdir -p /data/data/.built-packages | |
1218 | echo "$TERMUX_PKG_FULLVERSION" > "/data/data/.built-packages/$TERMUX_PKG_NAME" | |
9a104bda | 1219 | exit 0 |
7b1f1bd3 | 1220 | } |
2497d957 | 1221 | |
7b1f1bd3 FF |
1222 | termux_step_handle_arguments "$@" |
1223 | termux_step_setup_variables | |
1224 | termux_step_handle_buildarch | |
1225 | termux_step_start_build | |
59f0d218 | 1226 | termux_step_extract_package |
508fa73c | 1227 | cd "$TERMUX_PKG_SRCDIR" |
59f0d218 | 1228 | termux_step_post_extract_package |
7b1f1bd3 FF |
1229 | termux_step_handle_hostbuild |
1230 | termux_step_setup_toolchain | |
59f0d218 | 1231 | termux_step_patch_package |
7106823d | 1232 | termux_step_replace_guess_scripts |
ca7699c1 | 1233 | cd "$TERMUX_PKG_SRCDIR" |
59f0d218 | 1234 | termux_step_pre_configure |
7b1f1bd3 | 1235 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 1236 | termux_step_configure |
7b1f1bd3 | 1237 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 1238 | termux_step_post_configure |
7b1f1bd3 | 1239 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 1240 | termux_step_make |
7b1f1bd3 | 1241 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 1242 | termux_step_make_install |
7b1f1bd3 | 1243 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 1244 | termux_step_post_make_install |
7b1f1bd3 | 1245 | cd "$TERMUX_PKG_MASSAGEDIR" |
59f0d218 | 1246 | termux_step_extract_into_massagedir |
7b1f1bd3 | 1247 | cd "$TERMUX_PKG_MASSAGEDIR" |
59f0d218 | 1248 | termux_step_massage |
7b1f1bd3 | 1249 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
59f0d218 | 1250 | termux_step_post_massage |
7b1f1bd3 FF |
1251 | termux_step_create_datatar |
1252 | termux_step_create_debfile | |
1253 | termux_step_finish_build |