# Maintainer: Scott Jones <scottajones@gmail.com>
# Ported from omarchy-mac/omarchy-pkgs-aarch64 pkgbuilds/omarchy-mac at 02ed7b250f7edcf7c5f748acaf7b21ef0a764e9d.

pkgname=omarchy-mac
# pkgver matches packages/omarchy-mac/version at _commit. Bump pkgrel to re-pin
# or rebuild the same add-on version; reset it to 1 when pkgver increases.
pkgver=0.1.0
pkgrel=6
pkgdesc='Apple Silicon configuration and support services for Omarchy'
arch=('aarch64')
groups=('omarchy-platform-apple-silicon')
url='https://github.com/omacom/omarchy-mac'
license=('MIT')
makedepends=('git' 'findutils')
checkdepends=('diffutils' 'python' 'systemd')
# An exact quattro-upstream commit, never a branch.
_commit=ff7ce0d4dfaea9e17270b3061e642ee095b7b265
source=("omarchy-mac::git+https://github.com/omacom/omarchy-mac.git#commit=${_commit}")
sha256sums=('7530c284cd323d451540205c0a677c4e187070f0b8c4081a2e85f487f2ebb985')

prepare() {
  # Tests and staging must not be able to read the surrounding desktop source.
  rm -rf "$srcdir/addon"
  cp -a "$srcdir/omarchy-mac/packages/omarchy-mac" "$srcdir/addon"
  [[ $(<"$srcdir/addon/version") == "$pkgver" ]]
  [[ $(git -C "$srcdir/omarchy-mac" rev-parse HEAD) == "$_commit" ]]
}

check() {
  "$srcdir/addon/test/all"
}

package() {
  # Runtime-only: the builder does not need the Omarchy desktop to stage or
  # test the add-on.
  depends=('omarchy' 'bash' 'coreutils' 'diffutils' 'grep' 'sed' 'gawk' 'systemd' 'pciutils' 'kmod'
           'mkinitcpio' 'networkmanager' 'iwd' 'python' 'pipewire' 'pipewire-pulse' 'libpulse' 'wireplumber'
           'asahi-audio' 'alsa-ucm-conf-asahi' 'rtkit' 'pipewire-alsa')

  "$srcdir/addon/install" "$pkgdir"
  install -Dm644 "$srcdir/addon/README.md" "$pkgdir/usr/share/doc/$pkgname/README.md"
  install -Dm644 "$srcdir/addon/ORIGINS.md" "$pkgdir/usr/share/doc/$pkgname/ORIGINS.md"
  printf '%s\n' "$_commit" >"$pkgdir/usr/share/omarchy-mac/source-revision"
}
