# Maintainer: Caleb Connolly <caleb@connolly.tech>
# Co-Maintainer: Uclydde <julianbraha@gmail.com>
# Stable Linux kernel with patches for SM8150 devices
# Kernel config based on: arch/arm64/configs/defconfig and sm8150.config

_flavor="postmarketos-qcom-sm8150"
pkgname=linux-$_flavor
pkgver=5.12
pkgrel=1
pkgdesc="Mainline Kernel fork for SM8150 devices"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/sm8150-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bison findutils flex installkernel openssl-dev perl"

_repo="linux"
_config="config-$_flavor.$arch"
_commit="76851ee4194b4d85df168064cf380a4437b28b51"

# Source
source="
	$_repo-$_commit.tar.gz::https://gitlab.com/sm8150-mainline/$_repo/-/archive/$_commit/$_repo-$_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repo-$_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"/usr/share/dtb
	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="
1fc3ad729a1cb480bc457f10e2b249d17f0fdb72a6c77cc557024d20e28e7db410350e800090b81a8708d952a2b8faddeff9df71e62ee440f62f9fd77a0d195e  linux-76851ee4194b4d85df168064cf380a4437b28b51.tar.gz
58712c2a89e30495b53cde6d304d99130f7e606908d431581230959eefa7dac418e197835d35459e3736dcf1d945754ac55d457239aa3b014ebc62770b71fb2d  config-postmarketos-qcom-sm8150.aarch64
"
