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/Config/config.h" // C_INCLUDE_DIRS
18 #include "clang/Lex/HeaderSearch.h"
19 #include "clang/Lex/HeaderSearchOptions.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/ADT/Triple.h"
25 #include "llvm/ADT/Twine.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/FileSystem.h"
28 #include "llvm/Support/Path.h"
29 #include "llvm/Support/raw_ostream.h"
31 using namespace clang;
32 using namespace clang::frontend;
36 /// InitHeaderSearch - This class makes it easier to set the search paths of
37 /// a HeaderSearch object. InitHeaderSearch stores several search path lists
38 /// internally, which can be sent to a HeaderSearch object in one swoop.
39 class InitHeaderSearch {
40 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
41 typedef std::vector<std::pair<IncludeDirGroup,
42 DirectoryLookup> >::const_iterator path_iterator;
43 std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
44 HeaderSearch &Headers;
46 std::string IncludeSysroot;
51 InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
52 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
53 HasSysroot(!(sysroot.empty() || sysroot == "/")) {
56 /// AddPath - Add the specified path to the specified group list, prefixing
57 /// the sysroot if used.
58 void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
60 /// AddUnmappedPath - Add the specified path to the specified group list,
61 /// without performing any sysroot remapping.
62 void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
65 /// AddSystemHeaderPrefix - Add the specified prefix to the system header
67 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
68 SystemHeaderPrefixes.push_back(std::make_pair(Prefix, IsSystemHeader));
71 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
73 void AddGnuCPlusPlusIncludePaths(StringRef Base,
77 const llvm::Triple &triple);
79 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
81 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
85 /// AddMinGW64CXXPaths - Add the necessary paths to support
86 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
87 void AddMinGW64CXXPaths(StringRef Base,
90 // AddDefaultCIncludePaths - Add paths that should always be searched.
91 void AddDefaultCIncludePaths(const llvm::Triple &triple,
92 const HeaderSearchOptions &HSOpts);
94 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
96 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
97 const HeaderSearchOptions &HSOpts);
99 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
100 /// that e.g. stdio.h is found.
101 void AddDefaultIncludePaths(const LangOptions &Lang,
102 const llvm::Triple &triple,
103 const HeaderSearchOptions &HSOpts);
105 /// Realize - Merges all search path lists into one list and send it to
107 void Realize(const LangOptions &Lang);
110 } // end anonymous namespace.
112 static bool CanPrefixSysroot(StringRef Path) {
114 return !Path.empty() && llvm::sys::path::is_separator(Path[0]);
116 return llvm::sys::path::is_absolute(Path);
120 void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
122 // Add the path with sysroot prepended, if desired and this is a system header
125 SmallString<256> MappedPathStorage;
126 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
127 if (CanPrefixSysroot(MappedPathStr)) {
128 AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
133 AddUnmappedPath(Path, Group, isFramework);
136 void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
138 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
140 FileManager &FM = Headers.getFileMgr();
141 SmallString<256> MappedPathStorage;
142 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
144 // Compute the DirectoryLookup type.
145 SrcMgr::CharacteristicKind Type;
146 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
147 Type = SrcMgr::C_User;
148 } else if (Group == ExternCSystem) {
149 Type = SrcMgr::C_ExternCSystem;
151 Type = SrcMgr::C_System;
154 // If the directory exists, add it.
155 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
156 IncludePath.push_back(
157 std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
161 // Check to see if this is an apple-style headermap (which are not allowed to
164 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
165 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
166 // It is a headermap, add it to the search path.
167 IncludePath.push_back(
168 std::make_pair(Group,
169 DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
176 llvm::errs() << "ignoring nonexistent directory \""
177 << MappedPathStr << "\"\n";
180 void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
184 const llvm::Triple &triple) {
186 AddPath(Base, CXXSystem, false);
188 // Add the multilib dirs
189 llvm::Triple::ArchType arch = triple.getArch();
190 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
192 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false);
194 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false);
196 // Add the backward dir
197 AddPath(Base + "/backward", CXXSystem, false);
200 void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
203 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
205 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
207 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
211 void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
213 // Assumes Base is HeaderSearchOpts' ResourceDir
214 AddPath(Base + "/../../../include/c++/" + Version,
216 AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
218 AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
220 AddPath(Base + "/../../../include/c++/" + Version + "/backward",
224 void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
225 const HeaderSearchOptions &HSOpts) {
226 llvm::Triple::OSType os = triple.getOS();
228 if (HSOpts.UseStandardSystemIncludes) {
230 case llvm::Triple::FreeBSD:
231 case llvm::Triple::NetBSD:
232 case llvm::Triple::OpenBSD:
233 case llvm::Triple::Bitrig:
236 // FIXME: temporary hack: hard-coded paths.
237 AddPath("/usr/local/include", System, false);
242 // Builtin includes use #include_next directives and should be positioned
243 // just prior C include dirs.
244 if (HSOpts.UseBuiltinIncludes) {
245 // Ignore the sys root, we *always* look for clang headers relative to
247 SmallString<128> P = StringRef(HSOpts.ResourceDir);
248 llvm::sys::path::append(P, "include");
249 AddUnmappedPath(P.str(), ExternCSystem, false);
252 // All remaining additions are for system include directories, early exit if
253 // we aren't using them.
254 if (!HSOpts.UseStandardSystemIncludes)
257 // Add dirs specified via 'configure --with-c-include-dirs'.
258 StringRef CIncludeDirs(C_INCLUDE_DIRS);
259 if (CIncludeDirs != "") {
260 SmallVector<StringRef, 5> dirs;
261 CIncludeDirs.split(dirs, ":");
262 for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
265 AddPath(*i, ExternCSystem, false);
270 case llvm::Triple::Linux:
271 case llvm::Triple::Win32:
272 llvm_unreachable("Include management is handled in the driver.");
274 case llvm::Triple::Haiku:
275 AddPath("/boot/common/include", System, false);
276 AddPath("/boot/develop/headers/os", System, false);
277 AddPath("/boot/develop/headers/os/app", System, false);
278 AddPath("/boot/develop/headers/os/arch", System, false);
279 AddPath("/boot/develop/headers/os/device", System, false);
280 AddPath("/boot/develop/headers/os/drivers", System, false);
281 AddPath("/boot/develop/headers/os/game", System, false);
282 AddPath("/boot/develop/headers/os/interface", System, false);
283 AddPath("/boot/develop/headers/os/kernel", System, false);
284 AddPath("/boot/develop/headers/os/locale", System, false);
285 AddPath("/boot/develop/headers/os/mail", System, false);
286 AddPath("/boot/develop/headers/os/media", System, false);
287 AddPath("/boot/develop/headers/os/midi", System, false);
288 AddPath("/boot/develop/headers/os/midi2", System, false);
289 AddPath("/boot/develop/headers/os/net", System, false);
290 AddPath("/boot/develop/headers/os/storage", System, false);
291 AddPath("/boot/develop/headers/os/support", System, false);
292 AddPath("/boot/develop/headers/os/translation", System, false);
293 AddPath("/boot/develop/headers/os/add-ons/graphics", System, false);
294 AddPath("/boot/develop/headers/os/add-ons/input_server", System, false);
295 AddPath("/boot/develop/headers/os/add-ons/screen_saver", System, false);
296 AddPath("/boot/develop/headers/os/add-ons/tracker", System, false);
297 AddPath("/boot/develop/headers/os/be_apps/Deskbar", System, false);
298 AddPath("/boot/develop/headers/os/be_apps/NetPositive", System, false);
299 AddPath("/boot/develop/headers/os/be_apps/Tracker", System, false);
300 AddPath("/boot/develop/headers/cpp", System, false);
301 AddPath("/boot/develop/headers/cpp/i586-pc-haiku", System, false);
302 AddPath("/boot/develop/headers/3rdparty", System, false);
303 AddPath("/boot/develop/headers/bsd", System, false);
304 AddPath("/boot/develop/headers/glibc", System, false);
305 AddPath("/boot/develop/headers/posix", System, false);
306 AddPath("/boot/develop/headers", System, false);
308 case llvm::Triple::RTEMS:
310 case llvm::Triple::Cygwin:
311 AddPath("/usr/include/w32api", System, false);
313 case llvm::Triple::MinGW32: {
314 // mingw-w64 crt include paths
315 // <sysroot>/i686-w64-mingw32/include
316 SmallString<128> P = StringRef(HSOpts.ResourceDir);
317 llvm::sys::path::append(P, "../../../i686-w64-mingw32/include");
318 AddPath(P.str(), System, false);
320 // <sysroot>/x86_64-w64-mingw32/include
321 P.resize(HSOpts.ResourceDir.size());
322 llvm::sys::path::append(P, "../../../x86_64-w64-mingw32/include");
323 AddPath(P.str(), System, false);
325 // mingw.org crt include paths
327 P.resize(HSOpts.ResourceDir.size());
328 llvm::sys::path::append(P, "../../../include");
329 AddPath(P.str(), System, false);
330 AddPath("/mingw/include", System, false);
332 AddPath("c:/mingw/include", System, false);
341 if ( os != llvm::Triple::RTEMS )
342 AddPath("/usr/include", ExternCSystem, false);
345 void InitHeaderSearch::
346 AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
347 llvm::Triple::OSType os = triple.getOS();
348 // FIXME: temporary hack: hard-coded paths.
350 if (triple.isOSDarwin()) {
351 switch (triple.getArch()) {
354 case llvm::Triple::ppc:
355 case llvm::Triple::ppc64:
356 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
357 "powerpc-apple-darwin10", "", "ppc64",
359 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
360 "powerpc-apple-darwin10", "", "ppc64",
364 case llvm::Triple::x86:
365 case llvm::Triple::x86_64:
366 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
367 "i686-apple-darwin10", "", "x86_64", triple);
368 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
369 "i686-apple-darwin8", "", "", triple);
372 case llvm::Triple::arm:
373 case llvm::Triple::thumb:
374 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
375 "arm-apple-darwin10", "v7", "", triple);
376 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
377 "arm-apple-darwin10", "v6", "", triple);
384 case llvm::Triple::Linux:
385 case llvm::Triple::Win32:
386 llvm_unreachable("Include management is handled in the driver.");
388 case llvm::Triple::Cygwin:
390 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3");
391 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
392 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
393 // g++-4 / Cygwin-1.5
394 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
396 case llvm::Triple::MinGW32:
397 // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
398 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
399 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
400 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
401 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
402 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
403 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
404 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
405 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
406 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
407 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
408 // mingw.org C++ include paths
409 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
411 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.1");
412 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");
413 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");
414 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");
415 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
416 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
417 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
420 case llvm::Triple::DragonFly:
421 if (llvm::sys::fs::exists("/usr/lib/gcc47"))
422 AddPath("/usr/include/c++/4.7", CXXSystem, false);
424 AddPath("/usr/include/c++/4.4", CXXSystem, false);
426 case llvm::Triple::FreeBSD:
429 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple);
431 case llvm::Triple::OpenBSD: {
432 std::string t = triple.getTriple();
433 if (t.substr(0, 6) == "x86_64")
434 t.replace(0, 6, "amd64");
435 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
439 case llvm::Triple::Minix:
440 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
443 case llvm::Triple::Solaris:
444 AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
445 "i386-pc-solaris2.11", "", "", triple);
446 // Solaris - Fall though..
447 case llvm::Triple::AuroraUX:
449 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
450 "i386-pc-solaris2.11", "", "", triple);
457 void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
458 const llvm::Triple &triple,
459 const HeaderSearchOptions &HSOpts) {
460 // NB: This code path is going away. All of the logic is moving into the
461 // driver which has the information necessary to do target-specific
462 // selections of default include paths. Each target which moves there will be
463 // exempted from this logic here until we can delete the entire pile of code.
464 switch (triple.getOS()) {
466 break; // Everything else continues to use this routine's logic.
468 case llvm::Triple::Linux:
469 case llvm::Triple::Win32:
473 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
474 HSOpts.UseStandardSystemIncludes) {
475 if (HSOpts.UseLibcxx) {
476 if (triple.isOSDarwin()) {
477 // On Darwin, libc++ may be installed alongside the compiler in
479 if (!HSOpts.ResourceDir.empty()) {
480 // Remove version from foo/lib/clang/version
481 StringRef NoVer = llvm::sys::path::parent_path(HSOpts.ResourceDir);
482 // Remove clang from foo/lib/clang
483 StringRef Lib = llvm::sys::path::parent_path(NoVer);
484 // Remove lib from foo/lib
485 SmallString<128> P = llvm::sys::path::parent_path(Lib);
487 // Get foo/include/c++/v1
488 llvm::sys::path::append(P, "include", "c++", "v1");
489 AddUnmappedPath(P.str(), CXXSystem, false);
492 // On Solaris, include the support directory for things like xlocale and
493 // fudged system headers.
494 if (triple.getOS() == llvm::Triple::Solaris)
495 AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, false);
497 AddPath("/usr/include/c++/v1", CXXSystem, false);
499 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
503 AddDefaultCIncludePaths(triple, HSOpts);
505 // Add the default framework include paths on Darwin.
506 if (HSOpts.UseStandardSystemIncludes) {
507 if (triple.isOSDarwin()) {
508 AddPath("/System/Library/Frameworks", System, true);
509 AddPath("/Library/Frameworks", System, true);
514 /// RemoveDuplicates - If there are duplicate directory entries in the specified
515 /// search list, remove the later (dead) ones. Returns the number of non-system
516 /// headers removed, which is used to update NumAngled.
517 static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
518 unsigned First, bool Verbose) {
519 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
520 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
521 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
522 unsigned NonSystemRemoved = 0;
523 for (unsigned i = First; i != SearchList.size(); ++i) {
524 unsigned DirToRemove = i;
526 const DirectoryLookup &CurEntry = SearchList[i];
528 if (CurEntry.isNormalDir()) {
529 // If this isn't the first time we've seen this dir, remove it.
530 if (SeenDirs.insert(CurEntry.getDir()))
532 } else if (CurEntry.isFramework()) {
533 // If this isn't the first time we've seen this framework dir, remove it.
534 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
537 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
538 // If this isn't the first time we've seen this headermap, remove it.
539 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
543 // If we have a normal #include dir/framework/headermap that is shadowed
544 // later in the chain by a system include location, we actually want to
545 // ignore the user's request and drop the user dir... keeping the system
546 // dir. This is weird, but required to emulate GCC's search path correctly.
548 // Since dupes of system dirs are rare, just rescan to find the original
549 // that we're nuking instead of using a DenseMap.
550 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
551 // Find the dir that this is the same of.
553 for (FirstDir = 0; ; ++FirstDir) {
554 assert(FirstDir != i && "Didn't find dupe?");
556 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
558 // If these are different lookup types, then they can't be the dupe.
559 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
563 if (CurEntry.isNormalDir())
564 isSame = SearchEntry.getDir() == CurEntry.getDir();
565 else if (CurEntry.isFramework())
566 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
568 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
569 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
576 // If the first dir in the search path is a non-system dir, zap it
577 // instead of the system one.
578 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
579 DirToRemove = FirstDir;
583 llvm::errs() << "ignoring duplicate directory \""
584 << CurEntry.getName() << "\"\n";
585 if (DirToRemove != i)
586 llvm::errs() << " as it is a non-system directory that duplicates "
587 << "a system directory\n";
589 if (DirToRemove != i)
592 // This is reached if the current entry is a duplicate. Remove the
593 // DirToRemove (usually the current dir).
594 SearchList.erase(SearchList.begin()+DirToRemove);
597 return NonSystemRemoved;
601 void InitHeaderSearch::Realize(const LangOptions &Lang) {
602 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
603 std::vector<DirectoryLookup> SearchList;
604 SearchList.reserve(IncludePath.size());
606 // Quoted arguments go first.
607 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
609 if (it->first == Quoted)
610 SearchList.push_back(it->second);
612 // Deduplicate and remember index.
613 RemoveDuplicates(SearchList, 0, Verbose);
614 unsigned NumQuoted = SearchList.size();
616 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
618 if (it->first == Angled || it->first == IndexHeaderMap)
619 SearchList.push_back(it->second);
622 RemoveDuplicates(SearchList, NumQuoted, Verbose);
623 unsigned NumAngled = SearchList.size();
625 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
627 if (it->first == System || it->first == ExternCSystem ||
628 (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
629 (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
630 (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
631 (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
632 SearchList.push_back(it->second);
635 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
637 if (it->first == After)
638 SearchList.push_back(it->second);
641 // Remove duplicates across both the Angled and System directories. GCC does
642 // this and failing to remove duplicates across these two groups breaks
644 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
645 NumAngled -= NonSystemRemoved;
647 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
648 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
650 Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
652 // If verbose, print the list of directories that will be searched.
654 llvm::errs() << "#include \"...\" search starts here:\n";
655 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
657 llvm::errs() << "#include <...> search starts here:\n";
658 const char *Name = SearchList[i].getName();
660 if (SearchList[i].isNormalDir())
662 else if (SearchList[i].isFramework())
663 Suffix = " (framework directory)";
665 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
666 Suffix = " (headermap)";
668 llvm::errs() << " " << Name << Suffix << "\n";
670 llvm::errs() << "End of search list.\n";
674 void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
675 const HeaderSearchOptions &HSOpts,
676 const LangOptions &Lang,
677 const llvm::Triple &Triple) {
678 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
680 // Add the user defined entries.
681 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
682 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
683 if (E.IgnoreSysRoot) {
684 Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework);
686 Init.AddPath(E.Path, E.Group, E.IsFramework);
690 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
692 for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
693 Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
694 HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
696 if (HSOpts.UseBuiltinIncludes) {
697 // Set up the builtin include directory in the module map.
698 SmallString<128> P = StringRef(HSOpts.ResourceDir);
699 llvm::sys::path::append(P, "include");
700 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str()))
701 HS.getModuleMap().setBuiltinIncludeDir(Dir);