# s6-linux-init - PID 1 for an s6 system
name=s6-linux-init
version=1.1.3.0
release=1
desc="PID 1 for an s6 system"
url="https://skarnet.org/software/s6-linux-init/"
license="ISC"
depend="glibc skalibs execline s6"
makedepend=""
source="https://skarnet.org/software/s6-linux-init/s6-linux-init-1.1.3.0.tar.gz"
sha256="SKIP"

# depend= is metadata only - scraps-build does not stage a recipe's declared
# dependencies onto the build host before running build(). The skarnet chain
# needs each earlier package's headers and libraries to exist somewhere real
# at configure time, so this stages them out of the repo itself.
stage_deps() {
	STAGE="$SCRAPS_BUILDROOT/skarnet-stage"
	mkdir -p "$STAGE"
	for d in skalibs execline s6; do
		pkg=$(ls -t "${SCRAPS_REPO:-/home/apiwo/scraplinux-build/repo}"/main/x86_64/"$d"-*.scrapsz 2>/dev/null | head -1)
		[ -n "$pkg" ] || { echo "$d package not found - build it first" >&2; return 1; }
		tar -xf "$pkg" -C "$STAGE" --exclude=.PKGINFO --exclude=.FILES --exclude=.INSTALL
	done
}

build() {
	stage_deps || exit 1
	cd "s6-linux-init-$version"
	./configure --prefix=/usr --libdir=/usr/lib \
		--with-include="$STAGE/usr/include" \
		--with-lib="$STAGE/usr/lib/skalibs" \
		--with-lib="$STAGE/usr/lib/execline" \
		--with-lib="$STAGE/usr/lib/s6" \
		--with-lib="$STAGE/usr/lib" \
		--with-dynlib="$STAGE/usr/lib" \
		--with-sysdeps="$STAGE/usr/lib/skalibs/sysdeps" \
		--disable-allstatic
	# skarnet's deps.mak lists "-ls6" as a make *prerequisite*, not just a
	# linker flag. GNU make resolves those through .LIBPATTERNS against VPATH,
	# which only covers the standard library directories - so a staged
	# dependency is invisible to it and make reports "No rule to make target
	# '-ls6'". Putting the staging directory on VPATH is what makes it
	# findable.
	make -j"$JOBS" .LIBPATTERNS="$STAGE/usr/lib/lib%.a $STAGE/usr/lib/lib%.so"
}

package() {
	cd "s6-linux-init-$version"
	make DESTDIR="$pkgdir" install
}
