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

# source: BLFS 8.2
# patches: https://build.opensuse.org/package/show/devel:languages:python:Factory/python
TARBALL=Python-$PKGVER.tar.xz
MD5SUM=1f6db41ad91d9eb0a6f0c769b8613c5b
SRC_URL=http://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: 
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-FEATURE-SLE disable SSL verification-by-default in http clients
	#patch -Np1 -i ../pkg/python-2.7.9-sles-disable-verification-by-default.patch  &&
	# PATCH-FIX-UPSTREAM python-ncurses-6.0-accessors.patch dimstar@opensuse.org -- Fix build with NCurses 6.0 and OPAQUE_WINDOW set to 1
	patch -Np1 -i ../pkg/python-ncurses-6.0-accessors.patch  &&
	# PATCH-FIX-UPSTREAM bmwiedemann@suse.de -- allow python packages to build reproducibly
	patch -Np1 -i ../pkg/reproducible.patch  &&
	# PATCH-FIX-UPSTREAM taken from upstream fix py3 shebang
	patch -Np1 -i ../pkg/python-fix-shebang.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 &&
	
	true
}

### package - only collect the libraries
pkg_package() {
	# kill other duplicate stuff
	rm -r ./usr/$LIBDIR/python2.7/site-packages &&
	true
}

### 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/libpython2.7.so.1.0 &&
	rm -r /usr/$LIBDIR/python2.7/test && # delete rubbish
	
	pkg_build_slackdesc &&

	# multilib (CBLFS)
	mv -v /usr/bin/python{,-32} &&
	mv -v /usr/bin/python2{,-32} &&
	mv -v /usr/bin/python2.7{,-32} &&
	ln -sfv python2.7-32 /usr/bin/python2-32 &&
	ln -sfv python2-32 /usr/bin/python-32 &&
	mv -v /usr/include/python2.7/pyconfig{,-32}.h &&
	
	# kill duplicate binaries and include
	rm -rv /usr/bin/{2to3,*config,pydoc,idle,*.py} &&	
	mv -v /usr/include/python2.7/pyconfig-32.h /tmp &&
	rm -rf /usr/include/python2.7 && mkdir -p /usr/include/python2.7 &&
	mv -v /tmp/pyconfig* /usr/include/python2.7 &&
	true
}


