# Maintainer: Minecrell <minecrell@minecrell.net>
# Co-Maintainer: Nikita Travkin <nikita@trvn.ru>
# Kernel config based on: arch/arm64/configs/msm8916_defconfig

_flavor="postmarketos-qcom-msm8916"
pkgname=linux-$_flavor
pkgver=5.18
pkgrel=0
pkgdesc="Mainline kernel fork for Qualcomm MSM8916 devices"
arch="aarch64 armv7"
url="https://github.com/msm8916-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-anbox
	pmb:kconfigcheck-apparmor
	pmb:kconfigcheck-containers
	pmb:kconfigcheck-iwd
	pmb:kconfigcheck-nftables
	pmb:kconfigcheck-zram
"
makedepends="
	bison
	findutils
	flex
	gmp-dev
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
	postmarketos-installkernel
"

# Architecture
case "$CARCH" in
	aarch64) _carch="arm64" ;;
	arm*)    _carch="arm" ;;
esac

# Source
_tag=v${pkgver//_/-}-msm8916
source="
	$pkgname-$_tag.tar.gz::$url/archive/$_tag.tar.gz
	config-$_flavor.aarch64
	config-$_flavor.armv7
"
builddir="$srcdir/linux-${_tag#v}"

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

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION=$((pkgrel + 1 ))
}

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"/usr/share/dtb
	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="
1433f960797289936f3b7d2aa76e1b299506c3e9db4b2c50b0cc291e3a7ca8eb54c5bde7e26865cad676386ba8795e070b1fed64db1cffb305da18a5f551ecba  linux-postmarketos-qcom-msm8916-v5.18-msm8916.tar.gz
21efa9de397af835eca8c8558a59d1aaa0006785590ed936195f747572b15215a902eaa535ff00c5c64861cd4c127e41c03d5ff1379c69d2ca5e38f44ec9d0be  config-postmarketos-qcom-msm8916.aarch64
9ebefba76c62c5d9e7f14855a15878cd0ae32dc34b8a55f6d429fd7396d1891ddd9c73e6a5b3d0eb7a8c788876e652355c9c7c7df496a4e813486c4c55956048  config-postmarketos-qcom-msm8916.armv7
"