diff options
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r-- | gcc/cppinit.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 591b4bf..40b5059 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -529,6 +529,7 @@ cpp_create_reader (lang) CPP_OPTION (pfile, warn_endif_labels) = 1; CPP_OPTION (pfile, warn_deprecated) = 1; CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99); + CPP_OPTION (pfile, sysroot) = cpp_SYSROOT; CPP_OPTION (pfile, pending) = (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending)); @@ -757,46 +758,26 @@ init_standard_includes (pfile) { const struct default_include *p; const char *specd_prefix = CPP_OPTION (pfile, include_prefix); + int default_len, specd_len; + char *default_prefix; /* Search "translated" versions of GNU directories. These have /usr/local/lib/gcc... replaced by specd_prefix. */ + default_len = 0; + specd_len = 0; + default_prefix = NULL; if (specd_prefix != 0 && cpp_GCC_INCLUDE_DIR_len) { /* Remove the `include' from /usr/local/lib/gcc.../include. GCC_INCLUDE_DIR will always end in /include. */ - int default_len = cpp_GCC_INCLUDE_DIR_len; - char *default_prefix = (char *) alloca (default_len + 1); - int specd_len = strlen (specd_prefix); + default_len = cpp_GCC_INCLUDE_DIR_len; + default_prefix = (char *) alloca (default_len + 1); + specd_len = strlen (specd_prefix); memcpy (default_prefix, cpp_GCC_INCLUDE_DIR, default_len); default_prefix[default_len] = '\0'; - - for (p = cpp_include_defaults; p->fname; p++) - { - /* Some standard dirs are only for C++. */ - if (!p->cplusplus - || (CPP_OPTION (pfile, cplusplus) - && !CPP_OPTION (pfile, no_standard_cplusplus_includes))) - { - /* Does this dir start with the prefix? */ - if (!strncmp (p->fname, default_prefix, default_len)) - { - /* Yes; change prefix and add to search list. */ - int flen = strlen (p->fname); - int this_len = specd_len + flen - default_len; - char *str = (char *) xmalloc (this_len + 1); - memcpy (str, specd_prefix, specd_len); - memcpy (str + specd_len, - p->fname + default_len, - flen - default_len + 1); - - append_include_chain (pfile, str, SYSTEM, p->cxx_aware); - } - } - } } - /* Search ordinary names for GNU include directories. */ for (p = cpp_include_defaults; p->fname; p++) { /* Some standard dirs are only for C++. */ @@ -804,7 +785,30 @@ init_standard_includes (pfile) || (CPP_OPTION (pfile, cplusplus) && !CPP_OPTION (pfile, no_standard_cplusplus_includes))) { - char *str = update_path (p->fname, p->component); + char *str; + + /* Should this dir start with the sysroot? */ + if (p->add_sysroot && CPP_OPTION (pfile, sysroot)) + str = concat (CPP_OPTION (pfile, sysroot), p->fname, NULL); + + /* Does this dir start with the prefix? */ + else if (default_len + && !strncmp (p->fname, default_prefix, default_len)) + { + /* Yes; change prefix and add to search list. */ + int flen = strlen (p->fname); + int this_len = specd_len + flen - default_len; + + str = (char *) xmalloc (this_len + 1); + memcpy (str, specd_prefix, specd_len); + memcpy (str + specd_len, + p->fname + default_len, + flen - default_len + 1); + } + + else + str = update_path (p->fname, p->component); + append_include_chain (pfile, str, SYSTEM, p->cxx_aware); } } @@ -1161,6 +1165,7 @@ new_pending_directive (pend, text, handler) DEF_OPT("imacros", no_fil, OPT_imacros) \ DEF_OPT("include", no_fil, OPT_include) \ DEF_OPT("iprefix", no_pth, OPT_iprefix) \ + DEF_OPT("isysroot", no_dir, OPT_isysroot) \ DEF_OPT("isystem", no_dir, OPT_isystem) \ DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \ DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) @@ -1305,6 +1310,10 @@ cpp_handle_option (pfile, argc, argv) CPP_OPTION (pfile, include_prefix_len) = strlen (arg); break; + case OPT_isysroot: + CPP_OPTION (pfile, sysroot) = arg; + break; + case OPT_A: if (arg[0] == '-') { |