# 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=6.3
# When making kernel config changes please also submit a PR to
# https://github.com/msm8916-mainline/linux/blob/master/kernel/configs/pmos.config
# since the kernel config is regenerated on upgrades and all changes will be lost!
pkgrel=0
pkgdesc="Mainline kernel fork for Qualcomm MSM8909/MSM8916/MSM8939 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-community
"
makedepends="
	bison
	findutils
	flex
	gmp-dev
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
	postmarketos-installkernel
"
replaces="linux-postmarketos-qcom-msm8909 linux-postmarketos-qcom-msm8939"

# 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"/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="
2abc47e4431261e2f80d91d9a742718c1941767838c9843a7b7707d7c7edfcb44c1a713bc92e6a41e8643d28cb236e7437750d87cc59fa52ae16f05881ff04d2  linux-postmarketos-qcom-msm8916-v6.3-msm8916.tar.gz
172767eb7bfbf74cb8ba43e9019d27a7a32a63aae5ab3c835015415dbf525f7cee3730d8e6782f9059e4eb036cdd99f5053b62b43e794a1d0aceda7fbf64f839  config-postmarketos-qcom-msm8916.aarch64
7289abcb93bc564d42506fff033680cd5428dac4a6107e9b7ba5c278a1c553fa4e3799e0f7fc95ef2fba13587fadb228c6829624a2ac63b27be5742a3a8e4e8d  config-postmarketos-qcom-msm8916.armv7
"
