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

_flavor="postmarketos-qcom-sm8350"
pkgname=linux-$_flavor
pkgver=6.7
pkgrel=0
pkgdesc="Mainline kernel fork for SM8350"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/sm8350-mainline/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="ffb1b0db511df03829fa0c9682f2412c0db7f717"
_config="config-$_flavor.$arch"

# Source
source="
	$pkgname-$_commit.tar.gz::https://gitlab.com/sm8350-mainline/linux/-/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/linux-$_commit"
#_outdir=".output"

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
	#cp -r "$builddir"/arch/arm64/boot/dts/qcom \
	#	"$pkgdir"/boot/qcom
	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
69e66fcf50d336709aa8957a7a9f493dc3ba24e8ed806ba1aca7f324ccc4dc89ad83f574b2b052c2a1ed329f4a5f6b377449629e92ce5440495b22e2e4d41ff2  linux-postmarketos-qcom-sm8350-ffb1b0db511df03829fa0c9682f2412c0db7f717.tar.gz
11d36df575f82c8fe1f2836414bbada2da57a4374baa7ba62d71225662ad7b254352e3cf5b931dcad903e42705b0e0d2789550f39770ed287164daa2fabf26a9  config-postmarketos-qcom-sm8350.aarch64
"
