# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/odroidxu4_defconfig
# Maintainer: Dylan Van Assche <me@dylanvanassche.be>

pkgname=linux-odroid-hc2
pkgver=5.12.9
pkgrel=0
pkgdesc="ODROID XU3/XU4/HC1/HC2/MC1 kernel fork"
arch="armv7"
_carch="arm"
_flavor="odroid-hc2"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-nftables"
makedepends="
	bison
	devicepkg-dev
	findutils
	flex
	gmp-dev
	installkernel
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
	rsync
	xz
	linux-headers
	"
# Source
_config="config-$_flavor.$arch"
_pkgname="linux"
_commit="4f75c10941ab9e2856598f82bbd417545bd41681"
source="
	$_pkgname-$pkgver.tar.gz::https://github.com/tobetter/linux/archive/$_commit.tar.gz
	$_config
"
subpackages="$pkgname-dev"
builddir="$srcdir/$_pkgname-$_commit"

prepare() {
	default_prepare
	REPLACE_GCCH=0 \
		. downstreamkernel_prepare
}

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

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

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"
}

dev() {
	provides="linux-headers"
	replaces="linux-headers"

	cd $builddir

	# https://github.com/torvalds/linux/blob/master/Documentation/kbuild/headers_install.rst
	make -j1 headers_install \
		ARCH="$_carch" \
		INSTALL_HDR_PATH="$subpkgdir"/usr
}

sha512sums="
f19a86a4b33e744f8ee397781558c71040faa747f499b1069faa124d2e316aaae4a849ce1b35b8ae72bc80d06cff4185a9e6ac9d767024b11f0c72808ffe706b  linux-5.12.9.tar.gz
58d3c60b1fbfefa94dabe14182b3401d08666a6bedefa0abe26afdf09f3871381d9b68ab18a7cbcec7328f939be0dfd0b424ed09bbf12aef62f0095917dd970d  config-odroid-hc2.armv7
"
