# Template file for 'bananapi-uboot'
pkgname=bananapi-uboot
version=15.04
revision=2
hostmakedepends="sunxi-tools uboot-mkimage"
short_desc="Banana Pi uboot module"
maintainer="necrophcodr <necrophcodr@necrophcodr.me>"
license="GPL-2.0-only"
homepage="https://github.com/hardkernel/u-boot"
distfiles="https://github.com/Bananian/u-boot-bananapi/archive/bananian-v${version}.tar.gz"
checksum=8be162b0b8e85d3fbc2e14af3b71c4a204f4a9c63f6f13275f86629624c1d6a6

conf_files="/boot/uEnv.txt"
archs="armv7l*"

do_configure() {
	# Create a dummy header file for gcc10 since include/linux/compiler-gcc.h
	# generates an include for it but there is no such file.
	mkdir -p include/linux
	touch include/linux/compiler-gcc10.h
	# Also current gcc9 requires this. Need to find the reason and fix that.
	touch include/linux/compiler-gcc9.h

	make mrproper
	make Bananapi_config
}

do_build() {
	unset CFLAGS CXXFLAGS LDFLAGS

	if [ "$CROSS_BUILD" ]; then
		make CFLAGS="-fcommon" ARCH=arm CROSS_COMPILE=${XBPS_CROSS_TRIPLET}-
	else
		make CFLAGS="-fcommon" ARCH=arm
	fi

}

do_install() {
	# Certain files in 'files' directory *NEED* to be installed.
	# uEnv.txt: The boot configuration file, in pure text for readability.
	# script.fex: Pure text board configuration, compiled to script.bin.
	vmkdir boot
	cp ${FILESDIR}/uEnv.txt ${DESTDIR}/boot/
	fexc ${FILESDIR}/script.fex ${DESTDIR}/boot/script.bin
	vinstall u-boot-sunxi-with-spl.bin 644 boot
}
