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

_flavor="postmarketos-qcom-msm8916"
pkgname="linux-$_flavor"
pkgver=5.6
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"
makedepends="bison findutils flex installkernel openssl-dev perl"

# 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_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="62c357f4b4014c0af944d3fce58efbbc77b81eb59255527275f4d3005f8fa5a2e658286360d3c692a8f2735b3a544f6ab072d58acc4f429740a0ddc4977d527c  linux-postmarketos-qcom-msm8916-v5.6-msm8916.tar.gz
b2aa1c5526aa134d306d7da71f96153b620ea7c0a2d52d010cb64b424c1e1a85737d85c1d39f1067486c0e76f179a86a955b1dcc584bcfd229be1b3eadff8833  config-postmarketos-qcom-msm8916.aarch64
0ae872dac797763f3f3aea37c9f42817d453d9213aed206a9f64611edd46460a4cf81cd59f58722dcd01484f72cb8fd152cd924ace53c7d73d5728cfd8d64a8c  config-postmarketos-qcom-msm8916.armv7"
