# Contributor: Milan P. Stanić <mps@arvanta.net>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=crust
pkgver=0.6
pkgrel=1
pkgdesc="libre SCP firmware for Allwinner sunxi SoCs"
url="https://github.com/crust-firmware/crust"
arch="aarch64" # only needed for sunxi ARM64 SOCs
license="BSD-3-clause or GPL-2.0-only"
options="!check" # no tests
makedepends="gcc-or1k-elf binutils-or1k-elf dtc bison flex"
source="https://github.com/crust-firmware/crust/archive/v$pkgver/crust-v$pkgver.tar.gz
	"
_platforms="teres_i pinebook pinephone pinetab pine_h64 pine64_plus"
for platform in $_platforms
do
	subpackages="$subpackages $pkgname-$platform:_subpackage"
done

build() {
	for platform in $_platforms
	do
		msg "Building SCP firmware for: $platform"
		mkdir -p "$builddir"/build/$platform
		make CROSS_COMPILE=or1k-elf- "$platform"_defconfig
		make CROSS_COMPILE=or1k-elf- OBJ="$builddir"/build/$platform "$platform"_defconfig scp
		make clean
	done
}

package() {
	install -Dm644 "$builddir"/LICENSE.md "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.md
}

_subpackage() {
	pkgdesc="SCP Firmware for: ${subpkgname#crust-}"
	install -Dm644 "$builddir"/build/"${subpkgname#crust-}"/scp/scp.bin "$subpkgdir"/usr/share/crust/"${subpkgname#crust-}"/scp.bin
}

sha512sums="
4788e44e2b9bf37ddc073df6511cff20ecb682f0650bc42fedee01d1ea324d45722b7d16231566ab58d6788d5cc8a3d28beb9130a845d1871995ca22b5ef7df8  crust-v0.6.tar.gz
"
