# $OpenBSD: Makefile,v 1.53 2015/11/29 15:50:20 ajacoutot Exp $

COMMENT =	GNU system administration tool for networks

DISTNAME =	cfengine-3.7.2

SHARED_LIBS +=  promises	0.0 # 1.0
CATEGORIES =	sysutils
HOMEPAGE =	http://cfengine.com/

MAINTAINER =	Rodrigo Mosconi <openbsd@mosconi.mat.br>

# GPLv3 only
PERMIT_PACKAGE_CDROM =	Yes

MASTER_SITES =	https://cfengine-package-repos.s3.amazonaws.com/tarballs/

CFENGINE_BASE =		/var/cfengine
CFENGINE_EXAMPLES =	${PREFIX}/share/examples/cfengine
SUBST_VARS +=		CFENGINE_BASE CFENGINE_EXAMPLES

PSEUDO_FLAVORS =	fhs
FLAVORS =		pgsql mysql xml yaml virt
FLAVOR ?=

WANTLIB =		c crypto m pcre pthread qdbm z
SEPARATE_BUILD = 	Yes
CONFIGURE_STYLE =	gnu
USE_GMAKE =		Yes
MODULES =		converters/libiconv
LIB_DEPENDS =		databases/qdbm \
			devel/pcre
CONFIGURE_ENV +=	CPPFLAGS="-I${LOCALBASE}/include" \
			LDFLAGS="-L${LOCALBASE}/lib"
CONFIGURE_ARGS =	--with-openssl=/usr \
			--with-pcre \
			--with-qdbm \
			--without-libacl \
			--with-workdir=${CFENGINE_BASE}
MAKE_FLAGS +=		examplesdir="${CFENGINE_EXAMPLES}" \
			masterfilesdir="${CFENGINE_EXAMPLES}/CoreBase"

.if ${FLAVOR:Mpgsql}
WANTLIB +=		pq
CONFIGURE_ARGS +=	--with-postgresql
LIB_DEPENDS +=		databases/postgresql
.else
CONFIGURE_ARGS +=	--without-postgresql
.endif

.if ${FLAVOR:Mmysql}
WANTLIB +=		mysqlclient_r
CONFIGURE_ARGS +=	--with-mysql
LIB_DEPENDS +=		databases/mariadb
.else
CONFIGURE_ARGS +=	--without-mysql
.endif

.if ${FLAVOR:Mxml}
WANTLIB +=              xml2
CONFIGURE_ARGS +=       --with-libxml2
LIB_DEPENDS +=          textproc/libxml
.else
CONFIGURE_ARGS +=       --without-libxml2
.endif

.if ${FLAVOR:Myaml}
WANTLIB +=              yaml
CONFIGURE_ARGS +=       --with-libyaml
LIB_DEPENDS +=          devel/libyaml
.else
CONFIGURE_ARGS +=       --without-libyaml
.endif

.if ${FLAVOR:Mvirt}
WANTLIB +=              virt
CONFIGURE_ARGS +=       --with-libvirt
LIB_DEPENDS +=          sysutils/libvirt
.else
CONFIGURE_ARGS +=       --without-libvirt
.endif

.if ${FLAVOR:Mfhs}
CONFIGURE_ARGS +=       --enable-fhs
.else
CONFIGURE_ARGS +=       --disable-fhs
.endif

# tests not yet working
NO_TEST =		Yes
# also note some formatting errors with manpages (e.g. "You can think
# of.B cfengine as..." and poor formatting in INFORMATION sections;
# these are present with either mandoc or groff.

post-extract:
	perl -i -pe \
		's|^sbin_PROGRAMS.*rpmvercmp||;' \
		${WRKDIST}/ext/Makefile.in

post-install:
	${INSTALL_PROGRAM_DIR} ${WRKINST}${CFENGINE_BASE}/bin
.for i in cf-agent cf-execd cf-key cf-monitord cf-promises cf-report \
          cf-runagent cf-serverd
	ln -s ${TRUEPREFIX}/sbin/$i ${WRKINST}${CFENGINE_BASE}/bin/
.endfor

.include <bsd.port.mk>
