# Contributor: Thiago Foganholi <thiagaoplusplus@outlook.com>
# Maintainer: Thiago Foganholi <thiagaoplusplus@outlook.com>
# Kernel config based on: arch/arm/configs/exynos_defconfig

pkgname=linux-postmarketos-exynos4
pkgver=5.12.8
pkgrel=0
pkgdesc="Mainline kernel fork for Samsung Exynos4 devices"
arch="armv7"
_carch="arm"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native pmb:kconfigcheck-anbox"
makedepends="bison busybox-static-$arch findutils flex gmp-dev installkernel mpc1-dev mpfr-dev openssl-dev perl xz"

# Source
_config="config-$_flavor.$arch"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac
source="
	https://cdn.kernel.org/pub/linux/kernel/v${_kernver%%.*}.x/linux-$_kernver.tar.xz
	$_config
	0001-ARM-decompressor-Flush-tlb-before-swiching-domain-0-.patch
	0002-extcon-max8997-Add-CHGINS-and-CHGRM-interrupt-handli.patch
	0003-ARM-dts-exynos-Add-charger-supply-for-I9100.patch
	0004-power-supply-max8997_charger-Switch-to-new-binding.patch
	0005-ARM-dts-exynos-Add-front-camera-support-to-I9100.patch
	0006-ARM-dts-exynos-Disable-unused-camra-input-for-I9100.patch
	initramfs.list
	init
"
builddir="$srcdir/linux-$_kernver"

prepare_isorec() {
	# https://wiki.postmarketos.org/wiki/Boot_process#isorec
	cp -v /usr/$(arch_to_hostspec $arch)/bin/busybox.static \
		"$builddir"/usr/
	cp -v "$srcdir"/init "$builddir"/usr/
	cp -v "$srcdir"/initramfs.list "$builddir"/usr/
}

prepare() {
	default_prepare
	prepare_isorec
	cp -v "$srcdir/$_config" .config
}

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

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"

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

sha512sums="
8a5f1774bee223445ad147d2f83a7b3a2c19ea620d0f3964344bb33d003fec17d36279b522745c03467e361ebd61479a4f7122e5911bb6b817ff52ee55c736d9  linux-5.12.8.tar.xz
1fe836dc15c7523ddda9e1cbbd157a207954d3a63d6a27cba3b99c385e97b61489b1d923f0f0c7c4e339d26eb8237c6d8ff77faba03c8da2014676fc6990bdf6  config-postmarketos-exynos4.armv7
4bb111db4396a1981ad0883737c6594ca93701699846298b940d2ea202c666be0158a0f9ddc5b95b9147fa4cfe62639512ae78e9315f8d975b379ccc4e15da36  0001-ARM-decompressor-Flush-tlb-before-swiching-domain-0-.patch
dffe9934281e81b20e158ce9b80c6f1a91c5eaa06eb92ee655ee9430dba8aa066dd70a9fb163007f37556ea696ae0256a58f87408c8b7571d6d20f99c9492db2  0002-extcon-max8997-Add-CHGINS-and-CHGRM-interrupt-handli.patch
b70e8afa3779d471835bbdda4c8ddcf882bce58752993314655596961210235558e87dce3d1f07810ab5bb3d0471e89933a8008d7b97d8ebd05a408ffc947054  0003-ARM-dts-exynos-Add-charger-supply-for-I9100.patch
11160ac085aa912439a18995e323dfc89dfc61d85f1221af8f0116eed0f5b1fd087fc2828174c8c60f937495c31d72240c2f3c4249c29ceda6acd92f08d235c4  0004-power-supply-max8997_charger-Switch-to-new-binding.patch
30b457377bcf750a083b8a8acc3b91c7049c69b7f2e3e0dba9afe00e2c8918b1a9b2314fe553cbd808d827e845bdca10986c731d29082e20d2599d25c1956276  0005-ARM-dts-exynos-Add-front-camera-support-to-I9100.patch
96f629a33ef6001e6457331d627c3778232478969d4745b49b29a9e9cf33249508b12170bee5d3b28ec85775dd5e669d933d3d3852c2acd09d0df59266ac6f65  0006-ARM-dts-exynos-Disable-unused-camra-input-for-I9100.patch
aaff0332b90e1f9f62de1128cace934717336e54ab09de46477369fa808302482d97334e43a85ee8597c1bcab64d3484750103559fea2ce8cd51776156bf7591  initramfs.list
09f1f214a24300696809727a7b04378887c06ca6f40803ca51a12bf2176a360b2eb8632139d6a0722094e05cb2038bdb04018a1e3d33fc2697674552ade03bee  init
"
