# Maintainer: Ultracoolguy <ultracoolguy@disroot.org>
# Kernel config based on: defconfig, msm8953.config, and device configs

_flavor="postmarketos-qcom-msm8953"
pkgname=linux-$_flavor
pkgver=6.3.0
pkgrel=2
pkgdesc="Close to mainline linux kernel for Qualcomm Snapdragon MSM8953"
arch="aarch64"
_carch="arm64"
url="https://github.com/msm8953-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
"
makedepends="
	bash
	bison
	findutils
	flex
	openssl-dev
	perl
	postmarketos-installkernel
"

# Source
_commit="a8451e512cd99c360244728d68bd9bd5ebfa9ae1"

source="
	$pkgname-$_commit.tar.gz::https://github.com/msm8953-mainline/linux/archive/$_commit.tar.gz
	config-$_flavor.aarch64
"
builddir="$srcdir/linux-$_commit"

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

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

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 -Dm644 "$builddir/include/config/kernel.release" \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"
}

sha512sums="
10f96b51cbf4004b22416e535f7d267ea95393d24c662f67c4551a3c3089b0d2774ac97a375571e3df7de61e6b582df251fc6c24a3b05fa30c54464c9512be5e  linux-postmarketos-qcom-msm8953-a8451e512cd99c360244728d68bd9bd5ebfa9ae1.tar.gz
c9012c1d88c7c029acb53ac73e959e089e5832f1cfd64e6909256f6cdf9237fe494a824449cc7ec58155fa60512889ea9054d152dd3f1abfee3823b037988e64  config-postmarketos-qcom-msm8953.aarch64
"
