Nick Lewycky | df22c2c | 2010-07-25 03:12:58 +0000 | [diff] [blame] | 1 | //===--- InitHeaderSearch.cpp - Initialize header search paths ------------===// |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the InitHeaderSearch class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Oscar Fuentes | 2100fe9 | 2011-02-03 22:48:20 +0000 | [diff] [blame] | 14 | #ifdef HAVE_CLANG_CONFIG_H |
| 15 | # include "clang/Config/config.h" |
| 16 | #endif |
| 17 | |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 19 | #include "clang/Basic/FileManager.h" |
| 20 | #include "clang/Basic/LangOptions.h" |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 21 | #include "clang/Frontend/HeaderSearchOptions.h" |
| 22 | #include "clang/Lex/HeaderSearch.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallString.h" |
| 24 | #include "llvm/ADT/SmallPtrSet.h" |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallVector.h" |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/Triple.h" |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/Twine.h" |
Chris Lattner | d57a7ef | 2009-08-23 22:45:33 +0000 | [diff] [blame] | 29 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Path.h" |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 31 | #include "llvm/Config/config.h" |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 32 | #ifdef _MSC_VER |
| 33 | #define WIN32_LEAN_AND_MEAN 1 |
| 34 | #include <windows.h> |
| 35 | #endif |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 36 | using namespace clang; |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 37 | using namespace clang::frontend; |
| 38 | |
| 39 | namespace { |
| 40 | |
| 41 | /// InitHeaderSearch - This class makes it easier to set the search paths of |
| 42 | /// a HeaderSearch object. InitHeaderSearch stores several search path lists |
| 43 | /// internally, which can be sent to a HeaderSearch object in one swoop. |
| 44 | class InitHeaderSearch { |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 45 | std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath; |
| 46 | typedef std::vector<std::pair<IncludeDirGroup, |
| 47 | DirectoryLookup> >::const_iterator path_iterator; |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 48 | HeaderSearch &Headers; |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 49 | bool Verbose; |
Michael J. Spencer | af6530c | 2010-12-25 20:09:27 +0000 | [diff] [blame] | 50 | std::string IncludeSysroot; |
| 51 | bool IsNotEmptyOrRoot; |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 52 | |
| 53 | public: |
| 54 | |
Chandler Carruth | c09265a | 2010-11-15 07:15:26 +0000 | [diff] [blame] | 55 | InitHeaderSearch(HeaderSearch &HS, bool verbose, llvm::StringRef sysroot) |
Michael J. Spencer | af6530c | 2010-12-25 20:09:27 +0000 | [diff] [blame] | 56 | : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot), |
| 57 | IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) { |
Chandler Carruth | c09265a | 2010-11-15 07:15:26 +0000 | [diff] [blame] | 58 | } |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 59 | |
| 60 | /// AddPath - Add the specified path to the specified group list. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 61 | void AddPath(const llvm::Twine &Path, IncludeDirGroup Group, |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 62 | bool isCXXAware, bool isUserSupplied, |
| 63 | bool isFramework, bool IgnoreSysRoot = false); |
| 64 | |
mike-m | a608737 | 2010-05-05 17:00:31 +0000 | [diff] [blame] | 65 | /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 66 | /// libstdc++. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 67 | void AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, |
| 68 | llvm::StringRef ArchDir, |
| 69 | llvm::StringRef Dir32, |
| 70 | llvm::StringRef Dir64, |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 71 | const llvm::Triple &triple); |
| 72 | |
Michael J. Spencer | 06a8dc6 | 2010-12-21 16:45:42 +0000 | [diff] [blame] | 73 | /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 74 | /// libstdc++. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 75 | void AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, |
| 76 | llvm::StringRef Arch, |
| 77 | llvm::StringRef Version); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 78 | |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 79 | /// AddMinGW64CXXPaths - Add the necessary paths to support |
| 80 | /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64. |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 81 | void AddMinGW64CXXPaths(llvm::StringRef Base, |
| 82 | llvm::StringRef Version); |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 83 | |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 84 | /// AddDelimitedPaths - Add a list of paths delimited by the system PATH |
| 85 | /// separator. The processing follows that of the CPATH variable for gcc. |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 86 | void AddDelimitedPaths(llvm::StringRef String); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 87 | |
| 88 | // AddDefaultCIncludePaths - Add paths that should always be searched. |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 89 | void AddDefaultCIncludePaths(const llvm::Triple &triple, |
| 90 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 91 | |
| 92 | // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when |
| 93 | // compiling c++. |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 94 | void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, |
| 95 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 96 | |
| 97 | /// AddDefaultSystemIncludePaths - Adds the default system include paths so |
| 98 | /// that e.g. stdio.h is found. |
| 99 | void AddDefaultSystemIncludePaths(const LangOptions &Lang, |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 100 | const llvm::Triple &triple, |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 101 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 102 | |
| 103 | /// Realize - Merges all search path lists into one list and send it to |
| 104 | /// HeaderSearch. |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 105 | void Realize(const LangOptions &Lang); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 108 | } // end anonymous namespace. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 109 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 110 | void InitHeaderSearch::AddPath(const llvm::Twine &Path, |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 111 | IncludeDirGroup Group, bool isCXXAware, |
| 112 | bool isUserSupplied, bool isFramework, |
| 113 | bool IgnoreSysRoot) { |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 114 | assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 115 | FileManager &FM = Headers.getFileMgr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 116 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 117 | // Compute the actual path, taking into consideration -isysroot. |
Chandler Carruth | 5853b0f | 2010-11-15 00:05:18 +0000 | [diff] [blame] | 118 | llvm::SmallString<256> MappedPathStorage; |
Chandler Carruth | f372145 | 2010-11-15 00:48:13 +0000 | [diff] [blame] | 119 | llvm::StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 121 | // Handle isysroot. |
Rafael Espindola | 9a7e09d | 2011-03-02 21:30:07 +0000 | [diff] [blame] | 122 | if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot && |
NAKAMURA Takumi | 0f0cdab | 2011-05-02 04:50:10 +0000 | [diff] [blame] | 123 | #if defined(_WIN32) |
| 124 | !MappedPathStr.empty() && |
| 125 | llvm::sys::path::is_separator(MappedPathStr[0]) && |
| 126 | #else |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 127 | llvm::sys::path::is_absolute(MappedPathStr) && |
NAKAMURA Takumi | 0f0cdab | 2011-05-02 04:50:10 +0000 | [diff] [blame] | 128 | #endif |
Michael J. Spencer | af6530c | 2010-12-25 20:09:27 +0000 | [diff] [blame] | 129 | IsNotEmptyOrRoot) { |
Chandler Carruth | 5619ae5 | 2010-11-15 09:28:23 +0000 | [diff] [blame] | 130 | MappedPathStorage.clear(); |
Chandler Carruth | c09265a | 2010-11-15 07:15:26 +0000 | [diff] [blame] | 131 | MappedPathStr = |
Michael J. Spencer | af6530c | 2010-12-25 20:09:27 +0000 | [diff] [blame] | 132 | (IncludeSysroot + Path).toStringRef(MappedPathStorage); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 133 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 134 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 135 | // Compute the DirectoryLookup type. |
Chris Lattner | 9d72851 | 2008-10-27 01:19:25 +0000 | [diff] [blame] | 136 | SrcMgr::CharacteristicKind Type; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 137 | if (Group == Quoted || Group == Angled) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 138 | Type = SrcMgr::C_User; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 139 | else if (isCXXAware) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 140 | Type = SrcMgr::C_System; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 141 | else |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 142 | Type = SrcMgr::C_ExternCSystem; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
| 144 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 145 | // If the directory exists, add it. |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 146 | if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) { |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 147 | IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type, |
| 148 | isUserSupplied, isFramework))); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 149 | return; |
| 150 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 152 | // Check to see if this is an apple-style headermap (which are not allowed to |
| 153 | // be frameworks). |
| 154 | if (!isFramework) { |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 155 | if (const FileEntry *FE = FM.getFile(MappedPathStr)) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 156 | if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { |
| 157 | // It is a headermap, add it to the search path. |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 158 | IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type, |
| 159 | isUserSupplied))); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 160 | return; |
| 161 | } |
| 162 | } |
| 163 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 164 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 165 | if (Verbose) |
Chandler Carruth | f372145 | 2010-11-15 00:48:13 +0000 | [diff] [blame] | 166 | llvm::errs() << "ignoring nonexistent directory \"" |
| 167 | << MappedPathStr << "\"\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 171 | void InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) { |
| 172 | if (at.empty()) // Empty string should not add '.' path. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 173 | return; |
| 174 | |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 175 | llvm::StringRef::size_type delim; |
| 176 | while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) { |
| 177 | if (delim == 0) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 178 | AddPath(".", Angled, false, true, false); |
| 179 | else |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 180 | AddPath(at.substr(0, delim), Angled, false, true, false); |
| 181 | at = at.substr(delim + 1); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 182 | } |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 183 | |
| 184 | if (at.empty()) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 185 | AddPath(".", Angled, false, true, false); |
| 186 | else |
| 187 | AddPath(at, Angled, false, true, false); |
| 188 | } |
| 189 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 190 | void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, |
| 191 | llvm::StringRef ArchDir, |
| 192 | llvm::StringRef Dir32, |
| 193 | llvm::StringRef Dir64, |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 194 | const llvm::Triple &triple) { |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 195 | // Add the base dir |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 196 | AddPath(Base, CXXSystem, true, false, false); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 197 | |
| 198 | // Add the multilib dirs |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 199 | llvm::Triple::ArchType arch = triple.getArch(); |
| 200 | bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 201 | if (is64bit) |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 202 | AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false); |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 203 | else |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 204 | AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false); |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 205 | |
| 206 | // Add the backward dir |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 207 | AddPath(Base + "/backward", CXXSystem, true, false, false); |
Rafael Espindola | 2e9f652 | 2009-10-06 01:33:02 +0000 | [diff] [blame] | 208 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 209 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 210 | void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, |
| 211 | llvm::StringRef Arch, |
| 212 | llvm::StringRef Version) { |
Benjamin Kramer | ab8ae19 | 2010-01-20 16:18:11 +0000 | [diff] [blame] | 213 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 214 | CXXSystem, true, false, false); |
Chris Lattner | 8e9006b | 2010-09-03 16:45:53 +0000 | [diff] [blame] | 215 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 216 | CXXSystem, true, false, false); |
Benjamin Kramer | ab8ae19 | 2010-01-20 16:18:11 +0000 | [diff] [blame] | 217 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 218 | CXXSystem, true, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 219 | } |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 220 | |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 221 | void InitHeaderSearch::AddMinGW64CXXPaths(llvm::StringRef Base, |
| 222 | llvm::StringRef Version) { |
| 223 | // Assumes Base is HeaderSearchOpts' ResourceDir |
| 224 | AddPath(Base + "/../../../include/c++/" + Version, |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 225 | CXXSystem, true, false, false); |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 226 | AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32", |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 227 | CXXSystem, true, false, false); |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 228 | AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32", |
| 229 | CXXSystem, true, false, false); |
| 230 | AddPath(Base + "/../../../include/c++/" + Version + "/backward", |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 231 | CXXSystem, true, false, false); |
| 232 | } |
| 233 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 234 | // FIXME: This probably should goto to some platform utils place. |
| 235 | #ifdef _MSC_VER |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 236 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 237 | // Read registry string. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 238 | // This also supports a means to look for high-versioned keys by use |
| 239 | // of a $VERSION placeholder in the key path. |
| 240 | // $VERSION in the key path is a placeholder for the version number, |
| 241 | // causing the highest value path to be searched for and used. |
| 242 | // I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION". |
| 243 | // There can be additional characters in the component. Only the numberic |
| 244 | // characters are compared. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 245 | static bool getSystemRegistryString(const char *keyPath, const char *valueName, |
| 246 | char *value, size_t maxLength) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 247 | HKEY hRootKey = NULL; |
| 248 | HKEY hKey = NULL; |
| 249 | const char* subKey = NULL; |
| 250 | DWORD valueType; |
| 251 | DWORD valueSize = maxLength - 1; |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 252 | long lResult; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 253 | bool returnValue = false; |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 254 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 255 | if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { |
| 256 | hRootKey = HKEY_CLASSES_ROOT; |
| 257 | subKey = keyPath + 18; |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 258 | } else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 259 | hRootKey = HKEY_USERS; |
| 260 | subKey = keyPath + 11; |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 261 | } else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 262 | hRootKey = HKEY_LOCAL_MACHINE; |
| 263 | subKey = keyPath + 19; |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 264 | } else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 265 | hRootKey = HKEY_CURRENT_USER; |
| 266 | subKey = keyPath + 18; |
| 267 | } |
| 268 | else |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 269 | return false; |
| 270 | |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 271 | const char *placeHolder = strstr(subKey, "$VERSION"); |
| 272 | char bestName[256]; |
| 273 | bestName[0] = '\0'; |
| 274 | // If we have a $VERSION placeholder, do the highest-version search. |
| 275 | if (placeHolder) { |
| 276 | const char *keyEnd = placeHolder - 1; |
| 277 | const char *nextKey = placeHolder; |
| 278 | // Find end of previous key. |
| 279 | while ((keyEnd > subKey) && (*keyEnd != '\\')) |
| 280 | keyEnd--; |
| 281 | // Find end of key containing $VERSION. |
| 282 | while (*nextKey && (*nextKey != '\\')) |
| 283 | nextKey++; |
| 284 | size_t partialKeyLength = keyEnd - subKey; |
| 285 | char partialKey[256]; |
| 286 | if (partialKeyLength > sizeof(partialKey)) |
| 287 | partialKeyLength = sizeof(partialKey); |
| 288 | strncpy(partialKey, subKey, partialKeyLength); |
| 289 | partialKey[partialKeyLength] = '\0'; |
| 290 | HKEY hTopKey = NULL; |
| 291 | lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey); |
| 292 | if (lResult == ERROR_SUCCESS) { |
| 293 | char keyName[256]; |
| 294 | int bestIndex = -1; |
| 295 | double bestValue = 0.0; |
| 296 | DWORD index, size = sizeof(keyName) - 1; |
Nuno Lopes | 33cc243 | 2009-12-07 17:18:48 +0000 | [diff] [blame] | 297 | for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL, |
| 298 | NULL, NULL, NULL) == ERROR_SUCCESS; index++) { |
| 299 | const char *sp = keyName; |
| 300 | while (*sp && !isdigit(*sp)) |
| 301 | sp++; |
| 302 | if (!*sp) |
| 303 | continue; |
| 304 | const char *ep = sp + 1; |
| 305 | while (*ep && (isdigit(*ep) || (*ep == '.'))) |
| 306 | ep++; |
| 307 | char numBuf[32]; |
| 308 | strncpy(numBuf, sp, sizeof(numBuf) - 1); |
| 309 | numBuf[sizeof(numBuf) - 1] = '\0'; |
| 310 | double value = strtod(numBuf, NULL); |
| 311 | if (value > bestValue) { |
| 312 | bestIndex = (int)index; |
| 313 | bestValue = value; |
| 314 | strcpy(bestName, keyName); |
| 315 | } |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 316 | size = sizeof(keyName) - 1; |
| 317 | } |
| 318 | // If we found the highest versioned key, open the key and get the value. |
| 319 | if (bestIndex != -1) { |
| 320 | // Append rest of key. |
| 321 | strncat(bestName, nextKey, sizeof(bestName) - 1); |
| 322 | bestName[sizeof(bestName) - 1] = '\0'; |
| 323 | // Open the chosen key path remainder. |
| 324 | lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey); |
| 325 | if (lResult == ERROR_SUCCESS) { |
| 326 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 327 | (LPBYTE)value, &valueSize); |
| 328 | if (lResult == ERROR_SUCCESS) |
| 329 | returnValue = true; |
| 330 | RegCloseKey(hKey); |
| 331 | } |
| 332 | } |
| 333 | RegCloseKey(hTopKey); |
| 334 | } |
| 335 | } |
| 336 | else { |
| 337 | lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); |
| 338 | if (lResult == ERROR_SUCCESS) { |
| 339 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 340 | (LPBYTE)value, &valueSize); |
| 341 | if (lResult == ERROR_SUCCESS) |
| 342 | returnValue = true; |
| 343 | RegCloseKey(hKey); |
| 344 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 345 | } |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 346 | return returnValue; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 347 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 348 | #else // _MSC_VER |
| 349 | // Read registry string. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 350 | static bool getSystemRegistryString(const char*, const char*, char*, size_t) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 351 | return(false); |
| 352 | } |
| 353 | #endif // _MSC_VER |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 354 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 355 | // Get Visual Studio installation directory. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 356 | static bool getVisualStudioDir(std::string &path) { |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 357 | // First check the environment variables that vsvars32.bat sets. |
| 358 | const char* vcinstalldir = getenv("VCINSTALLDIR"); |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 359 | if (vcinstalldir) { |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 360 | char *p = const_cast<char *>(strstr(vcinstalldir, "\\VC")); |
| 361 | if (p) |
| 362 | *p = '\0'; |
| 363 | path = vcinstalldir; |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 364 | return true; |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 365 | } |
| 366 | |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 367 | char vsIDEInstallDir[256]; |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 368 | char vsExpressIDEInstallDir[256]; |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 369 | // Then try the windows registry. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 370 | bool hasVCDir = getSystemRegistryString( |
| 371 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION", |
| 372 | "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1); |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 373 | bool hasVCExpressDir = getSystemRegistryString( |
| 374 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\$VERSION", |
| 375 | "InstallDir", vsExpressIDEInstallDir, sizeof(vsExpressIDEInstallDir) - 1); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 376 | // If we have both vc80 and vc90, pick version we were compiled with. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 377 | if (hasVCDir && vsIDEInstallDir[0]) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 378 | char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); |
| 379 | if (p) |
| 380 | *p = '\0'; |
| 381 | path = vsIDEInstallDir; |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 382 | return true; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 383 | } |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 384 | |
| 385 | if (hasVCExpressDir && vsExpressIDEInstallDir[0]) { |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 386 | char *p = (char*)strstr(vsExpressIDEInstallDir, "\\Common7\\IDE"); |
| 387 | if (p) |
| 388 | *p = '\0'; |
| 389 | path = vsExpressIDEInstallDir; |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 390 | return true; |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 391 | } |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 392 | |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 393 | // Try the environment. |
| 394 | const char *vs100comntools = getenv("VS100COMNTOOLS"); |
| 395 | const char *vs90comntools = getenv("VS90COMNTOOLS"); |
| 396 | const char *vs80comntools = getenv("VS80COMNTOOLS"); |
| 397 | const char *vscomntools = NULL; |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 398 | |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 399 | // Try to find the version that we were compiled with |
| 400 | if(false) {} |
| 401 | #if (_MSC_VER >= 1600) // VC100 |
| 402 | else if(vs100comntools) { |
| 403 | vscomntools = vs100comntools; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 404 | } |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 405 | #elif (_MSC_VER == 1500) // VC80 |
| 406 | else if(vs90comntools) { |
| 407 | vscomntools = vs90comntools; |
| 408 | } |
| 409 | #elif (_MSC_VER == 1400) // VC80 |
| 410 | else if(vs80comntools) { |
| 411 | vscomntools = vs80comntools; |
| 412 | } |
| 413 | #endif |
| 414 | // Otherwise find any version we can |
| 415 | else if (vs100comntools) |
| 416 | vscomntools = vs100comntools; |
| 417 | else if (vs90comntools) |
| 418 | vscomntools = vs90comntools; |
| 419 | else if (vs80comntools) |
| 420 | vscomntools = vs80comntools; |
| 421 | |
| 422 | if (vscomntools && *vscomntools) { |
| 423 | char *p = const_cast<char *>(strstr(vscomntools, "\\Common7\\Tools")); |
| 424 | if (p) |
| 425 | *p = '\0'; |
| 426 | path = vscomntools; |
| 427 | return true; |
| 428 | } |
| 429 | return false; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 430 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 431 | |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 432 | // Get Windows SDK installation directory. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 433 | static bool getWindowsSDKDir(std::string &path) { |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 434 | char windowsSDKInstallDir[256]; |
| 435 | // Try the Windows registry. |
| 436 | bool hasSDKDir = getSystemRegistryString( |
| 437 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION", |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 438 | "InstallationFolder", |
| 439 | windowsSDKInstallDir, |
| 440 | sizeof(windowsSDKInstallDir) - 1); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 441 | // If we have both vc80 and vc90, pick version we were compiled with. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 442 | if (hasSDKDir && windowsSDKInstallDir[0]) { |
| 443 | path = windowsSDKInstallDir; |
| 444 | return(true); |
| 445 | } |
| 446 | return(false); |
| 447 | } |
| 448 | |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 449 | void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, |
| 450 | const HeaderSearchOptions &HSOpts) { |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 451 | llvm::Triple::OSType os = triple.getOS(); |
| 452 | |
| 453 | switch (os) { |
Roman Divacky | 6307660 | 2011-03-01 18:08:03 +0000 | [diff] [blame] | 454 | case llvm::Triple::FreeBSD: |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 455 | case llvm::Triple::NetBSD: |
| 456 | break; |
| 457 | default: |
| 458 | // FIXME: temporary hack: hard-coded paths. |
| 459 | AddPath("/usr/local/include", System, true, false, false); |
| 460 | break; |
| 461 | } |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 462 | |
| 463 | // Builtin includes use #include_next directives and should be positioned |
| 464 | // just prior C include dirs. |
| 465 | if (HSOpts.UseBuiltinIncludes) { |
| 466 | // Ignore the sys root, we *always* look for clang headers relative to |
| 467 | // supplied path. |
| 468 | llvm::sys::Path P(HSOpts.ResourceDir); |
| 469 | P.appendComponent("include"); |
| 470 | AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true); |
| 471 | } |
| 472 | |
| 473 | // Add dirs specified via 'configure --with-c-include-dirs'. |
Daniel Dunbar | c706468 | 2009-11-12 07:28:29 +0000 | [diff] [blame] | 474 | llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 475 | if (CIncludeDirs != "") { |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 476 | llvm::SmallVector<llvm::StringRef, 5> dirs; |
| 477 | CIncludeDirs.split(dirs, ":"); |
| 478 | for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin(); |
| 479 | i != dirs.end(); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 480 | ++i) |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 481 | AddPath(*i, System, false, false, false); |
| 482 | return; |
| 483 | } |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 484 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 485 | switch (os) { |
Daniel Dunbar | d11ee7f | 2010-09-09 17:38:18 +0000 | [diff] [blame] | 486 | case llvm::Triple::Win32: { |
| 487 | std::string VSDir; |
| 488 | std::string WindowsSDKDir; |
| 489 | if (getVisualStudioDir(VSDir)) { |
| 490 | AddPath(VSDir + "\\VC\\include", System, false, false, false); |
| 491 | if (getWindowsSDKDir(WindowsSDKDir)) |
| 492 | AddPath(WindowsSDKDir + "\\include", System, false, false, false); |
| 493 | else |
| 494 | AddPath(VSDir + "\\VC\\PlatformSDK\\Include", |
| 495 | System, false, false, false); |
| 496 | } else { |
| 497 | // Default install paths. |
| 498 | AddPath("C:/Program Files/Microsoft Visual Studio 10.0/VC/include", |
| 499 | System, false, false, false); |
| 500 | AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 501 | System, false, false, false); |
| 502 | AddPath( |
John Thompson | 9319f02 | 2009-11-23 17:49:27 +0000 | [diff] [blame] | 503 | "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
Daniel Dunbar | d11ee7f | 2010-09-09 17:38:18 +0000 | [diff] [blame] | 504 | System, false, false, false); |
| 505 | AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include", |
| 506 | System, false, false, false); |
| 507 | AddPath( |
John Thompson | 9319f02 | 2009-11-23 17:49:27 +0000 | [diff] [blame] | 508 | "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include", |
Daniel Dunbar | d11ee7f | 2010-09-09 17:38:18 +0000 | [diff] [blame] | 509 | System, false, false, false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 510 | } |
| 511 | break; |
Daniel Dunbar | d11ee7f | 2010-09-09 17:38:18 +0000 | [diff] [blame] | 512 | } |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 513 | case llvm::Triple::Haiku: |
| 514 | AddPath("/boot/common/include", System, true, false, false); |
| 515 | AddPath("/boot/develop/headers/os", System, true, false, false); |
| 516 | AddPath("/boot/develop/headers/os/app", System, true, false, false); |
| 517 | AddPath("/boot/develop/headers/os/arch", System, true, false, false); |
| 518 | AddPath("/boot/develop/headers/os/device", System, true, false, false); |
| 519 | AddPath("/boot/develop/headers/os/drivers", System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 520 | AddPath("/boot/develop/headers/os/game", System, true, false, false); |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 521 | AddPath("/boot/develop/headers/os/interface", System, true, false, false); |
| 522 | AddPath("/boot/develop/headers/os/kernel", System, true, false, false); |
| 523 | AddPath("/boot/develop/headers/os/locale", System, true, false, false); |
| 524 | AddPath("/boot/develop/headers/os/mail", System, true, false, false); |
| 525 | AddPath("/boot/develop/headers/os/media", System, true, false, false); |
| 526 | AddPath("/boot/develop/headers/os/midi", System, true, false, false); |
| 527 | AddPath("/boot/develop/headers/os/midi2", System, true, false, false); |
| 528 | AddPath("/boot/develop/headers/os/net", System, true, false, false); |
| 529 | AddPath("/boot/develop/headers/os/storage", System, true, false, false); |
| 530 | AddPath("/boot/develop/headers/os/support", System, true, false, false); |
| 531 | AddPath("/boot/develop/headers/os/translation", |
| 532 | System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 533 | AddPath("/boot/develop/headers/os/add-ons/graphics", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 534 | System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 535 | AddPath("/boot/develop/headers/os/add-ons/input_server", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 536 | System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 537 | AddPath("/boot/develop/headers/os/add-ons/screen_saver", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 538 | System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 539 | AddPath("/boot/develop/headers/os/add-ons/tracker", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 540 | System, true, false, false); |
| 541 | AddPath("/boot/develop/headers/os/be_apps/Deskbar", |
| 542 | System, true, false, false); |
| 543 | AddPath("/boot/develop/headers/os/be_apps/NetPositive", |
| 544 | System, true, false, false); |
| 545 | AddPath("/boot/develop/headers/os/be_apps/Tracker", |
| 546 | System, true, false, false); |
| 547 | AddPath("/boot/develop/headers/cpp", System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 548 | AddPath("/boot/develop/headers/cpp/i586-pc-haiku", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 549 | System, true, false, false); |
| 550 | AddPath("/boot/develop/headers/3rdparty", System, true, false, false); |
| 551 | AddPath("/boot/develop/headers/bsd", System, true, false, false); |
| 552 | AddPath("/boot/develop/headers/glibc", System, true, false, false); |
| 553 | AddPath("/boot/develop/headers/posix", System, true, false, false); |
| 554 | AddPath("/boot/develop/headers", System, true, false, false); |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 555 | break; |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 556 | case llvm::Triple::RTEMS: |
| 557 | break; |
NAKAMURA Takumi | 32df002 | 2010-10-11 02:27:37 +0000 | [diff] [blame] | 558 | case llvm::Triple::Cygwin: |
| 559 | AddPath("/usr/include/w32api", System, true, false, false); |
| 560 | break; |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 561 | case llvm::Triple::MinGW32: { |
| 562 | // mingw-w64 crt include paths |
| 563 | llvm::sys::Path P(HSOpts.ResourceDir); |
| 564 | P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include |
| 565 | AddPath(P.str(), System, true, false, false); |
| 566 | P = llvm::sys::Path(HSOpts.ResourceDir); |
| 567 | P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include |
| 568 | AddPath(P.str(), System, true, false, false); |
| 569 | // mingw.org crt include paths |
| 570 | P = llvm::sys::Path(HSOpts.ResourceDir); |
| 571 | P.appendComponent("../../../include"); // <sysroot>/include |
| 572 | AddPath(P.str(), System, true, false, false); |
| 573 | AddPath("/mingw/include", System, true, false, false); |
| 574 | AddPath("c:/mingw/include", System, true, false, false); |
| 575 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 576 | break; |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 577 | |
Eric Christopher | b3169da | 2011-06-03 13:06:30 +0000 | [diff] [blame] | 578 | case llvm::Triple::Linux: |
| 579 | // Generic Debian multiarch support: |
| 580 | if (triple.getArch() == llvm::Triple::x86_64) { |
| 581 | AddPath("/usr/include/x86_64-linux-gnu", System, false, false, false); |
| 582 | AddPath("/usr/include/i686-linux-gnu/64", System, false, false, false); |
| 583 | AddPath("/usr/include/i486-linux-gnu/64", System, false, false, false); |
Eric Christopher | 55ab5b0 | 2011-06-03 13:24:15 +0000 | [diff] [blame] | 584 | } else if (triple.getArch() == llvm::Triple::x86) { |
Eric Christopher | b3169da | 2011-06-03 13:06:30 +0000 | [diff] [blame] | 585 | AddPath("/usr/include/x86_64-linux-gnu/32", System, false, false, false); |
| 586 | AddPath("/usr/include/i686-linux-gnu", System, false, false, false); |
| 587 | AddPath("/usr/include/i486-linux-gnu", System, false, false, false); |
Eric Christopher | 55ab5b0 | 2011-06-03 13:24:15 +0000 | [diff] [blame] | 588 | } else if (triple.getArch() == llvm::Triple::arm) { |
| 589 | AddPath("/usr/include/arm-linux-gnueabi", System, false, false, false); |
Eric Christopher | b3169da | 2011-06-03 13:06:30 +0000 | [diff] [blame] | 590 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 591 | default: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 592 | break; |
| 593 | } |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 594 | |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 595 | if ( os != llvm::Triple::RTEMS ) |
| 596 | AddPath("/usr/include", System, false, false, false); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 599 | void InitHeaderSearch:: |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 600 | AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 601 | llvm::Triple::OSType os = triple.getOS(); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 602 | llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT); |
| 603 | if (CxxIncludeRoot != "") { |
| 604 | llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH); |
| 605 | if (CxxIncludeArch == "") |
| 606 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(), |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 607 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, |
| 608 | triple); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 609 | else |
| 610 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH, |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 611 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, |
| 612 | triple); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 613 | return; |
| 614 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 615 | // FIXME: temporary hack: hard-coded paths. |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 616 | |
| 617 | if (triple.isOSDarwin()) { |
Daniel Dunbar | f2070b3 | 2010-05-28 01:54:31 +0000 | [diff] [blame] | 618 | switch (triple.getArch()) { |
| 619 | default: break; |
| 620 | |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 621 | case llvm::Triple::ppc: |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 622 | case llvm::Triple::ppc64: |
Douglas Gregor | 616d436 | 2010-05-29 01:21:11 +0000 | [diff] [blame] | 623 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 624 | "powerpc-apple-darwin10", "", "ppc64", |
Douglas Gregor | 616d436 | 2010-05-29 01:21:11 +0000 | [diff] [blame] | 625 | triple); |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 626 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 627 | "powerpc-apple-darwin10", "", "ppc64", |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 628 | triple); |
| 629 | break; |
| 630 | |
Daniel Dunbar | f2070b3 | 2010-05-28 01:54:31 +0000 | [diff] [blame] | 631 | case llvm::Triple::x86: |
| 632 | case llvm::Triple::x86_64: |
| 633 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 634 | "i686-apple-darwin10", "", "x86_64", triple); |
| 635 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
| 636 | "i686-apple-darwin8", "", "", triple); |
| 637 | break; |
| 638 | |
| 639 | case llvm::Triple::arm: |
| 640 | case llvm::Triple::thumb: |
| 641 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 642 | "arm-apple-darwin10", "v7", "", triple); |
| 643 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 644 | "arm-apple-darwin10", "v6", "", triple); |
| 645 | break; |
| 646 | } |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 647 | return; |
| 648 | } |
| 649 | |
| 650 | switch (os) { |
| 651 | case llvm::Triple::Cygwin: |
| 652 | // Cygwin-1.7 |
| 653 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4"); |
| 654 | // g++-4 / Cygwin-1.5 |
| 655 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); |
| 656 | // FIXME: Do we support g++-3.4.4? |
| 657 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4"); |
| 658 | break; |
| 659 | case llvm::Triple::MinGW32: |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 660 | // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32) |
| 661 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0"); |
| 662 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1"); |
| 663 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2"); |
| 664 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3"); |
| 665 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0"); |
| 666 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1"); |
Douglas Gregor | f732f2b | 2011-07-05 14:16:05 +0000 | [diff] [blame^] | 667 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2"); |
| 668 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0"); |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 669 | // mingw.org C++ include paths |
| 670 | AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 671 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0"); |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 672 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 673 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 674 | break; |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 675 | case llvm::Triple::DragonFly: |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 676 | AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false); |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 677 | break; |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 678 | case llvm::Triple::Linux: |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 679 | //===------------------------------------------------------------------===// |
| 680 | // Debian based distros. |
| 681 | // Note: these distros symlink /usr/include/c++/X.Y.Z -> X.Y |
| 682 | //===------------------------------------------------------------------===// |
Eric Christopher | b3169da | 2011-06-03 13:06:30 +0000 | [diff] [blame] | 683 | |
| 684 | // Ubuntu 11.11 "Oneiric Ocelot" -- gcc-4.6.0 |
| 685 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6", |
| 686 | "x86_64-linux-gnu", "32", "", triple); |
| 687 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6", |
| 688 | "i686-linux-gnu", "", "64", triple); |
| 689 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6", |
| 690 | "i486-linux-gnu", "", "64", triple); |
| 691 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6", |
| 692 | "arm-linux-gnueabi", "", "", triple); |
| 693 | |
Axel Naumann | 14a0116 | 2011-05-04 09:25:56 +0000 | [diff] [blame] | 694 | // Ubuntu 11.04 "Natty Narwhal" -- gcc-4.5.2 |
| 695 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5", |
| 696 | "x86_64-linux-gnu", "32", "", triple); |
| 697 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5", |
| 698 | "i686-linux-gnu", "", "64", triple); |
| 699 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5", |
| 700 | "i486-linux-gnu", "", "64", triple); |
| 701 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5", |
| 702 | "arm-linux-gnueabi", "", "", triple); |
| 703 | |
Rafael Espindola | c12bbe5 | 2011-02-15 21:44:06 +0000 | [diff] [blame] | 704 | // Ubuntu 10.10 "Maverick Meerkat" -- gcc-4.4.5 |
Rafael Espindola | adafdba | 2011-02-15 21:16:43 +0000 | [diff] [blame] | 705 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
| 706 | "i686-linux-gnu", "", "64", triple); |
| 707 | // The rest of 10.10 is the same as previous versions. |
| 708 | |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 709 | // Ubuntu 10.04 LTS "Lucid Lynx" -- gcc-4.4.3 |
| 710 | // Ubuntu 9.10 "Karmic Koala" -- gcc-4.4.1 |
| 711 | // Debian 6.0 "squeeze" -- gcc-4.4.2 |
| 712 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
| 713 | "x86_64-linux-gnu", "32", "", triple); |
| 714 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
| 715 | "i486-linux-gnu", "", "64", triple); |
Nick Lewycky | db08355 | 2011-02-01 21:32:14 +0000 | [diff] [blame] | 716 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
| 717 | "arm-linux-gnueabi", "", "", triple); |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 718 | // Ubuntu 9.04 "Jaunty Jackalope" -- gcc-4.3.3 |
| 719 | // Ubuntu 8.10 "Intrepid Ibex" -- gcc-4.3.2 |
| 720 | // Debian 5.0 "lenny" -- gcc-4.3.2 |
| 721 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
| 722 | "x86_64-linux-gnu", "32", "", triple); |
| 723 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
| 724 | "i486-linux-gnu", "", "64", triple); |
Rafael Espindola | e7d6c2c | 2010-06-04 14:28:10 +0000 | [diff] [blame] | 725 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
| 726 | "arm-linux-gnueabi", "", "", triple); |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 727 | // Ubuntu 8.04.4 LTS "Hardy Heron" -- gcc-4.2.4 |
| 728 | // Ubuntu 8.04.[0-3] LTS "Hardy Heron" -- gcc-4.2.3 |
| 729 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", |
| 730 | "x86_64-linux-gnu", "32", "", triple); |
| 731 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", |
| 732 | "i486-linux-gnu", "", "64", triple); |
| 733 | // Ubuntu 7.10 "Gutsy Gibbon" -- gcc-4.1.3 |
| 734 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1", |
| 735 | "x86_64-linux-gnu", "32", "", triple); |
| 736 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1", |
| 737 | "i486-linux-gnu", "", "64", triple); |
| 738 | |
| 739 | //===------------------------------------------------------------------===// |
| 740 | // Redhat based distros. |
| 741 | //===------------------------------------------------------------------===// |
Eric Christopher | 8f1cc07 | 2011-04-06 18:22:53 +0000 | [diff] [blame] | 742 | // Fedora 15 |
| 743 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0", |
| 744 | "x86_64-redhat-linux", "32", "", triple); |
| 745 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0", |
| 746 | "i686-redhat-linux", "", "", triple); |
Rafael Espindola | 6638b3a | 2010-11-02 18:39:34 +0000 | [diff] [blame] | 747 | // Fedora 14 |
| 748 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1", |
| 749 | "x86_64-redhat-linux", "32", "", triple); |
| 750 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1", |
| 751 | "i686-redhat-linux", "", "", triple); |
NAKAMURA Takumi | c370398 | 2011-06-16 12:43:57 +0000 | [diff] [blame] | 752 | // RHEL5(gcc44) |
| 753 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4", |
| 754 | "x86_64-redhat-linux6E", "32", "", triple); |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 755 | // Fedora 13 |
Chris Lattner | 4336e19 | 2010-05-29 01:01:38 +0000 | [diff] [blame] | 756 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4", |
| 757 | "x86_64-redhat-linux", "32", "", triple); |
| 758 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4", |
| 759 | "i686-redhat-linux","", "", triple); |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 760 | // Fedora 12 |
| 761 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
| 762 | "x86_64-redhat-linux", "32", "", triple); |
| 763 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
| 764 | "i686-redhat-linux","", "", triple); |
| 765 | // Fedora 12 (pre-FEB-2010) |
| 766 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", |
| 767 | "x86_64-redhat-linux", "32", "", triple); |
| 768 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", |
| 769 | "i686-redhat-linux","", "", triple); |
| 770 | // Fedora 11 |
| 771 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
| 772 | "x86_64-redhat-linux", "32", "", triple); |
| 773 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
| 774 | "i586-redhat-linux","", "", triple); |
| 775 | // Fedora 10 |
| 776 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
| 777 | "x86_64-redhat-linux", "32", "", triple); |
| 778 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
| 779 | "i386-redhat-linux","", "", triple); |
| 780 | // Fedora 9 |
| 781 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", |
| 782 | "x86_64-redhat-linux", "32", "", triple); |
| 783 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", |
| 784 | "i386-redhat-linux", "", "", triple); |
| 785 | // Fedora 8 |
| 786 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", |
| 787 | "x86_64-redhat-linux", "", "", triple); |
| 788 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", |
| 789 | "i386-redhat-linux", "", "", triple); |
Eric Christopher | 199e09a | 2011-05-17 23:06:53 +0000 | [diff] [blame] | 790 | |
| 791 | // RHEL 5 |
| 792 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.1", |
| 793 | "x86_64-redhat-linux", "32", "", triple); |
| 794 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.1", |
| 795 | "i386-redhat-linux", "", "", triple); |
| 796 | |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 797 | |
| 798 | //===------------------------------------------------------------------===// |
| 799 | |
Benjamin Kramer | 0db3d72 | 2010-01-25 12:20:15 +0000 | [diff] [blame] | 800 | // Exherbo (2010-01-25) |
| 801 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
Torok Edwin | fc4b899 | 2009-12-18 17:29:14 +0000 | [diff] [blame] | 802 | "x86_64-pc-linux-gnu", "32", "", triple); |
Benjamin Kramer | 0db3d72 | 2010-01-25 12:20:15 +0000 | [diff] [blame] | 803 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
Torok Edwin | fc4b899 | 2009-12-18 17:29:14 +0000 | [diff] [blame] | 804 | "i686-pc-linux-gnu", "", "", triple); |
Chris Lattner | ea00f84 | 2010-04-23 15:55:20 +0000 | [diff] [blame] | 805 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 806 | // openSUSE 11.1 32 bit |
| 807 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 808 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 809 | // openSUSE 11.1 64 bit |
| 810 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 811 | "x86_64-suse-linux", "32", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 812 | // openSUSE 11.2 |
| 813 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 814 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 815 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 816 | "x86_64-suse-linux", "", "", triple); |
Rafael Espindola | 9d2c060 | 2010-11-25 18:51:59 +0000 | [diff] [blame] | 817 | |
| 818 | // openSUSE 11.4 |
| 819 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5", |
| 820 | "i586-suse-linux", "", "", triple); |
| 821 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5", |
| 822 | "x86_64-suse-linux", "", "", triple); |
| 823 | |
David Chisnall | 2eb3cce | 2011-05-19 12:04:49 +0000 | [diff] [blame] | 824 | // openSUSE 12.1 |
| 825 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6", |
| 826 | "i586-suse-linux", "", "", triple); |
| 827 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6", |
| 828 | "x86_64-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 829 | // Arch Linux 2008-06-24 |
| 830 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 831 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 832 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 833 | "x86_64-unknown-linux-gnu", "", "", triple); |
Nico Weber | 014f972 | 2011-04-25 20:59:30 +0000 | [diff] [blame] | 834 | |
| 835 | // Arch Linux gcc 4.6 |
Chandler Carruth | 37187cc | 2011-07-02 00:51:03 +0000 | [diff] [blame] | 836 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.1", |
| 837 | "i686-pc-linux-gnu", "", "", triple); |
| 838 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.1", |
| 839 | "x86_64-unknown-linux-gnu", "", "", triple); |
Nico Weber | 014f972 | 2011-04-25 20:59:30 +0000 | [diff] [blame] | 840 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0", |
| 841 | "i686-pc-linux-gnu", "", "", triple); |
| 842 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0", |
| 843 | "x86_64-unknown-linux-gnu", "", "", triple); |
| 844 | |
Douglas Gregor | 5370383 | 2011-03-14 15:33:44 +0000 | [diff] [blame] | 845 | // Gentoo x86 gcc 4.5.2 |
| 846 | AddGnuCPlusPlusIncludePaths( |
| 847 | "/usr/lib/gcc/i686-pc-linux-gnu/4.5.2/include/g++-v4", |
| 848 | "i686-pc-linux-gnu", "", "", triple); |
| 849 | // Gentoo x86 gcc 4.4.5 |
| 850 | AddGnuCPlusPlusIncludePaths( |
| 851 | "/usr/lib/gcc/i686-pc-linux-gnu/4.4.5/include/g++-v4", |
| 852 | "i686-pc-linux-gnu", "", "", triple); |
| 853 | // Gentoo x86 gcc 4.4.4 |
| 854 | AddGnuCPlusPlusIncludePaths( |
| 855 | "/usr/lib/gcc/i686-pc-linux-gnu/4.4.4/include/g++-v4", |
| 856 | "i686-pc-linux-gnu", "", "", triple); |
| 857 | // Gentoo x86 2010.0 stable |
Nuno Lopes | 0d155a5 | 2010-09-11 17:51:45 +0000 | [diff] [blame] | 858 | AddGnuCPlusPlusIncludePaths( |
| 859 | "/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/g++-v4", |
| 860 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 861 | // Gentoo x86 2009.1 stable |
| 862 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 863 | "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 864 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 865 | // Gentoo x86 2009.0 stable |
| 866 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 867 | "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 868 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 869 | // Gentoo x86 2008.0 stable |
| 870 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 871 | "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 872 | "i686-pc-linux-gnu", "", "", triple); |
Douglas Gregor | 5370383 | 2011-03-14 15:33:44 +0000 | [diff] [blame] | 873 | // Gentoo x86 llvm-gcc trunk |
| 874 | AddGnuCPlusPlusIncludePaths( |
| 875 | "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1", |
| 876 | "i686-pc-linux-gnu", "", "", triple); |
Nick Lewycky | 6693534 | 2010-07-24 21:33:13 +0000 | [diff] [blame] | 877 | |
Douglas Gregor | 5370383 | 2011-03-14 15:33:44 +0000 | [diff] [blame] | 878 | // Gentoo amd64 gcc 4.5.2 |
| 879 | AddGnuCPlusPlusIncludePaths( |
| 880 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4", |
| 881 | "x86_64-pc-linux-gnu", "32", "", triple); |
Chandler Carruth | fbfdb20 | 2010-11-28 07:20:14 +0000 | [diff] [blame] | 882 | // Gentoo amd64 gcc 4.4.5 |
| 883 | AddGnuCPlusPlusIncludePaths( |
| 884 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include/g++-v4", |
| 885 | "x86_64-pc-linux-gnu", "32", "", triple); |
Nico Weber | 8ad8a1c | 2010-11-16 12:42:55 +0000 | [diff] [blame] | 886 | // Gentoo amd64 gcc 4.4.4 |
| 887 | AddGnuCPlusPlusIncludePaths( |
| 888 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4", |
| 889 | "x86_64-pc-linux-gnu", "32", "", triple); |
Chandler Carruth | fbfdb20 | 2010-11-28 07:20:14 +0000 | [diff] [blame] | 890 | // Gentoo amd64 gcc 4.4.3 |
| 891 | AddGnuCPlusPlusIncludePaths( |
| 892 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4", |
| 893 | "x86_64-pc-linux-gnu", "32", "", triple); |
| 894 | // Gentoo amd64 gcc 4.3.2 |
| 895 | AddGnuCPlusPlusIncludePaths( |
| 896 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4", |
| 897 | "x86_64-pc-linux-gnu", "", "", triple); |
| 898 | // Gentoo amd64 stable |
| 899 | AddGnuCPlusPlusIncludePaths( |
| 900 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", |
Douglas Gregor | 5370383 | 2011-03-14 15:33:44 +0000 | [diff] [blame] | 901 | "x86_64-pc-linux-gnu", "", "", triple); |
Nico Weber | 8ad8a1c | 2010-11-16 12:42:55 +0000 | [diff] [blame] | 902 | |
Nick Lewycky | 6693534 | 2010-07-24 21:33:13 +0000 | [diff] [blame] | 903 | // Gentoo amd64 llvm-gcc trunk |
| 904 | AddGnuCPlusPlusIncludePaths( |
| 905 | "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1", |
| 906 | "x86_64-pc-linux-gnu", "", "", triple); |
Chandler Carruth | fbfdb20 | 2010-11-28 07:20:14 +0000 | [diff] [blame] | 907 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 908 | break; |
| 909 | case llvm::Triple::FreeBSD: |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 910 | // FreeBSD 8.0 |
| 911 | // FreeBSD 7.3 |
Nuno Lopes | afe859a | 2010-01-17 00:00:11 +0000 | [diff] [blame] | 912 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 913 | break; |
Anton Korobeynikov | ab07941 | 2010-08-31 22:39:50 +0000 | [diff] [blame] | 914 | case llvm::Triple::NetBSD: |
| 915 | AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple); |
| 916 | break; |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 917 | case llvm::Triple::OpenBSD: { |
| 918 | std::string t = triple.getTriple(); |
| 919 | if (t.substr(0, 6) == "x86_64") |
| 920 | t.replace(0, 6, "amd64"); |
| 921 | AddGnuCPlusPlusIncludePaths("/usr/include/g++", |
| 922 | t, "", "", triple); |
| 923 | break; |
| 924 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 925 | case llvm::Triple::Minix: |
| 926 | AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3", |
| 927 | "", "", "", triple); |
| 928 | break; |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 929 | case llvm::Triple::Solaris: |
| 930 | // Solaris - Fall though.. |
| 931 | case llvm::Triple::AuroraUX: |
| 932 | // AuroraUX |
| 933 | AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 934 | "i386-pc-solaris2.11", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 935 | break; |
| 936 | default: |
| 937 | break; |
| 938 | } |
| 939 | } |
| 940 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 941 | void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 942 | const llvm::Triple &triple, |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 943 | const HeaderSearchOptions &HSOpts) { |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 944 | if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes) { |
| 945 | if (HSOpts.UseLibcxx) |
| 946 | AddPath("/usr/include/c++/v1", CXXSystem, true, false, false); |
| 947 | else |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 948 | AddDefaultCPlusPlusIncludePaths(triple, HSOpts); |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 949 | } |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 950 | |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 951 | AddDefaultCIncludePaths(triple, HSOpts); |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 952 | |
| 953 | // Add the default framework include paths on Darwin. |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 954 | if (triple.isOSDarwin()) { |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 955 | AddPath("/System/Library/Frameworks", System, true, false, true); |
| 956 | AddPath("/Library/Frameworks", System, true, false, true); |
| 957 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 960 | /// RemoveDuplicates - If there are duplicate directory entries in the specified |
| 961 | /// search list, remove the later (dead) ones. |
| 962 | static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 963 | unsigned First, bool Verbose) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 964 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; |
| 965 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; |
| 966 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 967 | for (unsigned i = First; i != SearchList.size(); ++i) { |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 968 | unsigned DirToRemove = i; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 970 | const DirectoryLookup &CurEntry = SearchList[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 972 | if (CurEntry.isNormalDir()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 973 | // If this isn't the first time we've seen this dir, remove it. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 974 | if (SeenDirs.insert(CurEntry.getDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 975 | continue; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 976 | } else if (CurEntry.isFramework()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 977 | // If this isn't the first time we've seen this framework dir, remove it. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 978 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 979 | continue; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 980 | } else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 981 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 982 | // If this isn't the first time we've seen this headermap, remove it. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 983 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 984 | continue; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 985 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 987 | // If we have a normal #include dir/framework/headermap that is shadowed |
| 988 | // later in the chain by a system include location, we actually want to |
| 989 | // ignore the user's request and drop the user dir... keeping the system |
| 990 | // dir. This is weird, but required to emulate GCC's search path correctly. |
| 991 | // |
| 992 | // Since dupes of system dirs are rare, just rescan to find the original |
| 993 | // that we're nuking instead of using a DenseMap. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 994 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 995 | // Find the dir that this is the same of. |
| 996 | unsigned FirstDir; |
| 997 | for (FirstDir = 0; ; ++FirstDir) { |
| 998 | assert(FirstDir != i && "Didn't find dupe?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 999 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 1000 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; |
| 1001 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 1002 | // If these are different lookup types, then they can't be the dupe. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 1003 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 1004 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1005 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 1006 | bool isSame; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 1007 | if (CurEntry.isNormalDir()) |
| 1008 | isSame = SearchEntry.getDir() == CurEntry.getDir(); |
| 1009 | else if (CurEntry.isFramework()) |
| 1010 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 1011 | else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 1012 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 1013 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 1014 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 1016 | if (isSame) |
| 1017 | break; |
| 1018 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1019 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 1020 | // If the first dir in the search path is a non-system dir, zap it |
| 1021 | // instead of the system one. |
| 1022 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) |
| 1023 | DirToRemove = FirstDir; |
| 1024 | } |
| 1025 | |
| 1026 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 1027 | llvm::errs() << "ignoring duplicate directory \"" |
| 1028 | << CurEntry.getName() << "\"\n"; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 1029 | if (DirToRemove != i) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 1030 | llvm::errs() << " as it is a non-system directory that duplicates " |
| 1031 | << "a system directory\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1032 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1033 | |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 1034 | // This is reached if the current entry is a duplicate. Remove the |
| 1035 | // DirToRemove (usually the current dir). |
| 1036 | SearchList.erase(SearchList.begin()+DirToRemove); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1037 | --i; |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1042 | void InitHeaderSearch::Realize(const LangOptions &Lang) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1043 | // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. |
| 1044 | std::vector<DirectoryLookup> SearchList; |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1045 | SearchList.reserve(IncludePath.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 1047 | // Quoted arguments go first. |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1048 | for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); |
| 1049 | it != ie; ++it) { |
| 1050 | if (it->first == Quoted) |
| 1051 | SearchList.push_back(it->second); |
| 1052 | } |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 1053 | // Deduplicate and remember index. |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1054 | RemoveDuplicates(SearchList, 0, Verbose); |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 1055 | unsigned NumQuoted = SearchList.size(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1056 | |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1057 | for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); |
| 1058 | it != ie; ++it) { |
| 1059 | if (it->first == Angled) |
| 1060 | SearchList.push_back(it->second); |
| 1061 | } |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 1062 | |
| 1063 | RemoveDuplicates(SearchList, NumQuoted, Verbose); |
| 1064 | unsigned NumAngled = SearchList.size(); |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1065 | |
| 1066 | for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); |
| 1067 | it != ie; ++it) { |
| 1068 | if (it->first == System || (Lang.CPlusPlus && it->first == CXXSystem)) |
| 1069 | SearchList.push_back(it->second); |
| 1070 | } |
| 1071 | |
| 1072 | for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); |
| 1073 | it != ie; ++it) { |
| 1074 | if (it->first == After) |
| 1075 | SearchList.push_back(it->second); |
| 1076 | } |
| 1077 | |
Chris Lattner | 1d7f12b | 2011-06-16 22:58:10 +0000 | [diff] [blame] | 1078 | // Remove duplicates across both the Angled and System directories. GCC does |
| 1079 | // this and failing to remove duplicates across these two groups breaks |
| 1080 | // #include_next. |
| 1081 | RemoveDuplicates(SearchList, NumQuoted, Verbose); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1082 | |
| 1083 | bool DontSearchCurDir = false; // TODO: set to true if -I- is set? |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 1084 | Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1085 | |
| 1086 | // If verbose, print the list of directories that will be searched. |
| 1087 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 1088 | llvm::errs() << "#include \"...\" search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1089 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 1090 | if (i == NumQuoted) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 1091 | llvm::errs() << "#include <...> search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1092 | const char *Name = SearchList[i].getName(); |
| 1093 | const char *Suffix; |
| 1094 | if (SearchList[i].isNormalDir()) |
| 1095 | Suffix = ""; |
| 1096 | else if (SearchList[i].isFramework()) |
| 1097 | Suffix = " (framework directory)"; |
| 1098 | else { |
| 1099 | assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); |
| 1100 | Suffix = " (headermap)"; |
| 1101 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 1102 | llvm::errs() << " " << Name << Suffix << "\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1103 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 1104 | llvm::errs() << "End of search list.\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1105 | } |
| 1106 | } |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 1107 | |
Daniel Dunbar | 5814e65 | 2009-11-11 21:44:21 +0000 | [diff] [blame] | 1108 | void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, |
| 1109 | const HeaderSearchOptions &HSOpts, |
| 1110 | const LangOptions &Lang, |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 1111 | const llvm::Triple &Triple) { |
| 1112 | InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); |
| 1113 | |
| 1114 | // Add the user defined entries. |
| 1115 | for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { |
| 1116 | const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 1117 | Init.AddPath(E.Path, E.Group, false, E.IsUserSupplied, E.IsFramework, |
Bob Wilson | 5dd45f1 | 2011-06-21 21:53:08 +0000 | [diff] [blame] | 1118 | E.IgnoreSysRoot); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | // Add entries from CPATH and friends. |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 1122 | Init.AddDelimitedPaths(HSOpts.EnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 1123 | if (Lang.CPlusPlus && Lang.ObjC1) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 1124 | Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 1125 | else if (Lang.CPlusPlus) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 1126 | Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 1127 | else if (Lang.ObjC1) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 1128 | Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 1129 | else |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 1130 | Init.AddDelimitedPaths(HSOpts.CEnvIncPath); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 1131 | |
Daniel Dunbar | dd35ce9 | 2009-11-07 04:58:12 +0000 | [diff] [blame] | 1132 | if (HSOpts.UseStandardIncludes) |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 1133 | Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 1134 | |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 1135 | Init.Realize(Lang); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 1136 | } |