# Co-Maintainer: Luca Weiss <luca@lucaweiss.eu>
maintainer="Stefan Hansson <newbyte@postmarketos.org>"
_flavor="postmarketos-qcom-msm8226"
pkgname=linux-$_flavor
pkgver=6.16.12
pkgrel=2
pkgdesc="Mainline Kernel fork for APQ8026/MSM8226/MSM8926 devices"
arch="armv7"
_carch="arm"
url="https://github.com/msm8226-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
	xz
	zstd
"

_config="config-$_flavor.$arch"
_tag="v${pkgver/_/-}-msm8226"

# Source
source="
	https://github.com/msm8226-mainline/linux/archive/$_tag/linux-$_tag.tar.gz
	$_config
"
builddir="$srcdir/linux-${_tag#v}"

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"/usr \
		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="
144aff6be5f6b465fa9e7426cea5ee586ef88a9e4881760c244b317057b555fa03889a646f3f47dbd025ac9a540589ecf5cc540623562c4a9219caf9f1545ec4  linux-v6.16.12-msm8226.tar.gz
81160870e9a60b14c7f6796789328118485ee61083419d90a06cffeaaf6a10a4e140bf12cf8b0423265e93ca1301312c25881ee5c267328b1b6b6419638b15fc  config-postmarketos-qcom-msm8226.armv7
"
