match_asm_constraints: Use copy_rtx where needed (PR88001)
[official-gcc.git] / gcc / d / d-incpath.cc
blob87db816413415ab6bd623d18bd522da6021a7f2d
1 /* d-incpath.cc -- Set up combined import paths for the D frontend.
2 Copyright (C) 2006-2018 Free Software Foundation, Inc.
4 GCC is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
9 GCC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
18 #include "config.h"
19 #include "system.h"
20 #include "coretypes.h"
22 #include "dmd/globals.h"
24 #include "cppdefault.h"
26 /* Look for directories that start with the standard prefix.
27 "Translate" them, i.e: replace /usr/local/lib/gcc with
28 IPREFIX and search them first. Based on incpath.c. */
30 static char *
31 prefixed_path (const char *path, const char *iprefix)
33 size_t len;
35 if (cpp_relocated () && (len = cpp_PREFIX_len) != 0)
37 if (!strncmp (path, cpp_PREFIX, len))
39 static const char *relocated_prefix;
40 /* If this path starts with the configure-time prefix,
41 but the compiler has been relocated, replace it
42 with the run-time prefix. */
43 if (!relocated_prefix)
45 /* Make relative prefix expects the first argument
46 to be a program, not a directory. */
47 char *dummy = concat (gcc_exec_prefix, "dummy", NULL);
48 relocated_prefix
49 = make_relative_prefix (dummy,
50 cpp_EXEC_PREFIX,
51 cpp_PREFIX);
52 free (dummy);
55 return concat (relocated_prefix, path + len, NULL);
59 if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0)
61 if (!strncmp (path, cpp_GCC_INCLUDE_DIR, len))
62 return concat (iprefix, path + len, NULL);
65 return xstrdup (path);
68 /* Add PATHS to the global import lookup path. */
70 static void
71 add_globalpaths (Strings *paths)
73 if (paths)
75 if (!global.path)
76 global.path = new Strings ();
78 for (size_t i = 0; i < paths->dim; i++)
80 const char *path = (*paths)[i];
81 const char *target = lrealpath (path);
83 if (target == NULL || !FileName::exists (target))
85 if (target)
86 free (CONST_CAST (char *, target));
87 continue;
90 global.path->push (target);
95 /* Add PATHS to the global file import lookup path. */
97 static void
98 add_filepaths (Strings *paths)
100 if (paths)
102 if (!global.filePath)
103 global.filePath = new Strings ();
105 for (size_t i = 0; i < paths->dim; i++)
107 const char *path = (*paths)[i];
108 const char *target = lrealpath (path);
110 if (!FileName::exists (target))
112 free (CONST_CAST (char *, target));
113 continue;
116 global.filePath->push (target);
121 /* Add all search directories to compiler runtime.
122 if STDINC, also include standard library paths. */
124 void
125 add_import_paths (const char *iprefix, const char *imultilib, bool stdinc)
127 if (stdinc)
129 for (const default_include *p = cpp_include_defaults; p->fname; p++)
131 char *path;
133 /* Ignore C++ paths. */
134 if (p->cplusplus)
135 continue;
137 if (!p->add_sysroot)
138 path = prefixed_path (p->fname, iprefix);
139 else
140 path = xstrdup (p->fname);
142 /* Add D-specific suffix. */
143 path = concat (path, "/d", NULL);
145 /* Ignore duplicate entries. */
146 bool found = false;
147 for (size_t i = 0; i < global.params.imppath->dim; i++)
149 if (strcmp (path, (*global.params.imppath)[i]) == 0)
151 found = true;
152 break;
156 if (found)
158 free (path);
159 continue;
162 /* Multilib support. */
163 if (imultilib)
165 char *target_path = concat (path, "/", imultilib, NULL);
166 global.params.imppath->shift (target_path);
169 global.params.imppath->shift (path);
173 /* Add import search paths. */
174 if (global.params.imppath)
176 for (size_t i = 0; i < global.params.imppath->dim; i++)
178 const char *path = (*global.params.imppath)[i];
179 if (path)
180 add_globalpaths (FileName::splitPath (path));
184 /* Add string import search paths. */
185 if (global.params.fileImppath)
187 for (size_t i = 0; i < global.params.fileImppath->dim; i++)
189 const char *path = (*global.params.fileImppath)[i];
190 if (path)
191 add_filepaths (FileName::splitPath (path));