# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Contributor: Rémy Oudompheng <remy@archlinux.org>

pkgname=python-pyelftools
pkgver=0.33
pkgrel=1
pkgdesc='Python library for analyzing ELF files and DWARF debugging information'
arch=('any')
url='https://github.com/eliben/pyelftools'
license=('Unlicense')
depends=(
  'glibc'
  'python'
)
makedepends=(
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
options=('!strip')
source=("$url/archive/v$pkgver/${pkgname#python-}-$pkgver.tar.gz")
sha512sums=('9bd46b2f302599d3c86bd0f221bc3f527f8e5964dc35679e6f1af0106654d073bdaf099fbfa4189288166a06114cff05305a031fbb9ac71c94e81d7b1231c2e3')
b2sums=('221966cfa02a120e6bde768042755cc2fe75f7dbf090ee24588157e8eeed1241b868762bd7119758f4e113cd7160151f1e57edeb477ee8c8109218f8cdd3de74')

build() {
  cd ${pkgname#python-}-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd ${pkgname#python-}-$pkgver
  python test/run_all_unittests.py
  python test/run_examples_test.py
  if [ "$CARCH" == "x86_64" ]; then
    python test/run_readelf_tests.py
  else
    echo "Skipping readelf tests (require x86_64)"
  fi
}

package() {
  cd ${pkgname#python-}-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
  install -vDm 644 -t "$pkgdir/usr/share/doc/$pkgname" README.md CHANGES
  cp -vr examples "$pkgdir/usr/share/doc/$pkgname"
}
