# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/msm8939_defconfig

pkgname=linux-huawei-kiwi
pkgver=5.9_rc7
pkgrel=2
pkgdesc="Huawei Honor 5X kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="huawei-kiwi"
url="https://git.sr.ht/~bo41/msm8939-mainline-linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bash bc bison devicepkg-dev installkernel flex openssl-dev perl"

_repository="msm8939-mainline-linux"
_commit="1ea342fe183a9ab87579c6e7c8739c5374eac28c"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::$url/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repository-$_commit"

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"/usr/share/dtb
	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="
dc87df473760d08f95669b6eba0d8f4a266993f4689cccb6c7a744bb0c90124e08cad65fccdaa22b63349e36660d7483ad1b7cd12c03b15ba8ce0836a1876851  linux-huawei-kiwi-1ea342fe183a9ab87579c6e7c8739c5374eac28c.tar.gz
95824a4e59b7fab42bbf13dedf4bffcb08a6a36d1e77300ee50bf86eb4dc659924aa6406a18cf63bda80cecedadfff0eeba32a08d193ff9355dc0ff7e4a1e786  config-huawei-kiwi.aarch64
"
