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

_flavor="postmarketos-qcom-sm8250"
pkgname=linux-$_flavor
pkgver=6.3.0_rc1
pkgrel=0
pkgdesc="Mainline kernel fork for SM8250"
arch="aarch64"
_carch="arm64"
url="https://github.com/lujianhua/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
_commit="ddc806a03ff96274f95436371eefa1873f283080"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::$url/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/linux-$_commit"

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="
61cd62a648b73d5e166824d31f7a3a292bc8773631fca80aeca2c6ac4285a09d0aac11d1b5b84af4e8c97564e98662c1a0f2847160a9c10df18ab40c759873a9  linux-postmarketos-qcom-sm8250-ddc806a03ff96274f95436371eefa1873f283080.tar.gz
ce768ad8e3302d4b8b99f8233c817cc4680ae13aa5ef558ed1d81f6efb05baf1208baab81c454b02e45e4663817316a6efe2bc22c692f4f006b30edc7d6b1c76  config-postmarketos-qcom-sm8250.aarch64
"
