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

Diego Elio Pettenò flameeyes at flameeyes.eu
Sat Mar 24 03:22:20 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 e8f0cb5..8c0864a 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([doc],
 	[AC_HELP_STRING([--enable-doc], [make mans (require docbook2man installed) [default=auto]])],
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 3a3816e..4c72dc9 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 \
@@ -60,13 +58,10 @@ AM_CFLAGS=-I$(top_srcdir)/src \
 	-DLXCPATH=\"$(LXCPATH)\" \
 	-DLXCINITDIR=\"$(LXCINITDIR)\"
 
-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)
+liblxc_ at VERSION@_la_LIBADD = -lutil $(CAP_LIBS)
 
 bin_SCRIPTS = \
 	lxc-ps \
@@ -100,11 +95,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@
+LDADD=liblxc- at VERSION@.la
 
 lxc_attach_SOURCES = lxc_attach.c
 lxc_cgroup_SOURCES = lxc_cgroup.c
@@ -114,6 +105,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
@@ -123,15 +115,6 @@ 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*
-
 namespace.c: setns.h
 
 setns.h:
-- 
1.7.8.5





More information about the lxc-devel mailing list