# Unmaintained: Downstream port, only for reference.
# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/cepheus_defconfig

pkgname=linux-xiaomi-cepheus-downstream
pkgver=4.14.239
pkgrel=0
pkgdesc="Xiaomi Mi 9 (cepheus) downstream kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="xiaomi-cepheus-downstream"
url="https://github.com/EcrosoftXiao/kernel_xiaomi_cepheus"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="
	android-mkdtimg
	bash
	bc
	bison
	devicepkg-dev
	flex
	linux-headers
	openssl-dev
	perl
"

# Source
_repository="kernel_xiaomi_cepheus"
_commit="b8381357dcb21e10c86e81f62705fa1de6e942ed"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/EcrosoftXiao/$_repository/archive/$_commit.tar.gz
	$_config
	0001-Disable-YAML-for-dtc-build.patch
	0002-ipa_v3-fix-potential-buffer-overflow.patch
	0003-fix-invalid-printf-format.patch
	0004-Get-rid-of-Werror.patch
	0005-Use-real-mkdtimg-don-t-use-python2-one.patch
	0006-Do-not-skip-initramfs.patch
	0007-qpnp-fg-gen4-reduce-dmesg-spamming.patch
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

prepare() {
	default_prepare
	REPLACE_GCCH=0 . 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"

	# Install dtbo.img too
	install -Dm644 "$_outdir"/arch/arm64/boot/dtbo.img \
		"$pkgdir"/boot/dtbo.img-"$_flavor"
}

sha512sums="
53541473317d2205d1583cc663eb96394d4ce29acb31fb3bde4bf6fce6ca5ace5a184ff298b63f2984f2a92747c46c5b7bfd0e7b10c4b42f5b94e2c806dc9c2b  linux-xiaomi-cepheus-downstream-b8381357dcb21e10c86e81f62705fa1de6e942ed.tar.gz
18f7a156890472241656345dca18cfb9958119c84c57dc027da37b6e61b302318fe9c67acd0fdf1c6436dcda824ed1f8b600a1f988642ca33b3458c39f8ea795  config-xiaomi-cepheus-downstream.aarch64
9e4e499160e28132a251cdd09e24e3d9658ec42980b182e2756d62098de27d836c52ae3a6f24c57524e5f0b3040ceea301b1a1d0a3f226131df7eb56bf442f3d  0001-Disable-YAML-for-dtc-build.patch
f44ab25b7acdb0a80214491c8e9c4cea1e71039df115f760aeb38e80acdf0dd0b63b4dd7621201ad1db436bb4d95e3b7c4d3e66cbfdf29fdd486779dfbe99af8  0002-ipa_v3-fix-potential-buffer-overflow.patch
af74c336348c5e4d980e28225c7d93b2e1ce9be2e4d6b70721a103cf12fb93f2c22b50963265a9d76a84f2ba276c9ab18b07fe102121c0a1a52e87124db5fdd7  0003-fix-invalid-printf-format.patch
8d277e6e02f026955347978800be018e34ad40630a27283614eb087ab4e5d10785c0ad388b2a57c33b16f3268f3ecf541118cf9770ca093ef83cfbea56e6c8c8  0004-Get-rid-of-Werror.patch
8740bbbe90b410ca8958f488b8950e56243dd17dda67a9a2edbd3274d7c1d97106a19d76a28da447c32f5696e5672d511d410234b8a65dff3fa9a78ecdee99a8  0005-Use-real-mkdtimg-don-t-use-python2-one.patch
4727cdcdaa03c8df62d5e26930baa036d43363b5d1b7f43059fbd361c463a09fc7957cca357ef1e9ad7488647e00fc5656fdbc4d209010cc85b8d2c98268ae6d  0006-Do-not-skip-initramfs.patch
167f43e23b50f62031e8de827a00d839cc754926be6a8336ecee1ed9da5e2196c6cd0ff9988654a26fb636e13500c3520d18d47594c6f9956d379c96cd8bc858  0007-qpnp-fg-gen4-reduce-dmesg-spamming.patch
"
