# Maintainer (arch): Maxime Gauduin <alucryd@archlinux.org>
# Contributor: mortzu <me@mortzu.de>
# Contributor: fnord0 <fnord0@riseup.net>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: Márcio Silva <coadde@hyperbola.info>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>


# parabola changes and rationale:
#  - no significant change - re-package for linux-libre
#  - pin to kernel versions


# build order:
#   acpi_call-dkms          <- acpi_call-lts
#                              acpi_call
#   linux-libre-lts-headers <- acpi_call-lts
#                              tp_smapi-lts
#   linux-libre-headers     <- acpi_call
#                              tp_smapi
#
# NOTE: It is normally not necessary to edit any of these PKGBUILDs.
# These packages may be built as a batch, with the helper script:
#   'scripts/package-all-acpi_call-tp_smapi'
# Simply edit 'KERNEL_VER' and/or 'KERNEL_LTS_VER' in the helper script.
# It will build any or all of the above packages,
# but only those for which the PKGBUILD '_basekernel' differs,
# update '_basekernel', and commit the changes to VCS, if successful.


_basekernel=6.7.4

pkgname=acpi_call
pkgver=1.2.2
pkgrel=40
pkgrel+=.parabola1.basekernel${_basekernel}
pkgdesc='A linux kernel module that enables calls to ACPI methods through /proc/acpi/call'
pkgdesc+=" (for 'linux-libre')"
url='https://github.com/mkottman/acpi_call'
arch=('x86_64')
arch+=('armv7h' 'i686')
license=('GPL')
makedepends=(linux-libre-headers=${_basekernel} "acpi_call-dkms=$pkgver")
#makedepends+=(gcc=11.2.0) # `dkms` requires the same compiler version which built the kernel
conflicts=('acpi_call-dkms')

build() {
  _kernver=$(</usr/src/linux-libre/version)

  fakeroot dkms build --dkmstree "$srcdir" -m acpi_call/$pkgver -k $_kernver
}

package() {
  depends=(linux-libre=${_basekernel})

  _kernver=$(</usr/src/linux-libre/version)

  install -Dt "$pkgdir/usr/lib/modules/$_kernver/extramodules" -m0644 \
    acpi_call/${pkgver}/$_kernver/$CARCH/module/*

  # compress each module individually
  find "$pkgdir" -name '*.ko' -exec xz -T1 {} +

  echo acpi_call | install -Dm644 /dev/stdin "$pkgdir/usr/lib/modules-load.d/$pkgname.conf"

  mkdir -p "$pkgdir/usr/share"
  cp -a /usr/share/acpi_call "$pkgdir/usr/share/$pkgname"
}
