X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fc-incpath.c;h=f8b524d6e1176a5a0e7ded5d83050bc377375f23;hb=4c47c8b7d39c1da50b5cefeb4e28f9c9d77d19f4;hp=3a9585bd26de23edf8778804a9bbe61e71a1d4f5;hpb=a8bb4f69a81ee6ab68e7883a86c824781bbc5eb3;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/c-incpath.c b/gcc/c-incpath.c index 3a9585bd26d..f8b524d6e11 100644 --- a/gcc/c-incpath.c +++ b/gcc/c-incpath.c @@ -1,23 +1,23 @@ /* 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 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. Broken out of cppinit.c and cppfiles.c and rewritten Mar 2003. -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3, or (at your option) any + later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING3. If not see + . */ #include "config.h" #include "system.h" @@ -51,7 +51,8 @@ static const char dir_separator_str[] = { DIR_SEPARATOR, 0 }; 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); @@ -282,6 +283,19 @@ remove_duplicates (cpp_reader *pfile, struct cpp_dir *head, 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()). @@ -293,8 +307,17 @@ remove_duplicates (cpp_reader *pfile, struct cpp_dir *head, 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]) @@ -366,13 +389,18 @@ add_path (char *path, int chain, int cxx_aware, bool user_supplied_p) 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); @@ -419,7 +447,7 @@ register_include_chains (cpp_reader *pfile, const char *sysroot, 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);