static void add_env_var_paths (const char *, int);
static void add_standard_paths (const char *, const char *, const char *, int);
static void free_path (struct cpp_dir *, int);
-static void merge_include_chains (cpp_reader *, int);
+static void merge_include_chains (const char *, cpp_reader *, int);
+static void add_sysroot_to_chain (const char *, int);
static struct cpp_dir *remove_duplicates (cpp_reader *, struct cpp_dir *,
struct cpp_dir *,
struct cpp_dir *, int);
/* Should this directory start with the sysroot? */
if (sysroot && p->add_sysroot)
str = concat (sysroot, p->fname, NULL);
- else if (!p->add_sysroot && relocated)
+ else if (!p->add_sysroot && relocated
+ && strncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len) == 0)
{
- /* If the compiler is relocated, and this is a configured
- prefix relative path, then we use gcc_exec_prefix instead
- of the configured prefix. */
- gcc_assert (strncmp (p->fname, cpp_PREFIX,
- cpp_PREFIX_len) == 0);
- str = concat (gcc_exec_prefix, p->fname
- + cpp_PREFIX_len, NULL);
+ static const char *relocated_prefix;
+ /* 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
+ is GCC_EXEC_PREFIX. Compute the path from there back
+ to the toplevel prefix. */
+ if (!relocated_prefix)
+ {
+ char *dummy;
+ /* Make relative prefix expects the first argument
+ to be a program, not a directory. */
+ dummy = concat (gcc_exec_prefix, "dummy", NULL);
+ relocated_prefix
+ = make_relative_prefix (dummy,
+ cpp_EXEC_PREFIX,
+ cpp_PREFIX);
+ }
+ str = concat (relocated_prefix,
+ p->fname + cpp_PREFIX_len,
+ NULL);
str = update_path (str, p->component);
}
else
return head;
}
+/* Add SYSROOT to any user-supplied paths in CHAIN starting with
+ "=". */
+
+static void
+add_sysroot_to_chain (const char *sysroot, int chain)
+{
+ struct cpp_dir *p;
+
+ for (p = heads[chain]; p != NULL; p = p->next)
+ if (p->name[0] == '=' && p->user_supplied_p)
+ p->name = concat (sysroot, p->name + 1, NULL);
+}
+
/* Merge the four include chains together in the order quote, bracket,
system, after. Remove duplicate dirs (as determined by
INO_T_EQ()).
written -iquote bar -Ifoo -Iquux. */
static void
-merge_include_chains (cpp_reader *pfile, int verbose)
+merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose)
{
+ /* Add the sysroot to user-supplied paths starting with "=". */
+ if (sysroot)
+ {
+ add_sysroot_to_chain (sysroot, QUOTE);
+ add_sysroot_to_chain (sysroot, BRACKET);
+ add_sysroot_to_chain (sysroot, SYSTEM);
+ add_sysroot_to_chain (sysroot, AFTER);
+ }
+
/* Join the SYSTEM and AFTER chains. Remove duplicates in the
resulting SYSTEM chain. */
if (heads[SYSTEM])
cpp_dir *p;
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
- /* Convert all backslashes to slashes. The native CRT stat()
- function does not recognize a directory that ends in a backslash
- (unless it is a drive root dir, such "c:\"). Forward slashes,
- trailing or otherwise, cause no problems for stat(). */
- char* c;
- for (c = path; *c; c++)
- if (*c == '\\') *c = '/';
+ /* Remove unnecessary trailing slashes. On some versions of MS
+ Windows, trailing _forward_ slashes cause no problems for stat().
+ On newer versions, stat() does not recognize a directory that ends
+ in a '\\' or '/', unless it is a drive root dir, such as "c:/",
+ where it is obligatory. */
+ int pathlen = strlen (path);
+ char* end = path + pathlen - 1;
+ /* Preserve the lead '/' or lead "c:/". */
+ char* start = path + (pathlen > 2 && path[1] == ':' ? 3 : 1);
+
+ for (; end > start && IS_DIR_SEPARATOR (*end); end--)
+ *end = 0;
#endif
p = XNEW (cpp_dir);
target_c_incpath.extra_includes (sysroot, iprefix, stdinc);
- merge_include_chains (pfile, verbose);
+ merge_include_chains (sysroot, pfile, verbose);
cpp_set_include_chains (pfile, heads[QUOTE], heads[BRACKET],
quote_ignores_source_dir);