# Maintainer: Duje Mihanović <duje.mihanovic@skole.hr>

_flavor=samsung-coreprimevelte
pkgname=linux-$_flavor
pkgver=6.10_rc5
pkgrel=1
pkgdesc="Samsung Galaxy Core Prime VE LTE mainline kernel"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/LegoLivesMatter/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-nftables
pmb:kconfigcheck-zram"
makedepends="bash bc bison devicepkg-dev findutils flex gmp-dev mpc1-dev
mpfr-dev openssl-dev perl postmarketos-installkernel pxa-mkbootimg dtc"

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

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

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"

	install -D include/config/kernel.release \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"

	# Master DTB (deviceinfo_bootimg_qcdt)
	pxa1908-dtbTool -p scripts/dtc/ -o arch/$_carch/boot/dt.img arch/$_carch/boot/dts/marvell/
	install -Dm644 arch/$_carch/boot/dt.img "$pkgdir"/boot/dt.img
}

sha512sums="
e7b1980d55e981b4af20ab2079f77aee28f38023afff259c7fad6694f6faf5ce000bfb0ae56a76dd3d208888bdaf5e783bd0cdf85dd80f2317a2decdeee04298  linux-samsung-coreprimevelte-6.10-rc5.tar.gz
7ac769fcbf7ad97e2314649468f203ae9035b1c90b52c3cc1bc74f28fc9dac2d8c86493629f81aeae7ae26dfa9a30b2e095a8a50c0724fb449e60afe407b47c2  config-samsung-coreprimevelte.aarch64
"
