# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Levente Polyak <anthraxx@archlinux.org>
# Contributor: Pierre Schmitz <pierre@archlinux.de>

pkgbase=zlib
pkgname=(zlib minizip)
epoch=1
pkgver=1.2.13
pkgrel=3
arch=('x86_64')
license=('custom')
url="https://www.zlib.net/"
depends=('glibc')
options=(
  'staticlibs'  # needed by binutils testsuite
  'debug'
)
source=("https://zlib.net/zlib-${pkgver}.tar.gz"{,.asc})
sha256sums=('b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30'
            'SKIP')
validpgpkeys=('5ED46A6721D365587791E2AA783FCD8E58BCAFBA')

prepare() {
  cd $pkgbase-$pkgver/contrib/minizip
  cp Makefile Makefile.orig
  cp ../README.contrib readme.txt
  autoreconf -fiv
}

build() {
  cd $pkgbase-$pkgver

  CFLAGS+=" -ffat-lto-objects"
  ./configure --prefix=/usr
  make

  cd contrib/minizip
  ./configure --prefix=/usr --enable-static=no
  make
}

check() {
  make test -C $pkgbase-$pkgver

  make -f Makefile.orig test -C $pkgbase-$pkgver/contrib/minizip
}

package_zlib() {
  pkgdesc='Compression library implementing the deflate compression method found in gzip and PKZIP'
  provides=('libz.so')

  make install DESTDIR="${pkgdir}" -C $pkgbase-$pkgver
  install -D -m644 $pkgbase-$pkgver/LICENSE -t "${pkgdir}/usr/share/licenses/$pkgname/"
}

package_minizip() {
  pkgdesc='Mini zip and unzip based on zlib'
  depends=('zlib')

  make install DESTDIR="${pkgdir}" -C $pkgbase-$pkgver/contrib/$pkgname
  install -D -m644 $pkgbase-$pkgver/LICENSE -t "${pkgdir}/usr/share/licenses/$pkgname/"

  # https://github.com/madler/zlib/pull/229
  rm "${pkgdir}/usr/include/minizip/crypt.h"
}
