Commit 48209ce5 by John David Anglin Committed by John David Anglin

cppinit.c (remove_dup_dir): Add head_ptr argument to handle removal at head.

	* cppinit.c (remove_dup_dir): Add head_ptr argument to handle removal
	at head.
	(remove_dup_nonsys_dirs): New function.
	(remove_dup_dirs): Change argument head to head_ptr.  Remove warnings.
	(merge_include_chains): Remove non-system include directories from
	quote and bracket include chains when they duplicate equivalent system
	directories.
	* doc/cpp.texi (-I): Update.
        * doc/cppopts.texi (-I): Update.
        * doc/install.texi (--with-local-prefix): Further document usage of
	this option.
	* doc/invoke.texi (-I): Update.

From-SVN: r56468
parent 4ca79136
2002-08-20 John David Anglin <dave@hiauly1.hia.nrc.ca>
* cppinit.c (remove_dup_dir): Add head_ptr argument to handle removal
at head.
(remove_dup_nonsys_dirs): New function.
(remove_dup_dirs): Change argument head to head_ptr. Remove warnings.
(merge_include_chains): Remove non-system include directories from
quote and bracket include chains when they duplicate equivalent system
directories.
* doc/cpp.texi (-I): Update.
* doc/cppopts.texi (-I): Update.
* doc/install.texi (--with-local-prefix): Further document usage of
this option.
* doc/invoke.texi (-I): Update.
2002-08-20 Richard Henderson <rth@redhat.com> 2002-08-20 Richard Henderson <rth@redhat.com>
* expr.c (TARGET_MEM_FUNCTIONS): Transform to boolean. * expr.c (TARGET_MEM_FUNCTIONS): Transform to boolean.
......
...@@ -94,9 +94,13 @@ static void mark_named_operators PARAMS ((cpp_reader *)); ...@@ -94,9 +94,13 @@ static void mark_named_operators PARAMS ((cpp_reader *));
static void append_include_chain PARAMS ((cpp_reader *, static void append_include_chain PARAMS ((cpp_reader *,
char *, int, int)); char *, int, int));
static struct search_path * remove_dup_dir PARAMS ((cpp_reader *, static struct search_path * remove_dup_dir PARAMS ((cpp_reader *,
struct search_path *,
struct search_path **));
static struct search_path * remove_dup_nonsys_dirs PARAMS ((cpp_reader *,
struct search_path **,
struct search_path *)); struct search_path *));
static struct search_path * remove_dup_dirs PARAMS ((cpp_reader *, static struct search_path * remove_dup_dirs PARAMS ((cpp_reader *,
struct search_path *)); struct search_path **));
static void merge_include_chains PARAMS ((cpp_reader *)); static void merge_include_chains PARAMS ((cpp_reader *));
static bool push_include PARAMS ((cpp_reader *, static bool push_include PARAMS ((cpp_reader *,
struct pending_option *)); struct pending_option *));
...@@ -257,55 +261,92 @@ append_include_chain (pfile, dir, path, cxx_aware) ...@@ -257,55 +261,92 @@ append_include_chain (pfile, dir, path, cxx_aware)
} }
/* Handle a duplicated include path. PREV is the link in the chain /* Handle a duplicated include path. PREV is the link in the chain
before the duplicate. The duplicate is removed from the chain and before the duplicate, or NULL if the duplicate is at the head of
freed. Returns PREV. */ the chain. The duplicate is removed from the chain and freed.
Returns PREV. */
static struct search_path * static struct search_path *
remove_dup_dir (pfile, prev) remove_dup_dir (pfile, prev, head_ptr)
cpp_reader *pfile; cpp_reader *pfile;
struct search_path *prev; struct search_path *prev;
struct search_path **head_ptr;
{ {
struct search_path *cur = prev->next; struct search_path *cur;
if (prev != NULL)
{
cur = prev->next;
prev->next = cur->next;
}
else
{
cur = *head_ptr;
*head_ptr = cur->next;
}
if (CPP_OPTION (pfile, verbose)) if (CPP_OPTION (pfile, verbose))
fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name); fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
prev->next = cur->next;
free ((PTR) cur->name); free ((PTR) cur->name);
free (cur); free (cur);
return prev; return prev;
} }
/* Remove duplicate non-system directories for which there is an equivalent
system directory latter in the chain. The range for removal is between
*HEAD_PTR and END. Returns the directory before END, or NULL if none.
This algorithm is quadratic in the number system directories, which is
acceptable since there aren't usually that many of them. */
static struct search_path *
remove_dup_nonsys_dirs (pfile, head_ptr, end)
cpp_reader *pfile;
struct search_path **head_ptr;
struct search_path *end;
{
struct search_path *prev, *cur, *other;
for (cur = *head_ptr; cur; cur = cur->next)
{
if (cur->sysp)
{
for (other = *head_ptr, prev = NULL;
other != end;
other = other ? other->next : *head_ptr)
{
if (!other->sysp
&& INO_T_EQ (cur->ino, other->ino)
&& cur->dev == other->dev)
{
other = remove_dup_dir (pfile, prev, head_ptr);
if (CPP_OPTION (pfile, verbose))
fprintf (stderr,
_(" as it is a non-system directory that duplicates a system directory\n"));
}
prev = other;
}
}
}
return prev;
}
/* Remove duplicate directories from a chain. Returns the tail of the /* Remove duplicate directories from a chain. Returns the tail of the
chain, or NULL if the chain is empty. This algorithm is quadratic chain, or NULL if the chain is empty. This algorithm is quadratic
in the number of -I switches, which is acceptable since there in the number of -I switches, which is acceptable since there
aren't usually that many of them. */ aren't usually that many of them. */
static struct search_path * static struct search_path *
remove_dup_dirs (pfile, head) remove_dup_dirs (pfile, head_ptr)
cpp_reader *pfile; cpp_reader *pfile;
struct search_path *head; struct search_path **head_ptr;
{ {
struct search_path *prev = NULL, *cur, *other; struct search_path *prev = NULL, *cur, *other;
for (cur = head; cur; cur = cur->next) for (cur = *head_ptr; cur; cur = cur->next)
{ {
for (other = head; other != cur; other = other->next) for (other = *head_ptr; other != cur; other = other->next)
if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev) if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
{ {
if (cur->sysp && !other->sysp) cur = remove_dup_dir (pfile, prev, head_ptr);
{
cpp_error (pfile, DL_WARNING,
"changing search order for system directory \"%s\"",
cur->name);
if (strcmp (cur->name, other->name))
cpp_error (pfile, DL_WARNING,
" as it is the same as non-system directory \"%s\"",
other->name);
else
cpp_error (pfile, DL_WARNING,
" as it has already been specified as a non-system directory");
}
cur = remove_dup_dir (pfile, prev);
break; break;
} }
prev = cur; prev = cur;
...@@ -343,28 +384,33 @@ merge_include_chains (pfile) ...@@ -343,28 +384,33 @@ merge_include_chains (pfile)
else else
brack = systm; brack = systm;
/* This is a bit tricky. First we drop dupes from the quote-include /* This is a bit tricky. First we drop non-system dupes of system
list. Then we drop dupes from the bracket-include list. directories from the merged bracket-include list. Next we drop
Finally, if qtail and brack are the same directory, we cut out dupes from the bracket and quote include lists. Then we drop
brack and move brack up to point to qtail. non-system dupes from the merged quote-include list. Finally,
if qtail and brack are the same directory, we cut out brack and
move brack up to point to qtail.
We can't just merge the lists and then uniquify them because We can't just merge the lists and then uniquify them because
then we may lose directories from the <> search path that should then we may lose directories from the <> search path that should
be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
-Ibar -I- -Ifoo -Iquux. */ -Ibar -I- -Ifoo -Iquux. */
remove_dup_dirs (pfile, brack); remove_dup_nonsys_dirs (pfile, &brack, systm);
qtail = remove_dup_dirs (pfile, quote); remove_dup_dirs (pfile, &brack);
if (quote) if (quote)
{ {
qtail = remove_dup_dirs (pfile, &quote);
qtail->next = brack; qtail->next = brack;
qtail = remove_dup_nonsys_dirs (pfile, &quote, brack);
/* If brack == qtail, remove brack as it's simpler. */ /* If brack == qtail, remove brack as it's simpler. */
if (brack && INO_T_EQ (qtail->ino, brack->ino) if (qtail && brack && INO_T_EQ (qtail->ino, brack->ino)
&& qtail->dev == brack->dev) && qtail->dev == brack->dev)
brack = remove_dup_dir (pfile, qtail); brack = remove_dup_dir (pfile, qtail, &quote);
} }
else else
quote = brack; quote = brack;
......
...@@ -823,11 +823,22 @@ version of GCC in use. ...@@ -823,11 +823,22 @@ version of GCC in use.
You can add to this list with the @option{-I@var{dir}} command line You can add to this list with the @option{-I@var{dir}} command line
option. All the directories named by @option{-I} are searched, in option. All the directories named by @option{-I} are searched, in
left-to-right order, @emph{before} the default directories. You can left-to-right order, @emph{before} the default directories. The only
also prevent GCC from searching any of the default directories with the exception is when @file{dir} is already searched by default. In
@option{-nostdinc} option. This is useful when you are compiling an this case, the option is ignored and the search order for system
directories remains unchanged.
Duplicate directories are removed from the quote and bracket search
chains before the two chains are merged to make the final search chain.
Thus, it is possible for a directory to occur twice in the final search
chain if it was specified in both the quote and bracket chains.
You can prevent GCC from searching any of the default directories with
the @option{-nostdinc} option. This is useful when you are compiling an
operating system kernel or some other program that does not use the operating system kernel or some other program that does not use the
standard C library facilities, or the standard C library itself. standard C library facilities, or the standard C library itself.
@option{-I} options are not ignored as described above when
@option{-nostdinc} is in effect.
GCC looks for headers requested with @code{@w{#include "@var{file}"}} GCC looks for headers requested with @code{@w{#include "@var{file}"}}
first in the directory containing the current file, then in the same first in the directory containing the current file, then in the same
...@@ -836,12 +847,6 @@ For example, if @file{/usr/include/sys/stat.h} contains ...@@ -836,12 +847,6 @@ For example, if @file{/usr/include/sys/stat.h} contains
@code{@w{#include "types.h"}}, GCC looks for @file{types.h} first in @code{@w{#include "types.h"}}, GCC looks for @file{types.h} first in
@file{/usr/include/sys}, then in its usual search path. @file{/usr/include/sys}, then in its usual search path.
If you name a search directory with @option{-I@var{dir}} that is also a
system include directory, the @option{-I} wins; the directory will be
searched according to the @option{-I} ordering, and it will not be
treated as a system include directory. GCC will warn you when a system
include directory is hidden in this way.
@samp{#line} (@pxref{Line Control}) does not change GCC's idea of the @samp{#line} (@pxref{Line Control}) does not change GCC's idea of the
directory containing the current file. directory containing the current file.
...@@ -1074,8 +1079,8 @@ found in that directory will be considered system headers. ...@@ -1074,8 +1079,8 @@ found in that directory will be considered system headers.
All directories named by @option{-isystem} are searched @emph{after} all All directories named by @option{-isystem} are searched @emph{after} all
directories named by @option{-I}, no matter what their order was on the directories named by @option{-I}, no matter what their order was on the
command line. If the same directory is named by both @option{-I} and command line. If the same directory is named by both @option{-I} and
@option{-isystem}, @option{-I} wins; it is as if the @option{-isystem} option @option{-isystem}, the @option{-I} option is ignored. GCC provides an
had never been specified at all. GCC warns you when this happens. informative message when this occurs if @option{-v} is used.
@findex #pragma GCC system_header @findex #pragma GCC system_header
There is also a directive, @code{@w{#pragma GCC system_header}}, which There is also a directive, @code{@w{#pragma GCC system_header}}, which
...@@ -1817,9 +1822,7 @@ conformance to the C Standard. CPP follows the host convention when ...@@ -1817,9 +1822,7 @@ conformance to the C Standard. CPP follows the host convention when
processing system header files, but when processing user files processing system header files, but when processing user files
@code{__STDC__} is always 1. This has been reported to cause problems; @code{__STDC__} is always 1. This has been reported to cause problems;
for instance, some versions of Solaris provide X Windows headers that for instance, some versions of Solaris provide X Windows headers that
expect @code{__STDC__} to be either undefined or 1. You may be able to expect @code{__STDC__} to be either undefined or 1. @xref{Invocation}.
work around this sort of problem by using an @option{-I} option to
cancel treatment of those headers as system headers. @xref{Invocation}.
@item __STDC_VERSION__ @item __STDC_VERSION__
This macro expands to the C Standard's version number, a long integer This macro expands to the C Standard's version number, a long integer
......
...@@ -51,16 +51,14 @@ for header files. ...@@ -51,16 +51,14 @@ for header files.
@xref{Search Path}. @xref{Search Path}.
@end ifset @end ifset
Directories named by @option{-I} are searched before the standard Directories named by @option{-I} are searched before the standard
system include directories. system include directories. If the directory @var{dir} is a standard
system include directory, the option is ignored to ensure that the
It is dangerous to specify a standard system include directory in an default search order for system directories and the special treatment
@option{-I} option. This defeats the special treatment of system of system headers are not defeated
headers
@ifset cppmanual @ifset cppmanual
(@pxref{System Headers}) (@pxref{System Headers})
@end ifset @end ifset
. It can also defeat the repairs to buggy system headers which GCC .
makes when it is installed.
@item -o @var{file} @item -o @var{file}
@opindex o @opindex o
......
...@@ -467,6 +467,43 @@ any in that directory---are not part of GCC@. They are part of other ...@@ -467,6 +467,43 @@ any in that directory---are not part of GCC@. They are part of other
programs---perhaps many others. (GCC installs its own header files in programs---perhaps many others. (GCC installs its own header files in
another directory which is based on the @option{--prefix} value.) another directory which is based on the @option{--prefix} value.)
Both the local-prefix include directory and the GCC-prefix include
directory are part of GCC's "system include" directories. Although these
two directories are not fixed, they need to be searched in the proper
order for the correct processing of the include_next directive. The
local-prefix include directory is searched before the GCC-prefix
include directory. Another characteristic of system include directories
is that pedantic warnings are turned off for headers in these directories.
Some autoconf macros add @option{-I @var{directory}} options to the
compiler command line, to ensure that directories containing installed
packages' headers are searched. When @var{directory} is one of GCC's
system include directories, GCC will ignore the option so that system
directories continue to be processed in the correct order. This
may result in a search order different from what was specified but the
directory will still be searched.
GCC automatically searches for ordinary libraries using
@env{GCC_EXEC_PREFIX}. Thus, when the same installation prefix is
used for both GCC and packages, GCC will automatically search for
both headers and libraries. This provides a configuration that is
easy to use. GCC behaves in a manner similar to that when it is
installed as a system compiler in @file{/usr}.
Sites that need to install multiple versions of GCC may not want to
use the above simple configuration. It is possible to use the
@option{--program-prefix}, @option{--program-suffix} and
@option{--program-transform-name} options to install multiple versions
into a single directory, but it may be simpler to use different prefixes
and the @option{--with-local-prefix} option to specify the location of the
site-specific files for each version. It will then be necessary for
users to specify explicitly the location of local site libraries
(e.g., with @env{LIBRARY_PATH}).
The same value can be used for both @option{--with-local-prefix} and
@option{--prefix} provided it is not @file{/usr}. This can be used
to avoid the default search of @file{/usr/local/include}.
@strong{Do not} specify @file{/usr} as the @option{--with-local-prefix}! @strong{Do not} specify @file{/usr} as the @option{--with-local-prefix}!
The directory you use for @option{--with-local-prefix} @strong{must not} The directory you use for @option{--with-local-prefix} @strong{must not}
contain any of the system's standard header files. If it did contain contain any of the system's standard header files. If it did contain
......
...@@ -4281,15 +4281,13 @@ one @option{-I} option, the directories are scanned in left-to-right ...@@ -4281,15 +4281,13 @@ one @option{-I} option, the directories are scanned in left-to-right
order; the standard system directories come after. order; the standard system directories come after.
If a standard system include directory, or a directory specified with If a standard system include directory, or a directory specified with
@option{-isystem}, is also specified with @option{-I}, it will be @option{-isystem}, is also specified with @option{-I}, the @option{-I}
searched only in the position requested by @option{-I}. Also, it will option will be ignored. The directory will still be searched but as a
not be considered a system include directory. If that directory really system directory at its normal position in the system include chain.
does contain system headers, there is a good chance that they will This is to ensure that GCC's procedure to fix buggy system headers and
break. For instance, if GCC's installation procedure edited the headers the ordering for the include_next directive are not inadvertantly changed.
in @file{/usr/include} to fix bugs, @samp{-I/usr/include} will cause the If you really need to change the search order for system directories,
original, buggy headers to be found instead of the corrected ones. GCC use the @option{-nostdinc} and/or @option{-isystem} options.
will issue a warning when a system include directory is hidden in this
way.
@item -I- @item -I-
@opindex I- @opindex I-
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment