# Maintainer: Jelle van der Waa <jelle@vdwaa.nl>

pkgname=gsmartcontrol
pkgver=1.1.3
pkgrel=3
pkgdesc="A graphical user interface for the smartctl hard disk drive health inspection tool."
arch=('x86_64')
url="https://gsmartcontrol.sourceforge.io/home/"
license=('GPL')
depends=('smartmontools' 'gtkmm3' 'xorg-xmessage' 'hicolor-icon-theme')
optdepends=('polkit: to run gsmartcontrol directly from menu'
            'xterm: to update the drive database')
source=("https://sourceforge.net/projects/gsmartcontrol/files/${pkgver}/gsmartcontrol-${pkgver}.tar.bz2"
        org.archlinux.pkexec.gsmartcontrol.policy
        gsmartcontrol_polkit)
md5sums=('6953ed6f90b2551ebdb1ae2470f4acdc'
         '503989a7e6a9a287d81e91243d03f162'
         '33bdda04d8db1525f2507485f3f2a663')

prepare() {
	cd "${srcdir}/${pkgname}-${pkgver}"

        # Modify desktop file
        sed -i "s|^Exec=.*|Exec="@prefix@/bin/gsmartcontrol_polkit"|" \
                data/gsmartcontrol.desktop.in
}

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	CXXFLAGS+=' -std=c++11' ./configure --prefix=/usr --sbindir=/usr/bin/
	make 
}

check() {
	cd "${srcdir}/${pkgname}-${pkgver}"
        make check
}

package() {
	cd "${srcdir}/${pkgname}-${pkgver}"

	make DESTDIR=${pkgdir} install

        # Install launcher script
        install -m755 ${srcdir}/gsmartcontrol_polkit \
                "${pkgdir}/usr/bin/gsmartcontrol_polkit"

        # Install policy file
        install -Dm644 ${srcdir}/org.archlinux.pkexec.gsmartcontrol.policy \
                "${pkgdir}/usr/share/polkit-1/actions/org.archlinux.pkexec.gsmartcontrol.policy"
}
