Commit | Line | Data |
---|---|---|
59f0d218 FF |
1 | #!/bin/bash |
2 | ||
59f0d218 FF |
3 | set -e -o pipefail -u |
4 | ||
a0057943 | 5 | # Read settings from .termuxrc if existing: |
59f0d218 FF |
6 | test -f $HOME/.termuxrc && . $HOME/.termuxrc |
7 | ||
a0057943 | 8 | # Configurable settings: |
59f0d218 | 9 | : ${ANDROID_HOME:="${HOME}/lib/android-sdk"} |
a0057943 | 10 | : ${NDK:="${HOME}/lib/android-ndk"} |
59f0d218 | 11 | : ${TERMUX_MAKE_PROCESSES:='4'} |
a0057943 FF |
12 | : ${TERMUX_TOPDIR:="$HOME/.termux-build"} |
13 | : ${TERMUX_ARCH:="aarch64"} # (arm|aarch64|i686|x86_64) - the x86_64 arch is not yet used or tested. | |
c8b6264e | 14 | : ${TERMUX_CLANG:=""} # Set to non-empty to use clang. |
59f0d218 FF |
15 | : ${TERMUX_PREFIX:='/data/data/com.termux/files/usr'} |
16 | : ${TERMUX_ANDROID_HOME:='/data/data/com.termux/files/home'} | |
17 | : ${TERMUX_DEBUG:=""} | |
18 | : ${TERMUX_PROCESS_DEB:=""} | |
59f0d218 | 19 | : ${TERMUX_API_LEVEL:="21"} |
382cfb78 | 20 | : ${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="24.0.1"} |
202ed9d3 | 21 | : ${TERMUX_NDK_VERSION:="12"} |
a0057943 FF |
22 | |
23 | # Handle command-line arguments: | |
24 | show_usage () { | |
25 | echo "Usage: ./build-package.sh [-a ARCH] PACKAGE" | |
26 | echo "Build a package." | |
27 | echo "" | |
28 | exit 1 | |
29 | } | |
30 | while getopts :a:h option | |
31 | do | |
32 | case "$option" in | |
33 | a) TERMUX_ARCH="$OPTARG";; | |
34 | h) show_usage;; | |
35 | ?) echo "./build-package.sh: illegal option -$OPTARG"; exit 1;; | |
36 | esac | |
37 | done | |
38 | shift $(($OPTIND-1)) | |
39 | if [ "$#" -ne 1 ]; then show_usage; fi | |
40 | ||
41 | # Check the NDK: | |
42 | if [ ! -d "$NDK" ]; then | |
43 | echo 'ERROR: $NDK not defined as pointing at a directory - define it pointing at a android NDK installation!' | |
44 | exit 1 | |
45 | fi | |
46 | if grep -s -q "Pkg.Revision = $TERMUX_NDK_VERSION" $NDK/source.properties; then | |
47 | : | |
48 | else | |
49 | echo "Wrong NDK version - we need $TERMUX_NDK_VERSION" | |
50 | exit 1 | |
51 | fi | |
52 | ||
53 | # Compute standalone toolchain dir, bitness of arch and name of host platform: | |
3f300a10 | 54 | TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/toolchain-${TERMUX_ARCH}-ndk${TERMUX_NDK_VERSION}-api${TERMUX_API_LEVEL}-" |
c8b6264e | 55 | if [ "$TERMUX_CLANG" = "" ]; then |
a0057943 | 56 | TERMUX_STANDALONE_TOOLCHAIN+="gcc4.9" |
c8b6264e | 57 | else |
a0057943 | 58 | TERMUX_STANDALONE_TOOLCHAIN+="clang38" |
c8b6264e | 59 | fi |
3f300a10 FF |
60 | # Bump the below version if a change is made in toolchain setup, to ensure |
61 | # that everyone gets an updated toolchain: | |
62 | TERMUX_STANDALONE_TOOLCHAIN+="-v1" | |
63 | ||
a0057943 FF |
64 | if [ "x86_64" = $TERMUX_ARCH -o "aarch64" = $TERMUX_ARCH ]; then |
65 | TERMUX_ARCH_BITS=64 | |
66 | else | |
67 | TERMUX_ARCH_BITS=32 | |
68 | fi | |
69 | TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-android" | |
70 | if [ $TERMUX_ARCH = "arm" ]; then TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}eabi"; fi | |
71 | ||
72 | # Check the package to build: | |
73 | TERMUX_PKG_NAME=`basename $1` | |
74 | export TERMUX_SCRIPTDIR=`cd $(dirname $0); pwd` | |
75 | if [[ $1 == *"/"* ]]; then | |
76 | # Path to directory which may be outside this repo: | |
77 | if [ ! -d $1 ]; then echo "ERROR: '$1' seems to be a path but is not a directory"; exit 1; fi | |
78 | export TERMUX_PKG_BUILDER_DIR=`realpath $1` | |
79 | else | |
80 | # Package name: | |
81 | export TERMUX_PKG_BUILDER_DIR=$TERMUX_SCRIPTDIR/packages/$TERMUX_PKG_NAME | |
82 | fi | |
83 | TERMUX_PKG_BUILDER_SCRIPT=$TERMUX_PKG_BUILDER_DIR/build.sh | |
84 | if test ! -f $TERMUX_PKG_BUILDER_SCRIPT; then | |
85 | echo "ERROR: No build.sh script at supposed package dir $TERMUX_PKG_BUILDER_DIR!" | |
86 | exit 1 | |
87 | fi | |
88 | ||
89 | # Handle 'all' arch: | |
90 | if [ $TERMUX_ARCH = 'all' ]; then | |
91 | for arch in 'arm' 'i686' 'aarch64'; do | |
92 | ./build-package.sh -a $arch $1 | |
93 | done | |
94 | exit | |
95 | fi | |
96 | ||
59f0d218 FF |
97 | # We do not put all of build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/ into PATH |
98 | # to avoid stuff like arm-linux-androideabi-ld there to conflict with ones from | |
99 | # the standalone toolchain. | |
100 | TERMUX_DX=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/dx | |
382cfb78 FF |
101 | TERMUX_JACK=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/jack.jar |
102 | TERMUX_JILL=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/jill.jar | |
59f0d218 FF |
103 | |
104 | # We put this after system PATH to avoid picking up toolchain stripped python | |
105 | export PATH=$PATH:$TERMUX_STANDALONE_TOOLCHAIN/bin | |
106 | ||
107 | # Make $TERMUX_TAR and $TERMUX_TOUCH point at gnu versions: | |
108 | export TERMUX_TAR="tar" | |
ed021630 | 109 | test `uname` = "Darwin" && TERMUX_TAR=gtar |
59f0d218 FF |
110 | export TERMUX_TOUCH="touch" |
111 | test `uname` = "Darwin" && TERMUX_TOUCH=gtouch | |
112 | ||
59f0d218 | 113 | export prefix=${TERMUX_PREFIX} # prefix is used by some makefiles |
be0684c0 FF |
114 | export PREFIX=${TERMUX_PREFIX} # PREFIX is used by some makefiles |
115 | ||
59f0d218 | 116 | export AR=$TERMUX_HOST_PLATFORM-ar |
c8b6264e FF |
117 | if [ "$TERMUX_CLANG" = "" ]; then |
118 | export AS=${TERMUX_HOST_PLATFORM}-gcc | |
119 | export CC=$TERMUX_HOST_PLATFORM-gcc | |
120 | export CXX=$TERMUX_HOST_PLATFORM-g++ | |
121 | _SPECSFLAG="-specs=$TERMUX_SCRIPTDIR/termux.spec" | |
122 | else | |
bb5cfa8c | 123 | export AS=${TERMUX_HOST_PLATFORM}-gcc |
c8b6264e FF |
124 | export CC=$TERMUX_HOST_PLATFORM-clang |
125 | export CXX=$TERMUX_HOST_PLATFORM-clang++ | |
126 | # TODO: clang does not have specs file, how to ensure pie | |
127 | # binaries gets built? | |
128 | _SPECSFLAG="" | |
129 | fi | |
59f0d218 | 130 | export CPP=${TERMUX_HOST_PLATFORM}-cpp |
59f0d218 FF |
131 | export CC_FOR_BUILD=gcc |
132 | export LD=$TERMUX_HOST_PLATFORM-ld | |
133 | export OBJDUMP=$TERMUX_HOST_PLATFORM-objdump | |
134 | # Setup pkg-config for cross-compiling: | |
135 | export PKG_CONFIG=$TERMUX_STANDALONE_TOOLCHAIN/bin/${TERMUX_HOST_PLATFORM}-pkg-config | |
136 | export PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig | |
137 | export RANLIB=$TERMUX_HOST_PLATFORM-ranlib | |
138 | export READELF=$TERMUX_HOST_PLATFORM-readelf | |
139 | export STRIP=$TERMUX_HOST_PLATFORM-strip | |
140 | ||
59f0d218 FF |
141 | export CFLAGS="$_SPECSFLAG" |
142 | export LDFLAGS="$_SPECSFLAG -L${TERMUX_PREFIX}/lib" | |
143 | ||
144 | if [ "$TERMUX_ARCH" = "arm" ]; then | |
31309df7 FF |
145 | CFLAGS+=" -march=armv7-a -mfpu=neon -mfloat-abi=softfp" |
146 | # "first flag instructs the linker to pick libgcc.a, libgcov.a, and | |
147 | # crt*.o, which are tailored for armv7-a" | |
148 | # - https://developer.android.com/ndk/guides/standalone_toolchain.html | |
149 | LDFLAGS+=" -march=armv7-a -Wl,--fix-cortex-a8" | |
59f0d218 FF |
150 | elif [ $TERMUX_ARCH = "i686" ]; then |
151 | # From $NDK/docs/CPU-ARCH-ABIS.html: | |
152 | CFLAGS+=" -march=i686 -msse3 -mstackrealign -mfpmath=sse" | |
73f9ed9b FF |
153 | elif [ $TERMUX_ARCH = "aarch64" ]; then |
154 | LDFLAGS+=" -Wl,-rpath-link,$TERMUX_PREFIX/lib" | |
155 | LDFLAGS+=" -Wl,-rpath-link,$TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib" | |
a0057943 | 156 | elif [ $TERMUX_ARCH = "x86_64" ]; then |
f9129b8c | 157 | : |
a0057943 FF |
158 | else |
159 | echo "Error: Invalid arch '$TERMUX_ARCH' - support arches are 'arm', 'i686', 'aarch64', 'x86_64'" | |
160 | exit 1 | |
59f0d218 FF |
161 | fi |
162 | ||
163 | if [ -n "$TERMUX_DEBUG" ]; then | |
164 | CFLAGS+=" -g3 -Og -fstack-protector --param ssp-buffer-size=4 -D_FORTIFY_SOURCE=2" | |
165 | else | |
166 | CFLAGS+=" -Os" | |
167 | fi | |
168 | ||
169 | export CXXFLAGS="$CFLAGS" | |
170 | export CPPFLAGS="-I${TERMUX_PREFIX}/include" | |
171 | ||
172 | export ac_cv_func_getpwent=no | |
173 | export ac_cv_func_getpwnam=no | |
174 | export ac_cv_func_getpwuid=no | |
175 | ||
176 | if [ ! -d $TERMUX_STANDALONE_TOOLCHAIN ]; then | |
fef735ea FF |
177 | # See https://developer.android.com/ndk/guides/standalone_toolchain.html about toolchain naming. |
178 | if [ "i686" = $TERMUX_ARCH ]; then | |
59f0d218 | 179 | _TERMUX_NDK_TOOLCHAIN_NAME="x86" |
fef735ea FF |
180 | elif [ "x86_64" = $TERMUX_ARCH ]; then |
181 | _TERMUX_NDK_TOOLCHAIN_NAME="x86_64" | |
182 | else | |
183 | _TERMUX_NDK_TOOLCHAIN_NAME="$TERMUX_HOST_PLATFORM" | |
59f0d218 | 184 | fi |
c8b6264e FF |
185 | |
186 | if [ "$TERMUX_CLANG" = "" ]; then | |
187 | _TERMUX_TOOLCHAIN="${_TERMUX_NDK_TOOLCHAIN_NAME}-4.9" | |
188 | else | |
189 | _TERMUX_TOOLCHAIN="${_TERMUX_NDK_TOOLCHAIN_NAME}-clang" | |
190 | fi | |
a1a58436 FF |
191 | |
192 | # Do not put toolchain in place until we are done with setup, to avoid having a half setup | |
193 | # toolchain left in place if something goes wrong (or process is just aborted): | |
194 | _TERMUX_TOOLCHAIN_TMPDIR=${TERMUX_STANDALONE_TOOLCHAIN}-tmp | |
195 | rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR | |
196 | ||
c8b6264e | 197 | bash $NDK/build/tools/make-standalone-toolchain.sh --platform=android-$TERMUX_API_LEVEL --toolchain=${_TERMUX_TOOLCHAIN} \ |
a1a58436 | 198 | --install-dir=$_TERMUX_TOOLCHAIN_TMPDIR |
59f0d218 FF |
199 | if [ "arm" = $TERMUX_ARCH ]; then |
200 | # Fix to allow e.g. <bits/c++config.h> to be included: | |
a1a58436 | 201 | cp $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/arm-linux-androideabi/armv7-a/bits/* $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/bits |
59f0d218 | 202 | fi |
a1a58436 | 203 | cd $_TERMUX_TOOLCHAIN_TMPDIR/sysroot |
59f0d218 FF |
204 | for f in $TERMUX_SCRIPTDIR/ndk_patches/*.patch; do |
205 | sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" $f | \ | |
206 | sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ | |
a0057943 | 207 | patch --silent -p1; |
59f0d218 | 208 | done |
9462fe82 FF |
209 | # elf.h is taken from glibc since the elf.h in the NDK is lacking. |
210 | # sysexits.h is header-only and used by a few programs. | |
a1a58436 FF |
211 | cp $TERMUX_SCRIPTDIR/ndk_patches/{elf.h,sysexits.h} $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include |
212 | mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN | |
59f0d218 FF |
213 | fi |
214 | ||
3f300a10 FF |
215 | if [ ! -f $TERMUX_PREFIX/lib/libstdc++.so ]; then |
216 | # Setup libgnustl_shared.so in $PREFIX/lib and libstdc++.so as a symlink to it, | |
217 | # so that other C++ using packages links to it instead of the default android | |
218 | # C++ library which does not support exceptions or STL: | |
219 | # https://developer.android.com/ndk/guides/cpp-support.html | |
220 | # We do however want to avoid installing this, to avoid problems # where e.g. | |
221 | # libm.so on some i686 devices links against libstdc++.so. | |
222 | # The libgnustl_shared.so library will be packaged in the libgnustl package | |
223 | # which is part of the base Termux installation. | |
224 | mkdir -p $TERMUX_PREFIX/lib | |
225 | cd $TERMUX_PREFIX/lib | |
226 | _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/libgnustl_shared.so | |
227 | if [ $TERMUX_ARCH = arm ]; then | |
228 | _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/armv7-a/libgnustl_shared.so | |
229 | elif [ $TERMUX_ARCH = x86_64 ]; then | |
230 | _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib64/libgnustl_shared.so | |
231 | fi | |
232 | cp $_STL_LIBFILE . | |
233 | ln -f -s libgnustl_shared.so libstdc++.so | |
234 | fi | |
235 | ||
59f0d218 | 236 | export TERMUX_COMMON_CACHEDIR="$TERMUX_TOPDIR/_cache" |
a0057943 FF |
237 | export TERMUX_DEBDIR="$TERMUX_SCRIPTDIR/debs" |
238 | mkdir -p $TERMUX_COMMON_CACHEDIR $TERMUX_DEBDIR | |
59f0d218 | 239 | |
59f0d218 FF |
240 | TERMUX_PKG_BUILDDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/build |
241 | TERMUX_PKG_CACHEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/cache | |
242 | TERMUX_PKG_MASSAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/massage | |
243 | TERMUX_PKG_PACKAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/package | |
244 | TERMUX_PKG_SRCDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/src | |
245 | TERMUX_PKG_TMPDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/tmp | |
246 | TERMUX_PKG_HOSTBUILD_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/host-build | |
247 | TERMUX_PKG_PLATFORM_INDEPENDENT="" | |
248 | TERMUX_PKG_NO_DEVELSPLIT="" | |
249 | TERMUX_PKG_BUILD_REVISION="0" # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version | |
250 | TERMUX_PKG_EXTRA_CONFIGURE_ARGS="" | |
251 | TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS="" | |
252 | TERMUX_PKG_EXTRA_MAKE_ARGS="" | |
253 | TERMUX_PKG_BUILD_IN_SRC="" | |
254 | TERMUX_PKG_RM_AFTER_INSTALL="" | |
255 | TERMUX_PKG_DEPENDS="" | |
256 | TERMUX_PKG_HOMEPAGE="" | |
257 | TERMUX_PKG_DESCRIPTION="FIXME:Add description" | |
258 | TERMUX_PKG_FOLDERNAME="" | |
259 | TERMUX_PKG_KEEP_STATIC_LIBRARIES="false" | |
260 | TERMUX_PKG_KEEP_HEADER_FILES="false" | |
261 | TERMUX_PKG_ESSENTIAL="" | |
a8c61c7d | 262 | TERMUX_PKG_CONFLICTS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts |
768ce14e | 263 | TERMUX_PKG_REPLACES="" |
59f0d218 | 264 | TERMUX_PKG_CONFFILES="" |
7ad25005 | 265 | TERMUX_PKG_INCLUDE_IN_DEVPACKAGE="" |
28dc0ace | 266 | TERMUX_PKG_DEVPACKAGE_DEPENDS="" |
59f0d218 FF |
267 | # Set if a host build should be done in TERMUX_PKG_HOSTBUILD_DIR: |
268 | TERMUX_PKG_HOSTBUILD="" | |
269 | TERMUX_PKG_MAINTAINER="Fredrik Fornwall <fredrik@fornwall.net>" | |
270 | ||
271 | # Cleanup old state | |
a1a58436 | 272 | rm -Rf $TERMUX_PKG_BUILDDIR $TERMUX_PKG_PACKAGEDIR $TERMUX_PKG_SRCDIR $TERMUX_PKG_TMPDIR $TERMUX_PKG_MASSAGEDIR |
5822f920 | 273 | |
59f0d218 FF |
274 | # If $TERMUX_PREFIX already exists, it may have been built for a different arch |
275 | TERMUX_ARCH_FILE=/data/TERMUX_ARCH | |
276 | if [ -f "${TERMUX_ARCH_FILE}" ]; then | |
277 | TERMUX_PREVIOUS_ARCH=`cat $TERMUX_ARCH_FILE` | |
278 | if [ $TERMUX_PREVIOUS_ARCH != $TERMUX_ARCH ]; then | |
279 | TERMUX_DATA_BACKUPDIRS=$TERMUX_TOPDIR/_databackups | |
280 | mkdir -p $TERMUX_DATA_BACKUPDIRS | |
281 | TERMUX_DATA_PREVIOUS_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_PREVIOUS_ARCH | |
282 | TERMUX_DATA_CURRENT_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_ARCH | |
59f0d218 FF |
283 | # Save current /data (removing old backup if any) |
284 | if test -e $TERMUX_DATA_PREVIOUS_BACKUPDIR; then | |
285 | echo "ERROR: Directory already exists" | |
286 | exit 1 | |
287 | fi | |
288 | mv /data/data $TERMUX_DATA_PREVIOUS_BACKUPDIR | |
289 | # Restore new one (if any) | |
290 | if [ -d $TERMUX_DATA_CURRENT_BACKUPDIR ]; then | |
59f0d218 FF |
291 | mv $TERMUX_DATA_CURRENT_BACKUPDIR /data/data |
292 | fi | |
293 | fi | |
294 | fi | |
295 | echo $TERMUX_ARCH > $TERMUX_ARCH_FILE | |
296 | ||
2c1aa558 | 297 | # Ensure folders present (but not $TERMUX_PKG_SRCDIR, it will be created in build) |
fb45772b | 298 | mkdir -p $TERMUX_PKG_BUILDDIR $TERMUX_PKG_PACKAGEDIR $TERMUX_PKG_TMPDIR $TERMUX_PKG_CACHEDIR $TERMUX_PKG_MASSAGEDIR $PKG_CONFIG_LIBDIR $TERMUX_PREFIX/{bin,etc,lib,libexec,share,tmp,include} |
2c1aa558 | 299 | |
19fb617a FF |
300 | termux_download() { |
301 | URL="$1" | |
302 | DESTINATION="$2" | |
303 | ||
304 | TMPFILE=`mktemp $TERMUX_PKG_TMPDIR/download.XXXXXXXXX` | |
ed66b8ab | 305 | for i in 1 2 3 4 5 6; do |
19fb617a FF |
306 | if curl -L --fail --retry 2 -o "$TMPFILE" "$URL"; then |
307 | mv "$TMPFILE" "$DESTINATION" | |
308 | return | |
309 | else | |
310 | echo "Download of $1 failed (attempt $i/3)" 1>&2 | |
ed66b8ab | 311 | sleep 45 |
19fb617a FF |
312 | fi |
313 | done | |
314 | echo "Failed to download $1 - exiting" 1>&2 | |
315 | exit 1 | |
316 | } | |
317 | ||
318 | # Get fresh versions of config.sub and config.guess | |
319 | for f in config.sub config.guess; do | |
320 | if [ ! -f $TERMUX_COMMON_CACHEDIR/$f ]; then | |
321 | termux_download "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=${f};hb=HEAD" $TERMUX_COMMON_CACHEDIR/$f | |
322 | fi | |
323 | done | |
324 | ||
325 | # Have a debian-binary file ready for deb packaging: | |
326 | test ! -f $TERMUX_COMMON_CACHEDIR/debian-binary && echo "2.0" > $TERMUX_COMMON_CACHEDIR/debian-binary | |
327 | # The host tuple that may be given to --host configure flag, but normally autodetected so not needed explicitly | |
328 | TERMUX_HOST_TUPLE=`sh $TERMUX_COMMON_CACHEDIR/config.guess` | |
329 | ||
2c1aa558 FF |
330 | # Make $TERMUX_PREFIX/bin/sh executable on the builder, so that build script can assume that it works |
331 | # on both builder and host later on: | |
332 | ln -f -s /bin/sh $TERMUX_PREFIX/bin/sh | |
333 | ||
59f0d218 FF |
334 | if [ ! -f $PKG_CONFIG ]; then |
335 | echo "Creating pkg-config wrapper..." | |
336 | # We use path to host pkg-config to avoid picking up a cross-compiled pkg-config later on | |
337 | _HOST_PKGCONFIG=`which pkg-config` | |
338 | mkdir -p $TERMUX_STANDALONE_TOOLCHAIN/bin $PKG_CONFIG_LIBDIR | |
339 | cat > $PKG_CONFIG <<HERE | |
340 | #!/bin/sh | |
341 | export PKG_CONFIG_DIR= | |
342 | export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR | |
343 | # export PKG_CONFIG_SYSROOT_DIR=${TERMUX_PREFIX} | |
344 | exec $_HOST_PKGCONFIG "\$@" | |
345 | HERE | |
346 | chmod +x $PKG_CONFIG | |
347 | ||
348 | # Add a pkg-config file for the system zlib | |
349 | cat > $PKG_CONFIG_LIBDIR/zlib.pc <<HERE | |
350 | Name: zlib | |
351 | Description: zlib compression library | |
352 | Version: 1.2.3 | |
353 | ||
354 | Requires: | |
355 | Libs: -L$TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib -lz | |
356 | Cflags: -I$TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/include | |
357 | HERE | |
59f0d218 FF |
358 | fi |
359 | ||
360 | TERMUX_ELF_CLEANER=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner | |
0ae97c5e | 361 | TERMUX_ELF_CLEANER_SRC=$TERMUX_SCRIPTDIR/packages/termux-elf-cleaner/termux-elf-cleaner.cpp |
637f22d1 FF |
362 | if [ $TERMUX_ELF_CLEANER_SRC -nt $TERMUX_ELF_CLEANER ]; then |
363 | g++ -std=c++11 -Wall -Wextra -pedantic -Os $TERMUX_ELF_CLEANER_SRC -o $TERMUX_ELF_CLEANER | |
59f0d218 FF |
364 | fi |
365 | ||
366 | # Keep track of when build started so we can see what files have been created | |
367 | export TERMUX_BUILD_TS_FILE=$TERMUX_PKG_TMPDIR/timestamp_$TERMUX_PKG_NAME | |
5822f920 FF |
368 | sleep 1 # Sleep so that any generated files above (such as zlib.c and $PREFIX/bin/sh) |
369 | #get older timestamp then TERMUX_BUILD_TS_FILE | |
59f0d218 FF |
370 | rm -f $TERMUX_BUILD_TS_FILE && touch $TERMUX_BUILD_TS_FILE |
371 | ||
372 | # Run just after sourcing $TERMUX_PKG_BUILDER_SCRIPT | |
373 | termux_step_extract_package () { | |
374 | if [ -z "${TERMUX_PKG_SRCURL:=""}" ]; then | |
375 | mkdir -p $TERMUX_PKG_SRCDIR | |
376 | return | |
377 | fi | |
378 | cd $TERMUX_PKG_TMPDIR | |
379 | filename=`basename $TERMUX_PKG_SRCURL` | |
380 | file=$TERMUX_PKG_CACHEDIR/$filename | |
e45652b2 | 381 | test ! -f $file && termux_download $TERMUX_PKG_SRCURL $file |
59f0d218 FF |
382 | if [ "x$TERMUX_PKG_FOLDERNAME" = "x" ]; then |
383 | 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` | |
384 | folder=`echo $folder | sed 's/_/-/'` # dpkg uses _ in tar filename, but - in folder | |
385 | else | |
386 | folder=$TERMUX_PKG_FOLDERNAME | |
387 | fi | |
388 | rm -Rf $folder | |
389 | if [ ${file##*.} = zip ]; then | |
200e43d4 | 390 | unzip -q $file |
59f0d218 FF |
391 | else |
392 | $TERMUX_TAR xf $file | |
393 | fi | |
394 | mv $folder $TERMUX_PKG_SRCDIR | |
395 | } | |
396 | ||
397 | termux_step_post_extract_package () { | |
398 | return | |
399 | } | |
400 | ||
401 | # Perform a host build. Will be called in $TERMUX_PKG_HOSTBUILD_DIR. | |
402 | # After termux_step_post_extract_package() and before termux_step_patch_package() | |
403 | termux_step_host_build () { | |
404 | $TERMUX_PKG_SRCDIR/configure ${TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS} | |
405 | make | |
406 | } | |
407 | ||
408 | # This should not be overridden | |
409 | termux_step_patch_package () { | |
410 | cd $TERMUX_PKG_SRCDIR | |
8f7dda83 FF |
411 | # Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses: |
412 | for patch in $TERMUX_PKG_BUILDER_DIR/*.patch{$TERMUX_ARCH_BITS,}; do | |
dc6476e9 FF |
413 | test -f $patch && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" $patch | \ |
414 | sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ | |
a0057943 | 415 | patch --silent -p1 |
59f0d218 FF |
416 | done |
417 | ||
418 | find . -name config.sub -exec chmod u+w '{}' \; -exec cp $TERMUX_COMMON_CACHEDIR/config.sub '{}' \; | |
419 | find . -name config.guess -exec chmod u+w '{}' \; -exec cp $TERMUX_COMMON_CACHEDIR/config.guess '{}' \; | |
420 | } | |
421 | ||
422 | termux_step_pre_configure () { | |
423 | return | |
424 | } | |
425 | ||
426 | termux_step_configure () { | |
427 | if [ ! -e $TERMUX_PKG_SRCDIR/configure ]; then | |
428 | return | |
429 | fi | |
430 | ||
431 | DISABLE_STATIC="--disable-static" | |
432 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-static/}" ]; then | |
433 | # Do not --disable-static if package explicitly enables it (e.g. gdb needs enable-static to build) | |
434 | DISABLE_STATIC="" | |
435 | fi | |
436 | ||
437 | DISABLE_NLS="--disable-nls" | |
438 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-nls/}" ]; then | |
439 | # Do not --disable-nls if package explicitly enables it (for gettext itself) | |
440 | DISABLE_NLS="" | |
441 | fi | |
442 | ||
443 | ENABLE_SHARED="--enable-shared" | |
444 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--disable-shared/}" ]; then | |
445 | ENABLE_SHARED="" | |
446 | fi | |
447 | HOST_FLAG="--host=$TERMUX_HOST_PLATFORM" | |
448 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--host=/}" ]; then | |
449 | HOST_FLAG="" | |
450 | fi | |
451 | ||
452 | # Some packages provides a $PKG-config script which some configure scripts pickup instead of pkg-config: | |
453 | mkdir $TERMUX_PKG_TMPDIR/config-scripts | |
454 | for f in $TERMUX_PREFIX/bin/*config; do | |
455 | test -f $f && cp $f $TERMUX_PKG_TMPDIR/config-scripts | |
456 | done | |
59f0d218 FF |
457 | export PATH=$TERMUX_PKG_TMPDIR/config-scripts:$PATH |
458 | ||
150f95af FF |
459 | # See http://wiki.buici.com/xwiki/bin/view/Programing+C+and+C%2B%2B/Autoconf+and+RPL_MALLOC |
460 | # about this problem which may cause linker errors in test scripts not undef:ing malloc and | |
461 | # also cause problems with e.g. malloc interceptors such as libgc: | |
462 | local AVOID_AUTOCONF_WRAPPERS="ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes" | |
d2dfadf1 IN |
463 | # Similarly, disable gnulib's rpl_getcwd(). It returns the wrong value, affecting zile. See |
464 | # <https://github.com/termux/termux-packages/issues/76>. | |
d6fcd836 FF |
465 | 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" |
466 | 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 |
467 | # Remove rpl_gettimeofday reference when building at least coreutils: |
468 | AVOID_AUTOCONF_WRAPPERS+=" gl_cv_func_tzset_clobber=no gl_cv_func_gettimeofday_clobber=no gl_cv_func_gettimeofday_posix_signature=yes" | |
150f95af | 469 | |
6c269245 | 470 | env $AVOID_AUTOCONF_WRAPPERS $TERMUX_PKG_SRCDIR/configure \ |
59f0d218 FF |
471 | --disable-dependency-tracking \ |
472 | --prefix=$TERMUX_PREFIX \ | |
473 | --disable-rpath --disable-rpath-hack \ | |
474 | $HOST_FLAG \ | |
475 | $TERMUX_PKG_EXTRA_CONFIGURE_ARGS \ | |
476 | $DISABLE_NLS \ | |
477 | $ENABLE_SHARED \ | |
478 | $DISABLE_STATIC \ | |
479 | --libexecdir=$TERMUX_PREFIX/libexec | |
480 | } | |
481 | ||
482 | termux_step_post_configure () { | |
483 | return | |
484 | } | |
485 | ||
486 | termux_step_pre_make () { | |
487 | return | |
488 | } | |
489 | ||
490 | termux_step_make () { | |
491 | if ls *akefile &> /dev/null; then | |
492 | if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then | |
493 | make -j $TERMUX_MAKE_PROCESSES | |
494 | else | |
495 | make -j $TERMUX_MAKE_PROCESSES ${TERMUX_PKG_EXTRA_MAKE_ARGS} | |
496 | fi | |
497 | fi | |
498 | } | |
499 | ||
500 | termux_step_make_install () { | |
501 | if ls *akefile &> /dev/null; then | |
502 | : ${TERMUX_PKG_MAKE_INSTALL_TARGET:="install"}: | |
503 | # Some packages have problem with parallell install, and it does not buy much, so use -j 1. | |
504 | if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then | |
505 | make -j 1 ${TERMUX_PKG_MAKE_INSTALL_TARGET} | |
506 | else | |
507 | make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET} | |
508 | fi | |
509 | fi | |
510 | } | |
511 | ||
512 | termux_step_post_make_install () { | |
513 | return | |
514 | } | |
515 | ||
516 | termux_step_extract_into_massagedir () { | |
517 | TARBALL_ORIG=$TERMUX_PKG_PACKAGEDIR/${TERMUX_PKG_NAME}_orig.tar.gz | |
518 | ||
519 | # Build diff tar with what has changed during the build: | |
520 | cd $TERMUX_PREFIX | |
521 | $TERMUX_TAR -N $TERMUX_BUILD_TS_FILE -czf $TARBALL_ORIG . | |
522 | ||
523 | # Extract tar in order to massage it | |
524 | mkdir -p $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX | |
525 | cd $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX | |
526 | $TERMUX_TAR xf $TARBALL_ORIG | |
527 | } | |
528 | ||
529 | termux_step_massage () { | |
530 | cd $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX | |
531 | ||
532 | # Remove lib/charset.alias which is installed by gettext-using packages: | |
533 | rm -f lib/charset.alias | |
a0c80d57 | 534 | |
59f0d218 FF |
535 | # Remove non-english man pages: |
536 | test -d share/man && (cd share/man; for f in `ls | grep -v man`; do rm -Rf $f; done ) | |
a0c80d57 FF |
537 | |
538 | if [ -z ${TERMUX_PKG_KEEP_INFOPAGES+x} ]; then | |
539 | # Remove info pages: | |
540 | rm -Rf share/info | |
541 | fi | |
542 | ||
543 | # Remove other docs: | |
544 | rm -Rf share/doc share/locale | |
545 | ||
59f0d218 FF |
546 | # Remove old kept libraries (readline): |
547 | find . -name '*.old' -delete | |
a0c80d57 FF |
548 | |
549 | # Remove static libraries: | |
59f0d218 FF |
550 | if [ $TERMUX_PKG_KEEP_STATIC_LIBRARIES = "false" ]; then |
551 | find . -name '*.a' -delete | |
552 | find . -name '*.la' -delete | |
553 | fi | |
554 | ||
555 | # .. move over sbin to bin | |
556 | for file in sbin/*; do if test -f $file; then mv $file bin/; fi; done | |
557 | ||
558 | # file(1) may fail for certain unusual files, so disable pipefail | |
559 | set +e +o pipefail | |
560 | # Remove world permissions and add write permissions: | |
561 | find . -exec chmod u+w,o-rwx \{\} \; | |
562 | # .. strip binaries (setting them as writeable first) | |
563 | if [ "$TERMUX_DEBUG" = "" ]; then | |
8094c664 | 564 | find . -type f | xargs -r file | grep -E "(executable|shared object)" | grep ELF | cut -f 1 -d : | xargs -r $STRIP --strip-unneeded --preserve-dates -R '.gnu.version*' |
59f0d218 | 565 | fi |
59f0d218 | 566 | # Fix shebang paths: |
f37532bb FF |
567 | for file in `find -L . -type f`; do |
568 | 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 | |
59f0d218 FF |
569 | done |
570 | set -e -o pipefail | |
58235144 | 571 | # Remove DT_ entries which the android 5.1 linker warns about: |
92dcdb44 | 572 | if [ "$TERMUX_DEBUG" = "" ]; then |
8094c664 | 573 | find . -type f -print0 | xargs -r -0 $TERMUX_ELF_CLEANER |
92dcdb44 | 574 | fi |
59f0d218 FF |
575 | |
576 | test ! -z "$TERMUX_PKG_RM_AFTER_INSTALL" && rm -Rf $TERMUX_PKG_RM_AFTER_INSTALL | |
577 | ||
578 | find . -type d -empty -delete # Remove empty directories | |
579 | ||
580 | # Sub packages: | |
581 | if [ -d include -a -z "${TERMUX_PKG_NO_DEVELSPLIT}" ]; then | |
582 | # Add virtual -dev sub package if there are include files: | |
583 | _DEVEL_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-dev.subpackage.sh | |
7ad25005 | 584 | echo TERMUX_SUBPKG_INCLUDE=\"include share/man/man3 lib/pkgconfig share/aclocal $TERMUX_PKG_INCLUDE_IN_DEVPACKAGE\" > $_DEVEL_SUBPACKAGE_FILE |
59f0d218 | 585 | echo TERMUX_SUBPKG_DESCRIPTION=\"Development files for ${TERMUX_PKG_NAME}\" >> $_DEVEL_SUBPACKAGE_FILE |
28dc0ace FF |
586 | if [ -n "$TERMUX_PKG_DEVPACKAGE_DEPENDS" ]; then |
587 | echo TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME,$TERMUX_PKG_DEVPACKAGE_DEPENDS\" >> $_DEVEL_SUBPACKAGE_FILE | |
588 | else | |
589 | echo TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME\" >> $_DEVEL_SUBPACKAGE_FILE | |
590 | fi | |
ad04b25a FF |
591 | if [ x$TERMUX_PKG_CONFLICTS != x ]; then |
592 | # Assume that dev packages conflicts as well. | |
593 | echo "TERMUX_SUBPKG_CONFLICTS=${TERMUX_PKG_CONFLICTS}-dev" >> $_DEVEL_SUBPACKAGE_FILE | |
594 | fi | |
59f0d218 FF |
595 | fi |
596 | # Now build all sub packages | |
597 | rm -Rf $TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages | |
598 | for subpackage in $TERMUX_PKG_BUILDER_DIR/*.subpackage.sh $TERMUX_PKG_TMPDIR/*subpackage.sh; do | |
599 | test ! -f $subpackage && continue | |
600 | SUB_PKG_NAME=`basename $subpackage .subpackage.sh` | |
601 | # Default value is same as main package, but sub package may override: | |
602 | TERMUX_SUBPKG_PLATFORM_INDEPENDENT=$TERMUX_PKG_PLATFORM_INDEPENDENT | |
59f0d218 FF |
603 | SUB_PKG_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages/$SUB_PKG_NAME |
604 | TERMUX_SUBPKG_DEPENDS="" | |
ad04b25a | 605 | TERMUX_SUBPKG_CONFLICTS="" |
59f0d218 FF |
606 | SUB_PKG_MASSAGE_DIR=$SUB_PKG_DIR/massage/$TERMUX_PREFIX |
607 | SUB_PKG_PACKAGE_DIR=$SUB_PKG_DIR/package | |
608 | mkdir -p $SUB_PKG_MASSAGE_DIR $SUB_PKG_PACKAGE_DIR | |
609 | ||
610 | . $subpackage | |
611 | ||
612 | for includeset in $TERMUX_SUBPKG_INCLUDE; do | |
613 | _INCLUDE_DIRSET=`dirname $includeset` | |
614 | test "$_INCLUDE_DIRSET" = "." && _INCLUDE_DIRSET="" | |
4432ca97 FF |
615 | if [ -e $includeset -o -L $includeset ]; then |
616 | # Add the -L clause to handle relative symbolic links: | |
59f0d218 FF |
617 | mkdir -p $SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET |
618 | mv $includeset $SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET | |
619 | fi | |
620 | done | |
621 | ||
622 | SUB_PKG_ARCH=$TERMUX_ARCH | |
623 | test -n "$TERMUX_SUBPKG_PLATFORM_INDEPENDENT" && SUB_PKG_ARCH=all | |
624 | ||
625 | cd $SUB_PKG_DIR/massage | |
626 | SUB_PKG_INSTALLSIZE=`du -sk . | cut -f 1` | |
b96b5b14 | 627 | $TERMUX_TAR -cJf $SUB_PKG_PACKAGE_DIR/data.tar.xz . |
59f0d218 FF |
628 | |
629 | mkdir -p DEBIAN | |
630 | cd DEBIAN | |
631 | cat > control <<HERE | |
632 | Package: $SUB_PKG_NAME | |
633 | Architecture: ${SUB_PKG_ARCH} | |
634 | Installed-Size: ${SUB_PKG_INSTALLSIZE} | |
635 | Maintainer: $TERMUX_PKG_MAINTAINER | |
636 | Version: $TERMUX_PKG_FULLVERSION | |
637 | Description: $TERMUX_SUBPKG_DESCRIPTION | |
638 | Homepage: $TERMUX_PKG_HOMEPAGE | |
639 | HERE | |
640 | test ! -z "$TERMUX_SUBPKG_DEPENDS" && echo "Depends: $TERMUX_SUBPKG_DEPENDS" >> control | |
ad04b25a | 641 | test ! -z "$TERMUX_SUBPKG_CONFLICTS" && echo "Conflicts: $TERMUX_SUBPKG_CONFLICTS" >> control |
b96b5b14 | 642 | $TERMUX_TAR -cJf $SUB_PKG_PACKAGE_DIR/control.tar.xz . |
59f0d218 FF |
643 | |
644 | # Create the actual .deb file: | |
a0057943 | 645 | TERMUX_SUBPKG_DEBFILE=$TERMUX_DEBDIR/${SUB_PKG_NAME}_${TERMUX_PKG_FULLVERSION}_${SUB_PKG_ARCH}.deb |
59f0d218 FF |
646 | ar cr $TERMUX_SUBPKG_DEBFILE \ |
647 | $TERMUX_COMMON_CACHEDIR/debian-binary \ | |
b96b5b14 | 648 | $SUB_PKG_PACKAGE_DIR/control.tar.xz \ |
59f0d218 FF |
649 | $SUB_PKG_PACKAGE_DIR/data.tar.xz |
650 | if [ "$TERMUX_PROCESS_DEB" != "" ]; then | |
651 | $TERMUX_PROCESS_DEB $TERMUX_SUBPKG_DEBFILE | |
652 | fi | |
653 | ||
654 | # Go back to main package: | |
655 | cd $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX | |
656 | done | |
657 | ||
658 | # .. remove empty directories (NOTE: keep this last): | |
659 | find . -type d -empty -delete | |
660 | # Make sure user can read and write all files (problem with dpkg otherwise): | |
661 | chmod -R u+rw . | |
662 | } | |
663 | ||
664 | termux_step_post_massage () { | |
665 | return | |
666 | } | |
667 | ||
668 | termux_step_create_debscripts () { | |
669 | return | |
670 | } | |
671 | ||
3a189d89 | 672 | termux_setup_golang () { |
f6a56287 FF |
673 | export GOOS=android |
674 | export CGO_ENABLED=1 | |
675 | export GO_LDFLAGS="-extldflags=-pie" | |
676 | if [ "$TERMUX_ARCH" = "arm" ]; then | |
677 | export GOARCH=arm | |
678 | export GOARM=7 | |
679 | elif [ "$TERMUX_ARCH" = "i686" ]; then | |
680 | export GOARCH=386 | |
681 | export GO386=sse2 | |
682 | elif [ "$TERMUX_ARCH" = "aarch64" ]; then | |
683 | export GOARCH=arm64 | |
684 | elif [ "$TERMUX_ARCH" = "x86_64" ]; then | |
685 | export GOARCH=amd64 | |
686 | else | |
687 | echo "ERROR: Unsupported arch: $TERMUX_ARCH" | |
688 | exit 1 | |
689 | fi | |
690 | ||
d4e4fb87 | 691 | local TERMUX_GO_VERSION=go1.6.2 |
3a189d89 FF |
692 | local TERMUX_GO_PLATFORM=linux-amd64 |
693 | test `uname` = "Darwin" && TERMUX_GO_PLATFORM=darwin-amd64 | |
694 | ||
695 | export TERMUX_BUILDGO_FOLDER=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM} | |
696 | export GOROOT=$TERMUX_BUILDGO_FOLDER | |
697 | export PATH=$GOROOT/bin:$PATH | |
698 | ||
699 | if [ -d $TERMUX_BUILDGO_FOLDER ]; then return; fi | |
700 | ||
701 | local TERMUX_BUILDGO_TAR=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz | |
702 | rm -Rf $TERMUX_COMMON_CACHEDIR/go $TERMUX_BUILDGO_FOLDER | |
32db9f33 | 703 | termux_download https://storage.googleapis.com/golang/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz $TERMUX_BUILDGO_TAR |
3a189d89 FF |
704 | ( cd $TERMUX_COMMON_CACHEDIR; tar xf $TERMUX_BUILDGO_TAR; mv go $TERMUX_BUILDGO_FOLDER; rm $TERMUX_BUILDGO_TAR ) |
705 | } | |
706 | ||
59f0d218 FF |
707 | source $TERMUX_PKG_BUILDER_SCRIPT |
708 | ||
b0c46014 | 709 | if [ -n "${TERMUX_PKG_BLACKLISTED_ARCHES:=""}" -a "$TERMUX_PKG_BLACKLISTED_ARCHES" != "${TERMUX_PKG_BLACKLISTED_ARCHES/$TERMUX_ARCH/}" ]; then |
9a104bda FF |
710 | echo "Skipping building $TERMUX_PKG_NAME for arch $TERMUX_ARCH" |
711 | exit 0 | |
712 | fi | |
713 | ||
714 | echo "termux - building $1 for arch $TERMUX_ARCH..." | |
715 | test -t 1 && printf "\033]0;$1...\007" | |
716 | ||
59f0d218 FF |
717 | # Compute full version: |
718 | TERMUX_PKG_FULLVERSION=$TERMUX_PKG_VERSION | |
719 | if [ "$TERMUX_PKG_BUILD_REVISION" != "0" -o "$TERMUX_PKG_FULLVERSION" != "${TERMUX_PKG_FULLVERSION/-/}" ]; then | |
720 | # "0" is the default revision, so only include it if the upstream versions contains "-" itself | |
721 | TERMUX_PKG_FULLVERSION+="-$TERMUX_PKG_BUILD_REVISION" | |
722 | fi | |
723 | ||
724 | # Start by extracting the package src into $TERMUX_PKG_SRCURL: | |
725 | termux_step_extract_package | |
726 | # Optional post processing: | |
727 | termux_step_post_extract_package | |
728 | ||
729 | # Optional host build: | |
730 | if [ "x$TERMUX_PKG_HOSTBUILD" != "x" ]; then | |
731 | cd $TERMUX_PKG_SRCDIR | |
732 | for patch in $TERMUX_PKG_BUILDER_DIR/*.patch.beforehostbuild; do | |
a0057943 | 733 | test -f $patch && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" $patch | patch --silent -p1 |
59f0d218 FF |
734 | done |
735 | ||
736 | if [ -f "$TERMUX_PKG_HOSTBUILD_DIR/TERMUX_BUILT_FOR_$TERMUX_PKG_VERSION" ]; then | |
737 | echo "Using already built host build" | |
738 | else | |
739 | mkdir -p $TERMUX_PKG_HOSTBUILD_DIR | |
740 | cd $TERMUX_PKG_HOSTBUILD_DIR | |
741 | ||
742 | ORIG_AR=$AR; unset AR | |
743 | ORIG_AS=$AS; unset AS | |
744 | ORIG_CC=$CC; unset CC | |
745 | ORIG_CXX=$CXX; unset CXX | |
746 | ORIG_CPP=$CPP; unset CPP | |
747 | ORIG_CFLAGS=$CFLAGS; unset CFLAGS | |
748 | ORIG_CPPFLAGS=$CPPFLAGS; unset CPPFLAGS | |
749 | ORIG_CXXFLAGS=$CXXFLAGS; unset CXXFLAGS | |
750 | ORIG_LDFLAGS=$LDFLAGS; unset LDFLAGS | |
751 | ORIG_RANLIB=$RANLIB; unset RANLIB | |
752 | ORIG_LD=$LD; unset LD | |
753 | ORIG_PKG_CONFIG=$PKG_CONFIG; unset PKG_CONFIG | |
754 | ORIG_PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR; unset PKG_CONFIG_LIBDIR | |
755 | ORIG_STRIP=$STRIP; unset STRIP | |
756 | ||
757 | termux_step_host_build | |
758 | touch $TERMUX_PKG_HOSTBUILD_DIR/TERMUX_BUILT_FOR_$TERMUX_PKG_VERSION | |
759 | ||
760 | export AR=$ORIG_AR | |
761 | export AS=$ORIG_AS | |
762 | export CC=$ORIG_CC | |
763 | export CXX=$ORIG_CXX | |
764 | export CPP=$ORIG_CPP | |
765 | export CFLAGS=$ORIG_CFLAGS | |
766 | export CPPFLAGS=$ORIG_CPPFLAGS | |
767 | export CXXFLAGS=$ORIG_CXXFLAGS | |
768 | export LDFLAGS=$ORIG_LDFLAGS | |
769 | export RANLIB=$ORIG_RANLIB | |
770 | export LD=$ORIG_LD | |
771 | export PKG_CONFIG=$ORIG_PKG_CONFIG | |
772 | export PKG_CONFIG_LIBDIR=$ORIG_PKG_CONFIG_LIBDIR | |
773 | export STRIP=$ORIG_STRIP | |
774 | fi | |
775 | fi | |
776 | ||
777 | if [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libandroid-support/}" ]; then | |
778 | # If using the android support library, link to it and include its headers as system headers: | |
779 | export CPPFLAGS="$CPPFLAGS -isystem $TERMUX_PREFIX/include/libandroid-support" | |
780 | export LDFLAGS="$LDFLAGS -landroid-support" | |
781 | fi | |
782 | ||
783 | if [ -n "$TERMUX_PKG_BUILD_IN_SRC" ]; then | |
784 | echo "Building in src due to TERMUX_PKG_BUILD_IN_SRC being set" >> $TERMUX_PKG_BUILDDIR/BUILDING_IN_SRC.txt | |
785 | TERMUX_PKG_BUILDDIR=$TERMUX_PKG_SRCDIR | |
786 | fi | |
787 | ||
788 | cd $TERMUX_PKG_BUILDDIR | |
789 | termux_step_patch_package | |
790 | cd $TERMUX_PKG_BUILDDIR | |
791 | termux_step_pre_configure | |
792 | cd $TERMUX_PKG_BUILDDIR | |
793 | termux_step_configure | |
794 | cd $TERMUX_PKG_BUILDDIR | |
795 | termux_step_post_configure | |
796 | cd $TERMUX_PKG_BUILDDIR | |
797 | termux_step_pre_make | |
798 | cd $TERMUX_PKG_BUILDDIR | |
799 | termux_step_make | |
800 | cd $TERMUX_PKG_BUILDDIR | |
801 | termux_step_make_install | |
802 | cd $TERMUX_PKG_BUILDDIR | |
803 | termux_step_post_make_install | |
804 | cd $TERMUX_PKG_MASSAGEDIR | |
805 | termux_step_extract_into_massagedir | |
58235144 | 806 | cd $TERMUX_PKG_MASSAGEDIR |
59f0d218 | 807 | termux_step_massage |
f1cb02a4 | 808 | cd $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX |
59f0d218 FF |
809 | termux_step_post_massage |
810 | ||
811 | # Create data tarball containing files to package: | |
812 | cd $TERMUX_PKG_MASSAGEDIR | |
813 | if [ "`find . -type f`" = "" ]; then | |
814 | echo "ERROR: No files in package" | |
815 | exit 1 | |
816 | fi | |
b96b5b14 | 817 | $TERMUX_TAR -cJf $TERMUX_PKG_PACKAGEDIR/data.tar.xz . |
59f0d218 FF |
818 | |
819 | # Get install size. This will be written as the "Installed-Size" deb field so is measured in 1024-byte blocks: | |
820 | TERMUX_PKG_INSTALLSIZE=`du -sk . | cut -f 1` | |
821 | ||
822 | # Create deb package: | |
823 | # NOTE: From here on TERMUX_ARCH is set to "all" if TERMUX_PKG_PLATFORM_INDEPENDENT is set by the package | |
824 | test -n "$TERMUX_PKG_PLATFORM_INDEPENDENT" && TERMUX_ARCH=all | |
825 | ||
826 | cd $TERMUX_PKG_MASSAGEDIR | |
827 | ||
828 | mkdir -p DEBIAN | |
829 | cat > DEBIAN/control <<HERE | |
830 | Package: $TERMUX_PKG_NAME | |
831 | Architecture: ${TERMUX_ARCH} | |
832 | Installed-Size: ${TERMUX_PKG_INSTALLSIZE} | |
833 | Maintainer: $TERMUX_PKG_MAINTAINER | |
834 | Version: $TERMUX_PKG_FULLVERSION | |
835 | Description: $TERMUX_PKG_DESCRIPTION | |
836 | Homepage: $TERMUX_PKG_HOMEPAGE | |
837 | HERE | |
838 | test ! -z "$TERMUX_PKG_DEPENDS" && echo "Depends: $TERMUX_PKG_DEPENDS" >> DEBIAN/control | |
839 | test ! -z "$TERMUX_PKG_ESSENTIAL" && echo "Essential: yes" >> DEBIAN/control | |
a8c61c7d | 840 | test ! -z "$TERMUX_PKG_CONFLICTS" && echo "Conflicts: $TERMUX_PKG_CONFLICTS" >> DEBIAN/control |
768ce14e | 841 | test ! -z "$TERMUX_PKG_REPLACES" && echo "Replaces: $TERMUX_PKG_REPLACES" >> DEBIAN/control |
59f0d218 FF |
842 | |
843 | # Create DEBIAN/conffiles (see https://www.debian.org/doc/debian-policy/ap-pkg-conffiles.html): | |
844 | for f in $TERMUX_PKG_CONFFILES; do echo $TERMUX_PREFIX/$f >> DEBIAN/conffiles; done | |
845 | # Allow packages to create arbitrary control files: | |
846 | cd DEBIAN | |
847 | termux_step_create_debscripts | |
848 | ||
b96b5b14 FF |
849 | # Create control.tar.xz |
850 | $TERMUX_TAR -cJf $TERMUX_PKG_PACKAGEDIR/control.tar.xz . | |
59f0d218 | 851 | # In the .deb ar file there should be a file "debian-binary" with "2.0" as the content: |
a0057943 | 852 | TERMUX_PKG_DEBFILE=$TERMUX_DEBDIR/${TERMUX_PKG_NAME}_${TERMUX_PKG_FULLVERSION}_${TERMUX_ARCH}.deb |
59f0d218 FF |
853 | # Create the actual .deb file: |
854 | ar cr $TERMUX_PKG_DEBFILE \ | |
855 | $TERMUX_COMMON_CACHEDIR/debian-binary \ | |
b96b5b14 | 856 | $TERMUX_PKG_PACKAGEDIR/control.tar.xz \ |
59f0d218 FF |
857 | $TERMUX_PKG_PACKAGEDIR/data.tar.xz |
858 | ||
859 | if [ "$TERMUX_PROCESS_DEB" != "" ]; then | |
860 | $TERMUX_PROCESS_DEB $TERMUX_PKG_DEBFILE | |
861 | fi | |
862 | ||
863 | echo "termux - build of '$1' done" | |
864 | test -t 1 && printf "\033]0;$1 - DONE\007" | |
865 | exit 0 |