# runit - Small init and service supervision
name=runit
version=2.2.0
release=1
desc="Small init and service supervision"
url="http://smarden.org/runit/"
license="BSD-3-Clause"
depend="glibc"
makedepend=""
source="http://smarden.org/runit/runit-2.2.0.tar.gz"
sha256="SKIP"

# The tarball unpacks to admin/runit-<version>, not runit-<version>, so the
# generated template's `cd runit-2.2.0` never found anything. runit also has
# no configure and no install target - package() places the binaries itself.
build() {
	cd "admin/runit-$version/src"
	# runit's build reads the compiler and flags from these files rather
	# than the environment.
	#
	# -std=gnu17 is load-bearing: runit 2.2.0 is from 2014 and declares
	# function pointers as int (*op)(), which meant "unspecified arguments"
	# in C17 and means "no arguments" in C23. GCC 15 defaults to C23, so
	# every call through one of those pointers becomes "too many arguments
	# to function" and the build dies in half a dozen files at once.
	printf '%s -O2 -pipe -Wall -std=gnu17 -Wno-incompatible-pointer-types -Wno-implicit-function-declaration\n' "${CC:-cc}" > conf-cc
	printf '%s -static\n' "${CC:-cc}" > conf-ld
	make
}

package() {
	cd "admin/runit-$version"
	install -d "$pkgdir/usr/bin"
	for f in command/*; do
		[ -f "$f" ] && [ -x "$f" ] && install -m755 "$f" "$pkgdir/usr/bin/"
	done
	install -Dm644 package/COPYING "$pkgdir/usr/share/licenses/$name/COPYING" 2>/dev/null || :
	# runit-init is what PID 1 actually is.
	[ -f "$pkgdir/usr/bin/runit-init" ] && {
		install -d "$pkgdir/sbin"
		ln -sf /usr/bin/runit-init "$pkgdir/sbin/runit-init"
	}
	:
}
