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

pkgname="linux-ouya-ouya"
pkgver=3.1.10
pkgrel=1
pkgdesc="Ouya kernel fork"
arch="armv7"
_carch="arm"
_flavor="ouya-ouya"
url="https://github.com/milaq/android_kernel_boxer8_ouya"
license="GPL2"
options="!strip !check !tracedeps"
makedepends="gcc6 perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev devicepkg-dev"
# Compiling with GCC6
if [ "${CC:0:5}" != "gcc6-" ]; then
	CC="gcc6-$CC"
	HOSTCC="gcc6-gcc"
	CROSS_COMPILE="gcc6-$CROSS_COMPILE"
fi

# Source
_repository="android_kernel_boxer8_ouya"
_commit="49f035e65e689f8c227bac7a6c4ecf89ad9158af"
_config="config-${_flavor}.${arch}"
source="
	$pkgname-$_commit.tar.gz::https://github.com/milaq/${_repository}/archive/${_commit}.tar.gz
	$_config
	compiler-gcc6.h
	00_fix_return_address.patch""
"
builddir="$srcdir/${_repository}-${_commit}"

prepare() {
	default_prepare
	downstreamkernel_prepare "$srcdir" "$builddir" "$_config" "$_carch" "$HOSTCC"
}

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

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

	# zImage (find the right one)
	cd "$builddir/arch/$_carch/boot"
	_target="$pkgdir/boot/vmlinuz-$_flavor"
	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
}

sha512sums="7e29ed39c61693d85d344b6eb6180920431364124e8a261f28804585e7362ddbb3ad43c9610bed1ce83b1de7957261e450862081f53de98a5873b5a8aad1748e  linux-ouya-ouya-49f035e65e689f8c227bac7a6c4ecf89ad9158af.tar.gz
45f9f1ec802fe36dfa14a7f7c75abf767ae4521043b73561756d1eee662c7508c21024cee7d34b61f84ac43b27ee7e885dd085e19e3cdd82273c9e02f9fb8756  config-ouya-ouya.armv7
d80980e9474c82ba0ef1a6903b434d8bd1b092c40367ba543e72d2c119301c8b2d05265740e4104ca1ac5d15f6c4aa49e8776cb44264a9a28dc551e0d1850dcc  compiler-gcc6.h
6b7ecfd0939b920f263492484e8d60ff30c55614a750f5efd813a699729e65916e31b106e18bd6ea9858b37753403a6428f3a8d993c18b2459685aa29c1f2055  00_fix_return_address.patch"
