#!/bin/sh -ue
NAME=bmake
VERSION=master
RELEASE=1
SOURCE="https://www.crufty.net/ftp/pub/sjg/bmake.tar.gz"

build() {
	msg "applying patches..."
	for patch_file in "$PORTDIR/patches"/*.patch; do
		[ -e "$patch_file" ] || continue
		patch -p1 < "$patch_file" || die "patch failed"
	done

	_boot_cc="${CC:-cc}"
	_boot_cflags="${CFLAGS:-} -static"
	_boot_ldflags="${LDFLAGS:-} -static"

	msg "bootstrapping bmake (tests skipped)..."
	env BMAKE_SKIP_TESTS=1 \
		CC="$_boot_cc" CFLAGS="$_boot_cflags" LDFLAGS="$_boot_ldflags" \
		sh ./boot-strap --prefix="$PREFIX" op=build || die "boot-strap build failed"

	msg "installing bmake..."
	env BMAKE_SKIP_TESTS=1 \
		CC="$_boot_cc" CFLAGS="$_boot_cflags" LDFLAGS="$_boot_ldflags" \
		sh ./boot-strap --prefix="$PREFIX" --install-destdir="$PKG" --install || die "boot-strap install failed"

	if [ -f "$PKG/$PREFIX/bin/bmake" ]; then
		mkdir -p "$PKG/$PREFIX/bin"
		ln -sf bmake "$PKG/$PREFIX/bin/make"
	fi
}
. ${0%/*}/../../libsh/libdmake.sh
