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)
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/>. */
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. */
31 prefixed_path (const char *path
, const char *iprefix
)
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
);
49 = make_relative_prefix (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. */
71 add_globalpaths (Strings
*paths
)
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
))
86 free (CONST_CAST (char *, target
));
90 global
.path
->push (target
);
95 /* Add PATHS to the global file import lookup path. */
98 add_filepaths (Strings
*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
));
116 global
.filePath
->push (target
);
121 /* Add all search directories to compiler runtime.
122 if STDINC, also include standard library paths. */
125 add_import_paths (const char *iprefix
, const char *imultilib
, bool stdinc
)
129 for (const default_include
*p
= cpp_include_defaults
; p
->fname
; p
++)
133 /* Ignore C++ paths. */
138 path
= prefixed_path (p
->fname
, iprefix
);
140 path
= xstrdup (p
->fname
);
142 /* Add D-specific suffix. */
143 path
= concat (path
, "/d", NULL
);
145 /* Ignore duplicate entries. */
147 for (size_t i
= 0; i
< global
.params
.imppath
->dim
; i
++)
149 if (strcmp (path
, (*global
.params
.imppath
)[i
]) == 0)
162 /* Multilib support. */
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
];
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
];
191 add_filepaths (FileName::splitPath (path
));