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

_flavor="postmarketos-qcom-sm8350"
pkgname=linux-$_flavor
pkgver=5.16.0_rc1
pkgrel=1
pkgdesc="Mainline kernel fork for SM8350"
arch="aarch64"
_carch="arm64"
url="https://github.com/ElRoberto538/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-nftables
"
makedepends="
	bison
	devicepkg-dev
	findutils
	flex
	installkernel
	openssl-dev
	perl
"

_commit="a0b805589392f9766c1a75bdf1e4eead6611a5ff"
_config="config-$_flavor.$arch"

# Source
source="
	$pkgname-$_commit.tar.gz::https://github.com/ElRoberto538/linux/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/linux-$_commit"
_outdir="out"

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

	install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
		"$pkgdir/boot/vmlinuz"

	make 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="
12fd1f38033b646fcc59ae785c710aad289cdecb2295bec7f73aac46af4dc88eaee95d72f922c5313cba65c80f01c5d0a154c037e7859d893fa345ff56c0fe18  linux-postmarketos-qcom-sm8350-a0b805589392f9766c1a75bdf1e4eead6611a5ff.tar.gz
73b0fd441631ff6180a21c2082b707211116a9c032b85659d2d1261bc1f284472527f9f34adc87afabc676f5e544d3c3b4c2bb762351411dd0b3485d138c86b1  config-postmarketos-qcom-sm8350.aarch64
"
