# vim: filetype=automake

VZ_DRIVER_SOURCES = \
	vz/vz_driver.h \
	vz/vz_driver.c \
	vz/vz_utils.c \
	vz/vz_utils.h \
	vz/vz_sdk.h \
	vz/vz_sdk.c \
	$(NULL)


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


if WITH_VZ
noinst_LTLIBRARIES += libvirt_driver_vz_impl.la
libvirt_driver_vz_la_SOURCES =
libvirt_driver_vz_la_LIBADD = \
	libvirt_driver_vz_impl.la \
	libvirt.la \
	$(GLIB_LIBS) \
	../gnulib/lib/libgnu.la \
	$(NULL)
mod_LTLIBRARIES += libvirt_driver_vz.la
libvirt_driver_vz_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
libvirt_driver_vz_impl_la_CFLAGS = \
	-I$(srcdir)/conf \
	-I$(srcdir)/access \
	$(AM_CFLAGS) \
	$(PARALLELS_SDK_CFLAGS) \
	$(LIBNL_CFLAGS) \
	$(NULL)
libvirt_driver_vz_impl_la_SOURCES = $(VZ_DRIVER_SOURCES)
libvirt_driver_vz_impl_la_LIBADD = \
	$(PARALLELS_SDK_LIBS) \
	$(LIBNL_LIBS) \
	$(NULL)

sbin_PROGRAMS += virtvzd

nodist_conf_DATA += vz/virtvzd.conf
augeas_DATA += vz/virtvzd.aug
augeastest_DATA += vz/test_virtvzd.aug
CLEANFILES += vz/virtvzd.aug

virtvzd_SOURCES = $(REMOTE_DAEMON_SOURCES)
virtvzd_CFLAGS = \
       $(REMOTE_DAEMON_CFLAGS) \
       -DDAEMON_NAME="\"virtvzd\"" \
       -DMODULE_NAME="\"vz\"" \
       $(NULL)
virtvzd_LDFLAGS = $(REMOTE_DAEMON_LD_FLAGS)
virtvzd_LDADD = $(REMOTE_DAEMON_LD_ADD)

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

VIRTVZD_UNIT_VARS = \
	$(VIRTD_UNIT_VARS) \
	-e 's|[@]name[@]|Libvirt vz|g' \
	-e 's|[@]service[@]|virtvzd|g' \
	-e 's|[@]sockprefix[@]|virtvzd|g' \
	$(NULL)

virtvzd.service: vz/virtvzd.service.in $(top_builddir)/config.status
	$(AM_V_GEN)$(SED) $(VIRTVZD_UNIT_VARS) $< > $@-t && mv $@-t $@

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

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

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

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

endif WITH_VZ
