# Template file for 'libcap'
pkgname=libcap
version=2.78
revision=4
short_desc="POSIX capability library and utilities"
maintainer="finwo <finwo@pm.me>"
license="BSD-3-Clause OR GPL-2.0-only"
homepage="https://sites.google.com/site/fullycapable/"
distfiles="https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.78.tar.xz"
checksum=0d621e562fd932ccf67b9660fb018e468a683d7b827541df27813228c996bb11
# 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:
# - Pin cross-checked against kernel.org sha256sums.asc.
# - No configure step upstream; plain make with prefix/lib vars. Install
#   honors FAKEROOT (not DESTDIR).
# - iproute2's `ip` uses libcap for drop_cap() (ambient-capability hygiene),
#   and `ip vrf/netns exec` keeps working with it; FRR will want it later
#   for daemon privilege drops. Only libcap + progs are built: no pam_cap
#   (no PAM in UNOS), no go bindings, no C++ wrapper, no tests.
# - setcap/getcap/capsh ship as admin tools for the file-caps story.
# - Shared-only per packages/README.md: the .a files are removed.
# - Sysroot seed (second lib install + .pc prefix rewrite) so iproute2's
#   configure finds it via PKG_CONFIG_PATH.

do_build() {
  cd "${WRKSRC}"
  make -j"$(nproc)" -C libcap prefix=/usr lib=lib
  make -j"$(nproc)" -C progs prefix=/usr lib=lib
  [ -x libcap/libcap.so ] || die "libcap: shared lib missing after build"
}

do_install() {
  cd "${WRKSRC}"
  make -C libcap install prefix=/usr lib=lib FAKEROOT="${DESTDIR}"
  make -C libcap install prefix=/usr lib=lib FAKEROOT="${SYSROOT}"
  make -C progs install prefix=/usr lib=lib FAKEROOT="${DESTDIR}"
  rm -f "${DESTDIR}"/usr/lib/libcap.a "${DESTDIR}"/usr/lib/libpsx.a
  rm -f "${SYSROOT}"/usr/lib/libcap.a "${SYSROOT}"/usr/lib/libpsx.a
  for pc in libcap.pc libpsx.pc; do
    [ -f "${SYSROOT}/usr/lib/pkgconfig/${pc}" ] || die "libcap: no sysroot ${pc}"
  done
}
