Browse Source

build: Pass --as-needed to the linker for dselect to avoid libstdc++

We are not really using anything from libstdc++, so let's avoid the
dependency entirely. This makes this the only frontend not to pull
in the C++ run-time.
Guillem Jover 7 years ago
parent
commit
44cfbc4b31
4 changed files with 26 additions and 0 deletions
  1. 1 0
      configure.ac
  2. 2 0
      debian/changelog
  3. 4 0
      dselect/Makefile.am
  4. 19 0
      m4/dpkg-linker.m4

+ 1 - 0
configure.ac

@@ -36,6 +36,7 @@ DPKG_DIST_CHECK([test "$GMSGFMT" = ":" && test "$USE_NLS" = "yes"],
 AM_PROG_AR
 LT_INIT([disable-shared])
 DPKG_BUILD_SHARED_LIBS
+DPKG_LINKER_AS_NEEDED
 DPKG_LINKER_VERSION_SCRIPT
 
 # Allow compilation without optional programs

+ 2 - 0
debian/changelog

@@ -178,6 +178,8 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
       marked as deprecated by POSIX).
     - Print an actual newline instead of a literal \n in lcov output.
     - Do not honor DPKG_DATADIR on the installed Dpkg module.
+    - Pass --as-needed to the linker for dselect to avoid libstdc++ dependency.
+      Which makes of dselect the only front-end not pulling the C++ run-time.
 
   [ Updated man pages translations ]
   * German (Helge Kreutzmann).

+ 4 - 0
dselect/Makefile.am

@@ -17,6 +17,10 @@ AM_CXXFLAGS = \
 	-fno-rtti \
 	-fno-exceptions \
 	$(nil)
+if HAVE_LINKER_AS_NEEDED
+AM_LDFLAGS = \
+	-Wl,--as-needed
+endif
 
 
 bin_PROGRAMS = dselect

+ 19 - 0
m4/dpkg-linker.m4

@@ -23,6 +23,25 @@ AC_DEFUN([DPKG_LINKER_OPTIMIZATIONS], [
   ])
 ])
 
+# DPKG_LINKER_AS_NEEDED
+# ---------------------
+AC_DEFUN([DPKG_LINKER_AS_NEEDED], [
+  AC_CACHE_CHECK([for --as-needed linker flag], [dpkg_cv_linker_as_needed], [
+    save_LDFLAGS=$LDFLAGS
+    LDFLAGS="$LDFLAGS -Wl,--as-needed"
+    AC_LINK_IFELSE([
+      AC_LANG_PROGRAM([], [])
+    ], [
+      dpkg_cv_linker_as_needed=yes
+    ], [
+      dpkg_cv_linker_as_needed=no
+    ])
+    LDFLAGS="$save_LDFLAGS"
+  ])
+  AM_CONDITIONAL([HAVE_LINKER_AS_NEEDED],
+    [test "x$dpkg_cv_linker_as_needed" = "xyes"])
+])
+
 # DPKG_LINKER_VERSION_SCRIPT
 # --------------------------
 AC_DEFUN([DPKG_LINKER_VERSION_SCRIPT], [