# Reference: <https://postmarketos.org/vendorkernel>
# Maintainer: TQMatvey <maybeetube@gmail.com>
pkgname=linux-postmarketos-qcom-sm6225
pkgver=6.1
pkgrel=0
pkgdesc="Mainline Kernel fork for SM6225 devices"
arch="aarch64"
_carch="arm64"
_flavor="postmarketos-qcom-sm6225"
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-sm6225"
_commit="849f3f471b6268280dc8418e0bddda435ae5d4a5"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://gitlab.com/TQMatvey/$_repository/-/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repository-$_commit"


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

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

package() {
	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="
df2584f29d4e2c753eed2f843da9c2134211c6359d0bd58d0d5f3ab3baf6cdebf57e37997da5a92a2401669329fcb30dd3c8c2c65c7be1eb86fe67abc9c2da91  linux-postmarketos-qcom-sm6225-849f3f471b6268280dc8418e0bddda435ae5d4a5.tar.gz
ce5856fd55973fea0678dbe646e5688c142cee9c84ae4a5c76ab003a6f368de640577a5c13261393b8a4b72aa84a492a1e84683b5cc02ae0b6ad6396ae110765  config-postmarketos-qcom-sm6225.aarch64
"
