# Maintainer: Minecrell <minecrell@minecrell.net>
# Kernel config based on: arch/arm64/configs/msm8916_defconfig

_flavor="postmarketos-qcom-msm8916"
pkgname=linux-$_flavor
pkgver=5.13
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-containers pmb:kconfigcheck-nftables"
makedepends="bison findutils flex installkernel openssl-dev perl gmp-dev mpc1-dev mpfr-dev"

# 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="
e93323a898c6c6bf538dca00a47eda5d22b7e25ddc7f848a4b798504e668ed09cd94956180b4a0f1b86da0509efadf30169a1cca547d817390f8a726a4da0a44  linux-postmarketos-qcom-msm8916-v5.13-msm8916.tar.gz
f887a487f605c65efb36353d6150eabd458b4bdc6f0152dc0ad7e86a5677ca73336f7d8d166418bd35416b4ffc62a6b2235301d5ff6072e8d7df946317ce0ccd  config-postmarketos-qcom-msm8916.aarch64
ab6740283eb83a57a952046669a182df330b588d95752c2d1a4a3eba22e60596eee50eab26550159ecd5dff2dd20758ed4bda729aba614ca5e40ff90321c7030  config-postmarketos-qcom-msm8916.armv7
"
