Browse Source

build: Switch to use libtool for the static libraries

This makes it possible to embed libcompat inside libdpkg, so that the
static library that we ship is self contained with the required
compatibility code, specifically the MD5 functions.

This also prepares the build system for when we start building a
shared library, although it disables it by default.

Closes: #746122
Guillem Jover 10 years ago
parent
commit
93a8d74235

+ 4 - 0
.gitignore

@@ -1,6 +1,8 @@
 # Inherited ignores
 *.a
 *.o
+*.lo
+*.la
 *.so
 *.gcno
 *.gcda
@@ -11,6 +13,7 @@
 *~
 .*.swp
 .deps/
+.libs/
 Makefile
 Makefile.in
 
@@ -23,5 +26,6 @@ ChangeLog
 INSTALL
 configure
 config.*
+libtool
 aclocal.m4
 stamp-h1

+ 1 - 0
README

@@ -44,6 +44,7 @@ some required software needs to be installed:
 
   GNU autoconf >= 2.60
   GNU automake >= 1.11
+  GNU libtool >= 2.0
   GNU gettext >= 0.18.2 (or just autopoint if using --disable-nls)
   flex
 

+ 7 - 1
configure.ac

@@ -18,6 +18,13 @@ AM_GNU_GETTEXT([external])
 DPKG_DIST_CHECK([test "$GMSGFMT" = ":" && test "$USE_NLS" = "yes"],
                 [gettext required when NLS support enabled])
 
+# Shared libraries are disabled on purpose, currently there is no ABI stability
+# guarantee, and it will be broken at will. The infrastructure is in place just
+# to be able to test that its future activation will work.
+LT_INIT([disable-shared])
+DPKG_BUILD_SHARED_LIBS
+DPKG_LINKER_VERSION_SCRIPT
+
 # Allow compilation without optional programs
 DPKG_BUILD_PROG([dselect])
 DPKG_BUILD_PROG([start-stop-daemon])
@@ -42,7 +49,6 @@ AC_PROG_CXX
 DPKG_CXX_CXX11
 AC_PROG_LEX
 DPKG_DIST_CHECK([test "$LEX" = ":"], [lex program required])
-AC_PROG_RANLIB
 AC_CHECK_PROGS([DOXYGEN], [doxygen])
 AC_CHECK_PROG([HAVE_DOT], [dot], [YES], [NO])
 DPKG_PROG_PO4A

+ 5 - 0
debian/changelog

@@ -1,5 +1,10 @@
 dpkg (1.17.10) UNRELEASED; urgency=low
 
+  [ Guillem Jover ]
+  * Use libtool to build the static libraries, which makes it possible to
+    embed libcompat inside libdpkg, as required by some external programs
+    linking against the latter. Closes: #746122
+
   [ Updated manpages translations ]
   * German (Helge Kreutzmann).
 

+ 1 - 2
dpkg-deb/Makefile.am

@@ -18,8 +18,7 @@ dpkg_deb_SOURCES = \
 	main.c
 
 dpkg_deb_LDADD = \
-	../lib/dpkg/libdpkg.a \
-	../lib/compat/libcompat.a \
+	../lib/dpkg/libdpkg.la \
 	$(LIBINTL) \
 	$(ZLIB_LIBS) \
 	$(LIBLZMA_LIBS) \

+ 1 - 2
dpkg-split/Makefile.am

@@ -20,8 +20,7 @@ dpkg_split_SOURCES = \
 	split.c
 
 dpkg_split_LDADD = \
-	../lib/dpkg/libdpkg.a \
-	../lib/compat/libcompat.a \
+	../lib/dpkg/libdpkg.la \
 	$(LIBINTL)
 
 install-data-local:

+ 1 - 2
dselect/Makefile.am

@@ -42,8 +42,7 @@ dselect_SOURCES = \
 
 dselect_LDADD = \
 	$(CURSES_LIBS) \
-	../lib/dpkg/libdpkg.a \
-	../lib/compat/libcompat.a \
+	../lib/dpkg/libdpkg.la \
 	$(LIBINTL)
 
 

+ 15 - 15
lib/compat/Makefile.am

@@ -5,60 +5,60 @@ AM_CPPFLAGS = \
 	-I$(top_builddir)
 
 
-noinst_LIBRARIES = libcompat.a
+noinst_LTLIBRARIES = libcompat.la
 
-libcompat_a_SOURCES = \
+libcompat_la_SOURCES = \
 	empty.c \
 	compat.h \
 	gettext.h
 
 # FIXME: unconditionally include these for now.
-libcompat_a_SOURCES += md5.c md5.h
+libcompat_la_SOURCES += md5.c md5.h
 
 if !HAVE_GETOPT
-libcompat_a_SOURCES += getopt.c getopt.h
+libcompat_la_SOURCES += getopt.c getopt.h
 endif
 
 if !HAVE_GETOPT_LONG
-libcompat_a_SOURCES += getopt1.c
+libcompat_la_SOURCES += getopt1.c
 endif
 
 if !HAVE_OBSTACK_FREE
-libcompat_a_SOURCES += obstack.c obstack.h
+libcompat_la_SOURCES += obstack.c obstack.h
 endif
 
 if !HAVE_STRNLEN
-libcompat_a_SOURCES += strnlen.c
+libcompat_la_SOURCES += strnlen.c
 endif
 
 if !HAVE_STRNDUP
-libcompat_a_SOURCES += strndup.c
+libcompat_la_SOURCES += strndup.c
 endif
 
 if !HAVE_STRERROR
-libcompat_a_SOURCES += strerror.c
+libcompat_la_SOURCES += strerror.c
 endif
 
 if !HAVE_STRSIGNAL
-libcompat_a_SOURCES += strsignal.c
+libcompat_la_SOURCES += strsignal.c
 endif
 
 if !HAVE_C99_SNPRINTF
-libcompat_a_SOURCES += snprintf.c vsnprintf.c
+libcompat_la_SOURCES += snprintf.c vsnprintf.c
 endif
 
 if !HAVE_ASPRINTF
-libcompat_a_SOURCES += asprintf.c vasprintf.c
+libcompat_la_SOURCES += asprintf.c vasprintf.c
 endif
 
 if !HAVE_ALPHASORT
-libcompat_a_SOURCES += alphasort.c
+libcompat_la_SOURCES += alphasort.c
 endif
 
 if !HAVE_SCANDIR
-libcompat_a_SOURCES += scandir.c
+libcompat_la_SOURCES += scandir.c
 endif
 
 if !HAVE_UNSETENV
-libcompat_a_SOURCES += unsetenv.c
+libcompat_la_SOURCES += unsetenv.c
 endif

+ 17 - 2
lib/dpkg/Makefile.am

@@ -21,9 +21,24 @@ EXTRA_DIST = \
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libdpkg.pc
 
-lib_LIBRARIES = libdpkg.a
+lib_LTLIBRARIES = libdpkg.la
 
-libdpkg_a_SOURCES = \
+if HAVE_LINKER_VERSION_SCRIPT
+libdpkg_la_LDFLAGS = \
+	-Wl,--version-script=$(srcdir)/libdpkg.map
+endif
+libdpkg_la_LIBADD = \
+	../compat/libcompat.la
+if BUILD_SHARED
+libdpkg_la_LIBADD += \
+	$(LIBINTL) \
+	$(ZLIB_LIBS) \
+	$(LIBLZMA_LIBS) \
+	$(BZ2_LIBS)
+endif
+libdpkg_la_DEPENDENCIES = \
+	libdpkg.map
+libdpkg_la_SOURCES = \
 	dlist.h \
 	ar.c \
 	arch.c \

+ 1 - 2
lib/dpkg/test/Makefile.am

@@ -6,8 +6,7 @@ AM_CPPFLAGS = \
 	-I$(top_builddir) \
 	-I$(top_srcdir)/lib
 LDADD = \
-	$(top_builddir)/lib/dpkg/libdpkg.a \
-	$(top_builddir)/lib/compat/libcompat.a \
+	$(top_builddir)/lib/dpkg/libdpkg.la \
 	$(LIBINTL)
 
 

+ 10 - 1
m4/dpkg-build.m4

@@ -1,4 +1,13 @@
-# Copyright © 2010-2012 Guillem Jover <guillem@debian.org>
+# Copyright © 2010-2014 Guillem Jover <guillem@debian.org>
+
+# DPKG_BUILD_SHARED_LIBS()
+# ----------------------
+AC_DEFUN([DPKG_BUILD_SHARED_LIBS], [
+  m4_pattern_allow([DPKG_DEVEL_MODE])
+  AS_IF([test "$enable_shared" = "yes" && test -z "$DPKG_DEVEL_MODE"],
+        [AC_MSG_ERROR([building libdpkg as a shared library is not supported])])
+  AM_CONDITIONAL([BUILD_SHARED], [test "$enable_shared" = "yes"])
+])# DPKG_BUILD_SHARED_LIBS
 
 # DPKG_BUILD_PROG(PROG)
 # ---------------

+ 20 - 0
m4/dpkg-linker.m4

@@ -1,4 +1,5 @@
 # Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
+# Copyright © 2010, 2014 Guillem Jover <guillem@debian.org>
 
 # DPKG_LINKER_OPTIMISATIONS
 # --------------------------
@@ -16,3 +17,22 @@ AC_DEFUN([DPKG_LINKER_OPTIMISATIONS],
     LDFLAGS="$LDFLAGS -Wl,-O1"
   ])
 ])
+
+# DPKG_LINKER_VERSION_SCRIPT
+# --------------------------
+AC_DEFUN([DPKG_LINKER_VERSION_SCRIPT],
+[
+  AC_CACHE_CHECK([for --version-script linker flag],
+    [dpkg_cv_version_script],
+    [echo "{ global: symbol; local: *; };" >conftest.map
+    save_LDFLAGS=$LDFLAGS
+    LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
+                   [dpkg_cv_version_script=yes],
+                   [dpkg_cv_version_script=no])
+    LDFLAGS="$save_LDFLAGS"
+    rm -f conftest.map
+  ])
+  AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
+                 [test "x$dpkg_cv_version_script" = "xyes"])
+])

+ 1 - 2
src/Makefile.am

@@ -10,8 +10,7 @@ AM_CPPFLAGS = \
 	-I$(top_builddir) \
 	-I$(top_srcdir)/lib
 LDADD = \
-	../lib/dpkg/libdpkg.a \
-	../lib/compat/libcompat.a \
+	../lib/dpkg/libdpkg.la \
 	$(LIBINTL)
 
 

+ 2 - 2
utils/Makefile.am

@@ -24,7 +24,7 @@ update_alternatives_SOURCES = \
 	update-alternatives.c
 
 update_alternatives_LDADD = \
-	../lib/compat/libcompat.a \
+	../lib/compat/libcompat.la \
 	$(LIBINTL) \
 	$(UA_LIBS)
 
@@ -37,7 +37,7 @@ start_stop_daemon_SOURCES = \
 	start-stop-daemon.c
 
 start_stop_daemon_LDADD = \
-	../lib/compat/libcompat.a \
+	../lib/compat/libcompat.la \
 	$(SSD_LIBS)
 endif