# Maintainer: Henrik Grimler <henrik@grimler.se>
# Co-Maintainer: Jenneron <jenneron@protonmail.com>
# Kernel config based on: arch/arm/configs/exynos_defconfig
# and Hardkernel's odroidxu4_defconfig

pkgname=linux-postmarketos-exynos5
pkgver=6.1.7
pkgrel=0
pkgdesc="Mainline kernel fork for Samsung Exynos5 devices"
arch="armv7"
_carch="arm"
_flavor="${pkgname#linux-}"
url="https://gitlab.com/exynos5-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
"
makedepends="
	bash
	bison
	findutils
	flex
	postmarketos-installkernel
	openssl-dev
	perl
	gmp-dev
	mpc1-dev
	mpfr-dev
	xz
"

# Source
_config="config-$_flavor.$arch"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac
_tag="v${pkgver//_/-}-exynos5"
source="
	$pkgname-$_tag.tar.bz2::$url/-/archive/$_tag/linux-$_tag.tar.bz2
	$_config
"
builddir="$srcdir/linux-$_tag"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
5e61c7bd9cfc0dc6ccd3479fdcfa07ba319bbf172d498eaf27c5787a164c4153321d7f38ace68e4926633de1897186669e72c338366b0fec5f22f9ff16a0716d  linux-postmarketos-exynos5-v6.1.7-exynos5.tar.bz2
2acc30804c9de87f626bb954eafabab9e718b8b102412261feb0de107a7bbbf521d20734527d5a1dac4f2bc036f850fac001a077b470a33792f6e669e77812e2  config-postmarketos-exynos5.armv7
"
