1 //===--- InitHeaderSearch.cpp - Initialize header search paths ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the InitHeaderSearch class.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Frontend/Utils.h"
15 #include "clang/Basic/FileManager.h"
16 #include "clang/Basic/LangOptions.h"
17 #include "clang/Basic/Version.h"
18 #include "clang/Config/config.h" // C_INCLUDE_DIRS
19 #include "clang/Lex/HeaderSearch.h"
20 #include "clang/Lex/HeaderSearchOptions.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringExtras.h"
25 #include "llvm/ADT/Triple.h"
26 #include "llvm/ADT/Twine.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/FileSystem.h"
29 #include "llvm/Support/Path.h"
30 #include "llvm/Support/raw_ostream.h"
32 using namespace clang;
33 using namespace clang::frontend;
37 /// InitHeaderSearch - This class makes it easier to set the search paths of
38 /// a HeaderSearch object. InitHeaderSearch stores several search path lists
39 /// internally, which can be sent to a HeaderSearch object in one swoop.
40 class InitHeaderSearch {
41 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
42 typedef std::vector<std::pair<IncludeDirGroup,
43 DirectoryLookup> >::const_iterator path_iterator;
44 std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
45 HeaderSearch &Headers;
47 std::string IncludeSysroot;
52 InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
53 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
54 HasSysroot(!(sysroot.empty() || sysroot == "/")) {
57 /// AddPath - Add the specified path to the specified group list, prefixing
58 /// the sysroot if used.
59 void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
61 /// AddUnmappedPath - Add the specified path to the specified group list,
62 /// without performing any sysroot remapping.
63 void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
66 /// AddSystemHeaderPrefix - Add the specified prefix to the system header
68 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
69 SystemHeaderPrefixes.push_back(std::make_pair(Prefix, IsSystemHeader));
72 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
74 void AddGnuCPlusPlusIncludePaths(StringRef Base,
78 const llvm::Triple &triple);
80 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
82 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
86 /// AddMinGW64CXXPaths - Add the necessary paths to support
87 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
88 void AddMinGW64CXXPaths(StringRef Base,
91 // AddDefaultCIncludePaths - Add paths that should always be searched.
92 void AddDefaultCIncludePaths(const llvm::Triple &triple,
93 const HeaderSearchOptions &HSOpts);
95 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
97 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
98 const HeaderSearchOptions &HSOpts);
100 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
101 /// that e.g. stdio.h is found.
102 void AddDefaultIncludePaths(const LangOptions &Lang,
103 const llvm::Triple &triple,
104 const HeaderSearchOptions &HSOpts);
106 /// Realize - Merges all search path lists into one list and send it to
108 void Realize(const LangOptions &Lang);
111 } // end anonymous namespace.
113 static bool CanPrefixSysroot(StringRef Path) {
115 return !Path.empty() && llvm::sys::path::is_separator(Path[0]);
117 return llvm::sys::path::is_absolute(Path);
121 void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
123 // Add the path with sysroot prepended, if desired and this is a system header
126 SmallString<256> MappedPathStorage;
127 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
128 if (CanPrefixSysroot(MappedPathStr)) {
129 AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
134 AddUnmappedPath(Path, Group, isFramework);
137 void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
139 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
141 FileManager &FM = Headers.getFileMgr();
142 SmallString<256> MappedPathStorage;
143 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
145 // Compute the DirectoryLookup type.
146 SrcMgr::CharacteristicKind Type;
147 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
148 Type = SrcMgr::C_User;
149 } else if (Group == ExternCSystem) {
150 Type = SrcMgr::C_ExternCSystem;
152 Type = SrcMgr::C_System;
155 // If the directory exists, add it.
156 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
157 IncludePath.push_back(
158 std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
162 // Check to see if this is an apple-style headermap (which are not allowed to
165 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
166 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
167 // It is a headermap, add it to the search path.
168 IncludePath.push_back(
169 std::make_pair(Group,
170 DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
177 llvm::errs() << "ignoring nonexistent directory \""
178 << MappedPathStr << "\"\n";
181 void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
185 const llvm::Triple &triple) {
187 AddPath(Base, CXXSystem, false);
189 // Add the multilib dirs
190 llvm::Triple::ArchType arch = triple.getArch();
191 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
193 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false);
195 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false);
197 // Add the backward dir
198 AddPath(Base + "/backward", CXXSystem, false);
201 void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
204 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
206 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
208 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
212 void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
214 // Assumes Base is HeaderSearchOpts' ResourceDir
215 AddPath(Base + "/../../../include/c++/" + Version,
217 AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
219 AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
221 AddPath(Base + "/../../../include/c++/" + Version + "/backward",
225 void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
226 const HeaderSearchOptions &HSOpts) {
227 llvm::Triple::OSType os = triple.getOS();
229 if (HSOpts.UseStandardSystemIncludes) {
231 case llvm::Triple::FreeBSD:
232 case llvm::Triple::NetBSD:
233 case llvm::Triple::OpenBSD:
234 case llvm::Triple::Bitrig:
237 // FIXME: temporary hack: hard-coded paths.
238 AddPath("/usr/local/include", System, false);
243 // Builtin includes use #include_next directives and should be positioned
244 // just prior C include dirs.
245 if (HSOpts.UseBuiltinIncludes) {
246 // Ignore the sys root, we *always* look for clang headers relative to
248 SmallString<128> P = StringRef(HSOpts.ResourceDir);
249 llvm::sys::path::append(P, "include");
250 AddUnmappedPath(P.str(), ExternCSystem, false);
253 // All remaining additions are for system include directories, early exit if
254 // we aren't using them.
255 if (!HSOpts.UseStandardSystemIncludes)
258 // Add dirs specified via 'configure --with-c-include-dirs'.
259 StringRef CIncludeDirs(C_INCLUDE_DIRS);
260 if (CIncludeDirs != "") {
261 SmallVector<StringRef, 5> dirs;
262 CIncludeDirs.split(dirs, ":");
263 for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
266 AddPath(*i, ExternCSystem, false);
271 case llvm::Triple::Linux:
272 case llvm::Triple::Win32:
273 llvm_unreachable("Include management is handled in the driver.");
275 case llvm::Triple::Haiku:
276 AddPath("/boot/common/include", System, false);
277 AddPath("/boot/develop/headers/os", System, false);
278 AddPath("/boot/develop/headers/os/app", System, false);
279 AddPath("/boot/develop/headers/os/arch", System, false);
280 AddPath("/boot/develop/headers/os/device", System, false);
281 AddPath("/boot/develop/headers/os/drivers", System, false);
282 AddPath("/boot/develop/headers/os/game", System, false);
283 AddPath("/boot/develop/headers/os/interface", System, false);
284 AddPath("/boot/develop/headers/os/kernel", System, false);
285 AddPath("/boot/develop/headers/os/locale", System, false);
286 AddPath("/boot/develop/headers/os/mail", System, false);
287 AddPath("/boot/develop/headers/os/media", System, false);
288 AddPath("/boot/develop/headers/os/midi", System, false);
289 AddPath("/boot/develop/headers/os/midi2", System, false);
290 AddPath("/boot/develop/headers/os/net", System, false);
291 AddPath("/boot/develop/headers/os/storage", System, false);
292 AddPath("/boot/develop/headers/os/support", System, false);
293 AddPath("/boot/develop/headers/os/translation", System, false);
294 AddPath("/boot/develop/headers/os/add-ons/graphics", System, false);
295 AddPath("/boot/develop/headers/os/add-ons/input_server", System, false);
296 AddPath("/boot/develop/headers/os/add-ons/screen_saver", System, false);
297 AddPath("/boot/develop/headers/os/add-ons/tracker", System, false);
298 AddPath("/boot/develop/headers/os/be_apps/Deskbar", System, false);
299 AddPath("/boot/develop/headers/os/be_apps/NetPositive", System, false);
300 AddPath("/boot/develop/headers/os/be_apps/Tracker", System, false);
301 AddPath("/boot/develop/headers/cpp", System, false);
302 AddPath("/boot/develop/headers/cpp/i586-pc-haiku", System, false);
303 AddPath("/boot/develop/headers/3rdparty", System, false);
304 AddPath("/boot/develop/headers/bsd", System, false);
305 AddPath("/boot/develop/headers/glibc", System, false);
306 AddPath("/boot/develop/headers/posix", System, false);
307 AddPath("/boot/develop/headers", System, false);
309 case llvm::Triple::RTEMS:
311 case llvm::Triple::Cygwin:
312 AddPath("/usr/include/w32api", System, false);
314 case llvm::Triple::MinGW32: {
315 // mingw-w64 crt include paths
316 // <sysroot>/i686-w64-mingw32/include
317 SmallString<128> P = StringRef(HSOpts.ResourceDir);
318 llvm::sys::path::append(P, "../../../i686-w64-mingw32/include");
319 AddPath(P.str(), System, false);
321 // <sysroot>/x86_64-w64-mingw32/include
322 P.resize(HSOpts.ResourceDir.size());
323 llvm::sys::path::append(P, "../../../x86_64-w64-mingw32/include");
324 AddPath(P.str(), System, false);
326 // mingw.org crt include paths
328 P.resize(HSOpts.ResourceDir.size());
329 llvm::sys::path::append(P, "../../../include");
330 AddPath(P.str(), System, false);
331 AddPath("/mingw/include", System, false);
333 AddPath("c:/mingw/include", System, false);
337 case llvm::Triple::FreeBSD:
338 AddPath("/usr/include/clang/" CLANG_VERSION_STRING, System, false);
345 if ( os != llvm::Triple::RTEMS )
346 AddPath("/usr/include", ExternCSystem, false);
349 void InitHeaderSearch::
350 AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
351 llvm::Triple::OSType os = triple.getOS();
352 // FIXME: temporary hack: hard-coded paths.
354 if (triple.isOSDarwin()) {
355 switch (triple.getArch()) {
358 case llvm::Triple::ppc:
359 case llvm::Triple::ppc64:
360 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
361 "powerpc-apple-darwin10", "", "ppc64",
363 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
364 "powerpc-apple-darwin10", "", "ppc64",
368 case llvm::Triple::x86:
369 case llvm::Triple::x86_64:
370 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
371 "i686-apple-darwin10", "", "x86_64", triple);
372 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
373 "i686-apple-darwin8", "", "", triple);
376 case llvm::Triple::arm:
377 case llvm::Triple::thumb:
378 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
379 "arm-apple-darwin10", "v7", "", triple);
380 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
381 "arm-apple-darwin10", "v6", "", triple);
388 case llvm::Triple::Linux:
389 case llvm::Triple::Win32:
390 llvm_unreachable("Include management is handled in the driver.");
392 case llvm::Triple::Cygwin:
394 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3");
395 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
396 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
397 // g++-4 / Cygwin-1.5
398 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
400 case llvm::Triple::MinGW32:
401 // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
402 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
403 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
404 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
405 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
406 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
407 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
408 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
409 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
410 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
411 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
412 // mingw.org C++ include paths
413 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
415 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.1");
416 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");
417 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");
418 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");
419 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
420 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
421 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
424 case llvm::Triple::DragonFly:
425 if (llvm::sys::fs::exists("/usr/lib/gcc47"))
426 AddPath("/usr/include/c++/4.7", CXXSystem, false);
428 AddPath("/usr/include/c++/4.4", CXXSystem, false);
430 case llvm::Triple::OpenBSD: {
431 std::string t = triple.getTriple();
432 if (t.substr(0, 6) == "x86_64")
433 t.replace(0, 6, "amd64");
434 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
438 case llvm::Triple::Minix:
439 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
442 case llvm::Triple::Solaris:
443 AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
444 "i386-pc-solaris2.11", "", "", triple);
445 // Solaris - Fall though..
446 case llvm::Triple::AuroraUX:
448 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
449 "i386-pc-solaris2.11", "", "", triple);
456 void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
457 const llvm::Triple &triple,
458 const HeaderSearchOptions &HSOpts) {
459 // NB: This code path is going away. All of the logic is moving into the
460 // driver which has the information necessary to do target-specific
461 // selections of default include paths. Each target which moves there will be
462 // exempted from this logic here until we can delete the entire pile of code.
463 switch (triple.getOS()) {
465 break; // Everything else continues to use this routine's logic.
467 case llvm::Triple::Linux:
468 case llvm::Triple::Win32:
472 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
473 HSOpts.UseStandardSystemIncludes) {
474 if (HSOpts.UseLibcxx) {
475 if (triple.isOSDarwin()) {
476 // On Darwin, libc++ may be installed alongside the compiler in
478 if (!HSOpts.ResourceDir.empty()) {
479 // Remove version from foo/lib/clang/version
480 StringRef NoVer = llvm::sys::path::parent_path(HSOpts.ResourceDir);
481 // Remove clang from foo/lib/clang
482 StringRef Lib = llvm::sys::path::parent_path(NoVer);
483 // Remove lib from foo/lib
484 SmallString<128> P = llvm::sys::path::parent_path(Lib);
486 // Get foo/include/c++/v1
487 llvm::sys::path::append(P, "include", "c++", "v1");
488 AddUnmappedPath(P.str(), CXXSystem, false);
491 // On Solaris, include the support directory for things like xlocale and
492 // fudged system headers.
493 if (triple.getOS() == llvm::Triple::Solaris)
494 AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, false);
496 AddPath("/usr/include/c++/v1", CXXSystem, false);
498 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
502 AddDefaultCIncludePaths(triple, HSOpts);
504 // Add the default framework include paths on Darwin.
505 if (HSOpts.UseStandardSystemIncludes) {
506 if (triple.isOSDarwin()) {
507 AddPath("/System/Library/Frameworks", System, true);
508 AddPath("/Library/Frameworks", System, true);
513 /// RemoveDuplicates - If there are duplicate directory entries in the specified
514 /// search list, remove the later (dead) ones. Returns the number of non-system
515 /// headers removed, which is used to update NumAngled.
516 static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
517 unsigned First, bool Verbose) {
518 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
519 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
520 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
521 unsigned NonSystemRemoved = 0;
522 for (unsigned i = First; i != SearchList.size(); ++i) {
523 unsigned DirToRemove = i;
525 const DirectoryLookup &CurEntry = SearchList[i];
527 if (CurEntry.isNormalDir()) {
528 // If this isn't the first time we've seen this dir, remove it.
529 if (SeenDirs.insert(CurEntry.getDir()))
531 } else if (CurEntry.isFramework()) {
532 // If this isn't the first time we've seen this framework dir, remove it.
533 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
536 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
537 // If this isn't the first time we've seen this headermap, remove it.
538 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
542 // If we have a normal #include dir/framework/headermap that is shadowed
543 // later in the chain by a system include location, we actually want to
544 // ignore the user's request and drop the user dir... keeping the system
545 // dir. This is weird, but required to emulate GCC's search path correctly.
547 // Since dupes of system dirs are rare, just rescan to find the original
548 // that we're nuking instead of using a DenseMap.
549 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
550 // Find the dir that this is the same of.
552 for (FirstDir = 0; ; ++FirstDir) {
553 assert(FirstDir != i && "Didn't find dupe?");
555 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
557 // If these are different lookup types, then they can't be the dupe.
558 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
562 if (CurEntry.isNormalDir())
563 isSame = SearchEntry.getDir() == CurEntry.getDir();
564 else if (CurEntry.isFramework())
565 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
567 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
568 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
575 // If the first dir in the search path is a non-system dir, zap it
576 // instead of the system one.
577 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
578 DirToRemove = FirstDir;
582 llvm::errs() << "ignoring duplicate directory \""
583 << CurEntry.getName() << "\"\n";
584 if (DirToRemove != i)
585 llvm::errs() << " as it is a non-system directory that duplicates "
586 << "a system directory\n";
588 if (DirToRemove != i)
591 // This is reached if the current entry is a duplicate. Remove the
592 // DirToRemove (usually the current dir).
593 SearchList.erase(SearchList.begin()+DirToRemove);
596 return NonSystemRemoved;
600 void InitHeaderSearch::Realize(const LangOptions &Lang) {
601 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
602 std::vector<DirectoryLookup> SearchList;
603 SearchList.reserve(IncludePath.size());
605 // Quoted arguments go first.
606 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
608 if (it->first == Quoted)
609 SearchList.push_back(it->second);
611 // Deduplicate and remember index.
612 RemoveDuplicates(SearchList, 0, Verbose);
613 unsigned NumQuoted = SearchList.size();
615 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
617 if (it->first == Angled || it->first == IndexHeaderMap)
618 SearchList.push_back(it->second);
621 RemoveDuplicates(SearchList, NumQuoted, Verbose);
622 unsigned NumAngled = SearchList.size();
624 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
626 if (it->first == System || it->first == ExternCSystem ||
627 (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
628 (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
629 (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
630 (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
631 SearchList.push_back(it->second);
634 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
636 if (it->first == After)
637 SearchList.push_back(it->second);
640 // Remove duplicates across both the Angled and System directories. GCC does
641 // this and failing to remove duplicates across these two groups breaks
643 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
644 NumAngled -= NonSystemRemoved;
646 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
647 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
649 Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
651 // If verbose, print the list of directories that will be searched.
653 llvm::errs() << "#include \"...\" search starts here:\n";
654 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
656 llvm::errs() << "#include <...> search starts here:\n";
657 const char *Name = SearchList[i].getName();
659 if (SearchList[i].isNormalDir())
661 else if (SearchList[i].isFramework())
662 Suffix = " (framework directory)";
664 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
665 Suffix = " (headermap)";
667 llvm::errs() << " " << Name << Suffix << "\n";
669 llvm::errs() << "End of search list.\n";
673 void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
674 const HeaderSearchOptions &HSOpts,
675 const LangOptions &Lang,
676 const llvm::Triple &Triple) {
677 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
679 // Add the user defined entries.
680 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
681 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
682 if (E.IgnoreSysRoot) {
683 Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework);
685 Init.AddPath(E.Path, E.Group, E.IsFramework);
689 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
691 for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
692 Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
693 HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
695 if (HSOpts.UseBuiltinIncludes) {
696 // Set up the builtin include directory in the module map.
697 SmallString<128> P = StringRef(HSOpts.ResourceDir);
698 llvm::sys::path::append(P, "include");
699 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str()))
700 HS.getModuleMap().setBuiltinIncludeDir(Dir);