EAPI=8

DESCRIPTION="Dockapp for laptop power status and control (APM/ACPI/CPUFreq)"
HOMEPAGE="https://sourceforge.net/projects/wmlaptop/"
SRC_URI="mirror://sourceforge/wmlaptop/${P}.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~ia64 ~ppc ~ppc64 ~sparc ~x86"
IUSE="longrun acpi"

DEPEND="x11-libs/libX11
  x11-libs/libXext"
RDEPEND="${DEPEND}
  acpi? ( sys-power/acpi )
  virtual/logger"

src_prepare() {
  default
  # Optionally patch or sed Makefile to change install path
  sed -i \
    -e "s|^INSTALLDIR *=.*|INSTALLDIR = /usr/bin|" \
    Makefile || die
}

src_compile() {
  if use longrun; then
    emake -f Makefile.Longrun
  else
    emake
  fi
}

src_install() {
  dobin src/wmlaptop
  dodoc README README.IT INSTALL CHANGELOG BUGS AUTHORS THANKS LICENSE
  if [[ -f wmlaptop.conf.example ]]; then
    dodoc wmlaptop.conf.example
  fi
}

pkg_postinst() {
  elog "Frequency limits and other defaults can be stored in /etc/wmlaptop.conf"
  elog "or in \$XDG_CONFIG_HOME/wmlaptop/wmlaptop.conf. See"
  elog "/usr/share/doc/${PF}/wmlaptop.conf.example for the available settings."
  elog ""
  elog "To allow wmlaptop to shut down the system as a regular user, configure"
  elog "doas or sudo for /sbin/shutdown and select the command in the"
  elog "configuration file, for example:"
  elog ""
  elog "  shutdown_command = doas /sbin/shutdown"
  elog ""
  elog "or:"
  elog ""
  elog "  shutdown_command = sudo /sbin/shutdown"
}