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