# Reference: https://gitlab.com/ubports/porting/community-ports/android10/xiaomi-redmi-9c/kernel-xiaomi-mt6765
# Kernel config based on: arch/arm64/configs/angelican_defconfig

pkgname=linux-xiaomi-angelican
pkgver=4.9.190
pkgrel=0
pkgdesc="Xiaomi Redmi 9C NFC kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="xiaomi-angelican"
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
	python3
"

# Source
_repository="kernel-xiaomi-mt6765"
_commit="5b52fedbe4d7c6809b5040f7486a8b72812f3fba"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://gitlab.com/ubports/porting/community-ports/android10/xiaomi-redmi-9c/$_repository/-/archive/$_commit/$_repository-$_commit.tar.gz
	$_config
	001-touchscreen-firmware-loading-time.patch
	002-battery-percentage.patch
	003-fix-check-lxdialog-makefile.patch
	004-fix-check-lxdialog.patch
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

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

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" \
		"$_flavor" "$_outdir"

	make dtbs_install O="$_outdir" ARCH="$_carch" \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs

  make modules_install O="$_outdir" ARCH="$_carch" \
    INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs \
    INSTALL_MOD_PATH="$pkgdir" INSTALL_MOD_STRIP=1

	cat "$pkgdir"/boot/dtbs/mediatek/*.dtb > "$pkgdir"/boot/dtbs/mediatek/merged.dtb
}

sha512sums="
beeaa1b5b5d3e6f635508c6f421051080f7fdc296909db7448e4c706b6a54755badc2ea0c1316dbf0a1d394dbea15266a84dfa36d9818c8df99747484c9175b6  linux-xiaomi-angelican-5b52fedbe4d7c6809b5040f7486a8b72812f3fba.tar.gz
ee1a116d200f0b9ad63eb2ea132364dd7940a4b8edf1558475b8780506eabd56882f8338eaeba53faea0d59ab8f4eedd5d4f10c5bfd8b747d29f56c937ed40a3  config-xiaomi-angelican.aarch64
3fc36011ab030382f6b74e3821dcc75a236e12fe38bf18639fededc6c49a8c809d9ca1af5a9f2ed83f5f412a383918db14b4af48eda7087ec5997ca00e018152  001-touchscreen-firmware-loading-time.patch
2ed25978e3c91addf7e568b68ccb6036aa581da0981ec75527e25d15d0ee7dfed97100376e58ce6a6c07ef8a96210a30c0ad91b3cea29528aa89fc59980691bf  002-battery-percentage.patch
c33fad9de627e72f12e61e728fa1ec53ef15259c7790392a997cc7269e60e45da9534d58851c3b348a1729aaa134d1df305e33546e8a1f3654462f2c3c1d9563  003-fix-check-lxdialog-makefile.patch
182be3c596b9cc267ac108d7cf03fc8c328ccc6b36770800e4dcedea8d1bb65e3f5eacf590c2948f58b1418cc60a1670ba77dde8c259e428d158c31b6e1dbaf5  004-fix-check-lxdialog.patch
"
