2005-02-06 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / ld / ldmain.c
index 04672f3b5d3e157891bd4bd5d5d34aedfaecd7da..2b58d63129d74de17ff564899093ed9dcbc8eba5 100644 (file)
@@ -68,7 +68,7 @@ const char *output_filename = "a.out";
 char *program_name;
 
 /* The prefix for system library directories.  */
-char *ld_sysroot;
+const char *ld_sysroot;
 
 /* The canonical representation of ld_sysroot.  */
 char * ld_canon_sysroot;
@@ -110,6 +110,8 @@ ld_config_type config;
 
 sort_type sort_section;
 
+static const char *get_sysroot
+  (int, char **);
 static char *get_emulation
   (int, char **);
 static void set_scripts_dir
@@ -201,47 +203,18 @@ main (int argc, char **argv)
 
   xatexit (remove_output);
 
-#ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
-  ld_sysroot = make_relative_prefix (program_name, BINDIR,
-                                    TARGET_SYSTEM_ROOT);
-
-  if (ld_sysroot)
+  /* Set up the sysroot directory.  */
+  ld_sysroot = get_sysroot (argc, argv);
+  if (*ld_sysroot)
     {
-      struct stat s;
-      int res = stat (ld_sysroot, &s) == 0 && S_ISDIR (s.st_mode);
-
-      if (!res)
+      if (*TARGET_SYSTEM_ROOT == 0)
        {
-         free (ld_sysroot);
-         ld_sysroot = NULL;
-       }
-    }
-
-  if (! ld_sysroot)
-    {
-      ld_sysroot = make_relative_prefix (program_name, TOOLBINDIR,
-                                        TARGET_SYSTEM_ROOT);
-
-      if (ld_sysroot)
-       {
-         struct stat s;
-         int res = stat (ld_sysroot, &s) == 0 && S_ISDIR (s.st_mode);
-
-         if (!res)
-           {
-             free (ld_sysroot);
-             ld_sysroot = NULL;
-           }
+         einfo ("%P%F: this linker was not configured to use sysroots");
+         ld_sysroot = "";
        }
+      else
+       ld_canon_sysroot = lrealpath (ld_sysroot);
     }
-
-  if (! ld_sysroot)
-#endif
-    ld_sysroot = TARGET_SYSTEM_ROOT;
-
-  if (ld_sysroot && *ld_sysroot)
-    ld_canon_sysroot = lrealpath (ld_sysroot);
-
   if (ld_canon_sysroot)
     ld_canon_sysroot_len = strlen (ld_canon_sysroot);
   else
@@ -370,6 +343,9 @@ main (int argc, char **argv)
        einfo (_("%P%F: -r and -shared may not be used together\n"));
     }
 
+   if (!config.dynamic_link && link_info.shared)
+     einfo (_("%P%F: -static and -shared may not be used together\n"));
+
   if (! link_info.shared)
     {
       if (command_line.filter_shlib)
@@ -584,6 +560,51 @@ main (int argc, char **argv)
   return 0;
 }
 
+/* If the configured sysroot is relocatable, try relocating it based on
+   default prefix FROM.  Return the relocated directory if it exists,
+   otherwise return null.  */
+
+static char *
+get_relative_sysroot (const char *from ATTRIBUTE_UNUSED)
+{
+#ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
+  char *path;
+  struct stat s;
+
+  path = make_relative_prefix (program_name, from, TARGET_SYSTEM_ROOT);
+  if (path)
+    {
+      if (stat (path, &s) == 0 && S_ISDIR (s.st_mode))
+       return path;
+      free (path);
+    }
+#endif
+  return 0;
+}
+
+/* Return the sysroot directory.  Return "" if no sysroot is being used.  */
+
+static const char *
+get_sysroot (int argc, char **argv)
+{
+  int i;
+  const char *path;
+
+  for (i = 1; i < argc; i++)
+    if (strncmp (argv[i], "--sysroot=", strlen ("--sysroot=")) == 0)
+      return argv[i] + strlen ("--sysroot=");
+
+  path = get_relative_sysroot (BINDIR);
+  if (path)
+    return path;
+
+  path = get_relative_sysroot (TOOLBINDIR);
+  if (path)
+    return path;
+
+  return TARGET_SYSTEM_ROOT;
+}
+
 /* We need to find any explicitly given emulation in order to initialize the
    state that's needed by the lex&yacc argument parser (parse_args).  */
 
This page took 0.038496 seconds and 4 git commands to generate.