[lxc-devel] [PATCH 1/3] build: use libtool for linking the library, and link lxc-init statically.

Diego Elio Pettenò flameeyes at flameeyes.eu
Sun Nov 11 04:55:09 UTC 2012


The shared object versioning on the library (soname) was completely wrong,
as the ABI doesn't seem to be guaranteed between one version and the other,
so proposing all of them as .so.0 is very wrong.

Furthermore you generally want lxc-init static so that you don't have to add
(or have a compatible version of) libcap and liblxc within a container you
want to use lxc-execute with.

To solve the issue, use the good old libtool to take care of the library
building, and pass -all-static to the lxc-init linking stage.

Also drop the manual rpath handling, and leave it to libtool to manage.

Signed-off-by: Diego Elio Pettenò <flameeyes at flameeyes.eu>
---
 configure.ac        |  6 +-----
 src/lxc/Makefile.am | 31 +++++++------------------------
 2 files changed, 8 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index 900e1e7..a9a88c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,11 +12,7 @@ AM_PROG_CC_C_O
 AC_GNU_SOURCE
 AC_CHECK_PROG(SETCAP, setcap, yes, no, $PATH$PATH_SEPARATOR/sbin)
 
-AC_ARG_ENABLE([rpath],
-	[AC_HELP_STRING([--disable-rpath], [do not set rpath in executables])],
-	[], [enable_rpath=yes])
-
-AM_CONDITIONAL([ENABLE_RPATH], [test "x$enable_rpath" = "xyes"])
+LT_INIT
 
 AC_ARG_ENABLE([apparmor],
 	[AC_HELP_STRING([--enable-apparmor], [enable apparmor])],
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 50e67bb..b4d24a6 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -15,11 +15,9 @@ pkginclude_HEADERS = \
 		state.h \
 		attach.h
 
-sodir=$(libdir)
-# use PROGRAMS to avoid complains from automake
-so_PROGRAMS = liblxc.so
+lib_LTLIBRARIES = liblxc- at VERSION@.la
 
-liblxc_so_SOURCES = \
+liblxc_ at VERSION@_la_SOURCES = \
 	arguments.c arguments.h \
 	commands.c commands.h \
 	start.c start.h \
@@ -65,13 +63,10 @@ if ENABLE_APPARMOR
 AM_CFLAGS += -DHAVE_APPARMOR
 endif
 
-liblxc_so_CFLAGS = -fPIC -DPIC $(AM_CFLAGS)
+liblxc_ at VERSION@_la_LDFLAGS = \
+	-avoid-version
 
-liblxc_so_LDFLAGS = \
-	-shared \
-	-Wl,-soname,liblxc.so.$(firstword $(subst ., ,$(VERSION)))
-
-liblxc_so_LDADD = -lutil $(CAP_LIBS) $(APPARMOR_LIBS)
+liblxc_ at VERSION@_la_LIBADD = -lutil $(CAP_LIBS) $(APPARMOR_LIBS)
 
 bin_SCRIPTS = \
 	lxc-ps \
@@ -106,11 +101,7 @@ bin_PROGRAMS = \
 pkglibexec_PROGRAMS = \
 	lxc-init
 
-AM_LDFLAGS = -Wl,-E
-if ENABLE_RPATH
-AM_LDFLAGS += -Wl,-rpath -Wl,$(libdir)
-endif
-LDADD=liblxc.so @CAP_LIBS@ @APPARMOR_LIBS@
+LDADD=liblxc- at VERSION@.la
 
 lxc_attach_SOURCES = lxc_attach.c
 lxc_cgroup_SOURCES = lxc_cgroup.c
@@ -120,6 +111,7 @@ lxc_execute_SOURCES = lxc_execute.c
 lxc_freeze_SOURCES = lxc_freeze.c
 lxc_info_SOURCES = lxc_info.c
 lxc_init_SOURCES = lxc_init.c
+lxc_init_LDFLAGS = -all-static
 lxc_monitor_SOURCES = lxc_monitor.c
 lxc_restart_SOURCES = lxc_restart.c
 lxc_start_SOURCES = lxc_start.c
@@ -128,12 +120,3 @@ lxc_unfreeze_SOURCES = lxc_unfreeze.c
 lxc_unshare_SOURCES = lxc_unshare.c
 lxc_wait_SOURCES = lxc_wait.c
 lxc_kill_SOURCES = lxc_kill.c
-
-install-exec-local: install-soPROGRAMS
-	mv $(DESTDIR)$(libdir)/liblxc.so $(DESTDIR)$(libdir)/liblxc.so.$(VERSION)
-	/sbin/ldconfig -l $(DESTDIR)$(libdir)/liblxc.so.$(VERSION)
-	cd $(DESTDIR)$(libdir); \
-	ln -sf liblxc.so.$(firstword $(subst ., ,$(VERSION))) liblxc.so
-
-uninstall-local:
-	$(RM) $(DESTDIR)$(libdir)/liblxc.so*
-- 
1.8.0





More information about the lxc-devel mailing list