# Kernel config based on: arch/arm/configs/C8680_defconfig

pkgname=linux-gp-peak
pkgver=3.0.21
pkgrel=8
pkgdesc="Peak kernel fork"
arch="armhf"
_carch="arm"
_flavor="gp-peak"
url="https://kernel.org"
license="GPL2"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev devicepkg-dev gcc6"

# Compiler: this kernel was only tested with GCC6. Feel free to make a merge
# request if you find out that it is booting working with newer GCCs as
# well. See <https://postmarketos.org/vendorkernel> for instructions.
if [ "${CC:0:5}" != "gcc6-" ]; then
	CC="gcc6-$CC"
	HOSTCC="gcc6-gcc"
	CROSS_COMPILE="gcc6-$CROSS_COMPILE"
fi

# Source
_repository="gp-peak-kernel"
_commit="f02b7a6f10b257b0452d3de47e19e55836e57613"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/gp-b2g/$_repository/archive/$_commit.tar.gz
	$_config
	timeconst.pl-Eliminate-Perl-warning.patch
	00_fix_return_address.patch
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

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

package() {
	# kernel.release
	install -D "$builddir/$_outdir/include/config/kernel.release" \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"

	# zImage (find the right one)
	cd "$builddir/$_outdir/arch/$_carch/boot"
	_target="$pkgdir/boot/vmlinuz"
	for _zimg in zImage-dtb Image.gz-dtb *zImage Image; do
		[ -e "$_zimg" ] || continue
		msg "zImage found: $_zimg"
		install -Dm644 "$_zimg" "$_target"
		break
	done
	if ! [ -e "$_target" ]; then
		error "Could not find zImage in $PWD!"
		return 1
	fi

	# External modules install
	cd "$builddir"
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS" \
		INSTALL_MOD_PATH="$pkgdir" modules_install
}

sha512sums="e643530bc4e8540284820af137d300d8bf12fa352200095757a64e8e34a71d6e8892bf5887a988404864866751fb8fcac9e89b4429a76be59aeae670d04d533d  linux-gp-peak-f02b7a6f10b257b0452d3de47e19e55836e57613.tar.gz
8ea00d7a63f0173e6c7a3d99d9b56b7b2d2dc7029570769c72f4e8cc54b7b115e2d5b680c13952fb2c386f6b305980b4b72e5dc0a0b62e35ede6bed0cfffbc5e  config-gp-peak.armhf
1fcfb5f06a2bfdcc55d53054ca80d1b989599a39a5379d057a0724fc405187d74da4309a650e70b9c79d39444e81923cfc5c9199ed8c0a77c83dcd7998446bb7  timeconst.pl-Eliminate-Perl-warning.patch
ea1d3b5a234fa565e3c1a792de48f4fc4e6023d281d303c8e319c7ef28edc5739ab0e4dea0139a41f0a5c7d03e27921ccaa214fd0ac5c72245a094ce60128864  00_fix_return_address.patch"
