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