From c9ff52fb8a85599990620f7a5916c408a0f65fc5 Mon Sep 17 00:00:00 2001
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Tue, 4 Nov 2008 23:37:23 +0000
Subject: [PATCH] Move WITH_XXX driver feature flags into config.h instead of
 direct compiler/linker args

---
 ChangeLog         | 11 +++++++
 configure.in      | 83 +++++++++++++++++++++++++++++------------------
 proxy/Makefile.am |  4 +--
 qemud/Makefile.am |  2 --
 src/Makefile.am   | 29 +++++++++--------
 src/libvirt.c     |  2 +-
 tests/Makefile.am |  4 +--
 7 files changed, 81 insertions(+), 54 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3d384772f5..dcef06d9bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Tue Nov  4 23:33:31 UTC 2008 Daniel P. Berrange <berrange@redhat.com>
+
+	* configure.in: Set WITH_XXXX conditionals for drivers in
+	config.h instead of compiler args, and auto-disable stateful
+	drivers if daemon is disabled
+	* src/libvirt.c: Remove now redundant WITH_LIBVIRTD condition
+	* tests/Makefile.am, src/Makefile.am, qemud/Makefile.am: Remove
+	LIBVIRT_FEATURES args, now set via config.h instead. Add
+	explicit XEN_LIBS/CFLAGS instead of relying on setting via
+	global flags.
+
 Tue Nov  4 23:33:31 UTC 2008 Daniel P. Berrange <berrange@redhat.com>
 
 	Move domain events helpers into domain_events.c
diff --git a/configure.in b/configure.in
index 6635f645d8..c105eca809 100644
--- a/configure.in
+++ b/configure.in
@@ -232,59 +232,69 @@ fi
 AC_PATH_PROG([IPTABLES_PATH], [iptables], /sbin/iptables, [/usr/sbin:$PATH])
 AC_DEFINE_UNQUOTED([IPTABLES_PATH], "$IPTABLES_PATH", [path to iptables binary])
 
-dnl
-dnl Specify the xen-distribution directory to be able to compile on a
-dnl non-xenified host
-dnl
-AC_ARG_WITH([xen-distdir], [AC_HELP_STRING([--with-xen-distdir=path],
-            [distribution directory of Xen, default /usr])])
-if test "x$with_xen_distdir" != "x"
-then
-CPPFLAGS="$CPPFLAGS -I$withval/install/usr/include"
-LDFLAGS="$LDFLAGS -L$withval/install/usr/lib -L$withval/install/usr/lib64"
-fi
-
-LIBVIRT_FEATURES=
-WITH_XEN=0
-
 if test "$with_openvz" = "yes"; then
-    LIBVIRT_FEATURES="$LIBVIRT_FEATURES -DWITH_OPENVZ"
+    AC_DEFINE_UNQUOTED([WITH_OPENVZ], 1, [whether OpenVZ driver is enabled])
 fi
 AM_CONDITIONAL([WITH_OPENVZ], [test "$with_openvz" = "yes"])
 
+if test "$with_libvirtd" = "no" ; then
+  with_lxc=no
+fi
 if test "$with_lxc" = "yes" ; then
-    LIBVIRT_FEATURES="$LIBVIRT_FEATURES -DWITH_LXC"
+    AC_DEFINE_UNQUOTED([WITH_LXC], 1, [whether LXC driver is enabled])
 fi
 AM_CONDITIONAL([WITH_LXC], [test "$with_lxc" = "yes"])
 
+if test "$with_libvirtd" = "no" ; then
+  with_qemu=no
+fi
 if test "$with_qemu" = "yes" ; then
-    LIBVIRT_FEATURES="$LIBVIRT_FEATURES -DWITH_QEMU"
+    AC_DEFINE_UNQUOTED([WITH_QEMU], 1, [whether QEMU driver is enabled])
 fi
 AM_CONDITIONAL([WITH_QEMU], [test "$with_qemu" = "yes"])
 
 if test "$with_test" = "yes" ; then
-    LIBVIRT_FEATURES="$LIBVIRT_FEATURES -DWITH_TEST"
+    AC_DEFINE_UNQUOTED([WITH_TEST], 1, [whether Test driver is enabled])
 fi
 AM_CONDITIONAL([WITH_TEST], [test "$with_test" = "yes"])
 
 if test "$with_remote" = "yes" ; then
-    LIBVIRT_FEATURES="$LIBVIRT_FEATURES -DWITH_REMOTE"
+    AC_DEFINE_UNQUOTED([WITH_REMOTE], 1, [whether Remote driver is enabled])
 fi
 AM_CONDITIONAL([WITH_REMOTE], [test "$with_remote" = "yes"])
 
 if test "$with_libvirtd" = "yes" ; then
-    LIBVIRT_FEATURES="$LIBVIRT_FEATURES -DWITH_LIBVIRTD"
+    AC_DEFINE_UNQUOTED([WITH_LIBVIRTD], 1, [whether libvirtd daemon is enabled])
 fi
 AM_CONDITIONAL([WITH_LIBVIRTD], [test "$with_libvirtd" = "yes"])
 
-if test "$with_xen" = "yes" ; then
-    dnl search for the Xen store library
-    AC_SEARCH_LIBS(xs_read, [xenstore],
-                   [WITH_XEN=1],
-                   [AC_MSG_RESULT([Xen store library not found])])
-    if test "$WITH_XEN" != "0" ; then
-        LIBVIRT_FEATURES="$LIBVIRT_FEATURES -DWITH_XEN"
+XEN_LIBS=""
+XEN_CFLAGS=""
+dnl search for the Xen store library
+if test "$with_xen" != "no" ; then
+    if test "$with_xen" != "yes" -a "$with_xen" != "check" ; then
+        XEN_CFLAGS="-I$with_xen/include"
+        XEN_LIBS="-L$with_xen/lib64 -L$with_xen/lib"
     fi
+    fail=0
+    old_LIBS="$LIBS"
+    old_CFLAGS="$CFLAGS"
+    CFLAGS="$CFLAGS $XEN_CFLAGS"
+    LIBS="$LIBS $XEN_LIBS"
+    AC_CHECK_LIB([xenstore], [xs_read], [
+           with_xen=yes
+           XEN_LIBS="$XEN_LIBS -lxenstore"
+       ],[
+           if test "$with_xen" = "check" ; then
+               with_xen=no
+           else
+               with_xen=no
+               fail=1
+           fi
+       ])
+
+    test $fail = 1 &&
+      AC_MSG_ERROR([You must install the Xen development package to compile Xen driver with -lxenstore])
 
     AC_CHECK_HEADERS([xen/xen.h xen/version.h xen/dom0_ops.h],,[
 	AC_MSG_ERROR([Cannot find standard Xen headers. Is xen-devel installed?])
@@ -307,8 +317,15 @@ if test "$with_xen" = "yes" ; then
 #include <stdint.h>
 #include <xen/xen.h>
 ])
+    LIBS="$old_LIBS"
+    CFLAGS="$old_CFLAGS"
 fi
-AM_CONDITIONAL([WITH_XEN], [test "$WITH_XEN" = "1"])
+if test "$with_xen" = "yes"; then
+    AC_DEFINE_UNQUOTED([WITH_XEN], 1, [whether Xen driver is enabled])
+fi
+AM_CONDITIONAL([WITH_XEN], [test "$with_xen" = "yes"])
+AC_SUBST([XEN_CFLAGS])
+AC_SUBST([XEN_LIBS])
 
 dnl
 dnl check for kernel headers required by src/bridge.c
@@ -641,9 +658,6 @@ fi
 AC_SUBST([READLINE_CFLAGS])
 AC_SUBST([VIRSH_LIBS])
 
-AC_SUBST([WITH_XEN])
-AC_SUBST([LIBVIRT_FEATURES])
-
 
 AC_ARG_WITH([network],
 [  --with-network              with virtual network driver (on)],[],[with_network=yes])
@@ -1124,6 +1138,11 @@ AC_MSG_NOTICE([  numactl: $NUMACTL_CFLAGS $NUMACTL_LIBS])
 else
 AC_MSG_NOTICE([  numactl: no])
 fi
+if test "$with_xen" = "yes" ; then
+AC_MSG_NOTICE([  xen: $XEN_CFLAGS $XEN_LIBS])
+else
+AC_MSG_NOTICE([  xen: no])
+fi
 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([Test suite])
 AC_MSG_NOTICE([])
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 75ba6b4705..8a1f51c2bd 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -5,7 +5,7 @@ INCLUDES = -I$(top_srcdir)/gnulib/lib -I../gnulib/lib \
            -I$(top_builddir)/include -I@top_srcdir@/include \
 	   -I@top_srcdir@/proxy -I@top_srcdir@/src @LIBXML_CFLAGS@ \
 	   -DPROXY  -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-           -DGETTEXT_PACKAGE=\"$(PACKAGE)\" $(WARN_CFLAGS) $(LIBVIRT_FEATURES)
+           -DGETTEXT_PACKAGE=\"$(PACKAGE)\" $(WARN_CFLAGS) $(XEN_CFLAGS)
 
 libexec_PROGRAMS = libvirt_proxy
 
@@ -19,7 +19,7 @@ libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \
             @top_srcdir@/src/util.c \
 	    @top_srcdir@/src/event.c \
 	    @top_srcdir@/src/uuid.c
-libvirt_proxy_LDFLAGS = $(WARN_CFLAGS)
+libvirt_proxy_LDFLAGS = $(WARN_CFLAGS) $(XEN_LIBS)
 libvirt_proxy_DEPENDENCIES =
 libvirt_proxy_LDADD = ../gnulib/lib/libgnu.la
 
diff --git a/qemud/Makefile.am b/qemud/Makefile.am
index dd4c128c53..fd4ac1fb73 100644
--- a/qemud/Makefile.am
+++ b/qemud/Makefile.am
@@ -1,7 +1,5 @@
 ## Process this file with automake to produce Makefile.in
 
-INCLUDES = $(LIBVIRT_FEATURES)
-
 DAEMON_SOURCES =					\
 		event.c event.h				\
 		qemud.c qemud.h				\
diff --git a/src/Makefile.am b/src/Makefile.am
index 2c61d922ba..4779a22d84 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,14 +10,15 @@ INCLUDES = \
 	   $(SASL_CFLAGS) \
 	   $(SELINUX_CFLAGS) \
 	   $(NUMACTL_CFLAGS) \
+	   $(XEN_CFLAGS) \
 	   -DBINDIR=\""$(libexecdir)"\" \
 	   -DSBINDIR=\""$(sbindir)"\" \
 	   -DSYSCONF_DIR="\"$(sysconfdir)\"" \
 	   -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
            -DLOCAL_STATE_DIR=\""$(localstatedir)"\" \
            -DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
-	   $(WARN_CFLAGS) \
-	   $(LIBVIRT_FEATURES)
+	   $(WARN_CFLAGS)
+
 DEPS = libvirt.la
 LDADDS = @STATIC_BINARIES@ $(WARN_CFLAGS) libvirt.la ../gnulib/lib/libgnu.la
 VIRSH_LIBS = @VIRSH_LIBS@
@@ -48,7 +49,6 @@ GENERIC_LIB_SOURCES =						\
 		iptables.c iptables.h				\
 		memory.c memory.h				\
 		qparams.c qparams.h				\
-		stats_linux.c stats_linux.h			\
 		uuid.c uuid.h					\
 		util.c util.h					\
 		virterror.c virterror_internal.h		\
@@ -151,13 +151,13 @@ libvirt_la_SOURCES =						\
 		internal.h					\
 		datatypes.c datatypes.h				\
 		domain_event.c domain_event.h			\
+		stats_linux.c stats_linux.h			\
 		libvirt.c libvirt_internal.h			\
 		$(GENERIC_LIB_SOURCES)				\
 		$(DOMAIN_CONF_SOURCES)				\
 		$(NETWORK_CONF_SOURCES)				\
 		$(STORAGE_CONF_SOURCES)
 
-# Drivers usable outside daemon context
 if WITH_TEST
 libvirt_la_SOURCES += $(TEST_DRIVER_SOURCES)
 endif
@@ -174,14 +174,6 @@ if WITH_OPENVZ
 libvirt_la_SOURCES += $(OPENVZ_DRIVER_SOURCES)
 endif
 
-# Drivers usable inside daemon context
-if WITH_LIBVIRTD
-if WITH_NETWORK
-libvirt_la_SOURCES += $(NETWORK_DRIVER_SOURCES)
-endif
-libvirt_la_SOURCES += $(STORAGE_DRIVER_SOURCES)
-libvirt_la_SOURCES += $(STORAGE_DRIVER_FS_SOURCES)
-
 if WITH_QEMU
 libvirt_la_SOURCES += $(QEMU_DRIVER_SOURCES)
 endif
@@ -190,6 +182,16 @@ if WITH_LXC
 libvirt_la_SOURCES += $(LXC_DRIVER_SOURCES)
 endif
 
+
+if WITH_NETWORK
+libvirt_la_SOURCES += $(NETWORK_DRIVER_SOURCES)
+endif
+
+if WITH_STORAGE_DIR
+libvirt_la_SOURCES += $(STORAGE_DRIVER_SOURCES)
+libvirt_la_SOURCES += $(STORAGE_DRIVER_FS_SOURCES)
+endif
+
 if WITH_STORAGE_LVM
 libvirt_la_SOURCES += $(STORAGE_DRIVER_LVM_SOURCES)
 endif
@@ -201,7 +203,6 @@ endif
 if WITH_STORAGE_DISK
 libvirt_la_SOURCES += $(STORAGE_DRIVER_DISK_SOURCES)
 endif
-endif
 
 # Add all conditional sources just in case...
 EXTRA_DIST +=							\
@@ -220,7 +221,7 @@ EXTRA_DIST +=							\
 
 
 libvirt_la_LIBADD = $(LIBXML_LIBS) $(GNUTLS_LIBS) $(SASL_LIBS) $(SELINUX_LIBS) \
-                    $(NUMACTL_LIBS) \
+                    $(NUMACTL_LIBS) $(XEN_LIBS) \
 		    @CYGWIN_EXTRA_LIBADD@ ../gnulib/lib/libgnu.la
 libvirt_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvirt_sym.version \
                      -version-info @LIBVIRT_VERSION_INFO@ \
diff --git a/src/libvirt.c b/src/libvirt.c
index 88a54de5c3..f4dbe684b0 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -289,7 +289,6 @@ virInitialize(void)
 #ifdef WITH_XEN
     if (xenUnifiedRegister () == -1) return -1;
 #endif
-#ifdef WITH_LIBVIRTD
 #ifdef WITH_QEMU
     if (qemudRegister() == -1) return -1;
 #endif
@@ -302,6 +301,7 @@ virInitialize(void)
 #ifdef WITH_NETWORK
     if (networkRegister() == -1) return -1;
 #endif
+#ifdef WITH_STORAGE_DIR
     if (storageRegister() == -1) return -1;
 #endif
 #ifdef WITH_REMOTE
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ea577df4c5..327fca9f11 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,11 +15,9 @@ INCLUDES = \
 	$(GNUTLS_CFLAGS) \
 	$(SASL_CFLAGS) \
 	$(SELINUX_CFLAGS) \
-        -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L \
         -DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
          $(COVERAGE_CFLAGS) \
-         $(WARN_CFLAGS)	\
-	 $(LIBVIRT_FEATURES)
+         $(WARN_CFLAGS)
 
 LDADDS = \
 	@STATIC_BINARIES@ \