# Reference: <https://postmarketos.org/devicepkg>
maintainer="Aster Boese <asterboese@mailbox.org>"
pkgname=device-google-x64cros
pkgdesc="Google Chromebooks with x64 CPU"
pkgver=18
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="x86_64"
options="!check !archcheck"
depends="
	alsa-ucm-conf-cros
	depthcharge-tools
	postmarketos-base
	postmarketos-cros-common
	systemd-boot
	"
makedepends="devicepkg-dev"
install="$pkgname.post-install $pkgname.post-upgrade"
subpackages="
	$pkgname-kernel-lts:kernel_lts
	$pkgname-kernel-stable:kernel_stable
	$pkgname-firmware-intel:firmware_intel
	$pkgname-firmware-amd:firmware_amd
	"
source="
	00-amdgpu-firmware.files
	00-i915-firmware.files
	deviceinfo
	kernel-cmdline.conf
	modules-initfs
	"
# TODO: package iwlwifi-7265D-29.ucode separetely, so we don't depend
# on linux-firmware-other
_pmb_recommends="
	amd-ucode
	intel-ucode
	linux-firmware-amdgpu
	linux-firmware-i915
	linux-firmware-intel
	linux-firmware-other
	linux-firmware-rtl_nic
	linux-firmware-rtw88
	"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname
}

kernel_stable() {
	pkgdesc="Alpine Stable kernel"
	depends="linux-stable"
	provides="$pkgname-kernel-edge=$pkgver-r$pkgrel"
	replaces="$pkgname-kernel-edge"
	devicepkg_subpackage_kernel $startdir $pkgname $subpkgname
}

kernel_lts() {
	pkgdesc="Alpine LTS kernel"
	depends="linux-lts"
	devicepkg_subpackage_kernel $startdir $pkgname $subpkgname
}

firmware_amd() {
	install_if="$pkgname=$pkgver-r$pkgrel linux-firmware-amdgpu"

	install -Dm644 "$srcdir"/00-amdgpu-firmware.files \
		-t "$subpkgdir"/usr/share/mkinitfs/files-extra
}
firmware_intel() {
	install_if="$pkgname=$pkgver-r$pkgrel linux-firmware-i915"

	install -Dm644 "$srcdir"/00-i915-firmware.files \
		-t "$subpkgdir"/usr/share/mkinitfs/files-extra
}

sha512sums="
38c53d91a60d0402d4cc5428d65e1e8c26360c481c70b34593b1812c87241c32e91904a3bd31fbfe507f7fdb8b50c909eaad8c4c3a37ca962760567329f7f6ee  00-amdgpu-firmware.files
c17f5c505e0e280a9e51ac1b4264e7703b744fd3831d75ce95f41be4755ae4ccd24b7ca09ba1e236df499a5e748c64a0d2054c9d55d8c8c713fa8c5646ed9a3c  00-i915-firmware.files
04bb2a069251a537071e868164b8bf65882b16f6ff6f161cdc8712ec6948bf89ffa1b979c3e86cf0486f303102d8dd17258b89358d028879cf223bb374a20401  deviceinfo
7697e35721191d34aa3139e2fd1f8aab93751b5f3cc0497f2a18087eb4dc3ab4a45f9cac86230a469b6180bba3bc992bd71389fd59b099a46879e9868b3ebd0d  kernel-cmdline.conf
12d701be4f29b0d68b58156655c66b4cc969b6a449d8ab325c00fb5f8094901fe0105446e0e8c4c0dd7d1e1abf3157f336319c5dd638e4a5723493ad5d22fb60  modules-initfs
"
