# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: https://github.com/me176c-dev/archlinux-me176c/blob/master/linux-me176c/config

_flavor="asus-me176c"
pkgname="linux-${_flavor}"
pkgver=4.19.80
pkgrel=0
pkgdesc="Mainline kernel fork for ASUS MeMO Pad 7 (ME176C(X))"
arch="x86_64"
_carch="x86_64"
url="https://github.com/me176c-dev/linux-me176c"
license="GPL-2.0-only"
options="!strip !check !tracedeps"
depends_dev="perl gmp-dev elfutils-dev bash flex bison"
makedepends="$depends_dev sed installkernel bc linux-headers openssl-dev xz"

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

# Source
source="
	$pkgname-$pkgver.tar.gz::$url/archive/$pkgver.tar.gz
	config-$_flavor.$arch
"
builddir="$srcdir/linux-me176c-$pkgver"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$arch" .config
}

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

package() {
	mkdir -p "$pkgdir"/boot
	make install modules_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir"
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

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

sha512sums="7725d0fb7152d7727c769d831d00afd2dd9e0b9df7349c0a8cde4c432b42ea24cf06a4f5a9016a5e8b41f28fd71dfca8c5b9b67ecccbd2857682d19f18ba8655  linux-asus-me176c-4.19.80.tar.gz
fea1ad3104daa792678735bf190a8b351e8b7e529895b219aae1ed789e02bf9d13cd5ec9c9322ce080c3fd26da56e064a8e4053918dfd0a817b9f205b2559ce6  config-asus-me176c.x86_64"
