# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/defconfig
# Maintainer: Lux Aliaga <they@mint.lgbt>
pkgname=linux-postmarketos-qcom-sm6125
pkgver=6.1
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="77de535b8dbd8f483b5802c8937cb714bab5b485"
_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"/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="
e41aa6fa99cdb76f1748547e1b140721e30ced86d3e2aa2f94cc56be8a8f89fd0578f041061c0b6992cf49e73ee4b78cc6529943d37087c27894094730ca1e93  linux-postmarketos-qcom-sm6125-77de535b8dbd8f483b5802c8937cb714bab5b485.tar.gz
c16ec85c55d844b8744d03067fe5041a8b45ee51527116f27a1a14d16c3601bd1b960ce8667bfee1fc4e7c02fbd9b1a238a22a8a21dc8778f140754e72c260ee  config-postmarketos-qcom-sm6125.aarch64
"
