# Maintainer: Alexey Minnekhanov <alexeymin@postmarketos.org>
# Kernel config based on: arch/arm64/configs/defconfig

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

_tag="v$pkgver-sdm660"

source="
	linux-$_tag.tar.gz::https://github.com/sdm660-mainline/linux/archive/refs/tags/$_tag.tar.gz
	config-$_flavor.aarch64
"

_carch="arm64"

# for some reason, the directory inside .tar.gz does not match tag name: leading
#     "v" is missing, so we can't use $_tag here
builddir="$srcdir/linux-$pkgver-sdm660"

prepare() {
	default_prepare
	cp -v "$srcdir/config-$_flavor.$CARCH" "$builddir"/.config
}

build() {
	unset LDFLAGS
	# V=1: workaround for pma#1990
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor" \
		V=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="
cf71a37ad587805fc5393ac5eaf65ffd4fc98fd85fdd2bd5e4ee1b825ccee43194e45f6d54b4485b3c04f661a174a7fefc300004ae428b5b250b66603f388e14  linux-v6.0.10-sdm660.tar.gz
ac5f076165727416d4b7063cef82a3f606dbe32feefa67c4dd52e766ac105aced27e393b84f6ba4f59a662dfd6e0aaaf3cf8d8a143a25f30cdd6957f76fcc496  config-postmarketos-qcom-sdm660.aarch64
"