# Kernel config based on: defconfig, msm8953.config, and device configs
maintainer="Barnabas Czeman <trabarni@gmail.com>"
_flavor="postmarketos-qcom-msm8956"
pkgname=linux-$_flavor
pkgver=6.18.7
pkgrel=1
pkgdesc="Close to mainline linux kernel for Qualcomm Snapdragon MSM8953"
arch="aarch64"
_carch="arm64"
url="https://github.com/msm8956-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
"
makedepends="
	bison
	clang
	findutils
	flex
	lld
	llvm
	openssl-dev
	perl
	postmarketos-installkernel
	python3
	zstd
"

_tag="$pkgver-r0"

source="
	$pkgname-v$_tag.tar.gz::$url/archive/v$_tag.tar.gz
	config-$_flavor.aarch64
"
builddir="$srcdir/linux-$_tag"

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

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

package() {
	mkdir -p "$pkgdir"/boot

	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		LLVM=1 \
		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 -Dm644 "$builddir/arch/$_carch/boot/vmlinuz" \
		"$pkgdir/boot/vmlinuz"

	install -Dm644 "$builddir/include/config/kernel.release" \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"
}

sha512sums="
ecb8b641db1fe26bdb9be0a070894b0e3cc9b1cf4942cfeea7eccfa55d37ed8691df12c7cfcdbb43156e3957ea821f12c91912c3e2d9b35be20ec243c60943a1  linux-postmarketos-qcom-msm8956-v6.18.7-r0.tar.gz
855f35cdcd701aa47cbe51987e59abd4270ddf70fe292049b0ac50827f0c4f364e23ca3e930b9bab6a186f37575992ef3645956fb4a934b3ce179928dcb1bfbd  config-postmarketos-qcom-msm8956.aarch64
"
