# SliTaz package receipt.

PACKAGE="python3"
VERSION="3.9.2"
CATEGORY="development"
SHORT_DESC="The Python 3 programming language."
MAINTAINER="shann@slitaz.org"
LICENSE="GPL"
SOURCE="Python"
TARBALL="$SOURCE-$VERSION.tar.xz"
WEB_SITE="http://www.python.org/"
WGET_URL="https://www.python.org/ftp/python/$VERSION/$TARBALL"

RELATED="python3-dev python3-idle" # version must match
DEPENDS="openssl bzlib expat readline sqlite zlib ncursesw gdbm libffi"
BUILD_DEPENDS="openssl-dev bzip2-dev expat-dev readline-dev sqlite-dev \
zlib-dev ncursesw-dev tcl-dev db-dev gdbm-dev libffi-dev liblzma-dev"

# Rules to configure and make the package.
compile_rules()
{
	CFLAGS+=" -fPIC"
	./configure \
		--enable-shared \
		--with-system-expat \
		--with-system-ffi \
		--without-ensurepip \
		--build=${HOST_SYSTEM} \
		--host=${HOST_SYSTEM} &&
	make &&	make DESTDIR=$DESTDIR install

	#chmod 755 $install/usr/lib/libpython${VERSION%.*}m.so
	chmod 755 $install/usr/lib/libpython${VERSION%%.*}.so
	find $install -type f -name "*.pyc" -delete
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	python_version=${VERSION:0:3}
	mkdir -p $fs/usr/include/python${python_version}m
        mkdir -p $fs/usr
        mkdir $fs/usr/bin && mkdir $fs/usr/lib
	cp -a $install/usr/bin/* $fs/usr/bin
	cp -a $install/usr/lib/* $fs/usr/lib
	# needed for mercurial to work now
	#cp -a $install/usr/include/python${python_version}m/pyconfig.h \
	#	$fs/usr/include/python${python_version}m
	rm -f $fs/usr/bin/*-config
	# Split IDLE with TK dep
	rm -f $fs/usr/bin/idle*
	rm -rf $fs/usr/lib/python3.8/idlelib
}

# Post install commands for Tazpkg.       
pre_install()  
{
        # Removed symlinks if python2 installed
        if [ -d ${1}${INSTALLED}/python ]; then                   
            rm -f /usr/bin/2to3
        fi
}

post_remove()
{
        if [ -d ${1}${INSTALLED}/python ]; then         
            ln -s /usr/bin/2to3-2.7 /usr/bin/2to3
        fi
}