* configure.ac: Add --with-lib-path option. Define LIB_PATH and
authorIan Lance Taylor <ian@airs.com>
Thu, 3 Nov 2011 04:32:01 +0000 (04:32 +0000)
committerIan Lance Taylor <ian@airs.com>
Thu, 3 Nov 2011 04:32:01 +0000 (04:32 +0000)
NATIVE_LINKER.
* Makefile.am (AM_CPPFLAGS): Define TOOLLIBDIR.
* options.cc (General_options::finalize): Use library search path
from configure script if specified.  If not native and no sysroot,
only search TOOLLIBDIR.
* options.h (Search_directory::Search_directory): Change name to
const std::string&.
(General_options::add_to_library_path_with_sysroot): Change arg to
const std::string&.
* configure, Makefile.in, config.in: Rebuild.

gold/ChangeLog
gold/Makefile.am
gold/Makefile.in
gold/config.in
gold/configure
gold/configure.ac
gold/options.cc
gold/options.h

index eb87996d1fbe1c71f979f5459661349321b1fa97..aac3aa0f49542b6caf7d295f951c976569952d76 100644 (file)
@@ -1,3 +1,17 @@
+2011-11-02  Ian Lance Taylor  <iant@google.com>
+
+       * configure.ac: Add --with-lib-path option.  Define LIB_PATH and
+       NATIVE_LINKER.
+       * Makefile.am (AM_CPPFLAGS): Define TOOLLIBDIR.
+       * options.cc (General_options::finalize): Use library search path
+       from configure script if specified.  If not native and no sysroot,
+       only search TOOLLIBDIR.
+       * options.h (Search_directory::Search_directory): Change name to
+       const std::string&.
+       (General_options::add_to_library_path_with_sysroot): Change arg to
+       const std::string&.
+       * configure, Makefile.in, config.in: Rebuild.
+
 2011-11-02  Matthew Gretton-Dann  <matthew.gretton-dann@arm.com>
 
        * arm.cc (Target_arm::may_use_v5t_interworking): Check whether
index c1c3588ef08f0478f381b6c2aedca28e83463d00..d121ac444c44dd341975e535feff747c0537248a 100644 (file)
@@ -15,7 +15,7 @@ AM_CPPFLAGS = \
        -I$(srcdir) -I$(srcdir)/../include -I$(srcdir)/../elfcpp \
        -DLOCALEDIR="\"$(datadir)/locale\"" \
        -DBINDIR="\"$(bindir)\"" -DTOOLBINDIR="\"$(tooldir)/bin\"" \
-       @INCINTL@
+       -DTOOLLIBDIR="\"$(tooldir)/lib\"" @INCINTL@
 
 LIBIBERTY = ../libiberty/libiberty.a
 
index ff6d7c281cefa773d2190d0db83c10376d5b9ddf..0fa739ad3f46d4156fb7f861eacc99068b967e06 100644 (file)
@@ -369,7 +369,7 @@ AM_CPPFLAGS = \
        -I$(srcdir) -I$(srcdir)/../include -I$(srcdir)/../elfcpp \
        -DLOCALEDIR="\"$(datadir)/locale\"" \
        -DBINDIR="\"$(bindir)\"" -DTOOLBINDIR="\"$(tooldir)/bin\"" \
-       @INCINTL@
+       -DTOOLLIBDIR="\"$(tooldir)/lib\"" @INCINTL@
 
 LIBIBERTY = ../libiberty/libiberty.a
 @PLUGINS_TRUE@LIBDL = -ldl
index 86113763d9ba16bcd33e0d2966398d8e2059d8da..2854620ec94e552f73d0a6d5cebf643f6a0b7408 100644 (file)
 /* Define to 1 if you have the <zlib.h> header file. */
 #undef HAVE_ZLIB_H
 
+/* Default library search path */
+#undef LIB_PATH
+
+/* Whether configured as a native linker */
+#undef NATIVE_LINKER
+
 /* Name of package */
 #undef PACKAGE
 
index 708f540a23e53ded7980c85f0f2430a48de82676..3dddec67c2c5177fa93d34c38cce44f8865209de 100755 (executable)
@@ -775,6 +775,7 @@ enable_gold
 enable_threads
 enable_plugins
 enable_targets
+with_lib_path
 enable_dependency_tracking
 enable_nls
 enable_werror
@@ -1435,6 +1436,7 @@ Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
   --with-sysroot=DIR    search for usr/lib et al within DIR
+  --with-lib-path=dir1:dir2...  set default LIB_PATH
   --with-gold-ldflags=FLAGS  additional link flags for gold
   --with-gold-ldadd=LIBS     additional libraries for gold
 
@@ -3535,6 +3537,29 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+
+# Check whether --with-lib-path was given.
+if test "${with_lib_path+set}" = set; then :
+  withval=$with_lib_path; case "$withval" in
+ yes) LIB_PATH='"/lib:/usr/lib"' ;;
+ no) LIB_PATH='""' ;;
+ *) LIB_PATH='"'"$withval"'"' ;;
+ esac
+else
+  LIB_PATH='"::DEFAULT::"'
+fi
+
+
+cat >>confdefs.h <<_ACEOF
+#define LIB_PATH $LIB_PATH
+_ACEOF
+
+if test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias"; then
+
+$as_echo "#define NATIVE_LINKER 1" >>confdefs.h
+
+fi
+
 if test -n "$ac_tool_prefix"; then
   # Extract the first word of "${ac_tool_prefix}nm", so it can be a program name with args.
 set dummy ${ac_tool_prefix}nm; ac_word=$2
index 905dbaf1c706361406b927409697346ebaa138d3..1b46f4a8521ae9fb3a16310a5bd55a327f98863b 100644 (file)
@@ -238,6 +238,20 @@ AC_DEFINE_UNQUOTED(GOLD_DEFAULT_BIG_ENDIAN, $default_big_endian,
 AC_DEFINE_UNQUOTED(GOLD_DEFAULT_OSABI, $default_osabi,
                   [Default OSABI code])
 
+AC_ARG_WITH(lib-path,
+[  --with-lib-path=dir1:dir2...  set default LIB_PATH],
+[case "$withval" in
+ yes) LIB_PATH='"/lib:/usr/lib"' ;;
+ no) LIB_PATH='""' ;;
+ *) LIB_PATH='"'"$withval"'"' ;;
+ esac],
+[LIB_PATH='"::DEFAULT::"'])
+AC_DEFINE_UNQUOTED(LIB_PATH, $LIB_PATH,
+                  [Default library search path])
+if test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias"; then
+  AC_DEFINE(NATIVE_LINKER, 1, [Whether configured as a native linker])
+fi
+
 AC_CHECK_TOOL(NM, nm)
 
 AC_PROG_CC
index dcf6ba71ace25c080fa3d479cd09bbf94f1be921..64a8539d2ff1e1531d0ec90fccb30404821d7d86 100644 (file)
@@ -1121,33 +1121,48 @@ General_options::finalize()
                  program_name);
 #endif
 
+  std::string libpath;
   if (this->user_set_Y())
     {
-      std::string s = this->Y();
-      if (s.compare(0, 2, "P,") == 0)
-       s.erase(0, 2);
+      libpath = this->Y();
+      if (libpath.compare(0, 2, "P,") == 0)
+       libpath.erase(0, 2);
+    }
+  else if (!this->nostdlib())
+    {
+#ifndef NATIVE_LINKER
+#define NATIVE_LINKER 0
+#endif
+      const char* p = LIB_PATH;
+      if (strcmp(p, "::DEFAULT::") != 0)
+       libpath = p;
+      else if (NATIVE_LINKER
+              || this->user_set_sysroot()
+              || *TARGET_SYSTEM_ROOT != '\0')
+       {
+         this->add_to_library_path_with_sysroot("/lib");
+         this->add_to_library_path_with_sysroot("/usr/lib");
+       }
+      else
+       this->add_to_library_path_with_sysroot(TOOLLIBDIR);
+    }
 
+  if (!libpath.empty())
+    {
       size_t pos = 0;
       size_t next_pos;
       do
        {
-         next_pos = s.find(':', pos);
+         next_pos = libpath.find(':', pos);
          size_t len = (next_pos == std::string::npos
                        ? next_pos
                        : next_pos - pos);
          if (len != 0)
-           this->add_to_library_path_with_sysroot(s.substr(pos, len).c_str());
+           this->add_to_library_path_with_sysroot(libpath.substr(pos, len));
          pos = next_pos + 1;
        }
       while (next_pos != std::string::npos);
     }
-  else if (!this->nostdlib())
-    {
-      // Even if they don't specify it, we add -L /lib and -L /usr/lib.
-      // FIXME: We should only do this when configured in native mode.
-      this->add_to_library_path_with_sysroot("/lib");
-      this->add_to_library_path_with_sysroot("/usr/lib");
-    }
 
   // Parse the contents of -retain-symbols-file into a set.
   if (this->retain_symbols_file())
index 8876a1eedd66bd887c1e919100178350ee970231..534df26623f248cdb1d009e5f4d7a20d179e126a 100644 (file)
@@ -543,7 +543,7 @@ class Search_directory
   { }
 
   // This is the usual constructor.
-  Search_directory(const char* name, bool put_in_sysroot)
+  Search_directory(const std::string& name, bool put_in_sysroot)
     : name_(name), put_in_sysroot_(put_in_sysroot), is_in_sysroot_(false)
   {
     if (this->name_.empty())
@@ -1463,7 +1463,7 @@ class General_options
 
   // These are called by finalize() to set up the search-path correctly.
   void
-  add_to_library_path_with_sysroot(const char* arg)
+  add_to_library_path_with_sysroot(const std::string& arg)
   { this->add_search_directory_to_library_path(Search_directory(arg, true)); }
 
   // Apply any sysroot to the directory lists.