# Template file for 'bmake'
pkgname=bmake
version=20250225
revision=1
short_desc="Portable version of the NetBSD make build tool"
maintainer="Leah Neukirchen <leah@vuxu.org>"
license="BSD-3-Clause"
homepage="https://www.crufty.net/help/sjg/bmake.html"
distfiles="https://www.crufty.net/ftp/pub/sjg/bmake-${version}.tar.gz"
checksum=cc19b15438b454e334a23a8c91e3b87fd4b8be08c6fd9500d48e55cc683bba10
python_version=3
CFLAGS="-D_LARGE_FILE_SOURCE=1 -D_FILE_OFFSET_BITS=64"

do_configure() {
	vsed -i 's/op_test() {/& return 0;/' boot-strap
	if [ "$CROSS_BUILD" ]; then
		mkdir -p bmake-host
		cd bmake-host
		# Build a native bmake for installation
		unset CC LD AR CFLAGS LDFLAGS
		../boot-strap op=build
		cp linux*-*/bmake .
	fi
}

do_build() {
	mkdir -p bmake-build
	cd bmake-build
	if [ "$CROSS_BUILD" ]; then
		_args="--host=${XBPS_CROSS_TRIPLET}"
	fi
	../boot-strap ${_args} --prefix=/usr op=build
}

do_install() {
	cd bmake-build
	if [ "$CROSS_BUILD" ]; then
		vsed -i "s,^BMAKE=$,BMAKE=${wrksrc}/bmake-host/bmake," ../boot-strap
	fi
	../boot-strap --prefix=/usr --install-destdir=${DESTDIR} op=install
	rm -rf ${DESTDIR}/usr/share/man/cat1
	vman ../bmake.1

	sed -n '/#/q;p' ../make.c >LICENSE
	vlicense LICENSE
}
