# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/(CHANGEME!)

pkgname=linux-postmarketos-qcom-sm6125
pkgver=5.18.0
pkgrel=0
pkgdesc="Mainline Kernel fork for SM6125 devices"
arch="aarch64"
_carch="arm64"
_flavor="postmarketos-qcom-sm6125"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	flex
	openssl-dev
	perl
"

# Source
_repository="linux"
_commit="3398a1d7daeca76a3adef6e64e8f0f516f95195e"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://gitlab.com/sm6125-mainline/$_repository/-/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repository-$_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

	install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
		"$pkgdir/boot/vmlinuz"

	make 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="
a7f3278990e837143337e37f9d2fac1bb0fd6b859681de0e8226fae2addae2cfaa2d44d6bddf43004a887e189d22223a4debd2891cbf580d61b6b8fa184c5c2a  linux-xiaomi-laurel_sprout-3398a1d7daeca76a3adef6e64e8f0f516f95195e.tar.gz
695be42583078511a180cc2bc36f70a038ff1a3c5e81e084c70ee9341936159ee695884d3e43e5afd6be717ab35e3445ac577c04f4847670040d0c6ab28651fa  config-xiaomi-laurel_sprout.aarch64
"
