# vim: filetype=automake

NWFILTER_XML_FILES = $(wildcard $(srcdir)/nwfilter/xml/*.xml)

EXTRA_DIST += $(NWFILTER_XML_FILES)

NWFILTER_DRIVER_SOURCES = \
	nwfilter/nwfilter_driver.h \
	nwfilter/nwfilter_driver.c \
	nwfilter/nwfilter_tech_driver.h \
	nwfilter/nwfilter_gentech_driver.c \
	nwfilter/nwfilter_gentech_driver.h \
	nwfilter/nwfilter_dhcpsnoop.c \
	nwfilter/nwfilter_dhcpsnoop.h \
	nwfilter/nwfilter_ebiptables_driver.c \
	nwfilter/nwfilter_ebiptables_driver.h \
	nwfilter/nwfilter_learnipaddr.c \
	nwfilter/nwfilter_learnipaddr.h \
	$(NULL)

DRIVER_SOURCE_FILES += $(NWFILTER_DRIVER_SOURCES)
STATEFUL_DRIVER_SOURCE_FILES += $(NWFILTER_DRIVER_SOURCES)
EXTRA_DIST += $(NWFILTER_DRIVER_SOURCES)

if WITH_NWFILTER

nwfilterxmldir = $(sysconfdir)/libvirt/nwfilter
nwfilterxml_DATA = $(NWFILTER_XML_FILES)

noinst_LTLIBRARIES += libvirt_driver_nwfilter_impl.la
libvirt_driver_nwfilter_la_SOURCES =
libvirt_driver_nwfilter_la_LIBADD = libvirt_driver_nwfilter_impl.la
mod_LTLIBRARIES += libvirt_driver_nwfilter.la
libvirt_driver_nwfilter_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
libvirt_driver_nwfilter_impl_la_CFLAGS = \
	$(LIBPCAP_CFLAGS) \
	$(LIBNL_CFLAGS) \
	$(DBUS_CFLAGS) \
	-I$(srcdir)/access \
	-I$(srcdir)/conf \
	$(AM_CFLAGS) \
	$(NULL)
libvirt_driver_nwfilter_impl_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_nwfilter_impl_la_LIBADD = \
	libvirt.la \
	$(LIBPCAP_LIBS) \
	$(LIBNL_LIBS) \
	$(DBUS_LIBS) \
	$(GLIB_LIBS) \
	../gnulib/lib/libgnu.la \
	$(NULL)
libvirt_driver_nwfilter_impl_la_SOURCES = $(NWFILTER_DRIVER_SOURCES)

sbin_PROGRAMS += virtnwfilterd

nodist_conf_DATA += nwfilter/virtnwfilterd.conf
augeas_DATA += nwfilter/virtnwfilterd.aug
augeastest_DATA += nwfilter/test_virtnwfilterd.aug
CLEANFILES += nwfilter/virtnwfilterd.aug

virtnwfilterd_SOURCES = $(REMOTE_DAEMON_SOURCES)
virtnwfilterd_CFLAGS = \
       $(REMOTE_DAEMON_CFLAGS) \
       -DDAEMON_NAME="\"virtnwfilterd\"" \
       -DMODULE_NAME="\"nwfilter\"" \
       $(NULL)
virtnwfilterd_LDFLAGS = $(REMOTE_DAEMON_LD_FLAGS)
virtnwfilterd_LDADD = $(REMOTE_DAEMON_LD_ADD)

SYSTEMD_UNIT_FILES += \
	virtnwfilterd.service \
	virtnwfilterd.socket \
	virtnwfilterd-ro.socket \
	virtnwfilterd-admin.socket \
	$(NULL)
SYSTEMD_UNIT_FILES_IN += \
	nwfilter/virtnwfilterd.service.in \
	$(NULL)

VIRTNWFILTERD_UNIT_VARS = \
	$(VIRTD_UNIT_VARS) \
	-e 's|[@]name[@]|Libvirt nwfilter|g' \
	-e 's|[@]service[@]|virtnwfilterd|g' \
	-e 's|[@]sockprefix[@]|virtnwfilterd|g' \
	$(NULL)

virtnwfilterd.service: nwfilter/virtnwfilterd.service.in \
		$(top_builddir)/config.status
	$(AM_V_GEN)$(SED) $(VIRTNWFILTERD_UNIT_VARS) $< > $@-t && mv $@-t $@

virtnwfilter%.socket: remote/libvirt%.socket.in \
		$(top_builddir)/config.status
	$(AM_V_GEN)$(SED) $(VIRTNWFILTERD_UNIT_VARS) $< > $@-t && mv $@-t $@

nwfilter/virtnwfilterd.conf: remote/libvirtd.conf.in
	$(AM_V_GEN)$(SED) \
		-e '/[@]CUT_ENABLE_IP[@]/,/[@]END[@]/d' \
		-e 's/[@]DAEMON_NAME[@]/virtnwfilterd/' \
		$< > $@

nwfilter/virtnwfilterd.aug: remote/libvirtd.aug.in
	$(AM_V_GEN)$(SED) \
		-e '/[@]CUT_ENABLE_IP[@]/,/[@]END[@]/d' \
		-e 's/[@]DAEMON_NAME[@]/virtnwfilterd/' \
		-e 's/[@]DAEMON_NAME_UC[@]/Virtnwfilterd/' \
		$< > $@

nwfilter/test_virtnwfilterd.aug: remote/test_libvirtd.aug.in \
		nwfilter/virtnwfilterd.conf $(AUG_GENTEST_SCRIPT)
	$(AM_V_GEN)$(AUG_GENTEST) nwfilter/virtnwfilterd.conf \
		$(srcdir)/remote/test_libvirtd.aug.in | \
		$(SED) \
		-e '/[@]CUT_ENABLE_IP[@]/,/[@]END[@]/d' \
		-e 's/[@]DAEMON_NAME[@]/virtnwfilterd/' \
		-e 's/[@]DAEMON_NAME_UC[@]/Virtnwfilterd/' \
		> $@ || rm -f $@

endif WITH_NWFILTER
