# Template file for 'linkd'
pkgname=linkd
version=0.1.0
revision=1
short_desc="Network interface manager - ifupdown replacement with RESP plugins"
maintainer="finwo <finwo@pm.me>"
license="GPL-2.0-only"
homepage="https://git.finwo.net/app/linkd"
depends="busybox iproute2"
hostmakedepends="dep"
# First-party source, pinned by tag rather than sha256: see srcfiles in
# mk/build.sh. Until git.finwo.net serves tag archives, seed the cache by
# dropping the tarball at build/work/sources/linkd-v0.1.0.tar.gz -- the fetch
# is skipped whenever that file already exists.
srcfiles="https://git.finwo.net/app/linkd/archives/tags/v${version}.tar.gz"

do_build() {
  # linkd's Makefile assembles build/<triple>/ and runs `dep install` there,
  # which needs network access to git.finwo.net for its vendored libraries.
  # They are branch tips, so this build is not reproducible across upstream
  # changes; the tag above pins linkd's own code only.
  make -C "${WRKSRC}" -j"$(nproc)"
  [ -x "${WRKSRC}/build/linux-glibc-amd64/linkd" ] || die "linkd binary missing after build"
}

do_install() {
  vinstall "${WRKSRC}/build/linux-glibc-amd64/linkd" 755 usr/bin linkd
  # multicall: linkd dispatches on basename(argv[0])
  for link in linkctl ifup ifdown ifquery ifreload; do
    ln -sfn linkd "${DESTDIR}/usr/bin/${link}"
  done
  vinstall ${FILESDIR}/linkd-run 755 etc/sv/linkd run
  vinstall ${FILESDIR}/linkd-check 755 etc/sv/linkd check
  vinstall ${FILESDIR}/linkd-log-run 755 etc/sv/linkd/log run
  install -d "${DESTDIR}/var/log/linkd"
}
