# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=kbuild
pkgver=0.1.9998.3407
_ver=${pkgver/_/-}
pkgrel=1
pkgdesc="A makefile framework for writing simple makefiles for complex tasks"
url="http://svn.netlabs.org/kbuild/wiki"
arch="x86 x86_64 aarch64"
license="GPL-3.0"
makedepends="autoconf automake flex byacc texinfo"
subpackages="$pkgname-doc"
source="https://dev.alpinelinux.org/archive/kbuild/kbuild-$_ver-src.tar.xz
	underlinking.patch
	sys_siglist.patch
	0001-define-ALLPERMS-is-missing.patch
	sys-types.patch
	kobjcache.patch
	obstack.patch
	os-linux.patch
	"

builddir="$srcdir"/kbuild-$_ver
prepare() {
	update_config_guess
	update_config_sub
	default_prepare
	local i
	# Add a file with the svn revision this package was pulled from
	printf '%s\n' "KBUILD_SVN_REV := ${pkgver##*.}" > SvnInfo.kmk

	# bootstrapping breaks because of missing po/Makefile.in.in (r3149)
	sed '/^AC_CONFIG_FILES/s@ po/Makefile\.in@@' \
		-i src/kmk/configure.ac

	cd "$builddir"/src/kmk
	aclocal -I config && autoheader && autoconf && automake --add-missing
	cd "$builddir"/src/sed
	aclocal -I config && autoheader && autoconf && automake --add-missing

	# the bootstrap process will create a symlink to the system shell,
	# which happens to be (/bin/sh) a symlink to /bin/busybox
	# and busybox will get confused since there are no applet named
	# kmk_ash.
	echo '#!/bin/sh' >"$srcdir"/sh
	echo 'exec /bin/busybox sh "$@"' >> "$srcdir"/sh
	chmod +x "$srcdir"/sh
	sed -i -e "s:/bin/sh:$srcdir/sh:" "$builddir"/bootstrap.gmk
}

build() {
	kBuild/env.sh --full make -f bootstrap.gmk AUTORECONF=true
}

package() {
	kBuild/env.sh kmk NIX_INSTALL_DIR=/usr PATH_INS="$pkgdir" install
}

sha512sums="
0a1fddff595f7ccfdb65a1a660c82860f132796b42149b8b40808d0df489312dcd96402236150c8ec5ec32c1cc142ce7af1150e10fdb83bf798e4d690dd64314  kbuild-0.1.9998.3407-src.tar.xz
839c12659ae81e99c0c2f35f045ef8651c2d30ddb391ae76995ded6df19f4ca5ae728da96c16b7aab08cdf447030de645455751122a390755e0ff46c03cb23d6  underlinking.patch
a2c765d16d8b6c4c24c68d1f2754c7b7fa99b83e5456994df54a2d3ac41104fc3ad307434a0b8d94114aa667b07d9b7478e160a75267414b3daa436ea05e208a  sys_siglist.patch
e882eb6e09e01698cba66ee307ccaa14022299e322154a95acbd10248f52c639b5591561da1d1ced617523f868ad4c54caae13f46b7f9b971f9363ebb296e713  0001-define-ALLPERMS-is-missing.patch
58ae3ec4a1535fddd4af67803c081c9ca4cd66244ea2a7ddfbf59eb5b849421377116376d893d5e643a15413b902463affa51153afeb2d2217bac135122b66a5  sys-types.patch
7afcc78589ee66c60dd7a73819b4776531a4fc0f73c8a8824f4b53967f7c903095206455d2b113288ad4cf337e67c0dc82cd679b994096c5d9270f83d55689ad  kobjcache.patch
9f7a2baa250baf8da686d52d16cacae3648e70b044c812bfb3e33100675a1de010b86cf2bdd39d86b957c5ccd16790c443918d0f0a66dfd5b5d7209b667a255b  obstack.patch
042dee4ff7720708bee55982c876ce48645f856c902481317dad9abacc405aede40b9c4f7078bf0fe3a8fa85c788de029e7bbc6b1c5ad668a842265f6a9a873e  os-linux.patch
"
