# Maintainer: Yassine Oudjana (Tooniis) <y.oudjana@protonmail.com>
# Kernel config based on: arch/arm64/configs/defconfig

_flavor="postmarketos-qcom-msm8996"
pkgname=linux-$_flavor
pkgver=5.12.5
pkgrel=0
pkgdesc="Kernel close to mainline with extra patches for Qualcomm MSM8996 devices"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/msm8996-mainline/linux-msm8996"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bison findutils flex installkernel openssl-dev perl"

# Source
_tag=v${pkgver//_/-}-msm8996
source="
	linux-msm8996-$_tag.tar.gz::$url/-/archive/$_tag/linux-msm8996-$_tag.tar.gz
	config-$_flavor.$arch
"
builddir="$srcdir/linux-msm8996-$_tag"

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
	install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
		"$pkgdir/boot/vmlinuz-$_flavor"

	install -D "$builddir/include/config/kernel.release" \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/usr/share/dtb
}
sha512sums="
34e2eaca170758a28b7bdaf92221590a0d966b6b57e0e9ad16b0afafd2cae3c978d59b6f7c865dac6af78f148846b90d81e40cd8fbbbcefcf165b8fac071a171  linux-msm8996-v5.12.5-msm8996.tar.gz
c42b5f23b1cfd36abd9bb46269c7ede9b517a95a9efd768a9b4fe44a7e6bf3aa09cebcd782e9cf74feeee4f29c33eeb640a4fd49798522ce5ae7155cef6e1d77  config-postmarketos-qcom-msm8996.aarch64
"
