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