pkgbase=static-compat-zlib
_pkgname=zlib
pkgname=(static-compat-zlib static-compat-minizip)
epoch=1
pkgver=1.3.1
pkgrel=1
arch=(x86_64)
license=(Zlib)
url="https://www.zlib.net/"
makedepends=('static-compat-configure')
options=(staticlibs)
source=(https://github.com/madler/zlib/releases/download/v$pkgver/$_pkgname-$pkgver.tar.xz{,.asc})
sha512sums=('1e8e70b362d64a233591906a1f50b59001db04ca14aaffad522198b04680be501736e7d536b4191e2f99767e7001ca486cd802362cca2be05d5d409b83ea732d'
            'SKIP')
b2sums=('42d109223801a493de6d52e7343403d7fc3234a6ca816425fe41ac9c18019b01b93841acd28a235e99f2256a6a17f93624e96b2ddb58d588c8190a6bedb82910'
        'SKIP')
validpgpkeys=('5ED46A6721D365587791E2AA783FCD8E58BCAFBA')  # Mark Adler <madler@alumni.caltech.edu>

prepare() {
	cd "${srcdir}/zlib-$pkgver"
	grep -A 24 '^  Copyright' zlib.h > LICENSE
}

build() {
	source static-compat-environment

	cd "${srcdir}/zlib-$pkgver"

	static-compat-configure
	make

	cd contrib/minizip
	cp Makefile Makefile.orig
	cp ../README.contrib readme.txt
	autoreconf --install
	static-compat-configure
	make
}

check() {
	source static-compat-environment

	cd "${srcdir}/zlib-$pkgver"
	make test

	cd contrib/minizip
	make -f Makefile.orig test
}

package_static-compat-zlib() {
	pkgdesc='Compression library implementing the deflate compression method found in gzip and PKZIP'
	depends=('gcc-libs-static-compat')

	source static-compat-environment

	cd "${srcdir}/zlib-$pkgver"
	make install DESTDIR="${pkgdir}"
	rm -r "${pkgdir}/$static_compat_prefix/share/man"
	rm "${pkgdir}/$static_compat_prefix/lib"/*.so*
	install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/static-compat-zlib/LICENSE"
}

package_static-compat-minizip() {
	pkgdesc='Mini zip and unzip based on zlib'
	depends=('static-compat-zlib')

	source static-compat-environment

	cd "${srcdir}/zlib-$pkgver/contrib/minizip"
	make install DESTDIR="${pkgdir}"
	rm "${pkgdir}/$static_compat_prefix/lib"/*.so*
	install -D -m644 "${srcdir}/zlib-$pkgver/LICENSE" "${pkgdir}/usr/share/licenses/static-compat-minizip/LICENSE"

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