# Maintainer: PktSurf <smlinux@pktsurf.in>
app=python3
version=3.9.16
build=1sml
homepage="https://www.python.org/"
download="https://www.python.org/ftp/python/$version/Python-$version.tar.xz"
desc="object-oriented interpreted programming language"
requires="libffi expat file openssl sqlite libpng"
noautoconfsite=1

prepbuilddir() {
  mkandenterbuilddir
  rm -rf "Python-$version"

  tar xf $srcdir/Python-$version.tar.?z*
  cd "Python-$version"
  fixbuilddirpermissions

  applypatch $srcdir/musl-find_library.patch

  sed -i "s|^#.* /usr/local/bin/python|#!/bin/python3|" Lib/cgi.py
  find . -name "*.py" -exec \
  sed -i "s|#[ ]*![ ]*/usr/bin/env python$|#!/bin/env python3|" {} +
}

build() {
  LDFLAGS="-lncursesw -lterminfo" \
  ./configure \
    --prefix="/" \
    --bindir="/bin" \
    --libdir="/lib" \
    --with-system-expat \
    --with-system-ffi \
    --without-cxx-main \
    --without-ensurepip \
    --enable-shared

  make $MAKEFLAGS
  make install DESTDIR=$pkg

  cp LICENSE $pkgdocs/

  for test in sqlite3/test email/test ctypes/test test\
  unittest/test tkinter/test \
  bsddb/test json/tests lib2to3/tests\
  distutils/tests tests ; do
	rm -rf "$pkg"/lib/python3.9/"$test"
  done

  ( 
    cd $pkg/bin ; ln -s python3 python
  )

  mkfinalpkg
}

sha512sums="
b5fd0afe131c82bbce6ddf887c59eef6945910d6a9a2bc87c0927f4e4a096bf9ca4d25bcb729c40f6ebb8a65fbe8bf7b0b97a7c4a8c9e551240eb4f34b878653  Python-3.9.16.tar.xz
9abb510f769fee9c212be728f71802cdd3346b65f052dcc820686feee53a51ad106e4f34e439c5d9dd5da7a00559b07ad0fee4815ebd16fbfb170ba228fc37f5  musl-find_library.patch
"
