### this file is sourced not run
PKGVER=2.7.18
PKGBUILD=1
PKGARCH=i686

PYTHON_VER=${PKGVER%.*}

# source: BLFS 11.3
# patches: https://build.opensuse.org/package/show/devel:languages:python:Factory/python
TARBALL=Python-$PKGVER.tar.xz
MD5SUM=fd6cc8ec0a78c44036f825e739f36e5a
SRC_URL=https://www.python.org/ftp/python/$PKGVER/$TARBALL
BUNDLE=

SLACKREQ='libffi32 expat32 openssl32 sqlite3_32' # util-linux (need setarch/linux32)
SLACKDESC="python32: python32 $PKGVER (Python programming language)  
python32:  
python32: The Python 2 package contains the Python development environment. It 
python32: is useful for object-oriented programming, writing scripts, 
python32: prototyping large programs or developing entire applications. This 
python32: version is for backward compatibility with other dependent packages.  
python32: 
python32: This contains 32-bit python and libraries.
python32: 
python32: https://www.python.org/
python32:
"

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/Python* &&
	
	# OpenSUSE patches
	patch -Np1 -i ../pkg/python-2.7-dirs.patch  &&
	#patch -Np1 -i ../pkg/python-distutils-rpm-8.patch  &&
	patch -Np1 -i ../pkg/python-2.7.5-multilib.patch  &&
	patch -Np1 -i ../pkg/python-2.5.1-sqlite.patch  &&
	patch -Np1 -i ../pkg/python-2.7.4-canonicalize2.patch  &&
	patch -Np1 -i ../pkg/python-2.6-gettext-plurals.patch  &&
	patch -Np1 -i ../pkg/python-2.6b3-curses-panel.patch  &&
	#patch -Np1 -i ../pkg/sparc_longdouble.patch  &&
	patch -Np1 -i ../pkg/python-2.7.2-fix_date_time_compiler.patch  &&
	patch -Np1 -i ../pkg/remove-static-libpython.diff  &&
	# PATCH-FEATURE-OPENSUSE python-bundle-lang.patch bnc#617751 dimstar@opensuse.org -- gettext: when looking in default_localedir also check in locale-bundle.
	#patch -Np1 -i ../pkg/python-bundle-lang.patch  &&
	# PATCH-FIX-UPSTREAM Fix argument passing in libffi for aarch64
	#patch -Np1 -i ../pkg/python-2.7-libffi-aarch64.patch  &&
	patch -Np1 -i ../pkg/python-bsddb6.diff  &&
	# PATCH-FIX-UPSTREAM accept directory-based CA paths as well
	patch -Np1 -i ../pkg/python-2.7.9-ssl_ca_path.patch  &&
	# PATCH-FIX-UPSTREAM bmwiedemann@suse.de -- allow python packages to build reproducibly
	patch -Np1 -i ../pkg/reproducible.patch  &&
	# bypass boo#1078485 random failing tests
	patch -Np1 -i ../pkg/python-skip_random_failing_tests.patch  &&
	# PATCH-FIX-UPSTREAM sorted tar https://github.com/python/cpython/pull/2263
	patch -Np1 -i ../pkg/python-sorted_tar.patch &&
	patch -Np1 -i ../pkg/gcc8-alignment-fix.patch &&
	# drop Autoconf version requirement
	sed -i 's/^version_required/dnl version_required/' configure.ac &&

	# BLFS 11.3 security patches
	patch -Np1 -i ../pkg/Python-2.7.18-security_fixes-1.patch &&

	# BLFS 11.3 disable this one, python3 supplies superior script
	sed -i '/2to3/d' ./setup.py
	true
}

### default pkg_package
### build
pkg_build() {
	cd /tmp/Python*
	autoreconf -fi &&
	touch Parser/asdl* Python/Python-ast.c Include/Python-ast.h &&
	
	CONFFLAGS="$CONFFLAGS --enable-shared \
            --with-system-expat \
            --with-system-ffi   \
            --with-ensurepip=yes \
            --enable-ipv6        \
            --enable-unicode=ucs4"
	pkg_build_autoconf && 
	chmod -v 755 /usr/$LIBDIR/libpython${PYTHON_VER}.so.1.0 &&
	rm -r /usr/$LIBDIR/python${PYTHON_VER}/test && # delete rubbish
	
	pkg_build_slackdesc &&

	# multilib (CBLFS)
	# header
	mv -v /usr/include/python${PYTHON_VER}/pyconfig.h /tmp/pyconfig-32.h &&		
	rm -rf /usr/include/python${PYTHON_VER} && mkdir -p /usr/include/python${PYTHON_VER} &&
	mv -v /tmp/pyconfig-32.h /usr/include/python${PYTHON_VER} &&

	# symlinks
	rm -f /usr/bin/python{,2}  &&
	mv -v /usr/bin/python${PYTHON_VER}{,-32} &&
	ln -sfv python${PYTHON_VER}-32 /usr/bin/python2-32 &&
	ln -sfv python2-32 /usr/bin/python-32 &&

	# kill duplicate binaries and include
	rm -rv /usr/bin/{*config,pydoc,idle,*.py} &&
	rm -r  /usr/$LIBDIR/python${PYTHON_VER}/site-packages /usr/share/man &&

	true
}


