texlive-tlmgr: add subpackage
[termux-packages] / packages / python / build.sh
CommitLineData
0a1ce095 1TERMUX_PKG_HOMEPAGE=https://python.org/
3ea39a77 2TERMUX_PKG_DESCRIPTION="Python 3 programming language intended to enable clear programs"
a578e0de 3TERMUX_PKG_DEPENDS="libandroid-support, ncurses, readline, libffi, openssl, libutil, libbz2, libsqlite, gdbm, ncurses-ui-libs, libcrypt, liblzma"
449d39d0 4_MAJOR_VERSION=3.6
5e927b65 5TERMUX_PKG_VERSION=${_MAJOR_VERSION}.5
8dc5d78a 6TERMUX_PKG_REVISION=1
5e927b65 7TERMUX_PKG_SHA256=f434053ba1b5c8a5cc597e966ead3c5143012af827fd3f0697d21450bb8d87a6
0a1ce095 8TERMUX_PKG_SRCURL=https://www.python.org/ftp/python/${TERMUX_PKG_VERSION}/Python-${TERMUX_PKG_VERSION}.tar.xz
59f0d218
FF
9
10# The flag --with(out)-pymalloc (disable/enable specialized mallocs) is enabled by default and causes m suffix versions of python.
59f0d218
FF
11# Set ac_cv_func_wcsftime=no to avoid errors such as "character U+ca0025 is not in range [U+0000; U+10ffff]"
12# when executing e.g. "from time import time, strftime, localtime; print(strftime(str('%Y-%m-%d %H:%M'), localtime()))"
d519a96d 13TERMUX_PKG_EXTRA_CONFIGURE_ARGS="ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_func_wcsftime=no"
59f0d218
FF
14# Avoid trying to include <sys/timeb.h> which does not exist on android-21:
15TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" ac_cv_func_ftime=no"
16# Avoid trying to use AT_EACCESS which is not defined:
17TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" ac_cv_func_faccessat=no"
3cea6702
FF
18# The gethostbyname_r function does not exist on device libc:
19TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" ac_cv_func_gethostbyname_r=no"
2b0e9dc9 20TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" --build=$TERMUX_BUILD_TUPLE --with-system-ffi --without-ensurepip"
2df87e72
FF
21# Hard links does not work on Android 6:
22TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" ac_cv_func_linkat=no"
5d4f5d93
FF
23# Posix semaphores are not supported on Android:
24TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" ac_cv_posix_semaphores_enabled=no"
bbe29517
FF
25# Do not assume getaddrinfo is buggy when cross compiling:
26TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" ac_cv_buggy_getaddrinfo=no"
3efec446 27TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" --enable-loadable-sqlite-extensions"
8dc5d78a
FF
28# Fix https://github.com/termux/termux-packages/issues/2236:
29TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" ac_cv_little_endian_double=yes"
0a1ce095
FF
30TERMUX_PKG_RM_AFTER_INSTALL="
31bin/python${_MAJOR_VERSION}m bin/idle*
32lib/python${_MAJOR_VERSION}/idlelib
33lib/python${_MAJOR_VERSION}/test
34lib/python${_MAJOR_VERSION}/tkinter
35lib/python${_MAJOR_VERSION}/turtledemo
f3ad075f
FF
36lib/python${_MAJOR_VERSION}/ctypes/test
37lib/python${_MAJOR_VERSION}/distutils/tests
38lib/python${_MAJOR_VERSION}/sqlite3/test
39lib/python${_MAJOR_VERSION}/unittest/test
0a1ce095 40"
59f0d218 41
b2a8800c 42termux_step_pre_configure() {
96decc21
FF
43 # Needed when building with clang, as setup.py only probes
44 # gcc for include paths when finding headers for determining
45 # if extension modules should be built (specifically, the
46 # zlib extension module is not built without this):
47 CPPFLAGS+=" -I$TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/include"
206d821d 48 LDFLAGS+=" -L$TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib"
e85edee6 49 if [ $TERMUX_ARCH = x86_64 ]; then LDFLAGS+=64; fi
b2a8800c
FF
50}
51
59f0d218 52termux_step_post_make_install () {
0a1ce095
FF
53 (cd $TERMUX_PREFIX/bin && rm -f python && ln -s python3 python)
54 (cd $TERMUX_PREFIX/share/man/man1 && rm -f python.1 && ln -s python3.1 python.1)
4413a3b8
FF
55
56 # Save away pyconfig.h so that the python-dev subpackage does not take it.
57 # It is required by ensurepip so bundled with the main python package.
58 # Copied back in termux_step_post_massage() after the python-dev package has been built.
59 mv $TERMUX_PREFIX/include/python${_MAJOR_VERSION}m/pyconfig.h $TERMUX_PKG_TMPDIR/pyconfig.h
60}
61
62termux_step_post_massage () {
8f19a179
FF
63 # Verify that desired modules have been included:
64 for module in _ssl _bz2 zlib _curses _sqlite3 _lzma; do
65 if [ ! -f lib/python${_MAJOR_VERSION}/lib-dynload/${module}.*.so ]; then
72f69cdc 66 termux_error_exit "Python module library $module not built"
8f19a179
FF
67 fi
68 done
69
4413a3b8
FF
70 # Restore pyconfig.h saved away in termux_step_post_make_install() above:
71 mkdir -p $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/include/python${_MAJOR_VERSION}m/
8bdc9f3a 72 cp $TERMUX_PKG_TMPDIR/pyconfig.h $TERMUX_PREFIX/include/python${_MAJOR_VERSION}m/
4413a3b8 73 mv $TERMUX_PKG_TMPDIR/pyconfig.h $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/include/python${_MAJOR_VERSION}m/
ea46e793
FF
74
75 cd $TERMUX_PKG_MASSAGEDIR
76 find . -path '*/__pycache__*' -delete
4413a3b8
FF
77}
78
79termux_step_create_debscripts () {
80 ## POST INSTALL:
aa605e89 81 echo "#!$TERMUX_PREFIX/bin/sh" > postinst
82 echo 'echo "Setting up pip..."' >> postinst
a578e0de
FF
83 # Fix historical mistake which removed bin/pip but left site-packages/pip-*.dist-info,
84 # which causes ensurepip to avoid installing pip due to already existing pip install:
85 echo "if [ ! -f $TERMUX_PREFIX/bin/pip -a -d $TERMUX_PREFIX/lib/python${_MAJOR_VERSION}/site-packages/pip-*.dist-info ]; then rm -Rf $TERMUX_PREFIX/lib/python${_MAJOR_VERSION}/site-packages/pip-*.dist-info ; fi" >> postinst
86 # Setup bin/pip:
343a9157 87 echo "$TERMUX_PREFIX/bin/python -m ensurepip --upgrade --default-pip" >> postinst
4413a3b8
FF
88
89 ## PRE RM:
aa605e89 90 # Avoid running on update
91 echo "#!$TERMUX_PREFIX/bin/sh" > prerm:
92 echo 'if [ $1 != "remove" ]; then exit 0; fi' >> prerm
a578e0de
FF
93 # Uninstall everything installed through pip:
94 echo "pip freeze 2> /dev/null | xargs pip uninstall -y > /dev/null 2> /dev/null" >> prerm
95 # Cleanup __pycache__ folders:
315a0ef6 96 echo "find $TERMUX_PREFIX/lib/python${_MAJOR_VERSION} -depth -name __pycache__ -exec rm -rf {} \;" >> prerm
a578e0de
FF
97 # Remove contents of site-packages/ folder:
98 echo "rm -Rf $TERMUX_PREFIX/lib/python${_MAJOR_VERSION}/site-packages/*" >> prerm
99 # Remove bin/pip (and bin/pip3* variants) installed by ensurepip in postinst:
4413a3b8 100 echo "rm -f $TERMUX_PREFIX/bin/pip $TERMUX_PREFIX/bin/pip3*" >> prerm
4413a3b8 101
a578e0de
FF
102 echo "exit 0" >> postinst
103 echo "exit 0" >> prerm
4413a3b8 104 chmod 0755 postinst prerm
59f0d218 105}