# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=pyalpm
pkgbase="python-${_realname}"
pkgname=("python-${_realname}")
pkgver=0.10.5
pkgrel=2
pkgdesc="Libalpm bindings for Python"
arch=('i686' 'x86_64')
license=('GPL')
url="https://gitlab.archlinux.org/archlinux/pyalpm"
depends=("python" "libarchive")
makedepends=('gettext-devel'
             'heimdal-devel'
             'libarchive-devel'
             'libcurl-devel'
             'libgpgme-devel'
             'python-setuptools'
             'pacman'
             'python-pkgconfig')
provides=("python3-${_realname}")
conflicts=("python3-${_realname}")
replaces=("python3-${_realname}")
source=("git+https://gitlab.archlinux.org/archlinux/pyalpm.git#tag=${pkgver}"
        "0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch")
sha256sums=('SKIP'
            'e26201c95cf6511cc884a38a8ca17cd61154542c390bcd8f7484bdc8e560cee9')

prepare() {
  cd "${srcdir}/${_realname}"

  patch -p1 -i "${srcdir}"/0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch

  # The git repo uses symlinks in the scripts folder to
  # the actual source files in the pycman folder. Patch
  # files created by git will therefore not contain any
  # changes to the files in scripts so copy the patched
  # ones across now.
  pushd "${srcdir}"/${_realname}
    for _file in deptest query remove sync upgrade version; do
      cp -f pycman/action_${_file}.py scripts/pycman-${_file}
    done
  popd
}

build() {
  cd "${srcdir}/${_realname}"

  LIBALPM_STATIC=1 \
    /usr/bin/python setup.py build
}

package() {
  cd "${srcdir}/${_realname}"

  /usr/bin/python setup.py install --prefix=/usr --root="${pkgdir}" -O1
}
