xref: /netbsd-src/external/gpl3/gcc/dist/gcc/cppdefault.cc (revision 2683f5b185977c9184701f18c843971cd908b00e)
1 /* CPP Library.
2    Copyright (C) 1986-2022 Free Software Foundation, Inc.
3    Contributed by Per Bothner, 1994-95.
4    Based on CCCP program by Paul Rubin, June 1986
5    Adapted to ANSI C, Richard Stallman, Jan 1987
6 
7    This program is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by the
9    Free Software Foundation; either version 3, or (at your option) any
10    later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program; see the file COPYING3.  If not see
19    <http://www.gnu.org/licenses/>.  */
20 
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "cppdefault.h"
26 
27 #ifndef NATIVE_SYSTEM_HEADER_COMPONENT
28 #define NATIVE_SYSTEM_HEADER_COMPONENT 0
29 #endif
30 
31 #if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
32 # undef LOCAL_INCLUDE_DIR
33 # undef NATIVE_SYSTEM_HEADER_DIR
34 #else
35 # undef CROSS_INCLUDE_DIR
36 #endif
37 
38 const struct default_include cpp_include_defaults[]
39 #ifdef INCLUDE_DEFAULTS
40 = INCLUDE_DEFAULTS;
41 #else
42 = {
43 #ifdef GPLUSPLUS_INCLUDE_DIR
44     /* Pick up GNU C++ generic include files.  */
45     { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1,
46       GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
47 #endif
48 #ifdef GPLUSPLUS_TOOL_INCLUDE_DIR
49     /* Pick up GNU C++ target-dependent include files.  */
50     { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1,
51       GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 },
52 #endif
53 #ifdef GPLUSPLUS_BACKWARD_INCLUDE_DIR
54     /* Pick up GNU C++ backward and deprecated include files.  */
55     { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1,
56       GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
57 #endif
58 #ifdef GPLUSPLUS_LIBCXX_INCLUDE_DIR
59     /* Pick up libc++ include files, if we have -stdlib=libc++.  */
60     { GPLUSPLUS_LIBCXX_INCLUDE_DIR, "G++", 2, 1,
61       GPLUSPLUS_LIBCXX_INCLUDE_DIR_ADD_SYSROOT, 0 },
62 #endif
63 #ifdef GCC_INCLUDE_DIR
64 #ifndef GCC_INCLUDE_DIR_ADD_SYSROOT
65 #define GCC_INCLUDE_DIR_ADD_SYSROOT 0
66 #endif
67     /* This is the dir for gcc's private headers.  */
68     { GCC_INCLUDE_DIR, "GCC", 0, 0,
69       GCC_INCLUDE_DIR_ADD_SYSROOT, 0 },
70 #endif
71 #ifdef LOCAL_INCLUDE_DIR
72     /* /usr/local/include comes before the fixincluded header files.  */
73     { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 },
74     { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
75 #endif
76 #ifdef PREFIX_INCLUDE_DIR
77     { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0 },
78 #endif
79 #ifdef FIXED_INCLUDE_DIR
80     /* This is the dir for fixincludes.  */
81     { FIXED_INCLUDE_DIR, "GCC", 0, 0, 0,
82       /* A multilib suffix needs adding if different multilibs use
83 	 different headers.  */
84 #ifdef SYSROOT_HEADERS_SUFFIX_SPEC
85       1
86 #else
87       0
88 #endif
89     },
90 #endif
91 #ifdef CROSS_INCLUDE_DIR
92     /* One place the target system's headers might be.  */
93     { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0 },
94 #endif
95 #ifdef TOOL_INCLUDE_DIR
96     /* Another place the target system's headers might be.  */
97     { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0 },
98 #endif
99 #ifdef NATIVE_SYSTEM_HEADER_DIR
100     /* /usr/include comes dead last.  */
101     { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 },
102     { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 },
103 #endif
104     { 0, 0, 0, 0, 0, 0 }
105   };
106 #endif /* no INCLUDE_DEFAULTS */
107 
108 #ifdef GCC_INCLUDE_DIR
109 const char cpp_GCC_INCLUDE_DIR[] = GCC_INCLUDE_DIR;
110 const size_t cpp_GCC_INCLUDE_DIR_len = sizeof GCC_INCLUDE_DIR - 8;
111 #else
112 const char cpp_GCC_INCLUDE_DIR[] = "";
113 const size_t cpp_GCC_INCLUDE_DIR_len = 0;
114 #endif
115 
116 /* The configured prefix.  */
117 const char cpp_PREFIX[] = PREFIX;
118 const size_t cpp_PREFIX_len = sizeof PREFIX - 1;
119 const char cpp_EXEC_PREFIX[] = STANDARD_EXEC_PREFIX;
120 
121 /* This value is set by cpp_relocated at runtime */
122 const char *gcc_exec_prefix;
123 
124 /* Return true if the toolchain is relocated.  */
125 bool
cpp_relocated(void)126 cpp_relocated (void)
127 {
128   static int relocated = -1;
129 
130   /* A relocated toolchain ignores standard include directories.  */
131   if (relocated == -1)
132     {
133       /* Check if the toolchain was relocated?  */
134       gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
135       if (gcc_exec_prefix)
136        relocated = 1;
137       else
138        relocated = 0;
139     }
140 
141   return relocated;
142 }
143