Re: [libvirt] PATCH: 7/11: Build libtool convenience libraries of all drivers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A while ago we introduced a libvirt_test.so which is identical to
libvirt.so, but without the linker whitelist of symbols. This did
impose a little overhead in the build process - it meant we compiled
all source files twice.

A future patch will want to compile drivers into individual libraries
to allow dlopening, and it occurred to me that if we built some more
libtool convenience libraries we could avoid the double compilation.

The trick is that libvirt.la must not have any source files listed
against it. It must only be used to link together other convenience
libraries. So, I define a while set of libraries

 - libvirt_util.la - generic code not related to drivers or libvirt API
 - libvirt_driver.la - the libvirt public API and driver support code
 - libvirt_driver_XXXX.la - one for each of qemu, xen, test, remote,
                            openvz, lxc, storage, network

These are all convenience libraries, so libtool will just build a local
non-installed, static .a archive.

Now, the actual things we care about

 - libvirt.la - links to all of these convenience .la libraries together
                and adds the libvirt_sym.version script to filter symbols
 - libvirt_test.la - the same, but with the version script
 - libvirt_lxc - links to libvirt_util.la and libvirt_driver_lxc.la
 - virsh - links to libvirt.la

So the end result is that each source file is only ever compiled once,
and each library/program just links to the .a files is actually needs.


 Makefile.am |  107 +++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 71 insertions(+), 36 deletions(-)

Daniel

diff -r a5221822f20b src/Makefile.am
--- a/src/Makefile.am	Wed Oct 29 20:10:49 2008 +0000
+++ b/src/Makefile.am	Wed Oct 29 20:10:52 2008 +0000
@@ -6,11 +6,7 @@
 	   -I@top_srcdir@/include \
 	   -I@top_srcdir@/qemud \
 	   $(LIBXML_CFLAGS) \
-	   $(GNUTLS_CFLAGS) \
-	   $(SASL_CFLAGS) \
 	   $(SELINUX_CFLAGS) \
-	   $(NUMACTL_CFLAGS) \
-	   $(XEN_CFLAGS) \
 	   -DBINDIR=\""$(libexecdir)"\" \
 	   -DSBINDIR=\""$(sbindir)"\" \
 	   -DSYSCONF_DIR="\"$(sysconfdir)\"" \
@@ -18,10 +14,6 @@
            -DLOCAL_STATE_DIR=\""$(localstatedir)"\" \
            -DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
 	   $(WARN_CFLAGS)
-
-DEPS = libvirt.la
-LDADDS = @STATIC_BINARIES@ $(WARN_CFLAGS) libvirt.la ../gnulib/lib/libgnu.la
-VIRSH_LIBS = @VIRSH_LIBS@
 
 confdir = $(sysconfdir)/libvirt/
 conf_DATA = qemu.conf
@@ -40,7 +32,7 @@
 
 # These files are not related to driver APIs. Simply generic
 # helper APIs for various purposes
-GENERIC_LIB_SOURCES =						\
+UTIL_SOURCES =							\
 		bridge.c bridge.h				\
 		buf.c buf.h					\
 		conf.c conf.h					\
@@ -53,6 +45,16 @@
 		util.c util.h					\
 		virterror.c virterror_internal.h		\
 		xml.c xml.h
+
+# Internal generic driver infrastructure
+DRIVER_SOURCES = 						\
+		driver.h					\
+		internal.h					\
+		datatypes.c datatypes.h				\
+		domain_event.c domain_event.h			\
+		stats_linux.c stats_linux.h			\
+		libvirt.c libvirt_internal.h
+
 
 # Domain driver generic impl APIs
 DOMAIN_CONF_SOURCES =						\
@@ -146,62 +148,91 @@
 #
 # First deal with sources usable in non-daemon context
 
-libvirt_la_SOURCES =						\
-		driver.h					\
-		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)				\
+noinst_LTLIBRARIES = libvirt_util.la
+libvirt_la_LIBADD = libvirt_util.la
+libvirt_util_la_SOURCES =					\
+		$(UTIL_SOURCES)
+
+noinst_LTLIBRARIES += libvirt_driver.la
+libvirt_la_LIBADD += libvirt_driver.la
+libvirt_driver_la_SOURCES =					\
+		$(DRIVER_SOURCES)				\
 		$(DOMAIN_CONF_SOURCES)				\
 		$(NETWORK_CONF_SOURCES)				\
 		$(STORAGE_CONF_SOURCES)
 
 if WITH_TEST
-libvirt_la_SOURCES += $(TEST_DRIVER_SOURCES)
+noinst_LTLIBRARIES += libvirt_driver_test.la
+libvirt_la_LIBADD += libvirt_driver_test.la
+libvirt_driver_test_la_SOURCES = $(TEST_DRIVER_SOURCES)
 endif
 
 if WITH_REMOTE
-libvirt_la_SOURCES += $(REMOTE_DRIVER_SOURCES)
+noinst_LTLIBRARIES += libvirt_driver_remote.la
+libvirt_la_LIBADD += libvirt_driver_remote.la
+libvirt_driver_remote_la_CFLAGS =				\
+		$(GNUTLS_CFLAGS)				\
+		$(SASL_CFLAGS)
+libvirt_driver_remote_la_LDFLAGS =				\
+		$(GNUTLS_LIBS)					\
+		$(SASL_LIBS)
+libvirt_driver_remote_la_SOURCES = $(REMOTE_DRIVER_SOURCES)
 endif
 
 if WITH_XEN
-libvirt_la_SOURCES += $(XEN_DRIVER_SOURCES)
+noinst_LTLIBRARIES += libvirt_driver_xen.la
+libvirt_la_LIBADD += libvirt_driver_xen.la
+libvirt_driver_xen_la_CFLAGS = $(XEN_CFLAGS)
+libvirt_driver_xen_la_LDFLAGS = $(XEN_LIBS)
+libvirt_driver_xen_la_SOURCES = $(XEN_DRIVER_SOURCES)
 endif
 
 if WITH_OPENVZ
-libvirt_la_SOURCES += $(OPENVZ_DRIVER_SOURCES)
+noinst_LTLIBRARIES += libvirt_driver_openvz.la
+libvirt_la_LIBADD += libvirt_driver_openvz.la
+libvirt_driver_openvz_la_SOURCES = $(OPENVZ_DRIVER_SOURCES)
 endif
 
 if WITH_QEMU
-libvirt_la_SOURCES += $(QEMU_DRIVER_SOURCES)
+noinst_LTLIBRARIES += libvirt_driver_qemu.la
+libvirt_la_LIBADD += libvirt_driver_qemu.la
+libvirt_driver_qemu_la_CFLAGS = $(NUMACTL_CFLAGS)
+libvirt_driver_qemu_la_LDFLAGS = $(NUMACTL_LIBS)
+libvirt_driver_qemu_la_SOURCES = $(QEMU_DRIVER_SOURCES)
 endif
 
 if WITH_LXC
-libvirt_la_SOURCES += $(LXC_DRIVER_SOURCES)
+noinst_LTLIBRARIES += libvirt_driver_lxc.la
+libvirt_la_LIBADD += libvirt_driver_lxc.la
+libvirt_driver_lxc_la_SOURCES = $(LXC_DRIVER_SOURCES)
 endif
 
 
 if WITH_NETWORK
-libvirt_la_SOURCES += $(NETWORK_DRIVER_SOURCES)
+noinst_LTLIBRARIES += libvirt_driver_network.la
+libvirt_la_LIBADD += libvirt_driver_network.la
+libvirt_driver_network_la_SOURCES = $(NETWORK_DRIVER_SOURCES)
 endif
 
+# Needed to keep automake quiet about conditionals
+libvirt_driver_storage_la_SOURCES =
 if WITH_STORAGE_DIR
-libvirt_la_SOURCES += $(STORAGE_DRIVER_SOURCES)
-libvirt_la_SOURCES += $(STORAGE_DRIVER_FS_SOURCES)
+noinst_LTLIBRARIES += libvirt_driver_storage.la
+libvirt_la_LIBADD += libvirt_driver_storage.la
+libvirt_driver_storage_la_SOURCES += $(STORAGE_DRIVER_SOURCES)
+libvirt_driver_storage_la_SOURCES += $(STORAGE_DRIVER_FS_SOURCES)
 endif
 
 if WITH_STORAGE_LVM
-libvirt_la_SOURCES += $(STORAGE_DRIVER_LVM_SOURCES)
+libvirt_driver_storage_la_SOURCES += $(STORAGE_DRIVER_LVM_SOURCES)
 endif
 
 if WITH_STORAGE_ISCSI
-libvirt_la_SOURCES += $(STORAGE_DRIVER_ISCSI_SOURCES)
+libvirt_driver_storage_la_SOURCES += $(STORAGE_DRIVER_ISCSI_SOURCES)
 endif
 
 if WITH_STORAGE_DISK
-libvirt_la_SOURCES += $(STORAGE_DRIVER_DISK_SOURCES)
+libvirt_driver_storage_la_SOURCES += $(STORAGE_DRIVER_DISK_SOURCES)
 endif
 
 # Add all conditional sources just in case...
@@ -220,8 +251,9 @@
 		$(STORAGE_DRIVER_DISK_SOURCES)
 
 
-libvirt_la_LIBADD = $(LIBXML_LIBS) $(GNUTLS_LIBS) $(SASL_LIBS) $(SELINUX_LIBS) \
-                    $(NUMACTL_LIBS) $(XEN_LIBS) \
+# Empty source list - it merely links a bunch of convenience libs together
+libvirt_la_SOURCES =
+libvirt_la_LIBADD += $(LIBXML_LIBS) $(SELINUX_LIBS) \
 		    @CYGWIN_EXTRA_LIBADD@ ../gnulib/lib/libgnu.la
 libvirt_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libvirt_sym.version \
                      -version-info @LIBVIRT_VERSION_INFO@ \
@@ -232,7 +264,7 @@
 # Create an automake "convenience library" version of libvirt_la,
 # just for testing, since the test harness requires access to internal
 # bits and pieces that we don't want to make publicly accessible.
-noinst_LTLIBRARIES = libvirt_test.la
+noinst_LTLIBRARIES += libvirt_test.la
 
 # Convert libvirt_sym.version
 #      to libvirt_test_sym.version, and
@@ -256,8 +288,12 @@
 		virsh.c
 
 virsh_LDFLAGS = $(WARN_CFLAGS) $(COVERAGE_LDFLAGS)
-virsh_DEPENDENCIES = $(DEPS)
-virsh_LDADD = $(LDADDS) $(VIRSH_LIBS)
+virsh_LDADD = 							\
+		$(STATIC_BINARIES) 				\
+		$(WARN_CFLAGS)					\
+		libvirt.la					\
+		../gnulib/lib/libgnu.la				\
+		$(VIRSH_LIBS)
 virsh_CFLAGS = $(COVERAGE_CFLAGS) $(READLINE_CFLAGS)
 BUILT_SOURCES = virsh-net-edit.c virsh-pool-edit.c
 
@@ -294,7 +330,6 @@
 
 if WITH_WIN_ICON
 virsh_LDADD += virsh_win_icon.$(OBJEXT)
-virsh_DEPENDENCIES += virsh_win_icon.$(OBJEXT)
 
 # Before you edit virsh_win_icon.rc, please note the following
 # limitations of the resource file format:
@@ -340,7 +375,7 @@
 
 libvirt_lxc_SOURCES =						\
 		$(LXC_CONTROLLER_SOURCES)			\
-		$(GENERIC_LIB_SOURCES) 				\
+		$(UTIL_SOURCES) 				\
 		$(DOMAIN_CONF_SOURCES)
 libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(COVERAGE_LDCFLAGS)
 libvirt_lxc_LDADD = $(LIBXML_LIBS) ../gnulib/lib/libgnu.la

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]