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

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

# Source
_commit="b5b016f951f44dcc5a584d31843ea7e0ce5bf1c2"

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

_carch="arm64"

builddir="$srcdir/linux-$_commit"

prepare() {
	default_prepare
	cp -v "$srcdir/config-$_flavor.$CARCH" "$builddir"/.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="
3dfa002828db13baa9beb59aa7512051cec149924c2e29cc6ae87938ee6fe74b9ac013e0fb62e4be7213666f700b6e37f0d27b2bb860a54b4f0649f55e4a9590  linux-postmarketos-qcom-msm8953-b5b016f951f44dcc5a584d31843ea7e0ce5bf1c2.tar.gz
383094c7edc23fa6b61480093e86b996f5e6341379a155f9183c8a51ad1bf2f4aa8298b1ae1f2d8df327038a5d6c65a1928045b4d072d26da42bb52e59e705f8  config-postmarketos-qcom-msm8953.aarch64
"
