# Contributor: Ronald van Haren <ronald.archlinux.org>
# Contributor: Judd <jvinet@zeroflux.org>

_pkgname=bzip2
pkgname=static-compat-$_pkgname
pkgver=1.0.8
pkgrel=1
pkgdesc="A high-quality data compression program"
arch=('x86_64')
license=('BSD')
url="https://sourceware.org/bzip2/"
depends=('glibc-static-compat')
makedepends=('static-compat-environment')
options=(staticlibs)
source=(https://sourceware.org/pub/bzip2/$_pkgname-$pkgver.tar.gz{,.sig}
        bzip2.pc)
sha256sums=('ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269'
            'SKIP'
            'ad3c350428b73a1197e54d414a60fecfff23ecdd5059afd8ce2ca084d263064b')
validpgpkeys=('EC3CFE88F6CA0788774F5C1D1AA44BE649DE760A') # Mark Wielaard <mark@klomp.org>

prepare() {
  cd $_pkgname-$pkgver
  cp ../bzip2.pc bzip2.pc
  sed "s|@VERSION@|$pkgver|" -i bzip2.pc
}

build() {
  source static-compat-environment
  cd $_pkgname-$pkgver

  make libbz2.a CC="$CC $CFLAGS $CPPFLAGS $LDFLAGS"
}

check() {
  source static-compat-environment
  cd $_pkgname-$pkgver
  make test
}

package() {
  source static-compat-environment
  cd $_pkgname-$pkgver

  install -dm755 "$pkgdir/$static_compat_prefix"/{lib,include}
  cp -a libbz2.a "$pkgdir/$static_compat_prefix"/lib
  install -m644 bzlib.h "$pkgdir/$static_compat_prefix"/include/
  install -Dm644 bzip2.pc -t "$pkgdir/$static_compat_prefix"/lib/pkgconfig
  install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/${pkgname}/LICENSE
}
