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

_flavor="postmarketos-qcom-sm8250"
pkgname=linux-$_flavor
pkgver=6.4.0_rc2
pkgrel=0
pkgdesc="Mainline kernel fork for SM8250"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/sm8250-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-nftables
"
makedepends="
	bash
	bison
	findutils
	flex
	installkernel
	openssl-dev
	perl
"

# Source
_tag="sm8250-6.4.0-rc2"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_tag.tar.gz::https://gitlab.com/sm8250-mainline/linux/-/archive/$_tag/linux-$_tag.tar.gz
	$_config
"
builddir="$srcdir/linux-$_tag"

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

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

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="
a798fe5920765ced2d8158d43c757b6b7960ead6a34dcb67db725eb74d0b0d781ca81b69491726e09e6a3393c981ab6d0bcdbd6a3fa16147dd5c053ce58a9ade  linux-postmarketos-qcom-sm8250-sm8250-6.4.0-rc2.tar.gz
45a9db3511c344582fce30f4a6708c63145579cf38f64a1b2c394ad8be411667eb3e27d66cb50845826f57144919839858a90e88dca0c1c6f47502101f2f8b6d  config-postmarketos-qcom-sm8250.aarch64
"
