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

pkgname="linux-ouya-ouya-mainline"
pkgver=5.0
pkgrel=1
pkgdesc="Ouya kernel"
arch="armv7"
_carch="arm"
_flavor="ouya-ouya-mainline"
url="https://kernel.org"
license="GPL2"
options="!strip !check !tracedeps"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev xz flex bison openssl-dev"

# Compiler: latest GCC from Alpine
HOSTCC="${CC:-gcc}"
HOSTCC="${HOSTCC#${CROSS_COMPILE}}"

# Source
_repository="linux"
_rev="7c3acfbc49c690a8ec27f2269840a7e141182ab9"
_config="config-${_flavor}.${arch}"
source="
	$pkgname-$_rev.tar.gz::https://github.com/decatf/${_repository}/archive/${_rev}.tar.gz
	$_config
"
builddir="$srcdir/${_repository}-${_rev}"

prepare() {
	default_prepare

	mkdir -p "$srcdir"/build
	cp -v "$srcdir"/$_config "$srcdir"/build/.config
	make -C "$builddir" O="$srcdir"/build ARCH="$_carch" HOSTCC="$HOSTCC" \
		olddefconfig
}

build() {
	cd "$srcdir"/build
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-${_flavor}" \
		CFLAGS_MODULE=-fno-pic
}

package() {
	cd "$srcdir/build/arch/${_carch}/boot"

	if [ "$CARCH" == "aarch64" ]; then
		install -Dm644 "$srcdir/build/arch/${_carch}/boot/Image" \
			"$pkgdir/boot/vmlinuz-$_flavor"
	else
		install -Dm644 "$srcdir/build/arch/${_carch}/boot/"*zImage \
			"$pkgdir/boot/vmlinuz-$_flavor"
	fi

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

	cd "$srcdir"/build

	local _install
	case "$CARCH" in
	aarch64*|arm*)	_install="modules_install dtbs_install" ;;
	*)		_install="modules_install" ;;
	esac

	make -j1 $_install \
		ARCH="$_carch" \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"
}


sha512sums="5892de457aea6d4cbbfbcc902d24891dcc03c40638510d031d5007477241cb3616ca5c0a2fcad6882f4e8a341b767b3b6a18b42f496198bf08b326d2a1cd7fdd  linux-ouya-ouya-mainline-7c3acfbc49c690a8ec27f2269840a7e141182ab9.tar.gz
a00b15f5ae66ec31d5ad8ad5c4d3b9fb499d222dd095c2adb2ca317c964c6580f9cb0a1a5b0e93fd7a2ca501caa1189ec7da948629b001832a44bafeec8d6c4d  config-ouya-ouya-mainline.armv7"
