# $NetBSD: Makefile.common,v 1.28 2023/12/23 09:50:09 zafer Exp $
#
# used by sysutils/collectd/Makefile
# used by sysutils/collectd-amqp/Makefile
# used by sysutils/collectd-curl/Makefile
# used by sysutils/collectd-dbi/Makefile
# used by sysutils/collectd-dns/Makefile
# used by sysutils/collectd-gmond/Makefile
# used by sysutils/collectd-gps/Makefile
# used by sysutils/collectd-grpc/Makefile
# used by sysutils/collectd-kafka/Makefile
# used by sysutils/collectd-lua/Makefile
# used by sysutils/collectd-memcachec/Makefile
# used by sysutils/collectd-mongodb/Makefile
# used by sysutils/collectd-mysql/Makefile
# used by sysutils/collectd-network/Makefile
# used by sysutils/collectd-notify_desktop/Makefile
# used by sysutils/collectd-notify-email/Makefile
# used by sysutils/collectd-nut/Makefile
# used by sysutils/collectd-openldap/Makefile
# used by sysutils/collectd-pinba/Makefile
# used by sysutils/collectd-postgresql/Makefile
# used by sysutils/collectd-redis/Makefile
# used by sysutils/collectd-riemann/Makefile
# used by sysutils/collectd-rrdtool/Makefile
# used by sysutils/collectd-snmp/Makefile
# used by sysutils/collectd-tokyotyrant/Makefile
# used by sysutils/collectd-varnish/Makefile
# used by sysutils/collectd-virt/Makefile
# used by sysutils/collectd-write_prometheus/Makefile
# used by sysutils/collectd-xen/Makefile
# used by sysutils/collectd-xmms/Makefile
# used by sysutils/collectd-yajl/Makefile
# used by sysutils/p5-collectd/Makefile
# used by sysutils/py-collectd/Makefile

DISTNAME=	collectd-5.12.0
MASTER_SITES=	https://storage.googleapis.com/collectd-tarballs/
CATEGORIES=	sysutils
EXTRACT_SUFX=	.tar.bz2
EXTRACT_USING=	bsdtar

MAINTAINER=	pkgsrc-users@NetBSD.org
HOMEPAGE=	https://www.collectd.org/
LICENSE=	gnu-gpl-v2

GNU_CONFIGURE=		yes
USE_LIBTOOL=		yes
USE_TOOLS+=		autoconf automake pkg-config
USE_LANGUAGES=		c c99 c++

DISTINFO_FILE=		${.CURDIR}/../../sysutils/collectd/distinfo
PATCHDIR=		${.CURDIR}/../../sysutils/collectd/patches

.if !empty(COLLECTD_PACKAGE)
PKGNAME?=		${DISTNAME:S/collectd/collectd-${COLLECTD_PACKAGE}/}

DEPENDS+=		collectd>=${PKGVERSION_NOREV}:../../sysutils/collectd

COLLECTD_PLUGINS?=	${COLLECTD_PACKAGE:S/-/_/}

BUILD_TARGET=		${COLLECTD_PLUGINS:S/$/.la/}

.  for plugin in ${COLLECTD_PLUGINS}
CONFIGURE_ARGS+=	--enable-${plugin}
GENERATE_PLIST+=	${ECHO} "lib/collectd/${plugin}.la";
.  endfor

INSTALLATION_DIRS+=	lib/collectd

.  if ${COLLECTD_PLUGINS} == "perl"
post-install:
.  else
do-install:
.  endif
.  for plugin in ${COLLECTD_PLUGINS}
	cd ${WRKSRC} && ${SETENV} ${INSTALL_ENV} \
		${LIBTOOL} --mode=install ${INSTALL_LIB} ${plugin}.la \
		${DESTDIR}${PREFIX}/lib/collectd/${plugin}.la
.  endfor
.endif

.include "../../mk/bsd.prefs.mk"

BUILD_DEFS+=		VARBASE

# special case for grpc++ below
COLLECTD_LIBS=		aquaero5 atasmart curl dbi dpdk esmtp ganglia	\
			gcrypt gps hiredis iptc iptc jansson jevents	\
			ldap memcached microhttpd mnl modbus mongoc	\
			mosquitto mysql netapp netsnmp netsnmpagent	\
			oping owcapi pcap perl pq pqos protobuf		\
			protobuf-c python qpid-proton rabbitmq rdkafka	\
			routeros rrd sensors slurm ssl statgra		\
			tokyotyrant udev upsclient varnish xenctrl xmms	\
			yajl

CONFIGURE_ARGS+=	--with-cuda=no --with-java=no --with-mic=no	\
			--with-oracle=no --with-perl-bindings=no	\
			--disable-all-plugins

.for lib in ${COLLECTD_LIBS}
CONFIGURE_ARGS+=	--with-lib${lib}=${COLLECTD_LIB.${lib}:Uno}
.endfor
# can't use ENABLE_LIB.grpc++ as a variable name
CONFIGURE_ARGS+=	--with-libgrpc++=${COLLECTD_LIB.grpcpp:Uno}

CONFIGURE_ARGS+=	--disable-werror
CONFIGURE_ARGS+=	--localstatedir=${VARBASE}

CONFIGURE_ARGS.NetBSD+=	ac_cv_func_getfsstat=no
# aarch64 accidentally had this function for a bit.
CONFIGURE_ARGS.NetBSD+=	c_cv_have_htonll=no

CPPFLAGS.SunOS+=	-DSOLARIS2=${OS_VERSION:C/5.//}

SUBST_CLASSES+=		ver
SUBST_MESSAGE.ver=	Fixing canonical version number
SUBST_STAGE.ver=	pre-configure
SUBST_FILES.ver=	configure.ac
SUBST_SED.ver=		-e 's,m4_esyscmd(./version-gen.sh),${PKGVERSION_NOREV},'

pre-configure:
	cd ${WRKSRC} && autoreconf

.include "../../mk/pthread.buildlink3.mk"
