# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=kbuild
pkgver=0.1.9998_pre20131130
_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"
license="GPL-3.0"
depends=""
depends_dev=""
makedepends="autoconf automake flex bison"
install=""
subpackages="$pkgname-doc"
source="http://dev.gentoo.org/~polynomial-c/kBuild-${_ver}-src.tar.xz
	lchmod.patch
	strlcpy.patch
	underlinking.patch
	sys_siglist.patch
	kbuild-0.1.9998_pre20110817-gcc-4.7.patch
	0001-define-ALLPERMS-is-missing.patch
	sys-types.patch
	uclibc.patch
	kobjcache.patch
	obstack.patch
	glob.patch"

_builddir="$srcdir"/kBuild-$_ver
prepare() {
	local i
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
	cd "$_builddir"/src/kmk
	aclocal -I config && autoheader && autoconf && automake --add-missing \
		|| return 1
	cd "$_builddir"/src/sed
	aclocal -I config && autoheader && autoconf && automake --add-missing \
		|| return 1

	# 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() {
	cd "$_builddir"
	kBuild/env.sh --full make -f bootstrap.gmk AUTORECONF=true \
		|| return 1
}

package() {
	cd "$_builddir"
	kBuild/env.sh kmk NIX_INSTALL_DIR=/usr PATH_INS="$pkgdir" install \
		|| return 1
}

md5sums="a9fad7d9c26dba44c2c1ad3d93d49372  kBuild-0.1.9998-pre20131130-src.tar.xz
b3dd26cc185c96658d9b554eef2f811c  lchmod.patch
9b101e058900afb9986689076a214d54  strlcpy.patch
ca09174d7c885fdea1e3c2dc580d80b3  underlinking.patch
52c3450a3e2645f57871b0141c465776  sys_siglist.patch
2fdb2fb96c48371b2a15785926c9144b  kbuild-0.1.9998_pre20110817-gcc-4.7.patch
4fda881d60b2c80502ad4321d18161a4  0001-define-ALLPERMS-is-missing.patch
a4ad5a3bf960394856b9fafecfe921d4  sys-types.patch
b3c2d0e6902f1285c09d81f74e573c4f  uclibc.patch
e92680df9641e25dd4a58e6a2733dbea  kobjcache.patch
4d8f14019970a974b6fde15fd4b991d9  obstack.patch
db70c6fd949946029a6c95c0f7d565db  glob.patch"
sha256sums="def0a44cc0a91b6aa8a80f73ace0cfc315f298ba3e0d3d81fe52834091b68586  kBuild-0.1.9998-pre20131130-src.tar.xz
79909f11e631757140c5095af1347c9f48c065f25cdd875c555477529ca6a693  lchmod.patch
132305af7aa1cc94f4920ffe97775efcb6f0495f165035051298984d9f5ca4c0  strlcpy.patch
1c99c0579af3d9cf4148b7b61d98b92ff86eaec441b6630754007ae3c3b5a2cc  underlinking.patch
8adb0ffa45a0b49737bbde54b54405a7708a2281d608d8f713437fce77e11d07  sys_siglist.patch
420caeee42dca3fa9a474faa3ae6e34a884d26792ab3b6567a3b9ecf678a90e7  kbuild-0.1.9998_pre20110817-gcc-4.7.patch
c308a64bddc997826ee83dc8f165ad5072368cb2c837a97308e69238a0390d7e  0001-define-ALLPERMS-is-missing.patch
21ec6669485f97e0af37f3120bea2f688ed96df9c59a89cf1043645464db7a46  sys-types.patch
1f581e0cf8fefae174c8aeb1b279e956fc7712146bf4a58451f0b318795309e9  uclibc.patch
1f9788d65c597346f64cd2513875ed65d4ac199ce879dc313ce2970f40013f77  kobjcache.patch
7093e35ca03c4b82961157225c5509c42b9996128b31b5ec32154a72c154848e  obstack.patch
93a1cd4ebfdd22179299bc9f029a1e7800ff842a5775555c4fe1a1f322f910c0  glob.patch"
sha512sums="66f418c0e052389d2b5cfc4d46bc8598ceaeded369151047e455e921bef494ec42099cdc368d24b572eacd809bb7c124d07e0fab54788af01664b72f571fb047  kBuild-0.1.9998-pre20131130-src.tar.xz
3ab991b13a122e82125392d01e27ad8c06f2b5f5e0c5bb2fa024fdcf16a65f5f460c14222d84d50b31a2ad4040c89871ee2a47f885eca329c15bb9abb3f8f5df  lchmod.patch
fbab0dc51f4e2d14b020a6b63820a26eeee884ac9cfd5b59a6afc6243ffb7679c775ed8529f6161917bf3cc5e2a651c959706cdc404a4a79c1b29cc9f3a614a5  strlcpy.patch
839c12659ae81e99c0c2f35f045ef8651c2d30ddb391ae76995ded6df19f4ca5ae728da96c16b7aab08cdf447030de645455751122a390755e0ff46c03cb23d6  underlinking.patch
2e0cb32b6e296d92c4c092f798e83eee1fe49753826426fd957f9977149b64487547f71bde64b654a3f3a0511dfa9ac1c533ad0cd469c7bdd7e0acdfa3c2e3ac  sys_siglist.patch
7a0618e9dbd18ba10f1afd9c2a47f6efb136143a86008d2562eb2ff704f289b7150bbc10f2e3c57341b485252366ff46d49bd70c24cadba45f09496333ceaa76  kbuild-0.1.9998_pre20110817-gcc-4.7.patch
4bdcae4362ff0ac6b401c65120f54e395a41b98d4bdea796a1e85405c3444853b94626c2be6d9d703ffd904fb89ea0a14d1e847a67eb56d81faf48246220e166  0001-define-ALLPERMS-is-missing.patch
58ae3ec4a1535fddd4af67803c081c9ca4cd66244ea2a7ddfbf59eb5b849421377116376d893d5e643a15413b902463affa51153afeb2d2217bac135122b66a5  sys-types.patch
41d568b05af4d9f650e736cafc4fd4285cc592726de1ee3f599b26cf2277a9436477ff512b99c2dbe1abc3d21cb9d4f24a0568aa71418e2114e294171cc008f0  uclibc.patch
7afcc78589ee66c60dd7a73819b4776531a4fc0f73c8a8824f4b53967f7c903095206455d2b113288ad4cf337e67c0dc82cd679b994096c5d9270f83d55689ad  kobjcache.patch
dae18964bb4c7f46e277b147bae53cabb03d5bbd6199ec5a8deeaf6a6d12804b281ea6debf7eda44fee3bff12d6097d7b46385617a446e2a2a7570d83d03eb8e  obstack.patch
006a65b7c4fe968ea44362804888a0214ff696a2ce9dfbb3e3c9bd5a595bd91b018919e35bc0a2f587677f7606acab57c6f7531bdf7f122fc08c8c99b04fddab  glob.patch"
