[gcc r10-6269] gcc: Add new configure options to allow static libraries to be selected

Andrew Burgess aburgess@gcc.gnu.org
Mon Jan 27 22:02:00 GMT 2020


https://gcc.gnu.org/g:e7c26e04b2dd6266d62d5a5825ff7eb44d1cf14e

commit r10-6269-ge7c26e04b2dd6266d62d5a5825ff7eb44d1cf14e
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Wed Jan 22 14:54:26 2020 +0000

    gcc: Add new configure options to allow static libraries to be selected
    
    The motivation behind this change is to make it easier for a user to
    link against static libraries on a target where dynamic libraries are
    the default library type (for example GNU/Linux).
    
    Further, my motivation is really for linking libraries into GDB,
    however, the binutils-gdb/config/ directory is a copy of gcc/config/
    so changes for GDB need to be approved by the GCC project first.
    
    After making this change in the gcc/config/ directory I've run
    autoreconf on all of the configure scripts in the GCC tree and a
    couple have been updated, so I'll use one of these to describe what my
    change does.
    
    Consider libcpp, this library links against libiconv.  Currently if
    the user builds on a system with both static and dynamic libiconv
    installed then autotools will pick up the dynamic libiconv by
    default.  This is almost certainly the right thing to do.
    
    However, if the user wants to link against static libiconv then things
    are a little harder, they could remove the dynamic libiconv from their
    system, but this is probably a bad idea (other things might depend on
    that library), or the user can build their own version of libiconv,
    install it into a unique prefix, and then configure gcc using the
    --with-libiconv-prefix=DIR flag.  This works fine, but is somewhat
    annoying, the static library available, I just can't get autotools to
    use it.
    
    My change then adds a new flag --with-libiconv-type=TYPE, where type
    is either auto, static, or shared.  The default auto, ensures we keep
    the existing behaviour unchanged.
    
    If the user configures with --with-libiconv-type=static then the
    configure script will ignore any dynamic libiconv it finds, and will
    only look for a static libiconv, if no static libiconv is found then
    the configure will continue as though there is no libiconv at all
    available.
    
    Similarly a user can specify --with-libiconv-type=shared and force the
    use of shared libiconv, any static libiconv will be ignored.
    
    As I've implemented this change within the AC_LIB_LINKFLAGS_BODY macro
    then only libraries configured using the AC_LIB_LINKFLAGS or
    AC_LIB_HAVE_LINKFLAGS macros will gain the new configure flag.
    
    If this is accepted into GCC then there will be follow on patches for
    binutils and GDB to regenerate some configure scripts in those
    projects.
    
    For GCC only two configure scripts needed updated after this commit,
    libcpp and libstdc++-v3, both of which link against libiconv.
    
    config/ChangeLog:
    
    	* lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Add new
    	--with-libXXX-type=... option.  Use this to guide the selection of
    	either a shared library or a static library.
    
    libcpp/ChangeLog:
    
    	* configure: Regenerate.
    
    libstdc++-v3/ChangeLog:
    
    	* configure: Regenerate.

Diff:
---
 config/ChangeLog       |  6 ++++++
 config/lib-link.m4     | 22 ++++++++++++++++------
 libcpp/ChangeLog       |  4 ++++
 libcpp/configure       | 29 +++++++++++++++++++++++------
 libstdc++-v3/ChangeLog |  4 ++++
 libstdc++-v3/configure | 47 ++++++++++++++++++++++++++++++++---------------
 6 files changed, 85 insertions(+), 27 deletions(-)

diff --git a/config/ChangeLog b/config/ChangeLog
index 9c8e40a..fb33919 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,9 @@
+2020-01-27  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Add new
+	--with-libXXX-type=... option.  Use this to guide the selection of
+	either a shared library or a static library.
+
 2020-01-24  Maciej W. Rozycki  <macro@wdc.com>
 
 	* toolexeclibdir.m4: New file.
diff --git a/config/lib-link.m4 b/config/lib-link.m4
index eeb200d..662192e 100644
--- a/config/lib-link.m4
+++ b/config/lib-link.m4
@@ -150,6 +150,11 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
       fi
     fi
 ])
+  AC_LIB_ARG_WITH([lib$1-type],
+[  --with-lib$1-type=TYPE     type of library to search for (auto/static/shared) ],
+  [ with_lib$1_type=$withval ], [ with_lib$1_type=auto ])
+  lib_type=`eval echo \$with_lib$1_type`
+
   dnl Search the library and its dependencies in $additional_libdir and
   dnl $LDFLAGS. Using breadth-first-seach.
   LIB[]NAME=
@@ -195,13 +200,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
           found_so=
           found_a=
           if test $use_additional = yes; then
-            if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
+            if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then
               found_dir="$additional_libdir"
               found_so="$additional_libdir/lib$name.$shlibext"
               if test -f "$additional_libdir/lib$name.la"; then
                 found_la="$additional_libdir/lib$name.la"
               fi
-            else
+            elif test x$lib_type != xshared; then
               if test -f "$additional_libdir/lib$name.$libext"; then
                 found_dir="$additional_libdir"
                 found_a="$additional_libdir/lib$name.$libext"
@@ -217,13 +222,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
               case "$x" in
                 -L*)
                   dir=`echo "X$x" | sed -e 's/^X-L//'`
-                  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
+                  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext" && test x$lib_type != xstatic; then
                     found_dir="$dir"
                     found_so="$dir/lib$name.$shlibext"
                     if test -f "$dir/lib$name.la"; then
                       found_la="$dir/lib$name.la"
                     fi
-                  else
+                  elif test x$lib_type != xshared; then
                     if test -f "$dir/lib$name.$libext"; then
                       found_dir="$dir"
                       found_a="$dir/lib$name.$libext"
@@ -487,8 +492,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
             dnl known to the linker and runtime loader. (All the system
             dnl directories known to the linker should also be known to the
             dnl runtime loader, otherwise the system is severely misconfigured.)
-            LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
-            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
+            if x$lib_type = xauto || x$lib_type = xshared; then
+              LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
+              LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
+            else
+              LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l:lib$name.$libext"
+              LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l:lib$name.$libext"
+            fi
           fi
         fi
       fi
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index e84c0da..ea9d602 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,7 @@
+2020-01-27  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* configure: Regenerate.
+
 2020-01-24  Nathan Sidwell  <nathan@acm.org>
 
 	* expr.c (parse_has_include): Remove bogus controlling macro code.
diff --git a/libcpp/configure b/libcpp/configure
index a7aa35c..7e53cad 100755
--- a/libcpp/configure
+++ b/libcpp/configure
@@ -730,6 +730,7 @@ enable_werror_always
 with_gnu_ld
 enable_rpath
 with_libiconv_prefix
+with_libiconv_type
 enable_maintainer_mode
 enable_checking
 enable_canonical_system_headers
@@ -1383,6 +1384,7 @@ Optional Packages:
   --with-gnu-ld           assume the C compiler uses GNU ld default=no
   --with-libiconv-prefix[=DIR]  search for libiconv in DIR/include and DIR/lib
   --without-libiconv-prefix     don't search for libiconv in includedir and libdir
+  --with-libiconv-type=TYPE     type of library to search for (auto/static/shared)
 
 Some influential environment variables:
   CC          C compiler command
@@ -6753,6 +6755,16 @@ if test "${with_libiconv_prefix+set}" = set; then :
 
 fi
 
+
+# Check whether --with-libiconv-type was given.
+if test "${with_libiconv_type+set}" = set; then :
+  withval=$with_libiconv_type;  with_libiconv_type=$withval
+else
+   with_libiconv_type=auto
+fi
+
+  lib_type=`eval echo \$with_libiconv_type`
+
       LIBICONV=
   LTLIBICONV=
   INCICONV=
@@ -6790,13 +6802,13 @@ fi
           found_so=
           found_a=
           if test $use_additional = yes; then
-            if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
+            if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then
               found_dir="$additional_libdir"
               found_so="$additional_libdir/lib$name.$shlibext"
               if test -f "$additional_libdir/lib$name.la"; then
                 found_la="$additional_libdir/lib$name.la"
               fi
-            else
+            elif test x$lib_type != xshared; then
               if test -f "$additional_libdir/lib$name.$libext"; then
                 found_dir="$additional_libdir"
                 found_a="$additional_libdir/lib$name.$libext"
@@ -6820,13 +6832,13 @@ fi
               case "$x" in
                 -L*)
                   dir=`echo "X$x" | sed -e 's/^X-L//'`
-                  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
+                  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext" && test x$lib_type != xstatic; then
                     found_dir="$dir"
                     found_so="$dir/lib$name.$shlibext"
                     if test -f "$dir/lib$name.la"; then
                       found_la="$dir/lib$name.la"
                     fi
-                  else
+                  elif test x$lib_type != xshared; then
                     if test -f "$dir/lib$name.$libext"; then
                       found_dir="$dir"
                       found_a="$dir/lib$name.$libext"
@@ -7054,8 +7066,13 @@ fi
               done
             fi
           else
-                                                            LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name"
-            LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name"
+                                                            if x$lib_type = xauto || x$lib_type = xshared; then
+              LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name"
+              LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name"
+            else
+              LIBICONV="${LIBICONV}${LIBICONV:+ }-l:lib$name.$libext"
+              LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l:lib$name.$libext"
+            fi
           fi
         fi
       fi
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 2b877a8..e49950c 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,7 @@
+2020-01-27  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* configure: Regenerate.
+
 2020-01-27  Jonathan Wakely  <jwakely@redhat.com>
 
 	PR libstdc++/93426
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 3af3dec..60ad38b 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -931,6 +931,7 @@ enable_libstdcxx_time
 enable_tls
 enable_rpath
 with_libiconv_prefix
+with_libiconv_type
 with_system_libunwind
 enable_linux_futex
 enable_symvers
@@ -1665,6 +1666,7 @@ Optional Packages:
   --with-gnu-ld           assume the C compiler uses GNU ld default=no
   --with-libiconv-prefix[=DIR]  search for libiconv in DIR/include and DIR/lib
   --without-libiconv-prefix     don't search for libiconv in includedir and libdir
+  --with-libiconv-type=TYPE     type of library to search for (auto/static/shared)
   --with-system-libunwind use installed libunwind
   --with-default-libstdcxx-abi
                           set the std::string ABI to use by default
@@ -12057,7 +12059,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12060 "configure"
+#line 12062 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12163,7 +12165,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12166 "configure"
+#line 12168 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15855,7 +15857,7 @@ $as_echo "$glibcxx_cv_atomic_long_long" >&6; }
   # Fake what AC_TRY_COMPILE does.
 
     cat > conftest.$ac_ext << EOF
-#line 15858 "configure"
+#line 15860 "configure"
 int main()
 {
   typedef bool atomic_type;
@@ -15890,7 +15892,7 @@ $as_echo "$glibcxx_cv_atomic_bool" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 15893 "configure"
+#line 15895 "configure"
 int main()
 {
   typedef short atomic_type;
@@ -15925,7 +15927,7 @@ $as_echo "$glibcxx_cv_atomic_short" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 15928 "configure"
+#line 15930 "configure"
 int main()
 {
   // NB: _Atomic_word not necessarily int.
@@ -15961,7 +15963,7 @@ $as_echo "$glibcxx_cv_atomic_int" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 15964 "configure"
+#line 15966 "configure"
 int main()
 {
   typedef long long atomic_type;
@@ -16114,7 +16116,7 @@ $as_echo "mutex" >&6; }
   # unnecessary for this test.
 
     cat > conftest.$ac_ext << EOF
-#line 16117 "configure"
+#line 16119 "configure"
 int main()
 {
   _Decimal32 d1;
@@ -16156,7 +16158,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
   # unnecessary for this test.
 
     cat > conftest.$ac_ext << EOF
-#line 16159 "configure"
+#line 16161 "configure"
 template<typename T1, typename T2>
   struct same
   { typedef T2 type; };
@@ -16190,7 +16192,7 @@ $as_echo "$enable_int128" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 16193 "configure"
+#line 16195 "configure"
 template<typename T1, typename T2>
   struct same
   { typedef T2 type; };
@@ -29156,6 +29158,16 @@ if test "${with_libiconv_prefix+set}" = set; then :
 
 fi
 
+
+# Check whether --with-libiconv-type was given.
+if test "${with_libiconv_type+set}" = set; then :
+  withval=$with_libiconv_type;  with_libiconv_type=$withval
+else
+   with_libiconv_type=auto
+fi
+
+  lib_type=`eval echo \$with_libiconv_type`
+
       LIBICONV=
   LTLIBICONV=
   INCICONV=
@@ -29193,13 +29205,13 @@ fi
           found_so=
           found_a=
           if test $use_additional = yes; then
-            if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
+            if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then
               found_dir="$additional_libdir"
               found_so="$additional_libdir/lib$name.$shlibext"
               if test -f "$additional_libdir/lib$name.la"; then
                 found_la="$additional_libdir/lib$name.la"
               fi
-            else
+            elif test x$lib_type != xshared; then
               if test -f "$additional_libdir/lib$name.$libext"; then
                 found_dir="$additional_libdir"
                 found_a="$additional_libdir/lib$name.$libext"
@@ -29223,13 +29235,13 @@ fi
               case "$x" in
                 -L*)
                   dir=`echo "X$x" | sed -e 's/^X-L//'`
-                  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
+                  if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext" && test x$lib_type != xstatic; then
                     found_dir="$dir"
                     found_so="$dir/lib$name.$shlibext"
                     if test -f "$dir/lib$name.la"; then
                       found_la="$dir/lib$name.la"
                     fi
-                  else
+                  elif test x$lib_type != xshared; then
                     if test -f "$dir/lib$name.$libext"; then
                       found_dir="$dir"
                       found_a="$dir/lib$name.$libext"
@@ -29457,8 +29469,13 @@ fi
               done
             fi
           else
-                                                            LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name"
-            LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name"
+                                                            if x$lib_type = xauto || x$lib_type = xshared; then
+              LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name"
+              LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name"
+            else
+              LIBICONV="${LIBICONV}${LIBICONV:+ }-l:lib$name.$libext"
+              LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l:lib$name.$libext"
+            fi
           fi
         fi
       fi



More information about the Libstdc++-cvs mailing list