# Template file for 'zlib'
pkgname=zlib
version=1.3.1
revision=4
short_desc="General-purpose compression library"
maintainer="finwo <finwo@pm.me>"
license="Zlib"
homepage="https://zlib.net"
# NOTE: canonical zlib.net flaked on fetch during pinning; GitHub mirror
# used instead. Hash matches the widely published zlib-1.3.1 sha256.
distfiles="https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz"
checksum=9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23
# glibc first: the post-install runs /sbin/ldconfig, which needs libc
# present. busybox first: control scripts run under /bin/sh, which must
# exist before the script executes (ordering, not just runtime truth -
# apk runs each package's scripts right after unpacking it).
depends="glibc busybox"

# Notes:
# - apk-tools links zlib unconditionally (gzip .apk members). --shared for
#   the .so; the static .a is removed per the shared-only policy.
# - Sysroot seed (second install + .pc prefix rewrite) so apk-tools'
#   muon/meson configure finds it via PKG_CONFIG_PATH.

do_configure() {
  cd "${WRKSRC}"
  ./configure --prefix=/usr --shared
}

do_build() {
  cd "${WRKSRC}"
  make -j"$(nproc)"
}

do_install() {
  cd "${WRKSRC}"
  make install DESTDIR="${DESTDIR}"
  make install DESTDIR="${SYSROOT}"
  rm -f "${DESTDIR}/usr/lib/libz.a" "${SYSROOT}/usr/lib/libz.a"
  # The sysroot .pc prefix is rewritten and verified centrally by mk/build.sh,
  # which runs pc-fixup.sh after this function returns.
}
