# vim: filetype=automake

LOCK_DRIVER_SOURCES = \
	locking/lock_manager.c \
	locking/lock_manager.h \
	locking/lock_driver.h \
	locking/lock_driver_nop.h \
	locking/lock_driver_nop.c \
	locking/domain_lock.h \
	locking/domain_lock.c \
	$(NULL)

LOCK_DRIVER_SANLOCK_SOURCES = \
	locking/lock_driver_sanlock.c

LOCK_DRIVER_SANLOCK_HELPER_SOURCES = \
	locking/sanlock_helper.c

LOCK_PROTOCOL_GENERATED = \
	locking/lock_protocol.h \
	locking/lock_protocol.c \
	$(NULL)

LOCK_DAEMON_GENERATED = \
	locking/lock_daemon_dispatch_stubs.h
	$(NULL)

LOCK_PROTOCOL = $(srcdir)/locking/lock_protocol.x

LOCK_DRIVER_LOCKD_SOURCES = \
	locking/lock_driver_lockd.c \
	locking/lock_driver_lockd.h \
	$(NULL)

LOCK_DAEMON_SOURCES = \
	locking/lock_daemon.h \
	locking/lock_daemon.c \
	locking/lock_daemon_config.h \
	locking/lock_daemon_config.c \
	locking/lock_daemon_dispatch.c \
	locking/lock_daemon_dispatch.h \
	$(NULL)

EXTRA_DIST += \
	$(LOCK_PROTOCOL) \
	$(LOCK_PROTOCOL_GENERATED) \
	$(LOCK_DAEMON_GENERATED) \
	$(LOCK_DAEMON_SOURCES) \
	$(LOCK_DRIVER_LOCKD_SOURCES) \
	$(LOCK_DRIVER_SOURCES) \
	locking/sanlock.conf \
	locking/libvirt_sanlock.aug \
	locking/test_libvirt_sanlock.aug.in \
	locking/lockd.conf \
	locking/libvirt_lockd.aug \
	locking/test_libvirt_lockd.aug.in \
        locking/virtlockd.aug \
        locking/virtlockd.conf \
        locking/test_virtlockd.aug.in \
	$(NULL)

BUILT_SOURCES += \
	$(LOCK_PROTOCOL_GENERATED) \
	$(LOCK_DAEMON_GENERATED) \
	$(NULL)

MAINTAINERCLEANFILES += \
	$(LOCK_PROTOCOL_GENERATED) \
	$(LOCK_DAEMON_GENERATED) \
	$(NULL)

RPC_PROBE_FILES += $(srcdir)/locking/lock_protocol.x
SYSCONF_FILES += locking/virtlockd.sysconf

PODFILES += locking/virtlockd.pod
MANINFILES += virtlockd.8.in

CLEANFILES += $(man8_MANS)
MAINTAINERCLEANFILES += $(MANINFILES)

VIRTLOCKD_UNIT_FILES_IN = \
	locking/virtlockd.service.in \
	locking/virtlockd.socket.in \
	locking/virtlockd-admin.socket.in \
	$(NULL)

SYSTEMD_UNIT_FILES += $(notdir $(VIRTLOCKD_UNIT_FILES_IN:%.in=%))
SYSTEMD_UNIT_FILES_IN += $(VIRTLOCKD_UNIT_FILES_IN)

noinst_LTLIBRARIES += libvirt_driver_lock.la

libvirt_la_BUILT_LIBADD += libvirt_driver_lock.la
libvirt_driver_lock_la_SOURCES = \
	$(LOCK_DRIVER_SOURCES) \
	$(NULL)
libvirt_driver_lock_la_CFLAGS = \
	$(AM_CFLAGS) \
	-I$(srcdir)/conf \
	$(NULL)

lockdriverdir = $(libdir)/libvirt/lock-driver
lockdriver_LTLIBRARIES =

if WITH_LIBVIRTD
lockdriver_LTLIBRARIES += lockd.la
lockd_la_SOURCES = \
	$(LOCK_DRIVER_LOCKD_SOURCES) \
	$(LOCK_PROTOCOL_GENERATED) \
	$(NULL)
lockd_la_CFLAGS = \
	-I$(srcdir)/conf \
	$(XDR_CFLAGS) \
	$(AM_CFLAGS) \
	$(NULL)
lockd_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
lockd_la_LIBADD = \
	libvirt.la \
	$(GLIB_LIBS) \
	../gnulib/lib/libgnu.la \
	$(NULL)
augeas_DATA += locking/libvirt_lockd.aug
if WITH_DTRACE_PROBES
lockd_la_LIBADD += libvirt_probes.lo
endif WITH_DTRACE_PROBES

if WITH_SASL
lockd_la_CFLAGS += \
	$(SASL_CFLAGS) \
	$(NULL)
endif WITH_SASL

if WITH_QEMU
augeastest_DATA += locking/test_libvirt_lockd.aug
nodist_conf_DATA += locking/qemu-lockd.conf
endif WITH_QEMU

if WITH_LIBXL
nodist_conf_DATA += locking/libxl-lockd.conf
endif WITH_LIBXL

sbin_PROGRAMS += virtlockd

virtlockd_SOURCES = \
	$(LOCK_DAEMON_SOURCES) \
	$(LOCK_PROTOCOL_GENERATED) \
	$(LOCK_DAEMON_GENERATED) \
	$(NULL)
virtlockd_CFLAGS = \
	$(AM_CFLAGS) \
	$(PIE_CFLAGS) \
	$(XDR_CFLAGS) \
	$(NULL)
virtlockd_LDFLAGS = \
	$(AM_LDFLAGS) \
	$(PIE_LDFLAGS) \
	$(NO_UNDEFINED_LDFLAGS) \
	$(NULL)
virtlockd_LDADD = \
	libvirt.la \
	libvirt_driver_admin.la \
	$(GLIB_LIBS) \
	../gnulib/lib/libgnu.la \
	$(CYGWIN_EXTRA_LIBADD) \
	$(NULL)
if WITH_DTRACE_PROBES
virtlockd_LDADD += libvirt_probes.lo
endif WITH_DTRACE_PROBES

if WITH_SASL
virtlockd_CFLAGS += \
	$(SASL_CFLAGS) \
	$(NULL)
endif WITH_SASL

if WITH_SANLOCK
lockdriver_LTLIBRARIES += sanlock.la
sanlock_la_SOURCES = $(LOCK_DRIVER_SANLOCK_SOURCES)
sanlock_la_CFLAGS = -I$(srcdir)/conf $(AM_CFLAGS)
sanlock_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
sanlock_la_LIBADD = \
	-lsanlock_client \
	libvirt.la \
	$(GLIB_LIBS) \
	../gnulib/lib/libgnu.la \
	$(NULL)

augeas_DATA += locking/libvirt_sanlock.aug

if WITH_QEMU
augeastest_DATA += locking/test_libvirt_sanlock.aug
nodist_conf_DATA += locking/qemu-sanlock.conf
endif WITH_QEMU

if WITH_LIBXL
nodist_conf_DATA += locking/libxl-sanlock.conf
endif WITH_LIBXL

libexec_PROGRAMS += libvirt_sanlock_helper

libvirt_sanlock_helper_SOURCES = $(LOCK_DRIVER_SANLOCK_HELPER_SOURCES)
libvirt_sanlock_helper_CFLAGS = \
	-I$(srcdir)/conf \
	$(AM_CFLAGS) \
	$(PIE_CFLAGS) \
	$(NULL)
libvirt_sanlock_helper_LDFLAGS = \
	$(AM_LDFLAGS) \
	$(PIE_LDFLAGS) \
	$(NULL)
libvirt_sanlock_helper_LDADD = libvirt.la
endif WITH_SANLOCK

man8_MANS += virtlockd.8

conf_DATA += locking/virtlockd.conf

augeas_DATA += locking/virtlockd.aug
augeastest_DATA += locking/test_virtlockd.aug

INSTALL_DATA_DIRS += locking

install-data-locking:
	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/lockd"
	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/lockd/files"
	$(MKDIR_P) "$(DESTDIR)$(runstatedir)/libvirt/lockd"
if WITH_SANLOCK
	$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/sanlock"
endif WITH_SANLOCK

uninstall-data-locking:
	rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt/lockd/files" ||:
	rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt/lockd" ||:
	rmdir "$(DESTDIR)$(runstatedir)/libvirt/lockd" ||:
if WITH_SANLOCK
	rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt/sanlock" ||:
endif WITH_SANLOCK

if WITH_SANLOCK
if WITH_QEMU
locking/test_libvirt_sanlock.aug: locking/test_libvirt_sanlock.aug.in \
		locking/qemu-sanlock.conf $(AUG_GENTEST_SCRIPT)
	$(AM_V_GEN)$(AUG_GENTEST) locking/qemu-sanlock.conf $< > $@

endif WITH_QEMU
endif WITH_SANLOCK

if WITH_QEMU
locking/test_libvirt_lockd.aug: locking/test_libvirt_lockd.aug.in \
		locking/qemu-lockd.conf $(AUG_GENTEST_SCRIPT)
	$(AM_V_GEN)$(AUG_GENTEST) locking/qemu-lockd.conf $< > $@
endif WITH_QEMU

locking/test_virtlockd.aug: locking/test_virtlockd.aug.in \
		locking/virtlockd.conf $(AUG_GENTEST_SCRIPT)
	$(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/locking/virtlockd.conf $< > $@

endif WITH_LIBVIRTD

.PHONY: \
	install-data-locking \
	uninstall-data-locking \
	$(NULL)

locking/%-lockd.conf: $(srcdir)/locking/lockd.conf
	$(AM_V_GEN)$(MKDIR_P) locking ; \
	cp $< $@

locking/%-sanlock.conf: $(srcdir)/locking/sanlock.conf
	$(AM_V_GEN)$(MKDIR_P) locking ; \
	cp $< $@


locking/lock_daemon_dispatch_stubs.h: $(LOCK_PROTOCOL) \
		$(srcdir)/rpc/gendispatch.pl Makefile.am
	$(AM_V_GEN)perl -w $(srcdir)/rpc/gendispatch.pl --mode=server \
	    virLockSpaceProtocol VIR_LOCK_SPACE_PROTOCOL \
	    $(LOCK_PROTOCOL) > $(srcdir)/locking/lock_daemon_dispatch_stubs.h


virtlockd.service: locking/virtlockd.service.in $(top_builddir)/config.status
	$(AM_V_GEN)sed $(COMMON_UNIT_VARS) $< > $@-t && mv $@-t $@

virtlockd.socket: locking/virtlockd.socket.in $(top_builddir)/config.status
	$(AM_V_GEN)sed $(COMMON_UNIT_VARS) $< > $@-t && mv $@-t $@

virtlockd-admin.socket: locking/virtlockd-admin.socket.in \
                        $(top_builddir)/config.status
	$(AM_V_GEN)sed $(COMMON_UNIT_VARS) $< > $@-t && mv $@-t $@

virtlockd.8.in: locking/virtlockd.pod
	$(AM_V_GEN)$(POD2MAN) --section=8 $< $@-t1 && \
	if grep 'POD ERROR' $@-t1; then rm $@-t1; exit 1; fi && \
	sed \
		-e 's|SYSCONFDIR|\@sysconfdir\@|g' \
		-e 's|LOCALSTATEDIR|\@localstatedir\@|g' \
		< $@-t1 > $@-t2 && \
	rm -f $@-t1 && \
	mv $@-t2 $@
