# vim: filetype=automake

LIBXL_DRIVER_SOURCES = \
	libxl/xenxs_private.h \
	libxl/xen_common.c \
	libxl/xen_common.h \
	libxl/xen_xl.c \
	libxl/xen_xl.h \
	libxl/xen_xm.c \
	libxl/xen_xm.h \
	libxl/libxl_conf.c \
	libxl/libxl_conf.h \
	libxl/libxl_capabilities.c \
	libxl/libxl_capabilities.h \
	libxl/libxl_domain.c \
	libxl/libxl_domain.h \
	libxl/libxl_driver.c \
	libxl/libxl_driver.h \
	libxl/libxl_logger.c \
	libxl/libxl_logger.h \
	libxl/libxl_migration.c \
	libxl/libxl_migration.h \
	$(NULL)

DRIVER_SOURCE_FILES += $(LIBXL_DRIVER_SOURCES)
STATEFUL_DRIVER_SOURCE_FILES += $(LIBXL_DRIVER_SOURCES)
EXTRA_DIST += \
	$(LIBXL_DRIVER_SOURCES) \
	$(NULL)

if WITH_LIBXL
noinst_LTLIBRARIES += libvirt_driver_libxl_impl.la
libvirt_driver_libxl_la_SOURCES =
libvirt_driver_libxl_la_LIBADD = \
	libvirt_driver_libxl_impl.la \
	libvirt.la \
	$(GLIB_LIBS) \
	../gnulib/lib/libgnu.la \
	$(NULL)
mod_LTLIBRARIES += libvirt_driver_libxl.la
libvirt_driver_libxl_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)

libvirt_driver_libxl_impl_la_CFLAGS = \
	$(LIBXL_CFLAGS) \
	$(LIBXML_CFLAGS) \
	-I$(srcdir)/access \
	-I$(srcdir)/conf \
	-I$(srcdir)/secret \
	$(AM_CFLAGS) \
	$(NULL)
libvirt_driver_libxl_impl_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_libxl_impl_la_LIBADD = \
	$(LIBXL_LIBS) \
	$(LIBXML_LIBS) \
	$(NULL)
libvirt_driver_libxl_impl_la_SOURCES = $(LIBXL_DRIVER_SOURCES)

sbin_PROGRAMS += virtxend

nodist_conf_DATA += libxl/virtxend.conf
augeas_DATA += libxl/virtxend.aug
augeastest_DATA += libxl/test_virtxend.aug
CLEANFILES += libxl/virtxend.aug

virtxend_SOURCES = $(REMOTE_DAEMON_SOURCES)
virtxend_CFLAGS = \
       $(REMOTE_DAEMON_CFLAGS) \
       -DDAEMON_NAME="\"virtxend\"" \
       -DMODULE_NAME="\"libxl\"" \
       $(NULL)
virtxend_LDFLAGS = $(REMOTE_DAEMON_LD_FLAGS)
virtxend_LDADD = $(REMOTE_DAEMON_LD_ADD)

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

LIBXL_UNIT_COND = ConditionPathExists=/proc/xen/capabilities
LIBXL_UNIT_CONFLICT = Conflicts=$(LIBVIRTD_SOCKET_UNIT_FILES)

VIRTXEND_UNIT_VARS = \
	$(COMMON_UNIT_VARS) \
	-e 's|[@]deps[@]|$(LIBXL_UNIT_CONFLICT)\n$(LIBXL_UNIT_COND)|g' \
	-e 's|[@]name[@]|Libvirt libxl|g' \
	-e 's|[@]service[@]|virtxend|g' \
	-e 's|[@]sockprefix[@]|virtxend|g' \
	$(NULL)

virtxend.service: libxl/virtxend.service.in $(top_builddir)/config.status
	$(AM_V_GEN)$(SED) $(VIRTXEND_UNIT_VARS) $< > $@-t && mv $@-t $@

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

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

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

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

conf_DATA += libxl/libxl.conf
augeas_DATA += libxl/libvirtd_libxl.aug
augeastest_DATA += libxl/test_libvirtd_libxl.aug

libxl/test_libvirtd_libxl.aug: libxl/test_libvirtd_libxl.aug.in \
		$(srcdir)/libxl/libxl.conf $(AUG_GENTEST_SCRIPT)
	$(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/libxl/libxl.conf $< > $@

INSTALL_DATA_DIRS += libxl

install-data-libxl:
	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/libxl"
	$(MKDIR_P) "$(DESTDIR)$(runstatedir)/libvirt/libxl"
	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/log/libvirt/libxl"

uninstall-data-libxl:
	rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt/libxl" ||:
	rmdir "$(DESTDIR)$(runstatedir)/libvirt/libxl" ||:
	rmdir "$(DESTDIR)$(localstatedir)/log/libvirt/libxl" ||:

endif WITH_LIBXL

EXTRA_DIST += \
	libxl/libxl.conf \
	libxl/libvirtd_libxl.aug \
	libxl/test_libvirtd_libxl.aug.in \
	$(NULL)
