libitm.exp: Reorder lib loads into dependency order.
[gcc.git] / gcc / incpath.c
index aab6e15ab1a7fd3c6a5db0f212df9af926e4a292..018da982c14cd947f4896ac1cbd569ad18a5d653 100644 (file)
@@ -1,7 +1,5 @@
 /* Set up combined include path chain for the preprocessor.
-   Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010
-   Free Software Foundation, Inc.
+   Copyright (C) 1986-2013 Free Software Foundation, Inc.
 
    Broken out of cppinit.c and cppfiles.c and rewritten Mar 2003.
 
@@ -150,8 +148,19 @@ add_standard_paths (const char *sysroot, const char *iprefix,
              if (!filename_ncmp (p->fname, cpp_GCC_INCLUDE_DIR, len))
                {
                  char *str = concat (iprefix, p->fname + len, NULL);
-                 if (p->multilib && imultilib)
-                   str = concat (str, dir_separator_str, imultilib, NULL);
+                 if (p->multilib == 1 && imultilib)
+                   str = reconcat (str, str, dir_separator_str,
+                                   imultilib, NULL);
+                 else if (p->multilib == 2)
+                   {
+                     if (!imultiarch)
+                       {
+                         free (str);
+                         continue;
+                       }
+                     str = reconcat (str, str, dir_separator_str,
+                                     imultiarch, NULL);
+                   }
                  add_path (str, SYSTEM, p->cxx_aware, false);
                }
            }
@@ -166,11 +175,20 @@ add_standard_paths (const char *sysroot, const char *iprefix,
 
          /* Should this directory start with the sysroot?  */
          if (sysroot && p->add_sysroot)
-           str = concat (sysroot, p->fname, NULL);
+           {
+             char *sysroot_no_trailing_dir_separator = xstrdup (sysroot);
+             size_t sysroot_len = strlen (sysroot);
+
+             if (sysroot_len > 0 && sysroot[sysroot_len - 1] == DIR_SEPARATOR)
+               sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
+             str = concat (sysroot_no_trailing_dir_separator, p->fname, NULL);
+             free (sysroot_no_trailing_dir_separator);
+           }
          else if (!p->add_sysroot && relocated
                   && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len))
            {
              static const char *relocated_prefix;
+             char *ostr;
              /* If this path starts with the configure-time prefix,
                 but the compiler has been relocated, replace it
                 with the run-time prefix.  The run-time exec prefix
@@ -186,17 +204,28 @@ add_standard_paths (const char *sysroot, const char *iprefix,
                    = make_relative_prefix (dummy,
                                            cpp_EXEC_PREFIX,
                                            cpp_PREFIX);
+                 free (dummy);
                }
-             str = concat (relocated_prefix,
-                           p->fname + cpp_PREFIX_len,
-                           NULL);
-             str = update_path (str, p->component);
+             ostr = concat (relocated_prefix,
+                            p->fname + cpp_PREFIX_len,
+                            NULL);
+             str = update_path (ostr, p->component);
+             free (ostr);
            }
          else
            str = update_path (p->fname, p->component);
 
-         if (p->multilib && imultilib)
-           str = concat (str, dir_separator_str, imultilib, NULL);
+         if (p->multilib == 1 && imultilib)
+           str = reconcat (str, str, dir_separator_str, imultilib, NULL);
+         else if (p->multilib == 2)
+           {
+             if (!imultiarch)
+               {
+                 free (str);
+                 continue;
+               }
+             str = reconcat (str, str, dir_separator_str, imultiarch, NULL);
+           }
 
          add_path (str, SYSTEM, p->cxx_aware, false);
        }
@@ -362,8 +391,10 @@ merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose)
 void
 split_quote_chain (void)
 {
-  free_path (heads[QUOTE], REASON_QUIET);
-  free_path (tails[QUOTE], REASON_QUIET);
+  if (heads[QUOTE])
+    free_path (heads[QUOTE], REASON_QUIET);
+  if (tails[QUOTE])
+    free_path (tails[QUOTE], REASON_QUIET);
   heads[QUOTE] = heads[BRACKET];
   tails[QUOTE] = tails[BRACKET];
   heads[BRACKET] = NULL;
@@ -458,6 +489,15 @@ register_include_chains (cpp_reader *pfile, const char *sysroot,
   cpp_set_include_chains (pfile, heads[QUOTE], heads[BRACKET],
                          quote_ignores_source_dir);
 }
+
+/* Return the current chain of cpp dirs.  */
+
+struct cpp_dir *
+get_added_cpp_dirs (int chain)
+{
+  return heads[chain];
+}
+
 #if !(defined TARGET_EXTRA_INCLUDES) || !(defined TARGET_EXTRA_PRE_INCLUDES)
 static void hook_void_charptr_charptr_int (const char *sysroot ATTRIBUTE_UNUSED,
                                           const char *iprefix ATTRIBUTE_UNUSED,