# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: Manuel Hüsers <aur@huesers.de>
# Contributor: Iwan Timmer <irtimmer@gmail.com>
# Contributor: Timothée Ravier <tim at siosm dot fr>
# Contributor: Tom <reztho at archlinux dot org>

pkgbase=tuned-cachy
pkgname=("${pkgbase}" "${pkgbase}-ppd")
pkgver=2.27.0
pkgrel=2
pkgdesc='Daemon that performs monitoring and adaptive configuration of devices in the system'
arch=('any')
url="https://github.com/redhat-performance/tuned"
license=('GPL-2.0-or-later')
depends=('ethtool' 'gawk' 'hdparm' 'polkit' 'perf' 'python-configobj'
         'python-dbus' 'python-gobject' 'python-linux-procfs' 'python-pyudev')
makedepends=('desktop-file-utils' git)
source=("git+https://github.com/cachyos/tuned#commit=8e1829346cae8b3b7aec02516556c4179bcfc4d2")
sha512sums=('aca94f2eca7f6f5423861382e89e2fd579cfd7925510d19ef5e29558f5d35734b3a8a35ceae397832204387dd57054760fbb21ab7641678fd65e367e21706712')

prepare() {
  cd "tuned"

  sed -i 's|/sbin/|/bin/|g' tuned.service tuned-gui.py tuned-gui.desktop tuned/ppd/tuned-ppd.service
}

package_tuned-cachy() {
  provides=('tuned')
  conflicts=('tuned')
  optdepends=(
    'virt-what: Virtual machine detection'
    'systemtap: Detailed system monitoring'
    'tuned-cachy-ppd: power-profiles-daemon api translation'
    'wireless_tools: Wireless device power management'
    'x86_energy_perf_policy: Energy Performance Bias (EPB) support')
  backup=(
    'etc/tuned/active_profile'
    'etc/tuned/bootcmdline'
    'etc/tuned/cpu-partitioning-powersave-variables.conf'
    'etc/tuned/cpu-partitioning-variables.conf'
    'etc/tuned/post_loaded_profile'
    'etc/tuned/profile_mode'
    'etc/tuned/realtime-variables.conf'
    'etc/tuned/realtime-virtual-guest-variables.conf'
    'etc/tuned/realtime-virtual-host-variables.conf'
    'etc/tuned/tuned-main.conf')

  cd "tuned"

  make DESTDIR="${pkgdir}" SBINDIR="/usr/bin" LIBEXECDIR="/usr/lib" install
  rm -rv "${pkgdir}"/{run,var}

  python -m compileall -d /usr/lib "${pkgdir}/usr/lib"
  python -O -m compileall -d /usr/lib "${pkgdir}/usr/lib"
}

package_tuned-cachy-ppd() {
  pkgdesc='Daemon that allows applications to easily transition to TuneD from power-profiles-daemon (PPD)'
  depends=('tuned-cachy' 'python-pyinotify')
  provides=('tuned-ppd' 'power-profiles-daemon')
  conflicts=('tuned-ppd' 'power-profiles-daemon')
  backup=('etc/tuned/ppd.conf')

  cd "tuned"

  make DESTDIR="${pkgdir}" SBINDIR="/usr/bin" LIBEXECDIR="/usr/lib" install-ppd
}
