# Template file for 'cubieboard2-uboot'
pkgname=cubieboard2-uboot
version=2015.04
revision=1
wrksrc="u-boot-${version}"
hostmakedepends="bc git sunxi-tools uboot-mkimage"
short_desc="U-Boot for cubieboard2"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
license="GPL-2"
homepage="http://www.denx.de/wiki/U-Boot/WebHome"
distfiles="ftp://ftp.denx.de/pub/u-boot/u-boot-${version}.tar.bz2"
checksum=0a1a70df586655f527befa6f12e184e96ed61b126e5a567382321b17200f5d60

only_for_archs="armv7l armv7l-musl"

do_configure() {
	git clone https://github.com/linux-sunxi/sunxi-boards
}
do_build() {
	local _boards="Cubieboard2 Cubietruck"

	unset CFLAGS CXXFLAGS LDFLAGS

	for f in ${_boards}; do
		mkdir bin_${f}
		make distclean
		if [ -n "$CROSS_BUILD" ]; then
			make CROSS_COMPILE=${XBPS_CROSS_TRIPLET}- ${f}_config
			make CROSS_COMPILE=${XBPS_CROSS_TRIPLET}- ${makejobs}
		else
			make ${f}_config
			make ${makejobs}
		fi
		mv u-boot-sunxi-with-spl.bin bin_${f}
	done

	mkimage -A arm -O linux -T script -C none -n "U-Boot boot script" -d ${FILESDIR}/boot.txt boot.scr
}
do_install() {
	vmkdir boot
	vinstall bin_Cubieboard2/u-boot-sunxi-with-spl.bin 644 boot
	fex2bin sunxi-boards/sys_config/a20/cubieboard2.fex ${DESTDIR}/boot/script.bin
	vinstall ${FILESDIR}/boot.txt 644 boot
	vinstall boot.scr 644 boot
}

cubietruck-uboot_package() {
	short_desc="${short_desc/cubieboard2/cubietruck}"
	pkg_install () {
		vmkdir boot
		vinstall bin_Cubietruck/u-boot-sunxi-with-spl.bin 644 boot
		fex2bin sunxi-boards/sys_config/a20/cubietruck.fex ${DESTDIR}/boot/script.bin
		vinstall ${FILESDIR}/boot.txt 644 boot
		vinstall boot.scr 644 boot
	}
}
