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 | |
7b1f1bd3 | 11 | # Utility function to download a resource, optionally checking against a checksum. |
19fb617a | 12 | termux_download() { |
7b1f1bd3 FF |
13 | local URL="$1" |
14 | local DESTINATION="$2" | |
15 | local TMPFILE | |
16 | TMPFILE=$(mktemp "$TERMUX_PKG_TMPDIR/download.$TERMUX_PKG_NAME.XXXXXXXXX") | |
e239964b | 17 | echo "Downloading ${URL}" |
7b1f1bd3 | 18 | local TRYMAX=6 |
6ad2991c | 19 | for try in $(seq 1 $TRYMAX); do |
e239964b | 20 | if curl -L --fail --retry 2 -o "$TMPFILE" "$URL"; then |
7b1f1bd3 FF |
21 | local ACTUAL_CHECKSUM |
22 | ACTUAL_CHECKSUM=$(sha256sum "$TMPFILE" | cut -f 1 -d ' ') | |
23 | if [ $# = 3 ] && [ -n "$3" ]; then | |
e239964b | 24 | # Optional checksum argument: |
aea30235 | 25 | local EXPECTED=$3 |
7b1f1bd3 | 26 | if [ "$EXPECTED" != "$ACTUAL_CHECKSUM" ]; then |
a75313ee FF |
27 | >&2 printf "Wrong checksum for %s:\nExpected: %s\nActual: %s\n" \ |
28 | "$URL" "$EXPECTED" "$ACTUAL_CHECKSUM" | |
aea30235 FF |
29 | exit 1 |
30 | fi | |
e239964b | 31 | else |
a75313ee FF |
32 | printf "No validation of checksum for %s:\nActual: %s\n" \ |
33 | "$URL" "$ACTUAL_CHECKSUM" | |
e239964b FF |
34 | fi |
35 | mv "$TMPFILE" "$DESTINATION" | |
36 | return | |
37 | else | |
7b1f1bd3 | 38 | echo "Download of $URL failed (attempt $try/$TRYMAX)" 1>&2 |
e239964b FF |
39 | sleep 45 |
40 | fi | |
41 | done | |
42 | ||
7b1f1bd3 FF |
43 | termux_error_exit "Failed to download $URL" |
44 | } | |
45 | ||
46 | # Utility function for golang-using packages to setup a go toolchain. | |
01e699d9 | 47 | termux_setup_golang() { |
7b1f1bd3 FF |
48 | export GOOS=android |
49 | export CGO_ENABLED=1 | |
50 | export GO_LDFLAGS="-extldflags=-pie" | |
51 | if [ "$TERMUX_ARCH" = "arm" ]; then | |
52 | export GOARCH=arm | |
53 | export GOARM=7 | |
54 | elif [ "$TERMUX_ARCH" = "i686" ]; then | |
55 | export GOARCH=386 | |
56 | export GO386=sse2 | |
57 | elif [ "$TERMUX_ARCH" = "aarch64" ]; then | |
58 | export GOARCH=arm64 | |
59 | elif [ "$TERMUX_ARCH" = "x86_64" ]; then | |
60 | export GOARCH=amd64 | |
61 | else | |
62 | termux_error_exit "Unsupported arch: $TERMUX_ARCH" | |
63 | fi | |
64 | ||
8c9b8a9a | 65 | local TERMUX_GO_VERSION=go1.8rc2 |
7b1f1bd3 | 66 | local TERMUX_GO_PLATFORM=linux-amd64 |
7b1f1bd3 | 67 | |
93ae139b | 68 | local TERMUX_BUILDGO_FOLDER=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM} |
7b1f1bd3 FF |
69 | export GOROOT=$TERMUX_BUILDGO_FOLDER |
70 | export PATH=$GOROOT/bin:$PATH | |
71 | ||
72 | if [ -d "$TERMUX_BUILDGO_FOLDER" ]; then return; fi | |
73 | ||
74 | local TERMUX_BUILDGO_TAR=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz | |
75 | rm -Rf "$TERMUX_COMMON_CACHEDIR/go" "$TERMUX_BUILDGO_FOLDER" | |
76 | termux_download https://storage.googleapis.com/golang/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz \ | |
8c9b8a9a FF |
77 | "$TERMUX_BUILDGO_TAR" \ |
78 | d62c2d44d0c6b434e3cda12505f3c9fb880757e3396af1e9ba861f7b547cc864 | |
7b1f1bd3 FF |
79 | ( cd "$TERMUX_COMMON_CACHEDIR"; tar xf "$TERMUX_BUILDGO_TAR"; mv go "$TERMUX_BUILDGO_FOLDER"; rm "$TERMUX_BUILDGO_TAR" ) |
80 | } | |
81 | ||
bb8baaa2 FF |
82 | # Utility function for cmake-built packages to setup a current cmake. |
83 | termux_setup_cmake() { | |
84 | local TERMUX_CMAKE_MAJORVESION=3.7 | |
a55b3fa0 | 85 | local TERMUX_CMAKE_MINORVERSION=2 |
bb8baaa2 FF |
86 | local TERMUX_CMAKE_VERSION=$TERMUX_CMAKE_MAJORVESION.$TERMUX_CMAKE_MINORVERSION |
87 | local TERMUX_CMAKE_TARNAME=cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64.tar.gz | |
88 | local TERMUX_CMAKE_TARFILE=$TERMUX_PKG_TMPDIR/$TERMUX_CMAKE_TARNAME | |
89 | local TERMUX_CMAKE_FOLDER=$TERMUX_COMMON_CACHEDIR/cmake-$TERMUX_CMAKE_VERSION | |
90 | if [ ! -d $TERMUX_CMAKE_FOLDER ]; then | |
91 | termux_download https://cmake.org/files/v$TERMUX_CMAKE_MAJORVESION/$TERMUX_CMAKE_TARNAME \ | |
92 | $TERMUX_CMAKE_TARFILE \ | |
a55b3fa0 | 93 | 0e6ec35d4fa9bf79800118916b51928b6471d5725ff36f1d0de5ebb34dcd5406 |
bb8baaa2 FF |
94 | rm -Rf $TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64 |
95 | tar xf $TERMUX_CMAKE_TARFILE -C $TERMUX_PKG_TMPDIR | |
96 | mv $TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64 \ | |
97 | $TERMUX_CMAKE_FOLDER | |
98 | fi | |
99 | export PATH=$TERMUX_CMAKE_FOLDER/bin:$PATH | |
100 | } | |
101 | ||
7b1f1bd3 FF |
102 | # First step is to handle command-line arguments. Not to be overridden by packages. |
103 | termux_step_handle_arguments() { | |
104 | # shellcheck source=/dev/null | |
105 | test -f "$HOME/.termuxrc" && source "$HOME/.termuxrc" | |
106 | ||
107 | # Handle command-line arguments: | |
108 | _show_usage () { | |
109 | echo "Usage: ./build-package.sh [-a ARCH] [-d] [-D] PACKAGE" | |
110 | echo "Build a package by creating a .deb file in the debs/ folder." | |
111 | echo " -a The architecture to build for: aarch64(default), arm, i686, x86_64 or all." | |
112 | echo " -d Build with debug symbols." | |
113 | echo " -D Build a disabled package in disabled-packages/." | |
114 | echo " -s Skip dependency check." | |
115 | exit 1 | |
116 | } | |
117 | while getopts :a:hdDs option; do | |
118 | case "$option" in | |
119 | a) TERMUX_ARCH="$OPTARG";; | |
120 | h) _show_usage;; | |
121 | d) TERMUX_DEBUG=true;; | |
122 | D) local TERMUX_IS_DISABLED=true;; | |
123 | s) export TERMUX_SKIP_DEPCHECK=true;; | |
124 | ?) termux_error_exit "./build-package.sh: illegal option -$OPTARG";; | |
125 | esac | |
126 | done | |
127 | shift $((OPTIND-1)) | |
128 | ||
129 | if [ "$#" -ne 1 ]; then _show_usage; fi | |
130 | unset -f _show_usage | |
131 | ||
132 | # Handle 'all' arch: | |
133 | if [ -n "${TERMUX_ARCH+x}" ] && [ "${TERMUX_ARCH}" = 'all' ]; then | |
adc0d548 | 134 | for arch in 'aarch64' 'arm' 'i686' 'x86_64'; do |
7b1f1bd3 FF |
135 | ./build-package.sh -a $arch "$1" |
136 | done | |
137 | exit | |
138 | fi | |
139 | ||
140 | # Check the package to build: | |
141 | TERMUX_PKG_NAME=$(basename "$1") | |
142 | export TERMUX_SCRIPTDIR | |
143 | TERMUX_SCRIPTDIR=$(cd "$(dirname "$0")"; pwd) | |
144 | if [[ $1 == *"/"* ]]; then | |
145 | # Path to directory which may be outside this repo: | |
146 | if [ ! -d "$1" ]; then termux_error_exit "'$1' seems to be a path but is not a directory"; fi | |
147 | export TERMUX_PKG_BUILDER_DIR | |
148 | TERMUX_PKG_BUILDER_DIR=$(realpath "$1") | |
149 | else | |
150 | # Package name: | |
151 | if [ -n "${TERMUX_IS_DISABLED=""}" ]; then | |
152 | export TERMUX_PKG_BUILDER_DIR=$TERMUX_SCRIPTDIR/disabled-packages/$TERMUX_PKG_NAME | |
153 | else | |
154 | export TERMUX_PKG_BUILDER_DIR=$TERMUX_SCRIPTDIR/packages/$TERMUX_PKG_NAME | |
155 | fi | |
156 | fi | |
157 | TERMUX_PKG_BUILDER_SCRIPT=$TERMUX_PKG_BUILDER_DIR/build.sh | |
158 | if test ! -f "$TERMUX_PKG_BUILDER_SCRIPT"; then | |
159 | termux_error_exit "No build.sh script at package dir $TERMUX_PKG_BUILDER_DIR!" | |
160 | fi | |
161 | } | |
162 | ||
163 | # Setup variables used by the build. Not to be overridden by packages. | |
164 | termux_step_setup_variables() { | |
165 | : "${ANDROID_HOME:="${HOME}/lib/android-sdk"}" | |
166 | : "${NDK:="${HOME}/lib/android-ndk"}" | |
167 | : "${TERMUX_MAKE_PROCESSES:="4"}" | |
168 | : "${TERMUX_TOPDIR:="$HOME/.termux-build"}" | |
169 | : "${TERMUX_ARCH:="aarch64"}" # arm, aarch64, i686 or x86_64. | |
170 | : "${TERMUX_PREFIX:="/data/data/com.termux/files/usr"}" | |
171 | : "${TERMUX_ANDROID_HOME:="/data/data/com.termux/files/home"}" | |
172 | : "${TERMUX_DEBUG:=""}" | |
173 | : "${TERMUX_API_LEVEL:="21"}" | |
174 | : "${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="24.0.1"}" | |
175 | : "${TERMUX_NDK_VERSION:="13"}" | |
176 | ||
10b023b8 | 177 | if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then |
7b1f1bd3 FF |
178 | TERMUX_ARCH_BITS=64 |
179 | else | |
180 | TERMUX_ARCH_BITS=32 | |
181 | fi | |
182 | ||
183 | TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-android" | |
184 | if [ "$TERMUX_ARCH" = "arm" ]; then TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}eabi"; fi | |
185 | ||
186 | if [ ! -d "$NDK" ]; then | |
187 | termux_error_exit 'NDK not pointing at a directory!' | |
188 | fi | |
189 | if ! grep -s -q "Pkg.Revision = $TERMUX_NDK_VERSION" "$NDK/source.properties"; then | |
190 | termux_error_exit "Wrong NDK version - we need $TERMUX_NDK_VERSION" | |
191 | fi | |
192 | ||
2b0e9dc9 FF |
193 | # The build tuple that may be given to --build configure flag: |
194 | TERMUX_BUILD_TUPLE=$(sh "$TERMUX_SCRIPTDIR/scripts/config.guess") | |
195 | ||
7b1f1bd3 FF |
196 | # We do not put all of build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/ into PATH |
197 | # to avoid stuff like arm-linux-androideabi-ld there to conflict with ones from | |
198 | # the standalone toolchain. | |
199 | TERMUX_DX=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/dx | |
200 | TERMUX_JACK=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/jack.jar | |
201 | TERMUX_JILL=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/jill.jar | |
202 | ||
203 | TERMUX_COMMON_CACHEDIR="$TERMUX_TOPDIR/_cache" | |
204 | TERMUX_DEBDIR="$TERMUX_SCRIPTDIR/debs" | |
205 | TERMUX_ELF_CLEANER=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner | |
206 | ||
207 | TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/toolchain-${TERMUX_ARCH}-ndk${TERMUX_NDK_VERSION}-api${TERMUX_API_LEVEL}" | |
208 | # Bump the below version if a change is made in toolchain setup to ensure | |
209 | # that everyone gets an updated toolchain: | |
c4804ab8 | 210 | TERMUX_STANDALONE_TOOLCHAIN+="-v10" |
7b1f1bd3 FF |
211 | |
212 | export TERMUX_TAR="tar" | |
213 | export TERMUX_TOUCH="touch" | |
7b1f1bd3 FF |
214 | export prefix=${TERMUX_PREFIX} |
215 | export PREFIX=${TERMUX_PREFIX} | |
216 | export PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig | |
217 | ||
218 | TERMUX_PKG_BUILDDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/build | |
219 | TERMUX_PKG_CACHEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/cache | |
220 | TERMUX_PKG_MASSAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/massage | |
221 | TERMUX_PKG_PACKAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/package | |
222 | TERMUX_PKG_SRCDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/src | |
223 | TERMUX_PKG_SHA256="" | |
224 | TERMUX_PKG_TMPDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/tmp | |
225 | TERMUX_PKG_HOSTBUILD_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/host-build | |
226 | TERMUX_PKG_PLATFORM_INDEPENDENT="" | |
227 | TERMUX_PKG_NO_DEVELSPLIT="" | |
af4dc416 | 228 | TERMUX_PKG_REVISION="0" # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version |
7b1f1bd3 FF |
229 | TERMUX_PKG_EXTRA_CONFIGURE_ARGS="" |
230 | TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS="" | |
231 | TERMUX_PKG_EXTRA_MAKE_ARGS="" | |
232 | TERMUX_PKG_BUILD_IN_SRC="" | |
233 | TERMUX_PKG_RM_AFTER_INSTALL="" | |
234 | TERMUX_PKG_DEPENDS="" | |
235 | TERMUX_PKG_HOMEPAGE="" | |
236 | TERMUX_PKG_DESCRIPTION="FIXME:Add description" | |
237 | TERMUX_PKG_FOLDERNAME="" | |
238 | TERMUX_PKG_KEEP_STATIC_LIBRARIES="false" | |
239 | TERMUX_PKG_ESSENTIAL="" | |
240 | TERMUX_PKG_CONFLICTS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts | |
241 | TERMUX_PKG_REPLACES="" | |
242 | TERMUX_PKG_CONFFILES="" | |
243 | TERMUX_PKG_INCLUDE_IN_DEVPACKAGE="" | |
244 | TERMUX_PKG_DEVPACKAGE_DEPENDS="" | |
245 | # Set if a host build should be done in TERMUX_PKG_HOSTBUILD_DIR: | |
246 | TERMUX_PKG_HOSTBUILD="" | |
247 | TERMUX_PKG_MAINTAINER="Fredrik Fornwall @fornwall" | |
2f0de587 | 248 | TERMUX_PKG_CLANG=yes # does nothing for cmake based packages. clang is chosen by cmake |
58f7a21c | 249 | TERMUX_PKG_FORCE_CMAKE=no # if the package has autotools as well as cmake, then set this to prefer cmake |
7b1f1bd3 FF |
250 | |
251 | unset CFLAGS CPPFLAGS LDFLAGS CXXFLAGS | |
252 | } | |
253 | ||
254 | # Save away and restore build setups which may change between builds. | |
255 | termux_step_handle_buildarch() { | |
256 | # If $TERMUX_PREFIX already exists, it may have been built for a different arch | |
257 | local TERMUX_ARCH_FILE=/data/TERMUX_ARCH | |
258 | if [ -f "${TERMUX_ARCH_FILE}" ]; then | |
259 | local TERMUX_PREVIOUS_ARCH | |
260 | TERMUX_PREVIOUS_ARCH=$(cat $TERMUX_ARCH_FILE) | |
261 | if [ "$TERMUX_PREVIOUS_ARCH" != "$TERMUX_ARCH" ]; then | |
262 | local TERMUX_DATA_BACKUPDIRS=$TERMUX_TOPDIR/_databackups | |
263 | mkdir -p "$TERMUX_DATA_BACKUPDIRS" | |
264 | local TERMUX_DATA_PREVIOUS_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_PREVIOUS_ARCH | |
265 | local TERMUX_DATA_CURRENT_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_ARCH | |
266 | # Save current /data (removing old backup if any) | |
267 | if test -e "$TERMUX_DATA_PREVIOUS_BACKUPDIR"; then | |
268 | termux_error_exit "Directory already exists" | |
269 | fi | |
270 | mv /data/data "$TERMUX_DATA_PREVIOUS_BACKUPDIR" | |
271 | # Restore new one (if any) | |
272 | if [ -d "$TERMUX_DATA_CURRENT_BACKUPDIR" ]; then | |
273 | mv "$TERMUX_DATA_CURRENT_BACKUPDIR" /data/data | |
274 | fi | |
275 | fi | |
276 | fi | |
277 | ||
278 | # Keep track of current arch we are building for. | |
279 | echo "$TERMUX_ARCH" > $TERMUX_ARCH_FILE | |
19fb617a FF |
280 | } |
281 | ||
7b1f1bd3 FF |
282 | # Source the package build script and start building. No to be overridden by packages. |
283 | termux_step_start_build() { | |
284 | # shellcheck source=/dev/null | |
285 | source "$TERMUX_PKG_BUILDER_SCRIPT" | |
19fb617a | 286 | |
7b1f1bd3 FF |
287 | if [ -n "${TERMUX_PKG_BLACKLISTED_ARCHES:=""}" ] && [ "$TERMUX_PKG_BLACKLISTED_ARCHES" != "${TERMUX_PKG_BLACKLISTED_ARCHES/$TERMUX_ARCH/}" ]; then |
288 | echo "Skipping building $TERMUX_PKG_NAME for arch $TERMUX_ARCH" | |
289 | exit 0 | |
290 | fi | |
291 | ||
292 | if [ -z "${TERMUX_SKIP_DEPCHECK:=""}" ]; then | |
93ae139b FF |
293 | local p TERMUX_ALL_DEPS |
294 | TERMUX_ALL_DEPS=$(./scripts/buildorder.py "$TERMUX_PKG_NAME") | |
295 | for p in $TERMUX_ALL_DEPS; do | |
7b1f1bd3 FF |
296 | if [ "$p" != "$TERMUX_PKG_NAME" ]; then |
297 | echo "Building dependency $p if necessary..." | |
298 | ./build-package.sh -a $TERMUX_ARCH -s "$p" | |
299 | fi | |
300 | done | |
301 | fi | |
2c1aa558 | 302 | |
7b1f1bd3 | 303 | TERMUX_PKG_FULLVERSION=$TERMUX_PKG_VERSION |
af4dc416 | 304 | if [ "$TERMUX_PKG_REVISION" != "0" ] || [ "$TERMUX_PKG_FULLVERSION" != "${TERMUX_PKG_FULLVERSION/-/}" ]; then |
7b1f1bd3 | 305 | # "0" is the default revision, so only include it if the upstream versions contains "-" itself |
af4dc416 | 306 | TERMUX_PKG_FULLVERSION+="-$TERMUX_PKG_REVISION" |
7b1f1bd3 | 307 | fi |
59f0d218 | 308 | |
7b1f1bd3 FF |
309 | if [ -z "$TERMUX_DEBUG" ] && [ -e "/data/data/.built-packages/$TERMUX_PKG_NAME" ]; then |
310 | if [ "$(cat "/data/data/.built-packages/$TERMUX_PKG_NAME")" = "$TERMUX_PKG_FULLVERSION" ]; then | |
311 | echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION built - skipping (rm /data/data/.built-packages/$TERMUX_PKG_NAME to force rebuild)" | |
312 | exit 0 | |
313 | fi | |
314 | fi | |
315 | ||
316 | # Cleanup old state: | |
317 | rm -Rf "$TERMUX_PKG_BUILDDIR" \ | |
318 | "$TERMUX_PKG_PACKAGEDIR" \ | |
319 | "$TERMUX_PKG_SRCDIR" \ | |
320 | "$TERMUX_PKG_TMPDIR" \ | |
321 | "$TERMUX_PKG_MASSAGEDIR" | |
322 | ||
323 | # Ensure folders present (but not $TERMUX_PKG_SRCDIR, it will be created in build) | |
324 | mkdir -p "$TERMUX_COMMON_CACHEDIR" \ | |
325 | "$TERMUX_DEBDIR" \ | |
326 | "$TERMUX_PKG_BUILDDIR" \ | |
327 | "$TERMUX_PKG_PACKAGEDIR" \ | |
328 | "$TERMUX_PKG_TMPDIR" \ | |
329 | "$TERMUX_PKG_CACHEDIR" \ | |
330 | "$TERMUX_PKG_MASSAGEDIR" \ | |
331 | $PKG_CONFIG_LIBDIR \ | |
332 | $TERMUX_PREFIX/{bin,etc,lib,libexec,share,tmp,include} | |
333 | ||
334 | # Make $TERMUX_PREFIX/bin/sh executable on the builder, so that build | |
335 | # scripts can assume that it works on both builder and host later on: | |
336 | ln -f -s /bin/sh "$TERMUX_PREFIX/bin/sh" | |
337 | ||
338 | TERMUX_ELF_CLEANER_SRC=$TERMUX_SCRIPTDIR/packages/termux-elf-cleaner/termux-elf-cleaner.cpp | |
339 | if [ "$TERMUX_ELF_CLEANER_SRC" -nt "$TERMUX_ELF_CLEANER" ]; then | |
340 | g++ -std=c++11 -Wall -Wextra -pedantic -Os "$TERMUX_ELF_CLEANER_SRC" -o "$TERMUX_ELF_CLEANER" | |
341 | fi | |
342 | ||
343 | if [ -n "$TERMUX_PKG_BUILD_IN_SRC" ]; then | |
344 | echo "Building in src due to TERMUX_PKG_BUILD_IN_SRC being set" > "$TERMUX_PKG_BUILDDIR/BUILDING_IN_SRC.txt" | |
345 | TERMUX_PKG_BUILDDIR=$TERMUX_PKG_SRCDIR | |
346 | fi | |
347 | ||
348 | echo "termux - building $TERMUX_PKG_NAME for arch $TERMUX_ARCH..." | |
349 | test -t 1 && printf "\033]0;%s...\007" "$TERMUX_PKG_NAME" | |
350 | ||
351 | # Add a pkg-config file for the system zlib | |
352 | cat > "$PKG_CONFIG_LIBDIR/zlib.pc" <<-HERE | |
353 | Name: zlib | |
354 | Description: zlib compression library | |
355 | Version: 1.2.8 | |
356 | Requires: | |
357 | Libs: -lz | |
358 | HERE | |
359 | ||
360 | # Keep track of when build started so we can see what files have been created. | |
361 | # We start by sleeping so that any generated files above (such as zlib.pc) get | |
362 | # an older timestamp than the TERMUX_BUILD_TS_FILE. | |
363 | sleep 1 | |
364 | TERMUX_BUILD_TS_FILE=$TERMUX_PKG_TMPDIR/timestamp_$TERMUX_PKG_NAME | |
365 | touch "$TERMUX_BUILD_TS_FILE" | |
366 | } | |
367 | ||
368 | # Run just after sourcing $TERMUX_PKG_BUILDER_SCRIPT. May be overridden by packages. | |
01e699d9 | 369 | termux_step_extract_package() { |
7b1f1bd3 FF |
370 | if [ -z "${TERMUX_PKG_SRCURL:=""}" ]; then |
371 | mkdir -p "$TERMUX_PKG_SRCDIR" | |
372 | return | |
373 | fi | |
374 | cd "$TERMUX_PKG_TMPDIR" | |
375 | local filename | |
376 | filename=$(basename "$TERMUX_PKG_SRCURL") | |
377 | local file="$TERMUX_PKG_CACHEDIR/$filename" | |
378 | test ! -f "$file" && termux_download "$TERMUX_PKG_SRCURL" "$file" "$TERMUX_PKG_SHA256" | |
e239964b | 379 | |
59f0d218 FF |
380 | if [ "x$TERMUX_PKG_FOLDERNAME" = "x" ]; then |
381 | folder=`basename $filename .tar.bz2` && folder=`basename $folder .tar.gz` && folder=`basename $folder .tar.xz` && folder=`basename $folder .tar.lz` && folder=`basename $folder .tgz` && folder=`basename $folder .zip` | |
dd54dd13 | 382 | folder="${folder/_/-}" # dpkg uses _ in tar filename, but - in folder |
59f0d218 FF |
383 | else |
384 | folder=$TERMUX_PKG_FOLDERNAME | |
385 | fi | |
386 | rm -Rf $folder | |
7b1f1bd3 FF |
387 | if [ "${file##*.}" = zip ]; then |
388 | unzip -q "$file" | |
59f0d218 | 389 | else |
7b1f1bd3 | 390 | $TERMUX_TAR xf "$file" |
59f0d218 | 391 | fi |
7b1f1bd3 | 392 | mv $folder "$TERMUX_PKG_SRCDIR" |
59f0d218 FF |
393 | } |
394 | ||
7b1f1bd3 | 395 | # Hook for packages to act just after the package has been extracted. |
508fa73c | 396 | # Invoked in $TERMUX_PKG_SRCDIR. |
01e699d9 | 397 | termux_step_post_extract_package() { |
59f0d218 FF |
398 | return |
399 | } | |
400 | ||
7b1f1bd3 FF |
401 | # Optional host build. Not to be overridden by packages. |
402 | termux_step_handle_hostbuild() { | |
403 | if [ "x$TERMUX_PKG_HOSTBUILD" = "x" ]; then return; fi | |
93ae139b | 404 | |
7b1f1bd3 FF |
405 | cd "$TERMUX_PKG_SRCDIR" |
406 | for patch in $TERMUX_PKG_BUILDER_DIR/*.patch.beforehostbuild; do | |
407 | test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | patch --silent -p1 | |
408 | done | |
93ae139b FF |
409 | |
410 | local TERMUX_HOSTBUILD_MARKER="$TERMUX_PKG_HOSTBUILD_DIR/TERMUX_BUILT_FOR_$TERMUX_PKG_VERSION" | |
411 | if [ ! -f "$TERMUX_HOSTBUILD_MARKER" ]; then | |
412 | rm -Rf "$TERMUX_PKG_HOSTBUILD_DIR" | |
413 | mkdir -p "$TERMUX_PKG_HOSTBUILD_DIR" | |
7b1f1bd3 FF |
414 | cd "$TERMUX_PKG_HOSTBUILD_DIR" |
415 | termux_step_host_build | |
93ae139b | 416 | touch "$TERMUX_HOSTBUILD_MARKER" |
7b1f1bd3 FF |
417 | fi |
418 | } | |
419 | ||
59f0d218 FF |
420 | # Perform a host build. Will be called in $TERMUX_PKG_HOSTBUILD_DIR. |
421 | # After termux_step_post_extract_package() and before termux_step_patch_package() | |
01e699d9 | 422 | termux_step_host_build() { |
7b1f1bd3 | 423 | "$TERMUX_PKG_SRCDIR/configure" ${TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS} |
4663ac70 | 424 | make -j $TERMUX_MAKE_PROCESSES |
59f0d218 FF |
425 | } |
426 | ||
7b1f1bd3 FF |
427 | # Setup a standalone Android NDK toolchain. Not to be overridden by packages. |
428 | termux_step_setup_toolchain() { | |
429 | # We put this after system PATH to avoid picking up toolchain stripped python | |
430 | export PATH=$PATH:$TERMUX_STANDALONE_TOOLCHAIN/bin | |
431 | ||
619b9664 FF |
432 | export CFLAGS="" |
433 | export LDFLAGS="-L${TERMUX_PREFIX}/lib" | |
434 | ||
7b1f1bd3 FF |
435 | if [ "$TERMUX_PKG_CLANG" = "no" ]; then |
436 | export AS=${TERMUX_HOST_PLATFORM}-gcc | |
437 | export CC=$TERMUX_HOST_PLATFORM-gcc | |
438 | export CXX=$TERMUX_HOST_PLATFORM-g++ | |
619b9664 FF |
439 | LDFLAGS+=" -specs=$TERMUX_SCRIPTDIR/termux.spec" |
440 | CFLAGS+=" -specs=$TERMUX_SCRIPTDIR/termux.spec" | |
7b1f1bd3 | 441 | else |
2f0de587 | 442 | export AS=${TERMUX_HOST_PLATFORM}-clang |
7b1f1bd3 FF |
443 | export CC=$TERMUX_HOST_PLATFORM-clang |
444 | export CXX=$TERMUX_HOST_PLATFORM-clang++ | |
7b1f1bd3 | 445 | fi |
619b9664 FF |
446 | |
447 | export AR=$TERMUX_HOST_PLATFORM-ar | |
7b1f1bd3 FF |
448 | export CPP=${TERMUX_HOST_PLATFORM}-cpp |
449 | export CC_FOR_BUILD=gcc | |
450 | export LD=$TERMUX_HOST_PLATFORM-ld | |
451 | export OBJDUMP=$TERMUX_HOST_PLATFORM-objdump | |
452 | # Setup pkg-config for cross-compiling: | |
453 | export PKG_CONFIG=$TERMUX_STANDALONE_TOOLCHAIN/bin/${TERMUX_HOST_PLATFORM}-pkg-config | |
454 | export RANLIB=$TERMUX_HOST_PLATFORM-ranlib | |
455 | export READELF=$TERMUX_HOST_PLATFORM-readelf | |
456 | export STRIP=$TERMUX_HOST_PLATFORM-strip | |
457 | ||
7b1f1bd3 FF |
458 | # Android 7 started to support DT_RUNPATH (but not DT_RPATH), so we may want |
459 | # LDFLAGS+="-Wl,-rpath=$TERMUX_PREFIX/lib -Wl,--enable-new-dtags" | |
460 | # and no longer remove DT_RUNPATH in termux-elf-cleaner. | |
461 | ||
462 | if [ "$TERMUX_ARCH" = "arm" ]; then | |
c9e68e0d FF |
463 | # https://developer.android.com/ndk/guides/standalone_toolchain.html#abi_compatibility: |
464 | # "We recommend using the -mthumb compiler flag to force the generation of 16-bit Thumb-2 instructions". | |
465 | # With r13 of the ndk ruby 2.4.0 segfaults when built on arm with clang without -mthumb. | |
466 | CFLAGS+=" -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb" | |
7b1f1bd3 FF |
467 | LDFLAGS+=" -march=armv7-a -Wl,--fix-cortex-a8" |
468 | elif [ "$TERMUX_ARCH" = "i686" ]; then | |
469 | # From $NDK/docs/CPU-ARCH-ABIS.html: | |
470 | CFLAGS+=" -march=i686 -msse3 -mstackrealign -mfpmath=sse" | |
471 | elif [ "$TERMUX_ARCH" = "aarch64" ]; then | |
0d1dde5f | 472 | : |
7b1f1bd3 FF |
473 | elif [ "$TERMUX_ARCH" = "x86_64" ]; then |
474 | : | |
475 | else | |
476 | termux_error_exit "Invalid arch '$TERMUX_ARCH' - support arches are 'arm', 'i686', 'aarch64', 'x86_64'" | |
477 | fi | |
478 | ||
479 | if [ -n "$TERMUX_DEBUG" ]; then | |
480 | CFLAGS+=" -g3 -O1 -fstack-protector --param ssp-buffer-size=4 -D_FORTIFY_SOURCE=2" | |
481 | else | |
482 | CFLAGS+=" -Os" | |
483 | fi | |
484 | ||
485 | export CXXFLAGS="$CFLAGS" | |
486 | export CPPFLAGS="-I${TERMUX_PREFIX}/include" | |
487 | ||
488 | if [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libandroid-support/}" ]; then | |
489 | # If using the android support library, link to it and include its headers as system headers: | |
490 | CPPFLAGS+=" -isystem $TERMUX_PREFIX/include/libandroid-support" | |
491 | LDFLAGS+=" -landroid-support" | |
492 | fi | |
493 | ||
494 | export ac_cv_func_getpwent=no | |
495 | export ac_cv_func_getpwnam=no | |
496 | export ac_cv_func_getpwuid=no | |
497 | ||
498 | if [ ! -d $TERMUX_STANDALONE_TOOLCHAIN ]; then | |
499 | # Do not put toolchain in place until we are done with setup, to avoid having a half setup | |
500 | # toolchain left in place if something goes wrong (or process is just aborted): | |
2f0de587 | 501 | local _TERMUX_TOOLCHAIN_TMPDIR=${TERMUX_STANDALONE_TOOLCHAIN}-tmp |
7b1f1bd3 FF |
502 | rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR |
503 | ||
504 | local _NDK_ARCHNAME=$TERMUX_ARCH | |
505 | if [ "$TERMUX_ARCH" = "aarch64" ]; then | |
506 | _NDK_ARCHNAME=arm64 | |
507 | elif [ "$TERMUX_ARCH" = "i686" ]; then | |
508 | _NDK_ARCHNAME=x86 | |
509 | fi | |
2f0de587 | 510 | |
7b1f1bd3 FF |
511 | "$NDK/build/tools/make_standalone_toolchain.py" \ |
512 | --api "$TERMUX_API_LEVEL" \ | |
513 | --arch $_NDK_ARCHNAME \ | |
514 | --install-dir $_TERMUX_TOOLCHAIN_TMPDIR | |
515 | ||
07884eae FF |
516 | local wrapped plusplus CLANG_TARGET=$TERMUX_HOST_PLATFORM |
517 | if [ $TERMUX_ARCH = arm ]; then CLANG_TARGET=${CLANG_TARGET/arm-/armv7a-}; fi | |
518 | for wrapped in ${TERMUX_HOST_PLATFORM}-clang clang; do | |
519 | for plusplus in "" "++"; do | |
520 | local FILE_TO_REPLACE=$_TERMUX_TOOLCHAIN_TMPDIR/bin/${wrapped}${plusplus} | |
521 | if [ ! -f $FILE_TO_REPLACE ]; then | |
522 | termux_error_exit "No toolchain file to override: $FILE_TO_REPLACE" | |
523 | fi | |
524 | cp $TERMUX_SCRIPTDIR/scripts/clang-pie-wrapper $FILE_TO_REPLACE | |
525 | sed -i "s/COMPILER/clang38$plusplus/" $FILE_TO_REPLACE | |
526 | sed -i "s/CLANG_TARGET/$CLANG_TARGET/" $FILE_TO_REPLACE | |
527 | done | |
2f0de587 FF |
528 | done |
529 | ||
7b1f1bd3 FF |
530 | if [ "$TERMUX_ARCH" = "arm" ]; then |
531 | # Fix to allow e.g. <bits/c++config.h> to be included: | |
532 | cp $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/arm-linux-androideabi/armv7-a/bits/* \ | |
533 | $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/bits | |
0d1dde5f FF |
534 | elif [ "$TERMUX_ARCH" = "aarch64" ]; then |
535 | # Use gold by default to work around https://github.com/android-ndk/ndk/issues/148 | |
536 | cp $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld.gold \ | |
537 | $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld | |
c8d1a650 FF |
538 | cp $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld.gold \ |
539 | $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld | |
7b1f1bd3 FF |
540 | fi |
541 | ||
542 | cd $_TERMUX_TOOLCHAIN_TMPDIR/sysroot | |
543 | ||
544 | for f in $TERMUX_SCRIPTDIR/ndk_patches/*.patch; do | |
545 | sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$f" | \ | |
546 | sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ | |
547 | patch --silent -p1; | |
548 | done | |
549 | # elf.h is taken from glibc since the elf.h in the NDK is lacking. | |
550 | # sysexits.h is header-only and used by a few programs. | |
551 | cp "$TERMUX_SCRIPTDIR"/ndk_patches/{elf.h,sysexits.h} $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include | |
552 | ||
553 | $TERMUX_ELF_CLEANER usr/lib/*.so | |
554 | ||
555 | # zlib is really version 1.2.8 in the Android platform (at least | |
556 | # starting from Android 5), not older as the NDK headers claim. | |
557 | for file in zconf.h zlib.h; do | |
558 | curl -o $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include/$file \ | |
559 | https://raw.githubusercontent.com/madler/zlib/v1.2.8/$file | |
560 | done | |
561 | unset file | |
562 | ||
563 | mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN | |
564 | fi | |
565 | ||
566 | if [ ! -f $TERMUX_PREFIX/lib/libstdc++.so ]; then | |
567 | # Setup libgnustl_shared.so in $PREFIX/lib and libstdc++.so as a symlink to it, | |
568 | # so that other C++ using packages links to it instead of the default android | |
569 | # C++ library which does not support exceptions or STL: | |
570 | # https://developer.android.com/ndk/guides/cpp-support.html | |
571 | # We do however want to avoid installing this, to avoid problems where e.g. | |
572 | # libm.so on some i686 devices links against libstdc++.so. | |
573 | # The libgnustl_shared.so library will be packaged in the libgnustl package | |
574 | # which is part of the base Termux installation. | |
575 | mkdir -p "$TERMUX_PREFIX/lib" | |
576 | cd "$TERMUX_PREFIX/lib" | |
577 | _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/libgnustl_shared.so | |
578 | if [ "$TERMUX_ARCH" = arm ]; then | |
579 | _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/armv7-a/libgnustl_shared.so | |
580 | elif [ "$TERMUX_ARCH" = x86_64 ]; then | |
581 | _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib64/libgnustl_shared.so | |
582 | fi | |
583 | cp "$_STL_LIBFILE" . | |
584 | ln -f -s libgnustl_shared.so libstdc++.so | |
585 | fi | |
586 | ||
587 | # Create a pkg-config wrapper. We use path to host pkg-config to | |
588 | # avoid picking up a cross-compiled pkg-config later on. | |
589 | local _HOST_PKGCONFIG | |
590 | _HOST_PKGCONFIG=$(which pkg-config) | |
591 | mkdir -p $TERMUX_STANDALONE_TOOLCHAIN/bin "$PKG_CONFIG_LIBDIR" | |
592 | cat > "$PKG_CONFIG" <<-HERE | |
593 | #!/bin/sh | |
594 | export PKG_CONFIG_DIR= | |
595 | export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR | |
596 | exec $_HOST_PKGCONFIG "\$@" | |
597 | HERE | |
598 | chmod +x "$PKG_CONFIG" | |
599 | } | |
600 | ||
2b0e9dc9 | 601 | # Apply all *.patch files for the package. Not to be overridden by packages. |
01e699d9 | 602 | termux_step_patch_package() { |
7b1f1bd3 | 603 | cd "$TERMUX_PKG_SRCDIR" |
8f7dda83 FF |
604 | # Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses: |
605 | for patch in $TERMUX_PKG_BUILDER_DIR/*.patch{$TERMUX_ARCH_BITS,}; do | |
7b1f1bd3 | 606 | test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | \ |
dc6476e9 | 607 | sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ |
a0057943 | 608 | patch --silent -p1 |
59f0d218 FF |
609 | done |
610 | ||
7b1f1bd3 FF |
611 | find . -name config.sub -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.sub" '{}' \; |
612 | find . -name config.guess -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.guess" '{}' \; | |
59f0d218 FF |
613 | } |
614 | ||
7b1f1bd3 | 615 | # For package scripts to override. Called in $TERMUX_PKG_BUILDDIR. |
01e699d9 | 616 | termux_step_pre_configure() { |
7b1f1bd3 | 617 | return |
59f0d218 FF |
618 | } |
619 | ||
58f7a21c | 620 | termux_step_configure_autotools () { |
7b1f1bd3 | 621 | if [ ! -e "$TERMUX_PKG_SRCDIR/configure" ]; then return; fi |
59f0d218 FF |
622 | |
623 | DISABLE_STATIC="--disable-static" | |
624 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-static/}" ]; then | |
625 | # Do not --disable-static if package explicitly enables it (e.g. gdb needs enable-static to build) | |
626 | DISABLE_STATIC="" | |
627 | fi | |
628 | ||
629 | DISABLE_NLS="--disable-nls" | |
630 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-nls/}" ]; then | |
631 | # Do not --disable-nls if package explicitly enables it (for gettext itself) | |
632 | DISABLE_NLS="" | |
633 | fi | |
634 | ||
635 | ENABLE_SHARED="--enable-shared" | |
636 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--disable-shared/}" ]; then | |
637 | ENABLE_SHARED="" | |
638 | fi | |
639 | HOST_FLAG="--host=$TERMUX_HOST_PLATFORM" | |
640 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--host=/}" ]; then | |
641 | HOST_FLAG="" | |
642 | fi | |
643 | ||
644 | # Some packages provides a $PKG-config script which some configure scripts pickup instead of pkg-config: | |
7b1f1bd3 | 645 | mkdir "$TERMUX_PKG_TMPDIR/config-scripts" |
59f0d218 | 646 | for f in $TERMUX_PREFIX/bin/*config; do |
7b1f1bd3 | 647 | test -f "$f" && cp "$f" "$TERMUX_PKG_TMPDIR/config-scripts" |
59f0d218 | 648 | done |
59f0d218 FF |
649 | export PATH=$TERMUX_PKG_TMPDIR/config-scripts:$PATH |
650 | ||
150f95af FF |
651 | # See http://wiki.buici.com/xwiki/bin/view/Programing+C+and+C%2B%2B/Autoconf+and+RPL_MALLOC |
652 | # about this problem which may cause linker errors in test scripts not undef:ing malloc and | |
653 | # also cause problems with e.g. malloc interceptors such as libgc: | |
654 | local AVOID_AUTOCONF_WRAPPERS="ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes" | |
d2dfadf1 IN |
655 | # Similarly, disable gnulib's rpl_getcwd(). It returns the wrong value, affecting zile. See |
656 | # <https://github.com/termux/termux-packages/issues/76>. | |
d6fcd836 FF |
657 | AVOID_AUTOCONF_WRAPPERS+=" gl_cv_func_getcwd_null=yes gl_cv_func_getcwd_posix_signature=yes gl_cv_func_getcwd_path_max=yes gl_cv_func_getcwd_abort_bug=no" |
658 | AVOID_AUTOCONF_WRAPPERS+=" gl_cv_header_working_fcntl_h=yes gl_cv_func_fcntl_f_dupfd_cloexec=yes gl_cv_func_fcntl_f_dupfd_works=yes" | |
d6012486 FF |
659 | # Remove rpl_gettimeofday reference when building at least coreutils: |
660 | AVOID_AUTOCONF_WRAPPERS+=" gl_cv_func_tzset_clobber=no gl_cv_func_gettimeofday_clobber=no gl_cv_func_gettimeofday_posix_signature=yes" | |
150f95af | 661 | |
7b1f1bd3 FF |
662 | # NOTE: We do not want to quote AVOID_AUTOCONF_WRAPPERS as we want word expansion. |
663 | env $AVOID_AUTOCONF_WRAPPERS "$TERMUX_PKG_SRCDIR/configure" \ | |
59f0d218 FF |
664 | --disable-dependency-tracking \ |
665 | --prefix=$TERMUX_PREFIX \ | |
7b1f1bd3 | 666 | --disable-rpath --disable-rpath-hack \ |
59f0d218 FF |
667 | $HOST_FLAG \ |
668 | $TERMUX_PKG_EXTRA_CONFIGURE_ARGS \ | |
669 | $DISABLE_NLS \ | |
670 | $ENABLE_SHARED \ | |
671 | $DISABLE_STATIC \ | |
672 | --libexecdir=$TERMUX_PREFIX/libexec | |
673 | } | |
674 | ||
58f7a21c VB |
675 | termux_step_configure_cmake () { |
676 | termux_setup_cmake | |
677 | ||
58f7a21c VB |
678 | local TOOLCHAIN_ARGS="-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=$TERMUX_STANDALONE_TOOLCHAIN" |
679 | local BUILD_TYPE=MinSizeRel | |
680 | test -n "$TERMUX_DEBUG" && BUILD_TYPE=Debug | |
681 | ||
682 | local CMAKE_PROC=$TERMUX_ARCH | |
683 | test $CMAKE_PROC == "arm" && CMAKE_PROC='armv7-a' | |
684 | ||
2f0de587 FF |
685 | # XXX: CMAKE_{AR,RANLIB} needed for at least jsoncpp build to not |
686 | # pick up cross compiled binutils tool in $PREFIX/bin: | |
58f7a21c | 687 | cmake -G 'Unix Makefiles' $TERMUX_PKG_SRCDIR \ |
2f0de587 FF |
688 | -DCMAKE_AR=`which $AR` \ |
689 | -DCMAKE_RANLIB=`which $RANLIB` \ | |
58f7a21c VB |
690 | -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ |
691 | -DCMAKE_CROSSCOMPILING=True \ | |
692 | -DCMAKE_C_FLAGS="$CFLAGS $CPPFLAGS" \ | |
2f0de587 | 693 | -DCMAKE_CXX_FLAGS="$CXXFLAGS $CPPFLAGS" \ |
58f7a21c VB |
694 | -DCMAKE_LINKER="$TERMUX_STANDALONE_TOOLCHAIN/bin/$LD $LDFLAGS" \ |
695 | -DCMAKE_FIND_ROOT_PATH=$TERMUX_PREFIX \ | |
696 | -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ | |
697 | -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ | |
698 | -DCMAKE_INSTALL_PREFIX=$TERMUX_PREFIX \ | |
699 | -DCMAKE_MAKE_PROGRAM=`which make` \ | |
700 | -DCMAKE_SYSTEM_PROCESSOR=$CMAKE_PROC \ | |
701 | -DCMAKE_SYSTEM_NAME=Android \ | |
702 | -DCMAKE_SYSTEM_VERSION=21 \ | |
703 | -DCMAKE_SKIP_INSTALL_RPATH=ON \ | |
704 | -DCMAKE_USE_SYSTEM_LIBRARIES=True \ | |
705 | -DBUILD_TESTING=OFF \ | |
706 | $TERMUX_PKG_EXTRA_CONFIGURE_ARGS $TOOLCHAIN_ARGS | |
707 | } | |
708 | ||
709 | termux_step_configure () { | |
2f0de587 | 710 | if [ "$TERMUX_PKG_FORCE_CMAKE" == 'no' ] && [ -f "$TERMUX_PKG_SRCDIR/configure" ]; then |
58f7a21c VB |
711 | termux_step_configure_autotools |
712 | elif [ -f "$TERMUX_PKG_SRCDIR/CMakeLists.txt" ]; then | |
713 | termux_step_configure_cmake | |
714 | fi | |
715 | } | |
716 | ||
717 | termux_step_post_configure () { | |
7b1f1bd3 | 718 | return |
59f0d218 FF |
719 | } |
720 | ||
01e699d9 | 721 | termux_step_make() { |
caf5d0df | 722 | if ls ./*akefile &> /dev/null; then |
7b1f1bd3 FF |
723 | if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then |
724 | make -j $TERMUX_MAKE_PROCESSES | |
725 | else | |
2f0de587 | 726 | make -j $TERMUX_MAKE_PROCESSES ${TERMUX_PKG_EXTRA_MAKE_ARGS} |
7b1f1bd3 FF |
727 | fi |
728 | fi | |
59f0d218 FF |
729 | } |
730 | ||
01e699d9 | 731 | termux_step_make_install() { |
caf5d0df | 732 | if ls ./*akefile &> /dev/null; then |
dd54dd13 | 733 | : "${TERMUX_PKG_MAKE_INSTALL_TARGET:="install"}" |
7b1f1bd3 FF |
734 | # Some packages have problem with parallell install, and it does not buy much, so use -j 1. |
735 | if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then | |
736 | make -j 1 ${TERMUX_PKG_MAKE_INSTALL_TARGET} | |
737 | else | |
738 | make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET} | |
739 | fi | |
740 | fi | |
59f0d218 FF |
741 | } |
742 | ||
7b1f1bd3 | 743 | # Hook function for package scripts to override. |
01e699d9 | 744 | termux_step_post_make_install() { |
7b1f1bd3 | 745 | return |
59f0d218 FF |
746 | } |
747 | ||
01e699d9 | 748 | termux_step_extract_into_massagedir() { |
7b1f1bd3 | 749 | local TARBALL_ORIG=$TERMUX_PKG_PACKAGEDIR/${TERMUX_PKG_NAME}_orig.tar.gz |
59f0d218 FF |
750 | |
751 | # Build diff tar with what has changed during the build: | |
752 | cd $TERMUX_PREFIX | |
7b1f1bd3 | 753 | $TERMUX_TAR -N "$TERMUX_BUILD_TS_FILE" -czf "$TARBALL_ORIG" . |
59f0d218 FF |
754 | |
755 | # Extract tar in order to massage it | |
7b1f1bd3 FF |
756 | mkdir -p "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
757 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" | |
758 | $TERMUX_TAR xf "$TARBALL_ORIG" | |
759 | rm "$TARBALL_ORIG" | |
59f0d218 FF |
760 | } |
761 | ||
01e699d9 | 762 | termux_step_massage() { |
7b1f1bd3 | 763 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
59f0d218 FF |
764 | |
765 | # Remove lib/charset.alias which is installed by gettext-using packages: | |
766 | rm -f lib/charset.alias | |
a0c80d57 | 767 | |
59f0d218 FF |
768 | # Remove non-english man pages: |
769 | test -d share/man && (cd share/man; for f in `ls | grep -v man`; do rm -Rf $f; done ) | |
a0c80d57 | 770 | |
7b1f1bd3 | 771 | if [ -z "${TERMUX_PKG_KEEP_INFOPAGES+x}" ]; then |
a0c80d57 FF |
772 | # Remove info pages: |
773 | rm -Rf share/info | |
774 | fi | |
775 | ||
9db621c0 FF |
776 | # Remove locale files we're not interested in:: |
777 | rm -Rf share/locale | |
7b1f1bd3 | 778 | if [ -z "${TERMUX_PKG_KEEP_SHARE_DOC+x}" ]; then |
9db621c0 FF |
779 | # Remove info pages: |
780 | rm -Rf share/doc | |
781 | fi | |
a0c80d57 | 782 | |
59f0d218 FF |
783 | # Remove old kept libraries (readline): |
784 | find . -name '*.old' -delete | |
a0c80d57 FF |
785 | |
786 | # Remove static libraries: | |
59f0d218 FF |
787 | if [ $TERMUX_PKG_KEEP_STATIC_LIBRARIES = "false" ]; then |
788 | find . -name '*.a' -delete | |
789 | find . -name '*.la' -delete | |
790 | fi | |
791 | ||
1d678bce | 792 | # Move over sbin to bin: |
7b1f1bd3 | 793 | for file in sbin/*; do if test -f "$file"; then mv "$file" bin/; fi; done |
59f0d218 | 794 | |
40534bae FF |
795 | # Remove world permissions and add write permissions. |
796 | # The -f flag is used to suppress warnings about dangling symlinks (such | |
797 | # as ones to /system/... which may not exist on the build machine): | |
798 | find . -exec chmod -f u+w,o-rwx \{\} \; | |
59f0d218 | 799 | if [ "$TERMUX_DEBUG" = "" ]; then |
e5b151a0 FF |
800 | # Strip binaries. file(1) may fail for certain unusual files, so disable pipefail. |
801 | set +e +o pipefail | |
802 | find . -type f | xargs -r file | grep -E "(executable|shared object)" | grep ELF | cut -f 1 -d : | \ | |
7b1f1bd3 | 803 | xargs -r "$STRIP" --strip-unneeded --preserve-dates |
e5b151a0 | 804 | set -e -o pipefail |
59f0d218 | 805 | fi |
1d678bce | 806 | # Remove DT_ entries which the android 5.1 linker warns about: |
7b1f1bd3 | 807 | find . -type f -print0 | xargs -r -0 "$TERMUX_ELF_CLEANER" |
1d678bce FF |
808 | |
809 | # Fix shebang paths: | |
810 | for file in `find -L . -type f`; do | |
811 | 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 | |
812 | done | |
59f0d218 FF |
813 | |
814 | test ! -z "$TERMUX_PKG_RM_AFTER_INSTALL" && rm -Rf $TERMUX_PKG_RM_AFTER_INSTALL | |
815 | ||
816 | find . -type d -empty -delete # Remove empty directories | |
817 | ||
7b1f1bd3 FF |
818 | # Sub packages: |
819 | if [ -d include ] && [ -z "${TERMUX_PKG_NO_DEVELSPLIT}" ]; then | |
820 | # Add virtual -dev sub package if there are include files: | |
821 | local _DEVEL_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-dev.subpackage.sh | |
12ff30d5 | 822 | echo TERMUX_SUBPKG_INCLUDE=\"include share/man/man3 lib/pkgconfig share/aclocal lib/cmake $TERMUX_PKG_INCLUDE_IN_DEVPACKAGE\" > "$_DEVEL_SUBPACKAGE_FILE" |
dd54dd13 | 823 | echo "TERMUX_SUBPKG_DESCRIPTION=\"Development files for ${TERMUX_PKG_NAME}\"" >> "$_DEVEL_SUBPACKAGE_FILE" |
28dc0ace | 824 | if [ -n "$TERMUX_PKG_DEVPACKAGE_DEPENDS" ]; then |
01e699d9 | 825 | echo "TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME,$TERMUX_PKG_DEVPACKAGE_DEPENDS\"" >> $_DEVEL_SUBPACKAGE_FILE |
28dc0ace | 826 | else |
01e699d9 | 827 | echo "TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME\"" >> "$_DEVEL_SUBPACKAGE_FILE" |
28dc0ace | 828 | fi |
ad04b25a FF |
829 | if [ x$TERMUX_PKG_CONFLICTS != x ]; then |
830 | # Assume that dev packages conflicts as well. | |
7b1f1bd3 | 831 | echo "TERMUX_SUBPKG_CONFLICTS=${TERMUX_PKG_CONFLICTS}-dev" >> "$_DEVEL_SUBPACKAGE_FILE" |
ad04b25a | 832 | fi |
7b1f1bd3 FF |
833 | fi |
834 | # Now build all sub packages | |
835 | rm -Rf "$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages" | |
59f0d218 | 836 | for subpackage in $TERMUX_PKG_BUILDER_DIR/*.subpackage.sh $TERMUX_PKG_TMPDIR/*subpackage.sh; do |
7b1f1bd3 FF |
837 | test ! -f "$subpackage" && continue |
838 | local SUB_PKG_NAME | |
839 | SUB_PKG_NAME=$(basename "$subpackage" .subpackage.sh) | |
840 | # Default value is same as main package, but sub package may override: | |
841 | local TERMUX_SUBPKG_PLATFORM_INDEPENDENT=$TERMUX_PKG_PLATFORM_INDEPENDENT | |
842 | local SUB_PKG_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages/$SUB_PKG_NAME | |
843 | local TERMUX_SUBPKG_DEPENDS="" | |
844 | local TERMUX_SUBPKG_CONFLICTS="" | |
845 | local SUB_PKG_MASSAGE_DIR=$SUB_PKG_DIR/massage/$TERMUX_PREFIX | |
846 | local SUB_PKG_PACKAGE_DIR=$SUB_PKG_DIR/package | |
847 | mkdir -p "$SUB_PKG_MASSAGE_DIR" "$SUB_PKG_PACKAGE_DIR" | |
848 | ||
849 | # shellcheck source=/dev/null | |
850 | source $subpackage | |
851 | ||
852 | for includeset in $TERMUX_SUBPKG_INCLUDE; do | |
853 | local _INCLUDE_DIRSET | |
854 | _INCLUDE_DIRSET=$(dirname "$includeset") | |
855 | test "$_INCLUDE_DIRSET" = "." && _INCLUDE_DIRSET="" | |
856 | if [ -e "$includeset" ] || [ -L "$includeset" ]; then | |
4432ca97 | 857 | # Add the -L clause to handle relative symbolic links: |
7b1f1bd3 FF |
858 | mkdir -p "$SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET" |
859 | mv "$includeset" "$SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET" | |
860 | fi | |
861 | done | |
59f0d218 | 862 | |
7b1f1bd3 FF |
863 | local SUB_PKG_ARCH=$TERMUX_ARCH |
864 | test -n "$TERMUX_SUBPKG_PLATFORM_INDEPENDENT" && SUB_PKG_ARCH=all | |
59f0d218 | 865 | |
7b1f1bd3 FF |
866 | cd "$SUB_PKG_DIR/massage" |
867 | local SUB_PKG_INSTALLSIZE | |
868 | SUB_PKG_INSTALLSIZE=$(du -sk . | cut -f 1) | |
869 | $TERMUX_TAR -cJf "$SUB_PKG_PACKAGE_DIR/data.tar.xz" . | |
59f0d218 | 870 | |
7b1f1bd3 | 871 | mkdir -p DEBIAN |
59f0d218 | 872 | cd DEBIAN |
7b1f1bd3 FF |
873 | cat > control <<-HERE |
874 | Package: $SUB_PKG_NAME | |
875 | Architecture: ${SUB_PKG_ARCH} | |
876 | Installed-Size: ${SUB_PKG_INSTALLSIZE} | |
877 | Maintainer: $TERMUX_PKG_MAINTAINER | |
878 | Version: $TERMUX_PKG_FULLVERSION | |
879 | Description: $TERMUX_SUBPKG_DESCRIPTION | |
880 | Homepage: $TERMUX_PKG_HOMEPAGE | |
881 | HERE | |
882 | test ! -z "$TERMUX_SUBPKG_DEPENDS" && echo "Depends: $TERMUX_SUBPKG_DEPENDS" >> control | |
883 | test ! -z "$TERMUX_SUBPKG_CONFLICTS" && echo "Conflicts: $TERMUX_SUBPKG_CONFLICTS" >> control | |
884 | $TERMUX_TAR -cJf "$SUB_PKG_PACKAGE_DIR/control.tar.xz" . | |
885 | ||
886 | # Create the actual .deb file: | |
887 | TERMUX_SUBPKG_DEBFILE=$TERMUX_DEBDIR/${SUB_PKG_NAME}_${TERMUX_PKG_FULLVERSION}_${SUB_PKG_ARCH}.deb | |
888 | test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary" | |
889 | ar cr "$TERMUX_SUBPKG_DEBFILE" \ | |
890 | "$TERMUX_COMMON_CACHEDIR/debian-binary" \ | |
891 | "$SUB_PKG_PACKAGE_DIR/control.tar.xz" \ | |
892 | "$SUB_PKG_PACKAGE_DIR/data.tar.xz" | |
893 | ||
894 | # Go back to main package: | |
895 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" | |
59f0d218 FF |
896 | done |
897 | ||
898 | # .. remove empty directories (NOTE: keep this last): | |
899 | find . -type d -empty -delete | |
7b1f1bd3 FF |
900 | # Make sure user can read and write all files (problem with dpkg otherwise): |
901 | chmod -R u+rw . | |
59f0d218 FF |
902 | } |
903 | ||
01e699d9 | 904 | termux_step_post_massage() { |
7b1f1bd3 | 905 | return |
59f0d218 FF |
906 | } |
907 | ||
7b1f1bd3 FF |
908 | # Create data.tar.gz with files to package. Not to be overridden by package scripts. |
909 | termux_step_create_datatar() { | |
910 | # Create data tarball containing files to package: | |
911 | cd "$TERMUX_PKG_MASSAGEDIR" | |
912 | if [ -z "${TERMUX_PKG_METAPACKAGE+x}" ] && [ "$(find . -type f)" = "" ]; then | |
913 | termux_error_exit "No files in package" | |
f6a56287 | 914 | fi |
7b1f1bd3 FF |
915 | $TERMUX_TAR -cJf "$TERMUX_PKG_PACKAGEDIR/data.tar.xz" . |
916 | } | |
f6a56287 | 917 | |
01e699d9 | 918 | termux_step_create_debscripts() { |
7b1f1bd3 | 919 | return |
3a189d89 FF |
920 | } |
921 | ||
7b1f1bd3 FF |
922 | # Create the build deb file. Not to be overridden by package scripts. |
923 | termux_step_create_debfile() { | |
924 | # Get install size. This will be written as the "Installed-Size" deb field so is measured in 1024-byte blocks: | |
925 | local TERMUX_PKG_INSTALLSIZE | |
926 | TERMUX_PKG_INSTALLSIZE=$(du -sk . | cut -f 1) | |
927 | ||
928 | # From here on TERMUX_ARCH is set to "all" if TERMUX_PKG_PLATFORM_INDEPENDENT is set by the package | |
929 | test -n "$TERMUX_PKG_PLATFORM_INDEPENDENT" && TERMUX_ARCH=all | |
930 | ||
931 | mkdir -p DEBIAN | |
932 | cat > DEBIAN/control <<-HERE | |
933 | Package: $TERMUX_PKG_NAME | |
934 | Architecture: ${TERMUX_ARCH} | |
935 | Installed-Size: ${TERMUX_PKG_INSTALLSIZE} | |
936 | Maintainer: $TERMUX_PKG_MAINTAINER | |
937 | Version: $TERMUX_PKG_FULLVERSION | |
938 | Description: $TERMUX_PKG_DESCRIPTION | |
939 | Homepage: $TERMUX_PKG_HOMEPAGE | |
940 | HERE | |
941 | test ! -z "$TERMUX_PKG_DEPENDS" && echo "Depends: $TERMUX_PKG_DEPENDS" >> DEBIAN/control | |
942 | test ! -z "$TERMUX_PKG_ESSENTIAL" && echo "Essential: yes" >> DEBIAN/control | |
943 | test ! -z "$TERMUX_PKG_CONFLICTS" && echo "Conflicts: $TERMUX_PKG_CONFLICTS" >> DEBIAN/control | |
944 | test ! -z "$TERMUX_PKG_REPLACES" && echo "Replaces: $TERMUX_PKG_REPLACES" >> DEBIAN/control | |
945 | ||
946 | # Create DEBIAN/conffiles (see https://www.debian.org/doc/debian-policy/ap-pkg-conffiles.html): | |
947 | for f in $TERMUX_PKG_CONFFILES; do echo "$TERMUX_PREFIX/$f" >> DEBIAN/conffiles; done | |
948 | ||
949 | # Allow packages to create arbitrary control files. | |
950 | # XXX: Should be done in a better way without a function? | |
951 | cd DEBIAN | |
952 | termux_step_create_debscripts | |
953 | ||
954 | # Create control.tar.xz | |
955 | $TERMUX_TAR -cJf "$TERMUX_PKG_PACKAGEDIR/control.tar.xz" . | |
956 | ||
957 | test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary" | |
958 | TERMUX_PKG_DEBFILE=$TERMUX_DEBDIR/${TERMUX_PKG_NAME}_${TERMUX_PKG_FULLVERSION}_${TERMUX_ARCH}.deb | |
959 | # Create the actual .deb file: | |
960 | ar cr "$TERMUX_PKG_DEBFILE" \ | |
961 | "$TERMUX_COMMON_CACHEDIR/debian-binary" \ | |
962 | "$TERMUX_PKG_PACKAGEDIR/control.tar.xz" \ | |
963 | "$TERMUX_PKG_PACKAGEDIR/data.tar.xz" | |
964 | } | |
59f0d218 | 965 | |
7b1f1bd3 FF |
966 | # Finish the build. Not to be overridden by package scripts. |
967 | termux_step_finish_build() { | |
968 | echo "termux - build of '$TERMUX_PKG_NAME' done" | |
969 | test -t 1 && printf "\033]0;%s - DONE\007" "$TERMUX_PKG_NAME" | |
970 | mkdir -p /data/data/.built-packages | |
971 | echo "$TERMUX_PKG_FULLVERSION" > "/data/data/.built-packages/$TERMUX_PKG_NAME" | |
9a104bda | 972 | exit 0 |
7b1f1bd3 | 973 | } |
2497d957 | 974 | |
7b1f1bd3 FF |
975 | termux_step_handle_arguments "$@" |
976 | termux_step_setup_variables | |
977 | termux_step_handle_buildarch | |
978 | termux_step_start_build | |
59f0d218 | 979 | termux_step_extract_package |
508fa73c | 980 | cd "$TERMUX_PKG_SRCDIR" |
59f0d218 | 981 | termux_step_post_extract_package |
7b1f1bd3 FF |
982 | termux_step_handle_hostbuild |
983 | termux_step_setup_toolchain | |
59f0d218 | 984 | termux_step_patch_package |
7b1f1bd3 | 985 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 986 | termux_step_pre_configure |
7b1f1bd3 | 987 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 988 | termux_step_configure |
7b1f1bd3 | 989 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 990 | termux_step_post_configure |
7b1f1bd3 | 991 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 992 | termux_step_make |
7b1f1bd3 | 993 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 994 | termux_step_make_install |
7b1f1bd3 | 995 | cd "$TERMUX_PKG_BUILDDIR" |
59f0d218 | 996 | termux_step_post_make_install |
7b1f1bd3 | 997 | cd "$TERMUX_PKG_MASSAGEDIR" |
59f0d218 | 998 | termux_step_extract_into_massagedir |
7b1f1bd3 | 999 | cd "$TERMUX_PKG_MASSAGEDIR" |
59f0d218 | 1000 | termux_step_massage |
7b1f1bd3 | 1001 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
59f0d218 | 1002 | termux_step_post_massage |
7b1f1bd3 FF |
1003 | termux_step_create_datatar |
1004 | termux_step_create_debfile | |
1005 | termux_step_finish_build |