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