# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/(CHANGEME!)

pkgname=linux-xiaomi-laurel_sprout
pkgver=4.14.117
pkgrel=0
pkgdesc="Xiaomi Mi A3 kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="xiaomi-laurel_sprout"
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
	linux-headers
	perl
	clang
"

# Source
_repository="android_kernel_xiaomi_laurel_sprout"
_commit="18cce7c37b08cf3b8cb013ac648f03a7361ac215"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/AOSPA/$_repository/archive/$_commit.tar.gz
	$_config
	0001-always_boot_to_initramfs.patch
	0002-disable_skip_initramfs.patch
	0003-remove_bootloader_cmdline_opts.patch
	0004-selinux_include_generated_headers.patch
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

prepare() {
	default_prepare
	REPLACE_GCCH=0
	. downstreamkernel_prepare
}

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

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir"
	# Modules
	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="clang" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS" \
		INSTALL_MOD_PATH="$pkgdir" modules_install
}

sha512sums="
2cebedae30ffc2ff16b5f8d6b93f7edeb7d28e88cbecdf7835dcdd3ceaabc61a3b5aee3085fea385e4644aaadd371e0109356eb0a21135d97fcfe6bf6a4c8b04  linux-xiaomi-laurel_sprout-18cce7c37b08cf3b8cb013ac648f03a7361ac215.tar.gz
65b37d0298dd9121cd014dc9e15ad02148d306e6161c4f8d091757722d1cdc00447a52c9a06e6303d63e49b169c1992cc12f78ff81de3062600acd62495c17f9  config-xiaomi-laurel_sprout.aarch64
e2a7a404a7bd404dbda08663ca5f96c38e04e58bd781024c6904115a4775e089775a552583347ab8e2f745d5ab5653a63c08070b3b43b8b4a2f23696e747311e  0001-always_boot_to_initramfs.patch
65048fb6474fd543b14bc99d9d95cfe5297da239af211d327a8509f7777d489bd01dd911364e0c62ec0e68f4c22ebb3b145eabfe01cad2abf57cf46896a1e58f  0002-disable_skip_initramfs.patch
9ce867c4254b537ef5d2485780c26b72da8a3a8767ba71557f3b48d6c550e0e14c8c3e575b31bf65d2878f08a8a4926e48a1c2f1be534bf80a7a57f58313b0fd  0003-remove_bootloader_cmdline_opts.patch
6ab9db01d35f7f5cc2c19ebe5f65a7dc479a1c68de587300cdde9a6c759d34610666c72f0f321cd450cf56c13df3b54a774e0f7ebdbf0f8608fbfd66b49d04e7  0004-selinux_include_generated_headers.patch
"
