makedepends=(sqlite libffi)

description="Next generation of the python high-level scripting language"
url="http://www.python.org"

packager="Grat-OS Team"
maintainer="rems"

PKGMK_GROUPS=(devel man doc)
PKGMK_IGNORE_UNPACK="yes"

name=python
version=3.9.17
release=2

alias=(python3 Python)

source=(https://www.python.org/ftp/python/$version/Python-$version.tar.xz
        https://www.python.org/ftp/python/doc/$version/python-$version-docs-html.tar.bz2
        python.png)

prepare() {
	tar -xf Python-$version.tar.xz --no-overwrite-dir
}

build() {
  cd Python-$version

  CXX="/usr/bin/g++" \

 ./configure --prefix=/usr \
              --enable-shared \
              --with-system-expat \
              --with-system-ffi \
              --with-ensurepip=yes

  make
  make DESTDIR=$PKG install

  chmod -v 755 $PKG/usr/lib/libpython3.9.so
  chmod -v 755 $PKG/usr/lib/libpython3.so

  # Install all HTML Docs files with desktop menu integration
  install -v -dm755 $PKG/usr/share/doc/$name-$version/html

  cd $SRC
  tar --strip-components=1 \
      --no-same-owner \
      --no-same-permissions \
      -C $PKG/usr/share/doc/$name-$version/html \
      -xvf python-$version-docs-html.tar.bz2

  find $PKG/usr/share/doc/$name-$version -type d -exec chmod 0755 {} \;
  find $PKG/usr/share/doc/$name-$version -type f -exec chmod 0644 {} \;

  mkdir -p $PKG/usr/share/applications

  echo "[Desktop Entry]
Categories=Development;Documentation
Exec=xdg-open file:///usr/share/doc/$name-$version/html/index.html
Icon=$name
StartupNotify=false
Terminal=false
Type=Application
Name=Python Documentation
Name[fr]=Documentation Python" > $PKG/usr/share/applications/$name.desktop

  install -Dm644 $SRC/$name.png \
          $PKG/usr/share/icons/hicolor/16x16/apps/$name.png
}

doc() {
  cd $PKG
  bsdtar -cf \
  $PKGMK_PACKAGE_DIR/$name.doc${PKGMK_BUILDVER}any.cards.tar \
  usr/share/doc/$name-$version \
  usr/share/applications/$name.desktop \
  usr/share/icons/hicolor/16x16/apps/$name.png

  rm -r usr/share/{doc,applications/$name.desktop,icons/hicolor/16x16/apps/$name.png}
}
