# vim: filetype=automake

SECRET_DRIVER_SOURCES = \
	secret/secret_driver.h \
	secret/secret_driver.c \
	$(NULL)

SECRET_UTIL_SOURCES = \
	secret/secret_util.h \
	secret/secret_util.c \
	$(NULL)


DRIVER_SOURCE_FILES += $(SECRET_DRIVER_SOURCES)
STATEFUL_DRIVER_SOURCE_FILES += $(SECRET_DRIVER_SOURCES)
EXTRA_DIST += \
	$(SECRET_DRIVER_SOURCES) \
	$(SECRET_UTIL_SOURCES) \
	$(NULL)

noinst_LTLIBRARIES += libvirt_secret.la
libvirt_la_BUILT_LIBADD += libvirt_secret.la
libvirt_secret_la_CFLAGS = $(AM_CFLAGS)
libvirt_secret_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_secret_la_SOURCES = $(SECRET_UTIL_SOURCES)

if WITH_SECRETS
mod_LTLIBRARIES += libvirt_driver_secret.la
libvirt_driver_secret_la_CFLAGS = \
	-I$(srcdir)/access \
	-I$(srcdir)/conf \
	$(AM_CFLAGS) \
	$(NULL)
libvirt_driver_secret_la_LIBADD = \
	libvirt.la \
	$(GLIB_LIBS) \
	../gnulib/lib/libgnu.la \
	$(NULL)
libvirt_driver_secret_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
libvirt_driver_secret_la_SOURCES = $(SECRET_DRIVER_SOURCES)

sbin_PROGRAMS += virtsecretd

nodist_conf_DATA += secret/virtsecretd.conf
augeas_DATA += secret/virtsecretd.aug
augeastest_DATA += secret/test_virtsecretd.aug
CLEANFILES += secret/virtsecretd.aug

virtsecretd_SOURCES = $(REMOTE_DAEMON_SOURCES)
virtsecretd_CFLAGS = \
	$(REMOTE_DAEMON_CFLAGS) \
	-DDAEMON_NAME="\"virtsecretd\"" \
	-DMODULE_NAME="\"secret\"" \
	$(NULL)
virtsecretd_LDFLAGS = $(REMOTE_DAEMON_LD_FLAGS)
virtsecretd_LDADD = $(REMOTE_DAEMON_LD_ADD)

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

VIRTSECRETD_UNIT_VARS = \
	$(VIRTD_UNIT_VARS) \
	-e 's|[@]name[@]|Libvirt secret|g' \
	-e 's|[@]service[@]|virtsecretd|g' \
	-e 's|[@]sockprefix[@]|virtsecretd|g' \
	$(NULL)

virtsecretd.service: secret/virtsecretd.service.in \
		$(top_builddir)/config.status
	$(AM_V_GEN)$(SED) $(VIRTSECRETD_UNIT_VARS) $< > $@-t && mv $@-t $@

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

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

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

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

endif WITH_SECRETS
