APP=python3
VERSION=3.7.10
BUILD=1sml
HOMEPAGE='https://www.python.org/'
DOWNLOAD='https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tar.xz'
DESC="object-oriented interpreted programming language"
REQUIRES="libffi expat file openssl sqlite"
SM_NOAUTOCONFSITE=1

build() {
  mkandenterbuilddir
  rm -rf "Python-$VERSION"

  tar xf $SRCDIR/Python-$VERSION.tar.?z*
  cd "Python-$VERSION"
  fixbuilddirpermissions

  patch -p1 < $SRCDIR/fix-xattrs-glibc.patch
  patch -p1 < $SRCDIR/musl-find_library.patch
  patch -p1 < $SRCDIR/python3-includedirs.patch
  patch -p1 < $SRCDIR/python3-pathsearch.patch
  patch -p1 < $SRCDIR/python3-sysconfig-prefix.patch

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

  ac_cv_lib_readline_rl_callback_handler_install=no \
  ac_cv_lib_readline_rl_pre_input_hook=no \
  ac_cv_lib_readline_rl_completion_display_matches_hook=no \
  ac_cv_have_long_long_format=yes \
  ac_cv_func_timegm=yes \
  ac_cv_file__dev_ptc=no \
  ac_cv_file__dev_ptmx=yes \
  CFLAGS="$CFLAGS -D_BSD_SOURCE -DSMLINUX_STAGING_DIR='\"$PKG/\"'" \
  LDFLAGS="-lncursesw -lterminfo" \
  ./configure \
    --prefix= \
    --with-system-expat \
    --with-system-ffi \
    --without-cxx-main \
    --without-ensurepip

  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.7/"$test"
  done

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

  mkfinalpkg
}

SHA512SUMS="
5cb61739acbd29f526d25073443398b2ca0eef30d01d134e8236c8bbc7ab0586c44ec00689f5a75e6aedc0170acf4551721ada5e967e4b99a146cfcaad949128  Python-3.7.10.tar.xz
37b6ee5d0d5de43799316aa111423ba5a666c17dc7f81b04c330f59c1d1565540eac4c585abe2199bbed52ebe7426001edb1c53bd0a17486a2a8e052d0f494ad  fix-xattrs-glibc.patch
ab8eaa2858d5109049b1f9f553198d40e0ef8d78211ad6455f7b491af525bffb16738fed60fc84e960c4889568d25753b9e4a1494834fea48291b33f07000ec2  musl-find_library.patch
3542288821723c00651248935537ee2141e9510473c00b096713581bcc75d2e57ad73d69f4e0eaad9e9d231832f1764eb8f3cd52fac80a388e2b9caae25bfe92  python3-includedirs.patch
a72ac0cb27787f5dd52ef3cdec10f12be08009b0fbd6c21cfc3cec98083a8556513bf2548220376384268449f022f24fa488ff57e4d1f9ca4622ae94aca79281  python3-pathsearch.patch
f87338142ef6ce222c165c1aca618c71e6d2d4467007ff20a26cef95580f7bd01c7bac2d45741450b9e93191e67d798cf7ba71fb24c265f1f24e6d92f2f34dce  python3-sysconfig-prefix.patch
"
