# Maintainer: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Gerhard Brauer <gerhard.brauer@web.de>

pkgname=collectd
pkgver=5.9.1
pkgrel=1
pkgdesc='Daemon which collects system performance statistics periodically'
url='https://collectd.org/'
arch=('x86_64')
license=('GPL')

optdepends=('curl: apache, ascent, curl, nginx, and write_http plugins'
            'libdbi: dbi plugin'
            'libesmtp: notify_email plugin'
            'libgcrypt: encryption and authentication for network plugin'
            'libmemcached: memcachec plugin'
            'mariadb-libs: mysql plugin'
            'systemd-libs: UdevNameAttr option'
            'iproute2: netlink plugin'
            'net-snmp: snmp plugin'
            'libnotify: notify_desktop plugin'
            'openipmi: ipmi plugin'
            'liboping: ping plugin'
            'libpcap: dns plugin'
            'perl: perl plugin'
            'postgresql-libs: postgresql plugin'
            'python: python plugin'
            'rrdtool: rrdtool and rrdcached plugins'
            'lm_sensors: lm_sensors and sensors plugins'
            'libvirt: libvirt plugin'
            'libxml2: ascent and libvirt plugins'
            'yajl: curl_json plugin'
            'libatasmart: smart plugin'
            'lvm2: lvm plugin'
            'protobuf-c: write_riemann plugin'
            'mosquitto: MQTT plugin'
            'libmicrohttpd: prometheus plugin'
            'librabbitmq-c: amqp plugin')

makedepends=(${optdepends[@]%:*})
depends=('libltdl' 'iptables' 'libnsl')

source=("https://github.com/${pkgname}/${pkgname}/archive/${pkgname}-${pkgver}.tar.gz"
        'fix-failed-values-string.patch'
        'service')
sha256sums=('51fb72f51489cb33fa4ddd65b757d81d77c13a33b36f031d6ce2835a2eec9adb'
            'd9dca57380e69c8c10775d4e24fc40fd1bf838f7fd7cbbc9e1118e47f76ba0fe'
            'e45e261146563b0bf6967c669dff7ac2400f066f0eb4c022ac3fdb0ccadca2f9')

backup=('etc/collectd.conf')

prepare() {
	cd "${srcdir}/${pkgname}-${pkgname}-${pkgver}"
	./build.sh
	sed 's/ -Werror//g' -i configure
	patch -p1 -i ../fix-failed-values-string.patch
}

build() {
	cd "${srcdir}/${pkgname}-${pkgname}-${pkgver}"
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--sbindir=/usr/bin \
		--with-python=/usr/bin/python \
		--with-perl-bindings='INSTALLDIRS=vendor'
	make all
}

package() {
	cd "${srcdir}/${pkgname}-${pkgname}-${pkgver}"
	make DESTDIR="${pkgdir}" install
	rmdir "${pkgdir}/var/run" # FS#30201
	install -Dm644 ../service "${pkgdir}"/usr/lib/systemd/system/collectd.service
	install -Dm644 contrib/collectd2html.pl "${pkgdir}"/usr/share/collectd/collectd2html.pl
}
