1f4a2713aSLionel Sambuc //===--- InitHeaderSearch.cpp - Initialize header search paths ------------===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10f4a2713aSLionel Sambuc // This file implements the InitHeaderSearch class. 11f4a2713aSLionel Sambuc // 12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13f4a2713aSLionel Sambuc 14f4a2713aSLionel Sambuc #include "clang/Frontend/Utils.h" 15f4a2713aSLionel Sambuc #include "clang/Basic/FileManager.h" 16f4a2713aSLionel Sambuc #include "clang/Basic/LangOptions.h" 17f4a2713aSLionel Sambuc #include "clang/Config/config.h" // C_INCLUDE_DIRS 18f4a2713aSLionel Sambuc #include "clang/Lex/HeaderSearch.h" 19f4a2713aSLionel Sambuc #include "clang/Lex/HeaderSearchOptions.h" 20f4a2713aSLionel Sambuc #include "llvm/ADT/SmallPtrSet.h" 21f4a2713aSLionel Sambuc #include "llvm/ADT/SmallString.h" 22f4a2713aSLionel Sambuc #include "llvm/ADT/SmallVector.h" 23f4a2713aSLionel Sambuc #include "llvm/ADT/StringExtras.h" 24f4a2713aSLionel Sambuc #include "llvm/ADT/Triple.h" 25f4a2713aSLionel Sambuc #include "llvm/ADT/Twine.h" 26f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h" 27f4a2713aSLionel Sambuc #include "llvm/Support/FileSystem.h" 28f4a2713aSLionel Sambuc #include "llvm/Support/Path.h" 29f4a2713aSLionel Sambuc #include "llvm/Support/raw_ostream.h" 30f4a2713aSLionel Sambuc 31f4a2713aSLionel Sambuc using namespace clang; 32f4a2713aSLionel Sambuc using namespace clang::frontend; 33f4a2713aSLionel Sambuc 34f4a2713aSLionel Sambuc namespace { 35f4a2713aSLionel Sambuc 36f4a2713aSLionel Sambuc /// InitHeaderSearch - This class makes it easier to set the search paths of 37f4a2713aSLionel Sambuc /// a HeaderSearch object. InitHeaderSearch stores several search path lists 38f4a2713aSLionel Sambuc /// internally, which can be sent to a HeaderSearch object in one swoop. 39f4a2713aSLionel Sambuc class InitHeaderSearch { 40f4a2713aSLionel Sambuc std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath; 41f4a2713aSLionel Sambuc typedef std::vector<std::pair<IncludeDirGroup, 42f4a2713aSLionel Sambuc DirectoryLookup> >::const_iterator path_iterator; 43f4a2713aSLionel Sambuc std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes; 44f4a2713aSLionel Sambuc HeaderSearch &Headers; 45f4a2713aSLionel Sambuc bool Verbose; 46f4a2713aSLionel Sambuc std::string IncludeSysroot; 47f4a2713aSLionel Sambuc bool HasSysroot; 48f4a2713aSLionel Sambuc 49f4a2713aSLionel Sambuc public: 50f4a2713aSLionel Sambuc 51f4a2713aSLionel Sambuc InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot) 52f4a2713aSLionel Sambuc : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot), 53f4a2713aSLionel Sambuc HasSysroot(!(sysroot.empty() || sysroot == "/")) { 54f4a2713aSLionel Sambuc } 55f4a2713aSLionel Sambuc 56f4a2713aSLionel Sambuc /// AddPath - Add the specified path to the specified group list, prefixing 57f4a2713aSLionel Sambuc /// the sysroot if used. 58f4a2713aSLionel Sambuc void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework); 59f4a2713aSLionel Sambuc 60f4a2713aSLionel Sambuc /// AddUnmappedPath - Add the specified path to the specified group list, 61f4a2713aSLionel Sambuc /// without performing any sysroot remapping. 62f4a2713aSLionel Sambuc void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group, 63f4a2713aSLionel Sambuc bool isFramework); 64f4a2713aSLionel Sambuc 65f4a2713aSLionel Sambuc /// AddSystemHeaderPrefix - Add the specified prefix to the system header 66f4a2713aSLionel Sambuc /// prefix list. 67f4a2713aSLionel Sambuc void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) { 68f4a2713aSLionel Sambuc SystemHeaderPrefixes.push_back(std::make_pair(Prefix, IsSystemHeader)); 69f4a2713aSLionel Sambuc } 70f4a2713aSLionel Sambuc 71f4a2713aSLionel Sambuc /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu 72f4a2713aSLionel Sambuc /// libstdc++. 73f4a2713aSLionel Sambuc void AddGnuCPlusPlusIncludePaths(StringRef Base, 74f4a2713aSLionel Sambuc StringRef ArchDir, 75f4a2713aSLionel Sambuc StringRef Dir32, 76f4a2713aSLionel Sambuc StringRef Dir64, 77f4a2713aSLionel Sambuc const llvm::Triple &triple); 78f4a2713aSLionel Sambuc 79f4a2713aSLionel Sambuc /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW 80f4a2713aSLionel Sambuc /// libstdc++. 81f4a2713aSLionel Sambuc void AddMinGWCPlusPlusIncludePaths(StringRef Base, 82f4a2713aSLionel Sambuc StringRef Arch, 83f4a2713aSLionel Sambuc StringRef Version); 84f4a2713aSLionel Sambuc 85f4a2713aSLionel Sambuc /// AddMinGW64CXXPaths - Add the necessary paths to support 86f4a2713aSLionel Sambuc /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64. 87f4a2713aSLionel Sambuc void AddMinGW64CXXPaths(StringRef Base, 88f4a2713aSLionel Sambuc StringRef Version); 89f4a2713aSLionel Sambuc 90f4a2713aSLionel Sambuc // AddDefaultCIncludePaths - Add paths that should always be searched. 91f4a2713aSLionel Sambuc void AddDefaultCIncludePaths(const llvm::Triple &triple, 92f4a2713aSLionel Sambuc const HeaderSearchOptions &HSOpts); 93f4a2713aSLionel Sambuc 94f4a2713aSLionel Sambuc // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when 95f4a2713aSLionel Sambuc // compiling c++. 96f4a2713aSLionel Sambuc void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, 97f4a2713aSLionel Sambuc const HeaderSearchOptions &HSOpts); 98f4a2713aSLionel Sambuc 99f4a2713aSLionel Sambuc /// AddDefaultSystemIncludePaths - Adds the default system include paths so 100f4a2713aSLionel Sambuc /// that e.g. stdio.h is found. 101f4a2713aSLionel Sambuc void AddDefaultIncludePaths(const LangOptions &Lang, 102f4a2713aSLionel Sambuc const llvm::Triple &triple, 103f4a2713aSLionel Sambuc const HeaderSearchOptions &HSOpts); 104f4a2713aSLionel Sambuc 105f4a2713aSLionel Sambuc /// Realize - Merges all search path lists into one list and send it to 106f4a2713aSLionel Sambuc /// HeaderSearch. 107f4a2713aSLionel Sambuc void Realize(const LangOptions &Lang); 108f4a2713aSLionel Sambuc }; 109f4a2713aSLionel Sambuc 110f4a2713aSLionel Sambuc } // end anonymous namespace. 111f4a2713aSLionel Sambuc 112f4a2713aSLionel Sambuc static bool CanPrefixSysroot(StringRef Path) { 113f4a2713aSLionel Sambuc #if defined(_WIN32) 114f4a2713aSLionel Sambuc return !Path.empty() && llvm::sys::path::is_separator(Path[0]); 115f4a2713aSLionel Sambuc #else 116f4a2713aSLionel Sambuc return llvm::sys::path::is_absolute(Path); 117f4a2713aSLionel Sambuc #endif 118f4a2713aSLionel Sambuc } 119f4a2713aSLionel Sambuc 120f4a2713aSLionel Sambuc void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group, 121f4a2713aSLionel Sambuc bool isFramework) { 122f4a2713aSLionel Sambuc // Add the path with sysroot prepended, if desired and this is a system header 123f4a2713aSLionel Sambuc // group. 124f4a2713aSLionel Sambuc if (HasSysroot) { 125f4a2713aSLionel Sambuc SmallString<256> MappedPathStorage; 126f4a2713aSLionel Sambuc StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); 127f4a2713aSLionel Sambuc if (CanPrefixSysroot(MappedPathStr)) { 128f4a2713aSLionel Sambuc AddUnmappedPath(IncludeSysroot + Path, Group, isFramework); 129f4a2713aSLionel Sambuc return; 130f4a2713aSLionel Sambuc } 131f4a2713aSLionel Sambuc } 132f4a2713aSLionel Sambuc 133f4a2713aSLionel Sambuc AddUnmappedPath(Path, Group, isFramework); 134f4a2713aSLionel Sambuc } 135f4a2713aSLionel Sambuc 136f4a2713aSLionel Sambuc void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group, 137f4a2713aSLionel Sambuc bool isFramework) { 138f4a2713aSLionel Sambuc assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); 139f4a2713aSLionel Sambuc 140f4a2713aSLionel Sambuc FileManager &FM = Headers.getFileMgr(); 141f4a2713aSLionel Sambuc SmallString<256> MappedPathStorage; 142f4a2713aSLionel Sambuc StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); 143f4a2713aSLionel Sambuc 144f4a2713aSLionel Sambuc // Compute the DirectoryLookup type. 145f4a2713aSLionel Sambuc SrcMgr::CharacteristicKind Type; 146f4a2713aSLionel Sambuc if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) { 147f4a2713aSLionel Sambuc Type = SrcMgr::C_User; 148f4a2713aSLionel Sambuc } else if (Group == ExternCSystem) { 149f4a2713aSLionel Sambuc Type = SrcMgr::C_ExternCSystem; 150f4a2713aSLionel Sambuc } else { 151f4a2713aSLionel Sambuc Type = SrcMgr::C_System; 152f4a2713aSLionel Sambuc } 153f4a2713aSLionel Sambuc 154f4a2713aSLionel Sambuc // If the directory exists, add it. 155f4a2713aSLionel Sambuc if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) { 156f4a2713aSLionel Sambuc IncludePath.push_back( 157f4a2713aSLionel Sambuc std::make_pair(Group, DirectoryLookup(DE, Type, isFramework))); 158f4a2713aSLionel Sambuc return; 159f4a2713aSLionel Sambuc } 160f4a2713aSLionel Sambuc 161f4a2713aSLionel Sambuc // Check to see if this is an apple-style headermap (which are not allowed to 162f4a2713aSLionel Sambuc // be frameworks). 163f4a2713aSLionel Sambuc if (!isFramework) { 164f4a2713aSLionel Sambuc if (const FileEntry *FE = FM.getFile(MappedPathStr)) { 165f4a2713aSLionel Sambuc if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { 166f4a2713aSLionel Sambuc // It is a headermap, add it to the search path. 167f4a2713aSLionel Sambuc IncludePath.push_back( 168f4a2713aSLionel Sambuc std::make_pair(Group, 169f4a2713aSLionel Sambuc DirectoryLookup(HM, Type, Group == IndexHeaderMap))); 170f4a2713aSLionel Sambuc return; 171f4a2713aSLionel Sambuc } 172f4a2713aSLionel Sambuc } 173f4a2713aSLionel Sambuc } 174f4a2713aSLionel Sambuc 175f4a2713aSLionel Sambuc if (Verbose) 176f4a2713aSLionel Sambuc llvm::errs() << "ignoring nonexistent directory \"" 177f4a2713aSLionel Sambuc << MappedPathStr << "\"\n"; 178f4a2713aSLionel Sambuc } 179f4a2713aSLionel Sambuc 180f4a2713aSLionel Sambuc void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base, 181f4a2713aSLionel Sambuc StringRef ArchDir, 182f4a2713aSLionel Sambuc StringRef Dir32, 183f4a2713aSLionel Sambuc StringRef Dir64, 184f4a2713aSLionel Sambuc const llvm::Triple &triple) { 185f4a2713aSLionel Sambuc // Add the base dir 186f4a2713aSLionel Sambuc AddPath(Base, CXXSystem, false); 187f4a2713aSLionel Sambuc 188f4a2713aSLionel Sambuc // Add the multilib dirs 189f4a2713aSLionel Sambuc llvm::Triple::ArchType arch = triple.getArch(); 190f4a2713aSLionel Sambuc bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; 191f4a2713aSLionel Sambuc if (is64bit) 192f4a2713aSLionel Sambuc AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false); 193f4a2713aSLionel Sambuc else 194f4a2713aSLionel Sambuc AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false); 195f4a2713aSLionel Sambuc 196f4a2713aSLionel Sambuc // Add the backward dir 197f4a2713aSLionel Sambuc AddPath(Base + "/backward", CXXSystem, false); 198f4a2713aSLionel Sambuc } 199f4a2713aSLionel Sambuc 200f4a2713aSLionel Sambuc void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base, 201f4a2713aSLionel Sambuc StringRef Arch, 202f4a2713aSLionel Sambuc StringRef Version) { 203f4a2713aSLionel Sambuc AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", 204f4a2713aSLionel Sambuc CXXSystem, false); 205f4a2713aSLionel Sambuc AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, 206f4a2713aSLionel Sambuc CXXSystem, false); 207f4a2713aSLionel Sambuc AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", 208f4a2713aSLionel Sambuc CXXSystem, false); 209f4a2713aSLionel Sambuc } 210f4a2713aSLionel Sambuc 211f4a2713aSLionel Sambuc void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base, 212f4a2713aSLionel Sambuc StringRef Version) { 213f4a2713aSLionel Sambuc // Assumes Base is HeaderSearchOpts' ResourceDir 214f4a2713aSLionel Sambuc AddPath(Base + "/../../../include/c++/" + Version, 215f4a2713aSLionel Sambuc CXXSystem, false); 216f4a2713aSLionel Sambuc AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32", 217f4a2713aSLionel Sambuc CXXSystem, false); 218f4a2713aSLionel Sambuc AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32", 219f4a2713aSLionel Sambuc CXXSystem, false); 220f4a2713aSLionel Sambuc AddPath(Base + "/../../../include/c++/" + Version + "/backward", 221f4a2713aSLionel Sambuc CXXSystem, false); 222f4a2713aSLionel Sambuc } 223f4a2713aSLionel Sambuc 224f4a2713aSLionel Sambuc void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, 225f4a2713aSLionel Sambuc const HeaderSearchOptions &HSOpts) { 226f4a2713aSLionel Sambuc llvm::Triple::OSType os = triple.getOS(); 227f4a2713aSLionel Sambuc 228f4a2713aSLionel Sambuc if (HSOpts.UseStandardSystemIncludes) { 229f4a2713aSLionel Sambuc switch (os) { 230f4a2713aSLionel Sambuc case llvm::Triple::FreeBSD: 231f4a2713aSLionel Sambuc case llvm::Triple::NetBSD: 232f4a2713aSLionel Sambuc case llvm::Triple::OpenBSD: 233*4684ddb6SLionel Sambuc case llvm::Triple::Minix: 234f4a2713aSLionel Sambuc case llvm::Triple::Bitrig: 235f4a2713aSLionel Sambuc break; 236f4a2713aSLionel Sambuc default: 237f4a2713aSLionel Sambuc // FIXME: temporary hack: hard-coded paths. 238f4a2713aSLionel Sambuc AddPath("/usr/local/include", System, false); 239f4a2713aSLionel Sambuc break; 240f4a2713aSLionel Sambuc } 241f4a2713aSLionel Sambuc } 242f4a2713aSLionel Sambuc 243f4a2713aSLionel Sambuc // Builtin includes use #include_next directives and should be positioned 244f4a2713aSLionel Sambuc // just prior C include dirs. 245f4a2713aSLionel Sambuc if (HSOpts.UseBuiltinIncludes) { 246f4a2713aSLionel Sambuc // Ignore the sys root, we *always* look for clang headers relative to 247f4a2713aSLionel Sambuc // supplied path. 248f4a2713aSLionel Sambuc SmallString<128> P = StringRef(HSOpts.ResourceDir); 249f4a2713aSLionel Sambuc llvm::sys::path::append(P, "include"); 250f4a2713aSLionel Sambuc AddUnmappedPath(P.str(), ExternCSystem, false); 251f4a2713aSLionel Sambuc } 252f4a2713aSLionel Sambuc 253f4a2713aSLionel Sambuc // All remaining additions are for system include directories, early exit if 254f4a2713aSLionel Sambuc // we aren't using them. 255f4a2713aSLionel Sambuc if (!HSOpts.UseStandardSystemIncludes) 256f4a2713aSLionel Sambuc return; 257f4a2713aSLionel Sambuc 258f4a2713aSLionel Sambuc // Add dirs specified via 'configure --with-c-include-dirs'. 259f4a2713aSLionel Sambuc StringRef CIncludeDirs(C_INCLUDE_DIRS); 260f4a2713aSLionel Sambuc if (CIncludeDirs != "") { 261f4a2713aSLionel Sambuc SmallVector<StringRef, 5> dirs; 262f4a2713aSLionel Sambuc CIncludeDirs.split(dirs, ":"); 263f4a2713aSLionel Sambuc for (SmallVectorImpl<StringRef>::iterator i = dirs.begin(); 264f4a2713aSLionel Sambuc i != dirs.end(); 265f4a2713aSLionel Sambuc ++i) 266f4a2713aSLionel Sambuc AddPath(*i, ExternCSystem, false); 267f4a2713aSLionel Sambuc return; 268f4a2713aSLionel Sambuc } 269f4a2713aSLionel Sambuc 270f4a2713aSLionel Sambuc switch (os) { 271f4a2713aSLionel Sambuc case llvm::Triple::Linux: 272f4a2713aSLionel Sambuc case llvm::Triple::Win32: 273f4a2713aSLionel Sambuc llvm_unreachable("Include management is handled in the driver."); 274f4a2713aSLionel Sambuc 275f4a2713aSLionel Sambuc case llvm::Triple::Haiku: 276f4a2713aSLionel Sambuc AddPath("/boot/common/include", System, false); 277f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os", System, false); 278f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/app", System, false); 279f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/arch", System, false); 280f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/device", System, false); 281f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/drivers", System, false); 282f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/game", System, false); 283f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/interface", System, false); 284f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/kernel", System, false); 285f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/locale", System, false); 286f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/mail", System, false); 287f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/media", System, false); 288f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/midi", System, false); 289f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/midi2", System, false); 290f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/net", System, false); 291f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/storage", System, false); 292f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/support", System, false); 293f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/translation", System, false); 294f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/add-ons/graphics", System, false); 295f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/add-ons/input_server", System, false); 296f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/add-ons/screen_saver", System, false); 297f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/add-ons/tracker", System, false); 298f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/be_apps/Deskbar", System, false); 299f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/be_apps/NetPositive", System, false); 300f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/os/be_apps/Tracker", System, false); 301f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/cpp", System, false); 302f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/cpp/i586-pc-haiku", System, false); 303f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/3rdparty", System, false); 304f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/bsd", System, false); 305f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/glibc", System, false); 306f4a2713aSLionel Sambuc AddPath("/boot/develop/headers/posix", System, false); 307f4a2713aSLionel Sambuc AddPath("/boot/develop/headers", System, false); 308f4a2713aSLionel Sambuc break; 309f4a2713aSLionel Sambuc case llvm::Triple::RTEMS: 310f4a2713aSLionel Sambuc break; 311f4a2713aSLionel Sambuc case llvm::Triple::Cygwin: 312f4a2713aSLionel Sambuc AddPath("/usr/include/w32api", System, false); 313f4a2713aSLionel Sambuc break; 314f4a2713aSLionel Sambuc case llvm::Triple::MinGW32: { 315f4a2713aSLionel Sambuc // mingw-w64 crt include paths 316f4a2713aSLionel Sambuc // <sysroot>/i686-w64-mingw32/include 317f4a2713aSLionel Sambuc SmallString<128> P = StringRef(HSOpts.ResourceDir); 318f4a2713aSLionel Sambuc llvm::sys::path::append(P, "../../../i686-w64-mingw32/include"); 319f4a2713aSLionel Sambuc AddPath(P.str(), System, false); 320f4a2713aSLionel Sambuc 321f4a2713aSLionel Sambuc // <sysroot>/x86_64-w64-mingw32/include 322f4a2713aSLionel Sambuc P.resize(HSOpts.ResourceDir.size()); 323f4a2713aSLionel Sambuc llvm::sys::path::append(P, "../../../x86_64-w64-mingw32/include"); 324f4a2713aSLionel Sambuc AddPath(P.str(), System, false); 325f4a2713aSLionel Sambuc 326f4a2713aSLionel Sambuc // mingw.org crt include paths 327f4a2713aSLionel Sambuc // <sysroot>/include 328f4a2713aSLionel Sambuc P.resize(HSOpts.ResourceDir.size()); 329f4a2713aSLionel Sambuc llvm::sys::path::append(P, "../../../include"); 330f4a2713aSLionel Sambuc AddPath(P.str(), System, false); 331f4a2713aSLionel Sambuc AddPath("/mingw/include", System, false); 332f4a2713aSLionel Sambuc #if defined(_WIN32) 333f4a2713aSLionel Sambuc AddPath("c:/mingw/include", System, false); 334f4a2713aSLionel Sambuc #endif 335f4a2713aSLionel Sambuc } 336f4a2713aSLionel Sambuc break; 337f4a2713aSLionel Sambuc 338f4a2713aSLionel Sambuc default: 339f4a2713aSLionel Sambuc break; 340f4a2713aSLionel Sambuc } 341f4a2713aSLionel Sambuc 342f4a2713aSLionel Sambuc if ( os != llvm::Triple::RTEMS ) 343f4a2713aSLionel Sambuc AddPath("/usr/include", ExternCSystem, false); 344f4a2713aSLionel Sambuc } 345f4a2713aSLionel Sambuc 346f4a2713aSLionel Sambuc void InitHeaderSearch:: 347f4a2713aSLionel Sambuc AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { 348f4a2713aSLionel Sambuc llvm::Triple::OSType os = triple.getOS(); 349f4a2713aSLionel Sambuc // FIXME: temporary hack: hard-coded paths. 350f4a2713aSLionel Sambuc 351f4a2713aSLionel Sambuc if (triple.isOSDarwin()) { 352f4a2713aSLionel Sambuc switch (triple.getArch()) { 353f4a2713aSLionel Sambuc default: break; 354f4a2713aSLionel Sambuc 355f4a2713aSLionel Sambuc case llvm::Triple::ppc: 356f4a2713aSLionel Sambuc case llvm::Triple::ppc64: 357f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 358f4a2713aSLionel Sambuc "powerpc-apple-darwin10", "", "ppc64", 359f4a2713aSLionel Sambuc triple); 360f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", 361f4a2713aSLionel Sambuc "powerpc-apple-darwin10", "", "ppc64", 362f4a2713aSLionel Sambuc triple); 363f4a2713aSLionel Sambuc break; 364f4a2713aSLionel Sambuc 365f4a2713aSLionel Sambuc case llvm::Triple::x86: 366f4a2713aSLionel Sambuc case llvm::Triple::x86_64: 367f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 368f4a2713aSLionel Sambuc "i686-apple-darwin10", "", "x86_64", triple); 369f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", 370f4a2713aSLionel Sambuc "i686-apple-darwin8", "", "", triple); 371f4a2713aSLionel Sambuc break; 372f4a2713aSLionel Sambuc 373f4a2713aSLionel Sambuc case llvm::Triple::arm: 374f4a2713aSLionel Sambuc case llvm::Triple::thumb: 375f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 376f4a2713aSLionel Sambuc "arm-apple-darwin10", "v7", "", triple); 377f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 378f4a2713aSLionel Sambuc "arm-apple-darwin10", "v6", "", triple); 379f4a2713aSLionel Sambuc break; 380f4a2713aSLionel Sambuc } 381f4a2713aSLionel Sambuc return; 382f4a2713aSLionel Sambuc } 383f4a2713aSLionel Sambuc 384f4a2713aSLionel Sambuc switch (os) { 385f4a2713aSLionel Sambuc case llvm::Triple::Linux: 386f4a2713aSLionel Sambuc case llvm::Triple::Win32: 387f4a2713aSLionel Sambuc llvm_unreachable("Include management is handled in the driver."); 388f4a2713aSLionel Sambuc 389f4a2713aSLionel Sambuc case llvm::Triple::Cygwin: 390f4a2713aSLionel Sambuc // Cygwin-1.7 391f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3"); 392f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3"); 393f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4"); 394f4a2713aSLionel Sambuc // g++-4 / Cygwin-1.5 395f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); 396f4a2713aSLionel Sambuc break; 397f4a2713aSLionel Sambuc case llvm::Triple::MinGW32: 398f4a2713aSLionel Sambuc // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32) 399f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0"); 400f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1"); 401f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2"); 402f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3"); 403f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4"); 404f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0"); 405f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1"); 406f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2"); 407f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3"); 408f4a2713aSLionel Sambuc AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0"); 409f4a2713aSLionel Sambuc // mingw.org C++ include paths 410f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS 411f4a2713aSLionel Sambuc #if defined(_WIN32) 412f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.1"); 413f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2"); 414f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1"); 415f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2"); 416f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0"); 417f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); 418f4a2713aSLionel Sambuc AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); 419f4a2713aSLionel Sambuc #endif 420f4a2713aSLionel Sambuc break; 421f4a2713aSLionel Sambuc case llvm::Triple::DragonFly: 422f4a2713aSLionel Sambuc if (llvm::sys::fs::exists("/usr/lib/gcc47")) 423f4a2713aSLionel Sambuc AddPath("/usr/include/c++/4.7", CXXSystem, false); 424f4a2713aSLionel Sambuc else 425f4a2713aSLionel Sambuc AddPath("/usr/include/c++/4.4", CXXSystem, false); 426f4a2713aSLionel Sambuc break; 427f4a2713aSLionel Sambuc case llvm::Triple::FreeBSD: 428f4a2713aSLionel Sambuc // FreeBSD 8.0 429f4a2713aSLionel Sambuc // FreeBSD 7.3 430f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple); 431f4a2713aSLionel Sambuc break; 432f4a2713aSLionel Sambuc case llvm::Triple::OpenBSD: { 433f4a2713aSLionel Sambuc std::string t = triple.getTriple(); 434f4a2713aSLionel Sambuc if (t.substr(0, 6) == "x86_64") 435f4a2713aSLionel Sambuc t.replace(0, 6, "amd64"); 436f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/usr/include/g++", 437f4a2713aSLionel Sambuc t, "", "", triple); 438f4a2713aSLionel Sambuc break; 439f4a2713aSLionel Sambuc } 440f4a2713aSLionel Sambuc case llvm::Triple::Solaris: 441f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/", 442f4a2713aSLionel Sambuc "i386-pc-solaris2.11", "", "", triple); 443f4a2713aSLionel Sambuc // Solaris - Fall though.. 444f4a2713aSLionel Sambuc case llvm::Triple::AuroraUX: 445f4a2713aSLionel Sambuc // AuroraUX 446f4a2713aSLionel Sambuc AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", 447f4a2713aSLionel Sambuc "i386-pc-solaris2.11", "", "", triple); 448f4a2713aSLionel Sambuc break; 449f4a2713aSLionel Sambuc default: 450f4a2713aSLionel Sambuc break; 451f4a2713aSLionel Sambuc } 452f4a2713aSLionel Sambuc } 453f4a2713aSLionel Sambuc 454f4a2713aSLionel Sambuc void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang, 455f4a2713aSLionel Sambuc const llvm::Triple &triple, 456f4a2713aSLionel Sambuc const HeaderSearchOptions &HSOpts) { 457f4a2713aSLionel Sambuc // NB: This code path is going away. All of the logic is moving into the 458f4a2713aSLionel Sambuc // driver which has the information necessary to do target-specific 459f4a2713aSLionel Sambuc // selections of default include paths. Each target which moves there will be 460f4a2713aSLionel Sambuc // exempted from this logic here until we can delete the entire pile of code. 461f4a2713aSLionel Sambuc switch (triple.getOS()) { 462f4a2713aSLionel Sambuc default: 463f4a2713aSLionel Sambuc break; // Everything else continues to use this routine's logic. 464f4a2713aSLionel Sambuc 465f4a2713aSLionel Sambuc case llvm::Triple::Linux: 466f4a2713aSLionel Sambuc case llvm::Triple::Win32: 467f4a2713aSLionel Sambuc return; 468f4a2713aSLionel Sambuc } 469f4a2713aSLionel Sambuc 470f4a2713aSLionel Sambuc if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes && 471f4a2713aSLionel Sambuc HSOpts.UseStandardSystemIncludes) { 472f4a2713aSLionel Sambuc if (HSOpts.UseLibcxx) { 473f4a2713aSLionel Sambuc if (triple.isOSDarwin()) { 474f4a2713aSLionel Sambuc // On Darwin, libc++ may be installed alongside the compiler in 475f4a2713aSLionel Sambuc // include/c++/v1. 476f4a2713aSLionel Sambuc if (!HSOpts.ResourceDir.empty()) { 477f4a2713aSLionel Sambuc // Remove version from foo/lib/clang/version 478f4a2713aSLionel Sambuc StringRef NoVer = llvm::sys::path::parent_path(HSOpts.ResourceDir); 479f4a2713aSLionel Sambuc // Remove clang from foo/lib/clang 480f4a2713aSLionel Sambuc StringRef Lib = llvm::sys::path::parent_path(NoVer); 481f4a2713aSLionel Sambuc // Remove lib from foo/lib 482f4a2713aSLionel Sambuc SmallString<128> P = llvm::sys::path::parent_path(Lib); 483f4a2713aSLionel Sambuc 484f4a2713aSLionel Sambuc // Get foo/include/c++/v1 485f4a2713aSLionel Sambuc llvm::sys::path::append(P, "include", "c++", "v1"); 486f4a2713aSLionel Sambuc AddUnmappedPath(P.str(), CXXSystem, false); 487f4a2713aSLionel Sambuc } 488f4a2713aSLionel Sambuc } 489f4a2713aSLionel Sambuc // On Solaris, include the support directory for things like xlocale and 490f4a2713aSLionel Sambuc // fudged system headers. 491f4a2713aSLionel Sambuc if (triple.getOS() == llvm::Triple::Solaris) 492f4a2713aSLionel Sambuc AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, false); 493f4a2713aSLionel Sambuc 494f4a2713aSLionel Sambuc AddPath("/usr/include/c++/v1", CXXSystem, false); 495f4a2713aSLionel Sambuc } else { 496f4a2713aSLionel Sambuc AddDefaultCPlusPlusIncludePaths(triple, HSOpts); 497f4a2713aSLionel Sambuc } 498f4a2713aSLionel Sambuc } 499f4a2713aSLionel Sambuc 500f4a2713aSLionel Sambuc AddDefaultCIncludePaths(triple, HSOpts); 501f4a2713aSLionel Sambuc 502f4a2713aSLionel Sambuc // Add the default framework include paths on Darwin. 503f4a2713aSLionel Sambuc if (HSOpts.UseStandardSystemIncludes) { 504f4a2713aSLionel Sambuc if (triple.isOSDarwin()) { 505f4a2713aSLionel Sambuc AddPath("/System/Library/Frameworks", System, true); 506f4a2713aSLionel Sambuc AddPath("/Library/Frameworks", System, true); 507f4a2713aSLionel Sambuc } 508f4a2713aSLionel Sambuc } 509f4a2713aSLionel Sambuc } 510f4a2713aSLionel Sambuc 511f4a2713aSLionel Sambuc /// RemoveDuplicates - If there are duplicate directory entries in the specified 512f4a2713aSLionel Sambuc /// search list, remove the later (dead) ones. Returns the number of non-system 513f4a2713aSLionel Sambuc /// headers removed, which is used to update NumAngled. 514f4a2713aSLionel Sambuc static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, 515f4a2713aSLionel Sambuc unsigned First, bool Verbose) { 516f4a2713aSLionel Sambuc llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; 517f4a2713aSLionel Sambuc llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; 518f4a2713aSLionel Sambuc llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; 519f4a2713aSLionel Sambuc unsigned NonSystemRemoved = 0; 520f4a2713aSLionel Sambuc for (unsigned i = First; i != SearchList.size(); ++i) { 521f4a2713aSLionel Sambuc unsigned DirToRemove = i; 522f4a2713aSLionel Sambuc 523f4a2713aSLionel Sambuc const DirectoryLookup &CurEntry = SearchList[i]; 524f4a2713aSLionel Sambuc 525f4a2713aSLionel Sambuc if (CurEntry.isNormalDir()) { 526f4a2713aSLionel Sambuc // If this isn't the first time we've seen this dir, remove it. 527f4a2713aSLionel Sambuc if (SeenDirs.insert(CurEntry.getDir())) 528f4a2713aSLionel Sambuc continue; 529f4a2713aSLionel Sambuc } else if (CurEntry.isFramework()) { 530f4a2713aSLionel Sambuc // If this isn't the first time we've seen this framework dir, remove it. 531f4a2713aSLionel Sambuc if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) 532f4a2713aSLionel Sambuc continue; 533f4a2713aSLionel Sambuc } else { 534f4a2713aSLionel Sambuc assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 535f4a2713aSLionel Sambuc // If this isn't the first time we've seen this headermap, remove it. 536f4a2713aSLionel Sambuc if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) 537f4a2713aSLionel Sambuc continue; 538f4a2713aSLionel Sambuc } 539f4a2713aSLionel Sambuc 540f4a2713aSLionel Sambuc // If we have a normal #include dir/framework/headermap that is shadowed 541f4a2713aSLionel Sambuc // later in the chain by a system include location, we actually want to 542f4a2713aSLionel Sambuc // ignore the user's request and drop the user dir... keeping the system 543f4a2713aSLionel Sambuc // dir. This is weird, but required to emulate GCC's search path correctly. 544f4a2713aSLionel Sambuc // 545f4a2713aSLionel Sambuc // Since dupes of system dirs are rare, just rescan to find the original 546f4a2713aSLionel Sambuc // that we're nuking instead of using a DenseMap. 547f4a2713aSLionel Sambuc if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { 548f4a2713aSLionel Sambuc // Find the dir that this is the same of. 549f4a2713aSLionel Sambuc unsigned FirstDir; 550f4a2713aSLionel Sambuc for (FirstDir = 0; ; ++FirstDir) { 551f4a2713aSLionel Sambuc assert(FirstDir != i && "Didn't find dupe?"); 552f4a2713aSLionel Sambuc 553f4a2713aSLionel Sambuc const DirectoryLookup &SearchEntry = SearchList[FirstDir]; 554f4a2713aSLionel Sambuc 555f4a2713aSLionel Sambuc // If these are different lookup types, then they can't be the dupe. 556f4a2713aSLionel Sambuc if (SearchEntry.getLookupType() != CurEntry.getLookupType()) 557f4a2713aSLionel Sambuc continue; 558f4a2713aSLionel Sambuc 559f4a2713aSLionel Sambuc bool isSame; 560f4a2713aSLionel Sambuc if (CurEntry.isNormalDir()) 561f4a2713aSLionel Sambuc isSame = SearchEntry.getDir() == CurEntry.getDir(); 562f4a2713aSLionel Sambuc else if (CurEntry.isFramework()) 563f4a2713aSLionel Sambuc isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); 564f4a2713aSLionel Sambuc else { 565f4a2713aSLionel Sambuc assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 566f4a2713aSLionel Sambuc isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); 567f4a2713aSLionel Sambuc } 568f4a2713aSLionel Sambuc 569f4a2713aSLionel Sambuc if (isSame) 570f4a2713aSLionel Sambuc break; 571f4a2713aSLionel Sambuc } 572f4a2713aSLionel Sambuc 573f4a2713aSLionel Sambuc // If the first dir in the search path is a non-system dir, zap it 574f4a2713aSLionel Sambuc // instead of the system one. 575f4a2713aSLionel Sambuc if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) 576f4a2713aSLionel Sambuc DirToRemove = FirstDir; 577f4a2713aSLionel Sambuc } 578f4a2713aSLionel Sambuc 579f4a2713aSLionel Sambuc if (Verbose) { 580f4a2713aSLionel Sambuc llvm::errs() << "ignoring duplicate directory \"" 581f4a2713aSLionel Sambuc << CurEntry.getName() << "\"\n"; 582f4a2713aSLionel Sambuc if (DirToRemove != i) 583f4a2713aSLionel Sambuc llvm::errs() << " as it is a non-system directory that duplicates " 584f4a2713aSLionel Sambuc << "a system directory\n"; 585f4a2713aSLionel Sambuc } 586f4a2713aSLionel Sambuc if (DirToRemove != i) 587f4a2713aSLionel Sambuc ++NonSystemRemoved; 588f4a2713aSLionel Sambuc 589f4a2713aSLionel Sambuc // This is reached if the current entry is a duplicate. Remove the 590f4a2713aSLionel Sambuc // DirToRemove (usually the current dir). 591f4a2713aSLionel Sambuc SearchList.erase(SearchList.begin()+DirToRemove); 592f4a2713aSLionel Sambuc --i; 593f4a2713aSLionel Sambuc } 594f4a2713aSLionel Sambuc return NonSystemRemoved; 595f4a2713aSLionel Sambuc } 596f4a2713aSLionel Sambuc 597f4a2713aSLionel Sambuc 598f4a2713aSLionel Sambuc void InitHeaderSearch::Realize(const LangOptions &Lang) { 599f4a2713aSLionel Sambuc // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. 600f4a2713aSLionel Sambuc std::vector<DirectoryLookup> SearchList; 601f4a2713aSLionel Sambuc SearchList.reserve(IncludePath.size()); 602f4a2713aSLionel Sambuc 603f4a2713aSLionel Sambuc // Quoted arguments go first. 604f4a2713aSLionel Sambuc for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 605f4a2713aSLionel Sambuc it != ie; ++it) { 606f4a2713aSLionel Sambuc if (it->first == Quoted) 607f4a2713aSLionel Sambuc SearchList.push_back(it->second); 608f4a2713aSLionel Sambuc } 609f4a2713aSLionel Sambuc // Deduplicate and remember index. 610f4a2713aSLionel Sambuc RemoveDuplicates(SearchList, 0, Verbose); 611f4a2713aSLionel Sambuc unsigned NumQuoted = SearchList.size(); 612f4a2713aSLionel Sambuc 613f4a2713aSLionel Sambuc for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 614f4a2713aSLionel Sambuc it != ie; ++it) { 615f4a2713aSLionel Sambuc if (it->first == Angled || it->first == IndexHeaderMap) 616f4a2713aSLionel Sambuc SearchList.push_back(it->second); 617f4a2713aSLionel Sambuc } 618f4a2713aSLionel Sambuc 619f4a2713aSLionel Sambuc RemoveDuplicates(SearchList, NumQuoted, Verbose); 620f4a2713aSLionel Sambuc unsigned NumAngled = SearchList.size(); 621f4a2713aSLionel Sambuc 622f4a2713aSLionel Sambuc for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 623f4a2713aSLionel Sambuc it != ie; ++it) { 624f4a2713aSLionel Sambuc if (it->first == System || it->first == ExternCSystem || 625f4a2713aSLionel Sambuc (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) || 626f4a2713aSLionel Sambuc (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) || 627f4a2713aSLionel Sambuc (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) || 628f4a2713aSLionel Sambuc (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem)) 629f4a2713aSLionel Sambuc SearchList.push_back(it->second); 630f4a2713aSLionel Sambuc } 631f4a2713aSLionel Sambuc 632f4a2713aSLionel Sambuc for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 633f4a2713aSLionel Sambuc it != ie; ++it) { 634f4a2713aSLionel Sambuc if (it->first == After) 635f4a2713aSLionel Sambuc SearchList.push_back(it->second); 636f4a2713aSLionel Sambuc } 637f4a2713aSLionel Sambuc 638f4a2713aSLionel Sambuc // Remove duplicates across both the Angled and System directories. GCC does 639f4a2713aSLionel Sambuc // this and failing to remove duplicates across these two groups breaks 640f4a2713aSLionel Sambuc // #include_next. 641f4a2713aSLionel Sambuc unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose); 642f4a2713aSLionel Sambuc NumAngled -= NonSystemRemoved; 643f4a2713aSLionel Sambuc 644f4a2713aSLionel Sambuc bool DontSearchCurDir = false; // TODO: set to true if -I- is set? 645f4a2713aSLionel Sambuc Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir); 646f4a2713aSLionel Sambuc 647f4a2713aSLionel Sambuc Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes); 648f4a2713aSLionel Sambuc 649f4a2713aSLionel Sambuc // If verbose, print the list of directories that will be searched. 650f4a2713aSLionel Sambuc if (Verbose) { 651f4a2713aSLionel Sambuc llvm::errs() << "#include \"...\" search starts here:\n"; 652f4a2713aSLionel Sambuc for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { 653f4a2713aSLionel Sambuc if (i == NumQuoted) 654f4a2713aSLionel Sambuc llvm::errs() << "#include <...> search starts here:\n"; 655f4a2713aSLionel Sambuc const char *Name = SearchList[i].getName(); 656f4a2713aSLionel Sambuc const char *Suffix; 657f4a2713aSLionel Sambuc if (SearchList[i].isNormalDir()) 658f4a2713aSLionel Sambuc Suffix = ""; 659f4a2713aSLionel Sambuc else if (SearchList[i].isFramework()) 660f4a2713aSLionel Sambuc Suffix = " (framework directory)"; 661f4a2713aSLionel Sambuc else { 662f4a2713aSLionel Sambuc assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); 663f4a2713aSLionel Sambuc Suffix = " (headermap)"; 664f4a2713aSLionel Sambuc } 665f4a2713aSLionel Sambuc llvm::errs() << " " << Name << Suffix << "\n"; 666f4a2713aSLionel Sambuc } 667f4a2713aSLionel Sambuc llvm::errs() << "End of search list.\n"; 668f4a2713aSLionel Sambuc } 669f4a2713aSLionel Sambuc } 670f4a2713aSLionel Sambuc 671f4a2713aSLionel Sambuc void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, 672f4a2713aSLionel Sambuc const HeaderSearchOptions &HSOpts, 673f4a2713aSLionel Sambuc const LangOptions &Lang, 674f4a2713aSLionel Sambuc const llvm::Triple &Triple) { 675f4a2713aSLionel Sambuc InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); 676f4a2713aSLionel Sambuc 677f4a2713aSLionel Sambuc // Add the user defined entries. 678f4a2713aSLionel Sambuc for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { 679f4a2713aSLionel Sambuc const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; 680f4a2713aSLionel Sambuc if (E.IgnoreSysRoot) { 681f4a2713aSLionel Sambuc Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework); 682f4a2713aSLionel Sambuc } else { 683f4a2713aSLionel Sambuc Init.AddPath(E.Path, E.Group, E.IsFramework); 684f4a2713aSLionel Sambuc } 685f4a2713aSLionel Sambuc } 686f4a2713aSLionel Sambuc 687f4a2713aSLionel Sambuc Init.AddDefaultIncludePaths(Lang, Triple, HSOpts); 688f4a2713aSLionel Sambuc 689f4a2713aSLionel Sambuc for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i) 690f4a2713aSLionel Sambuc Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix, 691f4a2713aSLionel Sambuc HSOpts.SystemHeaderPrefixes[i].IsSystemHeader); 692f4a2713aSLionel Sambuc 693f4a2713aSLionel Sambuc if (HSOpts.UseBuiltinIncludes) { 694f4a2713aSLionel Sambuc // Set up the builtin include directory in the module map. 695f4a2713aSLionel Sambuc SmallString<128> P = StringRef(HSOpts.ResourceDir); 696f4a2713aSLionel Sambuc llvm::sys::path::append(P, "include"); 697f4a2713aSLionel Sambuc if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str())) 698f4a2713aSLionel Sambuc HS.getModuleMap().setBuiltinIncludeDir(Dir); 699f4a2713aSLionel Sambuc } 700f4a2713aSLionel Sambuc 701f4a2713aSLionel Sambuc Init.Realize(Lang); 702f4a2713aSLionel Sambuc } 703