# Contributor: Tero Hilpinen <tero.hilpinen@symbio.com>
# Contributor: Timo Teräs <timo.teras@iki.fi>
# Maintainer: Timo Teräs <timo.teras@iki.fi>

pkgname=sbsigntool
pkgver=0.8
pkgrel=1
_ccancommit=261b10869ddbb4ac650ef8886c5052b1a8dbeecd
pkgdesc="Secure Boot signing tools"
url="https://git.kernel.org/pub/scm/linux/kernel/git/jejb/sbsigntools.git/"
arch="x86_64"
license="GPL"
depends=""
makedepends="autoconf automake bash binutils-dev gnu-efi-dev help2man libressl-dev util-linux-dev"
options="!check"	# testsuite is not functional
install=""
subpackages="$pkgname-doc"
source="https://git.kernel.org/pub/scm/linux/kernel/git/jejb/sbsigntools.git/snapshot/sbsigntools-$pkgver.tar.gz
	ccan-$_ccancommit.tar.gz::http://git.ozlabs.org/?p=ccan;a=snapshot;h=$_ccancommit;sf=tgz
	0001-fix-autogen.patch
	"
builddir="$srcdir/sbsigntools-$pkgver"

prepare() {
	default_prepare
	cd "$builddir"
	rm -rf "$builddir"/lib/ccan.git "$builddir"/lib/ccan
	ln -s ../../ccan-$(echo $_ccancommit | cut -b -7) "$builddir"/lib/ccan.git

	# fix ccan for musl and to work outside git checkout
	sed -i -e 's,sys/unistd.h,unistd.h,g' "$builddir"/lib/ccan.git/ccan/opt/usage.c
	sed -i -e 's,--git-only "$module_dir","$module_srcdir",g' "$builddir"/lib/ccan.git/tools/create-ccan-tree

	# autogen.sh is missing 'list', instantiate ccan here
        lib/ccan.git/tools/create-ccan-tree \
                --build-type=automake lib/ccan \
		"talloc read_write_all build_assert array_size endian list"

	./autogen.sh
}

build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var
	make
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
}

sha512sums="b6ab1e1e8aca6be7a560156b80b643e697467f5a45bd29dc30dba12b445755a938bcc803e7199eb9bf0fa033d31d2392360116377f9ac939c1c939e5d95023e4  sbsigntools-0.8.tar.gz
730c70cf88cfbf23796053aa689e419f433285c7fec7a6f4b5cf13efead12f99752db70790ff321da374180e3178aed105ce5bd3f66daadf545ef9b5bb02f6cd  ccan-261b10869ddbb4ac650ef8886c5052b1a8dbeecd.tar.gz
9bf0a12c7735d09e1562ad901676a7ca9572265abee88580d4f830723a28423062d5b77fe02f21414884aeb046e84cf09da599754eafaad660c5938469c460a9  0001-fix-autogen.patch"
