# Template file for 'netdata'
pkgname=netdata
version=1.37.1
revision=1
build_style=gnu-configure
build_helper=qemu
configure_args="--with-user=_netdata ac_cv_file_externaldeps_libbpf_libbpf_a=no
 $(vopt_if cloud --enable-cloud --disable-cloud) $(vopt_if ipmi --enable-plugin-freeipmi)
 $(vopt_if xen --enable-plugin-xenstat) $(vopt_if cups --enable-plugin-cups)"
hostmakedepends="pkg-config autoconf automake $(vopt_if cloud "protobuf protobuf-devel")"
makedepends="json-c-devel libcap-devel liblz4-devel libmnl-devel
 libnetfilter_acct-devel openssl-devel libuuid-devel libuv-devel zlib-devel
 snappy-devel $(vopt_if cloud protobuf-devel) $(vopt_if ipmi freeipmi-devel)
 $(vopt_if xen "xen-devel yajl-devel") $(vopt_if cups cups-devel)"
depends="libcap-progs"
short_desc="Real-time performance monitoring, done right"
maintainer="Michael Aldridge <maldridge@voidlinux.org>"
license="GPL-3.0-or-later"
homepage="https://www.netdata.cloud/"
distfiles="https://github.com/netdata/netdata/releases/download/v${version}/netdata-v${version}.tar.gz"
checksum=2caa042d43ca61007a61294a5ececa037d83a1973bd38032233760341eb1706b
python_version=3
make_dirs="
 /var/lib/netdata          0755 _netdata _netdata
 /var/lib/netdata/registry 0755 _netdata root
 /var/cache/netdata        0755 _netdata _netdata
 /var/log/netdata          0755 _netdata _netdata
"

build_options="cloud ipmi cups xen"
desc_option_cloud="Enable support for netdata cloud"
desc_option_ipmi="Enable IPMI plugin"
desc_option_xen="Enable xenstat plugin"
build_options_default="cloud"

system_accounts="_netdata"
conf_files="/etc/${pkgname}/*.conf"

if [ "$XBPS_TARGET_NO_ATOMIC8" ]; then
	makedepends+=" libatomic-devel"
	CFLAGS+=" -DLINK_ATOMIC"
	export LIBS="-latomic"
fi

pre_configure() {
	if [ "$CROSS_BUILD" ]; then
		sed -i "s|	\$(builddir)/judyltablesgen\$(EXEEXT)|	qemu-${XBPS_TARGET_QEMU_MACHINE}-static \$(builddir)/judyltablesgen\$(EXEEXT)|g" Makefile.am
	fi

	autoreconf -ivf
}

post_install() {
	vsv netdata
	vcopy ${FILESDIR}/netdata.conf etc/$pkgname/
}

netdata-plugins-python_package() {
	short_desc+=" - Python Plugins"
	depends="${sourcepkg}>=${version}_${revision} python3"
	pkg_install() {
		vmove usr/libexec/netdata/plugins.d/python.d.plugin
		vmove usr/libexec/netdata/python.d
		vmove etc/netdata/python.d
	}
}
