# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Roman Kyrylych <roman@archlinux.org>
# Contributor: Damir Perisa <damir@archlinux.org>

pkgname=hddtemp
_pkgver=0.3-beta15
_patchver="$_pkgver-54"
pkgver="${_patchver//-/.}"
pkgrel=5
pkgdesc='Gives you the temperature of your hard drive by reading S.M.A.R.T. information'
arch=(x86_64 aarch64 riscv)
license=(GPL)
url='https://savannah.nongnu.org/projects/hddtemp/'
backup=('etc/hddtemp.db')
_archive="$pkgname-$_pkgver"
source=("https://download.savannah.gnu.org/releases/$pkgname/$pkgname-$_pkgver.tar.bz2"
        "https://deb.debian.org/debian/pool/main/h/$pkgname/${pkgname}_$_patchver.diff.gz"
        "$pkgname.service")
sha256sums=('618541584054093d53be8a2d9e81c97174f30f00af91cb8700a97e442d79ef5b'
            '9164a2de2e91310bf98d1f88cc25cb10ec83db5219e1958793492b1eb003733c'
            '7f6fda4379630a21a8014d8f471eef6451fa15d73df32ec90a85d6a3f9d0c7d4')

prepare() {
	cd "$_archive"
	patch -p1 -i "../${pkgname}_$_patchver.diff"
	autoreconf -fvi # enable RISC-V
}

build() {
	cd "$_archive"
	./configure \
		--prefix=/usr \
		--sbindir=/usr/bin \
		--mandir=/usr/share/man \
		--with-db-path="/etc/hddtemp.db"
	make
}

package() {
	cd "$_archive"
	make DESTDIR="$pkgdir" install
	install -Dm0644 -t "$pkgdir/etc/" debian/hddtemp.db
	install -Dm0644 -t "$pkgdir/usr/lib/systemd/system/" "../$pkgname.service"
}
