# NOTE: Please ensure any changes made to this kernel are also applied to the
#       16k varient.

# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/defconfig
# Co-Maintainer: Nick Chan <towinchenmi@gmail.com>
maintainer="Aster Boese <asterboese@mailbox.org>"
_flavor="postmarketos-apple-4k"
pkgname=linux-$_flavor
pkgver=7.0.4
pkgrel=0
pkgdesc="Mainline kernel fork for Apple iPhone and iPad devices (4k)"
arch="aarch64"
_carch="arm64"
url="https://kernel.org"
license="GPL-2.0-only"
options="!check !strip !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-rust
	"
makedepends="
	bash
	bc
	bison
	clang
	clang-libclang
	devicepkg-dev
	elfutils-dev
	flex
	linux-headers
	lld
	llvm
	openssl-dev
	perl
	python3
	rust
	rust-bindgen
	rustfmt
	rust-src
	"
source="
	https://github.com/HoolockLinux/linux/archive/refs/tags/hoolock-$pkgver.tar.gz
	config-$_flavor.$arch
	"
builddir="$srcdir/linux-hoolock-$pkgver"

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

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

package() {
	install -Dm644 "$builddir"/arch/"$_carch"/boot/vmlinuz \
		-t "$pkgdir"/boot/

	make modules_install dtbs_install \
		ARCH="$_carch" \
		LLVM=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs \
		INSTALL_MOD_PATH="$pkgdir"/usr \
		INSTALL_MOD_STRIP=1 \
		INSTALL_PATH="$pkgdir"/boot
	rm -f "$pkgdir"/usr/lib/modules/*/build "$pkgdir"/usr/lib/modules/*/source

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

sha512sums="
d95ced0eddb5f2e989719b7af3664fb7b40dafe2e9f035de730125e4b2185c3f9dfd504101b6b2e719509041e7865f9f9cce9688adad127999f1b08a292a8382  hoolock-7.0.4.tar.gz
9e88d32d517f12d9b942314482b2cd0f79138b7fad07daa231b5ef69a61f5c31a7ff75ab11a3d99d4e827be9b89acbed5a8d4ef9a3d5242be8ab181d72257e7b  config-postmarketos-apple-4k.aarch64
"
