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

_flavor="postmarketos-mediatek-mt6735"
pkgname=linux-$_flavor
pkgver=6.1.9
pkgrel=1
pkgdesc="Linux kernel with patches for devices with the MediaTek MT6735 SoC"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/mt6735-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-zram
"
makedepends="bash bison findutils flex installkernel openssl-dev perl"

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

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

build() {
	unset LDFLAGS
	# V=1: workaround for pma#1990
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION=$((pkgrel + 1 )) V=1
}

package() {
	mkdir -p "$pkgdir"/boot
	install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
		"$pkgdir/boot/vmlinuz"

	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"/boot/dtbs
}
sha512sums="
34bf27d0934cd6962a8e84cb79d59fe7b5cc7aed62eee0b2150d0dd77c4fa5a1ad803674bb61192feca99d1ad2e61a1c7d2579f03657fe978dd41d550c84a410  linux-v6.1.9-mt6735.tar.gz
2f7974844331e9e25e997659005ebb05262c34f7c673f8ff91f30804cd725298ae51dcee715275e86b1e7e75ff8de4299404938f48277ab4145354ee38fd22c7  config-postmarketos-mediatek-mt6735.aarch64
"
