/* 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
- Free Software Foundation, Inc.
+ Copyright (C) 1986-2015 Free Software Foundation, Inc.
Broken out of cppinit.c and cppfiles.c and rewritten Mar 2003.
#include "config.h"
#include "system.h"
#include "coretypes.h"
-#include "machmode.h"
#include "target.h"
#include "tm.h"
#include "cpplib.h"
#include "incpath.h"
#include "cppdefault.h"
-/* Windows does not natively support inodes, and neither does MSDOS.
- Cygwin's emulation can generate non-unique inodes, so don't use it.
+/* Microsoft Windows does not natively support inodes.
VMS has non-numeric inodes. */
#ifdef VMS
# define INO_T_EQ(A, B) (!memcmp (&(A), &(B), sizeof (A)))
-# define INO_T_COPY(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof (SRC))
-#elif !((defined _WIN32 && !defined (_UWIN)) || defined __MSDOS__)
+# define INO_T_COPY(DEST, SRC) memcpy (&(DEST), &(SRC), sizeof (SRC))
+#elif !defined (HOST_LACKS_INODE_NUMBERS)
# define INO_T_EQ(A, B) ((A) == (B))
# define INO_T_COPY(DEST, SRC) (DEST) = (SRC)
#endif
#if defined INO_T_EQ
#define DIRS_EQ(A, B) ((A)->dev == (B)->dev \
- && INO_T_EQ((A)->ino, (B)->ino))
+ && INO_T_EQ ((A)->ino, (B)->ino))
#else
-#define DIRS_EQ(A, B) (!strcasecmp ((A)->name, (B)->name))
+#define DIRS_EQ(A, B) (!filename_cmp ((A)->canonical_name, (B)->canonical_name))
#endif
static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
{
char *p, *q, *path;
- GET_ENVIRONMENT (q, env_var);
+ q = getenv (env_var);
if (!q)
return;
const char *imultilib, int cxx_stdinc)
{
const struct default_include *p;
- int relocated = cpp_relocated();
+ int relocated = cpp_relocated ();
size_t len;
if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0)
now. */
if (sysroot && p->add_sysroot)
continue;
- if (!strncmp (p->fname, cpp_GCC_INCLUDE_DIR, len))
+ 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);
}
}
/* 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
- && strncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len) == 0)
+ && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len))
{
static const char *relocated_prefix;
- /* If this path starts with the configure-time prefix,
- but the compiler has been relocated, replace it
+ 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
is GCC_EXEC_PREFIX. Compute the path from there back
to the toplevel prefix. */
/* Make relative prefix expects the first argument
to be a program, not a directory. */
dummy = concat (gcc_exec_prefix, "dummy", NULL);
- relocated_prefix
+ relocated_prefix
= 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);
}
/* If -Wmissing-include-dirs is given, warn. */
cpp_options *opts = cpp_get_options (pfile);
if (opts->warn_missing_include_dirs && cur->user_supplied_p)
- cpp_errno (pfile, CPP_DL_WARNING, cur->name);
+ cpp_warning (pfile, CPP_W_MISSING_INCLUDE_DIRS, "%s: %s",
+ cur->name, xstrerror (errno));
reason = REASON_NOENT;
}
}
else if (!S_ISDIR (st.st_mode))
- cpp_error_with_line (pfile, CPP_DL_ERROR, 0, 0,
+ cpp_error_with_line (pfile, CPP_DL_WARNING, 0, 0,
"%s: not a directory", cur->name);
else
{
void
split_quote_chain (void)
{
+ 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;
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);
p->next = NULL;
p->name = path;
+#ifndef INO_T_EQ
+ p->canonical_name = lrealpath (path);
+#endif
if (chain == SYSTEM || chain == AFTER)
p->sysp = 1 + !cxx_aware;
else
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,