# execline - Non-interactive scripting language for s6
name=execline
version=2.9.7.0
release=1
desc="Non-interactive scripting language for s6"
url="https://skarnet.org/software/execline/"
license="ISC"
depend="glibc skalibs"
makedepend=""
source="https://skarnet.org/software/execline/execline-2.9.7.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(). Every package in
# the skarnet chain needs skalibs' headers, libraries and sysdeps directory
# to exist somewhere real at configure time, so each one stages it out of
# the repo itself.
stage_skalibs() {
	STAGE="$SCRAPS_BUILDROOT/skarnet-stage"
	[ -f "$STAGE/usr/lib/skalibs/sysdeps/target" ] && return 0
	pkg=$(ls -t "${SCRAPS_REPO:-/home/apiwo/scraplinux-build/repo}"/main/x86_64/skalibs-*.spz 2>/dev/null | head -1)
	[ -n "$pkg" ] || { echo "skalibs package not found - build skalibs first" >&2; return 1; }
	mkdir -p "$STAGE"
	tar -xf "$pkg" -C "$STAGE" --exclude=.PKGINFO --exclude=.FILES --exclude=.INSTALL
}

build() {
	# scraps-build exports LD_LIBRARY_PATH pointing at the sysroot before
	# build() runs, for recipes that compile-and-run a helper against the
	# target's own libs - this one doesn't, and stage_skalibs()'s plain
	# mkdir/tar crash instead, loading the sysroot's own libc.so.6
	# ("undefined symbol: __pointer_chk_guard, version GLIBC_PRIVATE") -
	# same fix as openrc/glibc-32's recipes already carry.
	unset LD_LIBRARY_PATH
	stage_skalibs || exit 1
	cd "execline-$version"
	./configure --prefix=/usr --libdir=/usr/lib \
		--with-include="$STAGE/usr/include" \
		--with-lib="$STAGE/usr/lib/skalibs" \
		--with-lib="$STAGE/usr/lib" \
		--with-dynlib="$STAGE/usr/lib" \
		--with-sysdeps="$STAGE/usr/lib/skalibs/sysdeps" \
		--enable-allstatic
	# --disable-allstatic linked execlineb against libexecline.so/
	# libskarnet.so, .so files package() never actually installs (only
	# the .a archives) - every execline binary shipped unrunnable, missing
	# its own interpreter's own shared libraries. --enable-allstatic
	# matches what skarnet actually ships: fully self-contained binaries,
	# no runtime dependency on a same-package .so that was never there.
	make -j"$JOBS"
}

package() {
	cd "execline-$version"
	make DESTDIR="$pkgdir" install
}
