# Archived: unmaintained
# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: https://github.com/Qs315490/linux_latte/blob/main/arch/x86/configs/xiaomipad2_defconfig
maintainer=""
pkgname=linux-xiaomi-latte
pkgver=6.16.0
pkgrel=1
pkgdesc="Upstream Kernel For XiaoMi Pad2"
arch="x86_64"
_carch="x86_64"
_flavor="xiaomi-latte"
url="https://github.com/torvalds/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-community pmb:kconfigcheck-uefi"
makedepends="
	bash
	bc
	bison
	ccache
	clang
	devicepkg-dev
	elfutils-dev
	flex
	linux-headers
	lld
	llvm
	openssl-dev
	perl
	python3
	sbsigntool
"

# Source
_config=config-$_flavor.$arch
_commit="038d61fd642278bab63ee8ef722c50d10ab01e8f"
source="
	$pkgname-$_commit.tar.gz::https://github.com/torvalds/linux/archive/$_commit.tar.gz
	$_config
	latte-audio-fix.patch
	latte-i915-fix.patch
	MOK.crt
	MOK.key
"
builddir="$srcdir/linux-$_commit"
_outdir="out"

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

build() {
	unset LDFLAGS
	make ARCH="$_carch" LLVM=1 LOCALVERSION= \
			KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	mkdir -p "$pkgdir"/boot

	install -Dm0644 "$builddir/arch/$_carch/boot/bzImage" \
		"$pkgdir"/boot/vmlinuz

	# package kernel modules
	make modules_install \
		ARCH="$_carch" \
		LLVM=1 \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1

	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

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

	# self sign kernel for Secure Boot
	sbsign --key "$startdir"/MOK.key --cert "$startdir"/MOK.crt --output "$pkgdir"/boot/vmlinuz "$pkgdir"/boot/vmlinuz
}

sha512sums="
9cfd1b774fce4237966f32c1880e087490885b8464cefb468c777b6ff022e9ec22a0ec0c051940fff86813c5f535e7c8e291f8998fd5ae8eaebcd546729b1ee6  linux-xiaomi-latte-038d61fd642278bab63ee8ef722c50d10ab01e8f.tar.gz
75d693df309cd3884fb39d69cd71bd8f3e628653c26ef6103aa7ec0f9d2abd53a0925b90e1711971615c4edc57918cd3244a4b518b31f9032b13e8cdf8b67348  config-xiaomi-latte.x86_64
7e3eeb8d54e2bf13bd9b126259daf2dd38cf698c3e66401a953d2ff235a87cfab33ea3f45575ec21cec3987f8cc0fd07f2aabc0c419753e215a851e219502025  latte-audio-fix.patch
7a311bb9ff309349fb5dc11a8a9b18f6595abb28108da60a67cd95dd9c713f150f29068c001400f47010fab1809f092ef2cc4393bab98a64592334ca8650519a  latte-i915-fix.patch
fedc27118b43badbcd47f44ac127ff9f02ce4e53ba04350c5bd893d6f6f6ff687c73f8cc7b15e8c71bc0def1ec63247ab675e95b339402edbaa744a3d8acf39d  MOK.crt
1b5d43a851e7dc4085e34368b145752d4f8d00671db097f09b85a0152e1427486e7887f9a7fd876b9f97ca4f22dcd584c496f2d8bd9a7d2e64cc1fecad8ce0f0  MOK.key
"
