Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1 | //===--- InitHeaderSearch.cpp - Initialize header search paths ----------*-===// |
| 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 | |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/Utils.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 15 | #include "clang/Basic/FileManager.h" |
| 16 | #include "clang/Basic/LangOptions.h" |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/HeaderSearchOptions.h" |
| 18 | #include "clang/Lex/HeaderSearch.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallString.h" |
| 20 | #include "llvm/ADT/SmallPtrSet.h" |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/Triple.h" |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Twine.h" |
Chris Lattner | d57a7ef | 2009-08-23 22:45:33 +0000 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 26 | #include "llvm/System/Path.h" |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 27 | #include "llvm/Config/config.h" |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 28 | #ifdef _MSC_VER |
| 29 | #define WIN32_LEAN_AND_MEAN 1 |
| 30 | #include <windows.h> |
| 31 | #endif |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 32 | using namespace clang; |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 33 | using namespace clang::frontend; |
| 34 | |
| 35 | namespace { |
| 36 | |
| 37 | /// InitHeaderSearch - This class makes it easier to set the search paths of |
| 38 | /// a HeaderSearch object. InitHeaderSearch stores several search path lists |
| 39 | /// internally, which can be sent to a HeaderSearch object in one swoop. |
| 40 | class InitHeaderSearch { |
| 41 | std::vector<DirectoryLookup> IncludeGroup[4]; |
| 42 | HeaderSearch& Headers; |
| 43 | bool Verbose; |
| 44 | std::string isysroot; |
| 45 | |
| 46 | public: |
| 47 | |
| 48 | InitHeaderSearch(HeaderSearch &HS, |
| 49 | bool verbose = false, const std::string &iSysroot = "") |
| 50 | : Headers(HS), Verbose(verbose), isysroot(iSysroot) {} |
| 51 | |
| 52 | /// AddPath - Add the specified path to the specified group list. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 53 | void AddPath(const llvm::Twine &Path, IncludeDirGroup Group, |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 54 | bool isCXXAware, bool isUserSupplied, |
| 55 | bool isFramework, bool IgnoreSysRoot = false); |
| 56 | |
mike-m | a608737 | 2010-05-05 17:00:31 +0000 | [diff] [blame] | 57 | /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 58 | /// libstdc++. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 59 | void AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, |
| 60 | llvm::StringRef ArchDir, |
| 61 | llvm::StringRef Dir32, |
| 62 | llvm::StringRef Dir64, |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 63 | const llvm::Triple &triple); |
| 64 | |
| 65 | /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to suport a MinGW |
| 66 | /// libstdc++. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 67 | void AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, |
| 68 | llvm::StringRef Arch, |
| 69 | llvm::StringRef Version); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 70 | |
| 71 | /// AddDelimitedPaths - Add a list of paths delimited by the system PATH |
| 72 | /// separator. The processing follows that of the CPATH variable for gcc. |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 73 | void AddDelimitedPaths(llvm::StringRef String); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 74 | |
| 75 | // AddDefaultCIncludePaths - Add paths that should always be searched. |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 76 | void AddDefaultCIncludePaths(const llvm::Triple &triple, |
| 77 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 78 | |
| 79 | // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when |
| 80 | // compiling c++. |
| 81 | void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple); |
| 82 | |
| 83 | /// AddDefaultSystemIncludePaths - Adds the default system include paths so |
| 84 | /// that e.g. stdio.h is found. |
| 85 | void AddDefaultSystemIncludePaths(const LangOptions &Lang, |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 86 | const llvm::Triple &triple, |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 87 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 88 | |
| 89 | /// Realize - Merges all search path lists into one list and send it to |
| 90 | /// HeaderSearch. |
| 91 | void Realize(); |
| 92 | }; |
| 93 | |
| 94 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 95 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 96 | void InitHeaderSearch::AddPath(const llvm::Twine &Path, |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 97 | IncludeDirGroup Group, bool isCXXAware, |
| 98 | bool isUserSupplied, bool isFramework, |
| 99 | bool IgnoreSysRoot) { |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 100 | assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 101 | FileManager &FM = Headers.getFileMgr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 103 | // Compute the actual path, taking into consideration -isysroot. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 104 | llvm::SmallString<256> MappedPathStr; |
| 105 | llvm::raw_svector_ostream MappedPath(MappedPathStr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 107 | // Handle isysroot. |
Chris Lattner | 6858dd3 | 2009-02-19 06:48:28 +0000 | [diff] [blame] | 108 | if (Group == System && !IgnoreSysRoot) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 109 | // FIXME: Portability. This should be a sys::Path interface, this doesn't |
| 110 | // handle things like C:\ right, nor win32 \\network\device\blah. |
| 111 | if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 112 | MappedPath << isysroot; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 113 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 115 | Path.print(MappedPath); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 116 | |
| 117 | // Compute the DirectoryLookup type. |
Chris Lattner | 9d72851 | 2008-10-27 01:19:25 +0000 | [diff] [blame] | 118 | SrcMgr::CharacteristicKind Type; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 119 | if (Group == Quoted || Group == Angled) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 120 | Type = SrcMgr::C_User; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 121 | else if (isCXXAware) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 122 | Type = SrcMgr::C_System; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 123 | else |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 124 | Type = SrcMgr::C_ExternCSystem; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | |
| 126 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 127 | // If the directory exists, add it. |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 128 | if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 129 | IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied, |
| 130 | isFramework)); |
| 131 | return; |
| 132 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 133 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 134 | // Check to see if this is an apple-style headermap (which are not allowed to |
| 135 | // be frameworks). |
| 136 | if (!isFramework) { |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 137 | if (const FileEntry *FE = FM.getFile(MappedPath.str())) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 138 | if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { |
| 139 | // It is a headermap, add it to the search path. |
| 140 | IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied)); |
| 141 | return; |
| 142 | } |
| 143 | } |
| 144 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 146 | if (Verbose) |
Daniel Dunbar | 7765934 | 2009-08-19 20:04:03 +0000 | [diff] [blame] | 147 | llvm::errs() << "ignoring nonexistent directory \"" |
| 148 | << MappedPath.str() << "\"\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 152 | void InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) { |
| 153 | if (at.empty()) // Empty string should not add '.' path. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 154 | return; |
| 155 | |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 156 | llvm::StringRef::size_type delim; |
| 157 | while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) { |
| 158 | if (delim == 0) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 159 | AddPath(".", Angled, false, true, false); |
| 160 | else |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 161 | AddPath(at.substr(0, delim), Angled, false, true, false); |
| 162 | at = at.substr(delim + 1); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 163 | } |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 164 | |
| 165 | if (at.empty()) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 166 | AddPath(".", Angled, false, true, false); |
| 167 | else |
| 168 | AddPath(at, Angled, false, true, false); |
| 169 | } |
| 170 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 171 | void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, |
| 172 | llvm::StringRef ArchDir, |
| 173 | llvm::StringRef Dir32, |
| 174 | llvm::StringRef Dir64, |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 175 | const llvm::Triple &triple) { |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 176 | // Add the base dir |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 177 | AddPath(Base, System, true, false, false); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 178 | |
| 179 | // Add the multilib dirs |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 180 | llvm::Triple::ArchType arch = triple.getArch(); |
| 181 | bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 182 | if (is64bit) |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 183 | AddPath(Base + "/" + ArchDir + "/" + Dir64, System, true, false, false); |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 184 | else |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 185 | AddPath(Base + "/" + ArchDir + "/" + Dir32, System, true, false, false); |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 186 | |
| 187 | // Add the backward dir |
| 188 | AddPath(Base + "/backward", System, true, false, false); |
Rafael Espindola | 2e9f652 | 2009-10-06 01:33:02 +0000 | [diff] [blame] | 189 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 190 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 191 | void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, |
| 192 | llvm::StringRef Arch, |
| 193 | llvm::StringRef Version) { |
Benjamin Kramer | ab8ae19 | 2010-01-20 16:18:11 +0000 | [diff] [blame] | 194 | AddPath(Base + "/" + Arch + "/" + Version + "/include", |
| 195 | System, true, false, false); |
| 196 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", |
| 197 | System, true, false, false); |
| 198 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", |
| 199 | System, true, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 200 | } |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 201 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 202 | // FIXME: This probably should goto to some platform utils place. |
| 203 | #ifdef _MSC_VER |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 204 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 205 | // Read registry string. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 206 | // This also supports a means to look for high-versioned keys by use |
| 207 | // of a $VERSION placeholder in the key path. |
| 208 | // $VERSION in the key path is a placeholder for the version number, |
| 209 | // causing the highest value path to be searched for and used. |
| 210 | // I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION". |
| 211 | // There can be additional characters in the component. Only the numberic |
| 212 | // characters are compared. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 213 | static bool getSystemRegistryString(const char *keyPath, const char *valueName, |
| 214 | char *value, size_t maxLength) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 215 | HKEY hRootKey = NULL; |
| 216 | HKEY hKey = NULL; |
| 217 | const char* subKey = NULL; |
| 218 | DWORD valueType; |
| 219 | DWORD valueSize = maxLength - 1; |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 220 | long lResult; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 221 | bool returnValue = false; |
| 222 | if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { |
| 223 | hRootKey = HKEY_CLASSES_ROOT; |
| 224 | subKey = keyPath + 18; |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 225 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 226 | else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { |
| 227 | hRootKey = HKEY_USERS; |
| 228 | subKey = keyPath + 11; |
| 229 | } |
| 230 | else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { |
| 231 | hRootKey = HKEY_LOCAL_MACHINE; |
| 232 | subKey = keyPath + 19; |
| 233 | } |
| 234 | else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { |
| 235 | hRootKey = HKEY_CURRENT_USER; |
| 236 | subKey = keyPath + 18; |
| 237 | } |
| 238 | else |
| 239 | return(false); |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 240 | const char *placeHolder = strstr(subKey, "$VERSION"); |
| 241 | char bestName[256]; |
| 242 | bestName[0] = '\0'; |
| 243 | // If we have a $VERSION placeholder, do the highest-version search. |
| 244 | if (placeHolder) { |
| 245 | const char *keyEnd = placeHolder - 1; |
| 246 | const char *nextKey = placeHolder; |
| 247 | // Find end of previous key. |
| 248 | while ((keyEnd > subKey) && (*keyEnd != '\\')) |
| 249 | keyEnd--; |
| 250 | // Find end of key containing $VERSION. |
| 251 | while (*nextKey && (*nextKey != '\\')) |
| 252 | nextKey++; |
| 253 | size_t partialKeyLength = keyEnd - subKey; |
| 254 | char partialKey[256]; |
| 255 | if (partialKeyLength > sizeof(partialKey)) |
| 256 | partialKeyLength = sizeof(partialKey); |
| 257 | strncpy(partialKey, subKey, partialKeyLength); |
| 258 | partialKey[partialKeyLength] = '\0'; |
| 259 | HKEY hTopKey = NULL; |
| 260 | lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey); |
| 261 | if (lResult == ERROR_SUCCESS) { |
| 262 | char keyName[256]; |
| 263 | int bestIndex = -1; |
| 264 | double bestValue = 0.0; |
| 265 | DWORD index, size = sizeof(keyName) - 1; |
Nuno Lopes | 33cc243 | 2009-12-07 17:18:48 +0000 | [diff] [blame] | 266 | for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL, |
| 267 | NULL, NULL, NULL) == ERROR_SUCCESS; index++) { |
| 268 | const char *sp = keyName; |
| 269 | while (*sp && !isdigit(*sp)) |
| 270 | sp++; |
| 271 | if (!*sp) |
| 272 | continue; |
| 273 | const char *ep = sp + 1; |
| 274 | while (*ep && (isdigit(*ep) || (*ep == '.'))) |
| 275 | ep++; |
| 276 | char numBuf[32]; |
| 277 | strncpy(numBuf, sp, sizeof(numBuf) - 1); |
| 278 | numBuf[sizeof(numBuf) - 1] = '\0'; |
| 279 | double value = strtod(numBuf, NULL); |
| 280 | if (value > bestValue) { |
| 281 | bestIndex = (int)index; |
| 282 | bestValue = value; |
| 283 | strcpy(bestName, keyName); |
| 284 | } |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 285 | size = sizeof(keyName) - 1; |
| 286 | } |
| 287 | // If we found the highest versioned key, open the key and get the value. |
| 288 | if (bestIndex != -1) { |
| 289 | // Append rest of key. |
| 290 | strncat(bestName, nextKey, sizeof(bestName) - 1); |
| 291 | bestName[sizeof(bestName) - 1] = '\0'; |
| 292 | // Open the chosen key path remainder. |
| 293 | lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey); |
| 294 | if (lResult == ERROR_SUCCESS) { |
| 295 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 296 | (LPBYTE)value, &valueSize); |
| 297 | if (lResult == ERROR_SUCCESS) |
| 298 | returnValue = true; |
| 299 | RegCloseKey(hKey); |
| 300 | } |
| 301 | } |
| 302 | RegCloseKey(hTopKey); |
| 303 | } |
| 304 | } |
| 305 | else { |
| 306 | lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); |
| 307 | if (lResult == ERROR_SUCCESS) { |
| 308 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 309 | (LPBYTE)value, &valueSize); |
| 310 | if (lResult == ERROR_SUCCESS) |
| 311 | returnValue = true; |
| 312 | RegCloseKey(hKey); |
| 313 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 314 | } |
| 315 | return(returnValue); |
| 316 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 317 | #else // _MSC_VER |
| 318 | // Read registry string. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 319 | static bool getSystemRegistryString(const char*, const char*, char*, size_t) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 320 | return(false); |
| 321 | } |
| 322 | #endif // _MSC_VER |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 323 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 324 | // Get Visual Studio installation directory. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 325 | static bool getVisualStudioDir(std::string &path) { |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 326 | char vsIDEInstallDir[256]; |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 327 | char vsExpressIDEInstallDir[256]; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 328 | // Try the Windows registry first. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 329 | bool hasVCDir = getSystemRegistryString( |
| 330 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION", |
| 331 | "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1); |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 332 | bool hasVCExpressDir = getSystemRegistryString( |
| 333 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\$VERSION", |
| 334 | "InstallDir", vsExpressIDEInstallDir, sizeof(vsExpressIDEInstallDir) - 1); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 335 | // 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] | 336 | if (hasVCDir && vsIDEInstallDir[0]) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 337 | char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); |
| 338 | if (p) |
| 339 | *p = '\0'; |
| 340 | path = vsIDEInstallDir; |
| 341 | return(true); |
| 342 | } |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 343 | else if (hasVCExpressDir && vsExpressIDEInstallDir[0]) { |
| 344 | char *p = (char*)strstr(vsExpressIDEInstallDir, "\\Common7\\IDE"); |
| 345 | if (p) |
| 346 | *p = '\0'; |
| 347 | path = vsExpressIDEInstallDir; |
| 348 | return(true); |
| 349 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 350 | else { |
| 351 | // Try the environment. |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 352 | const char* vs100comntools = getenv("VS100COMNTOOLS"); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 353 | const char* vs90comntools = getenv("VS90COMNTOOLS"); |
| 354 | const char* vs80comntools = getenv("VS80COMNTOOLS"); |
| 355 | const char* vscomntools = NULL; |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 356 | |
| 357 | // Try to find the version that we were compiled with |
| 358 | if(false) {} |
| 359 | #if (_MSC_VER >= 1600) // VC100 |
| 360 | else if(vs100comntools) { |
| 361 | vscomntools = vs100comntools; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 362 | } |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 363 | #elif (_MSC_VER == 1500) // VC80 |
| 364 | else if(vs90comntools) { |
| 365 | vscomntools = vs90comntools; |
| 366 | } |
| 367 | #elif (_MSC_VER == 1400) // VC80 |
| 368 | else if(vs80comntools) { |
| 369 | vscomntools = vs80comntools; |
| 370 | } |
| 371 | #endif |
| 372 | // Otherwise find any version we can |
| 373 | else if (vs100comntools) |
| 374 | vscomntools = vs100comntools; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 375 | else if (vs90comntools) |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 376 | vscomntools = vs90comntools; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 377 | else if (vs80comntools) |
| 378 | vscomntools = vs80comntools; |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 379 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 380 | if (vscomntools && *vscomntools) { |
Dan Gohman | cb421fa | 2010-04-19 16:39:44 +0000 | [diff] [blame] | 381 | char *p = const_cast<char *>(strstr(vscomntools, "\\Common7\\Tools")); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 382 | if (p) |
| 383 | *p = '\0'; |
| 384 | path = vscomntools; |
| 385 | return(true); |
| 386 | } |
| 387 | else |
| 388 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 389 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 390 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 391 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 392 | |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 393 | // Get Windows SDK installation directory. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 394 | static bool getWindowsSDKDir(std::string &path) { |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 395 | char windowsSDKInstallDir[256]; |
| 396 | // Try the Windows registry. |
| 397 | bool hasSDKDir = getSystemRegistryString( |
| 398 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION", |
| 399 | "InstallationFolder", windowsSDKInstallDir, sizeof(windowsSDKInstallDir) - 1); |
| 400 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 401 | if (hasSDKDir && windowsSDKInstallDir[0]) { |
| 402 | path = windowsSDKInstallDir; |
| 403 | return(true); |
| 404 | } |
| 405 | return(false); |
| 406 | } |
| 407 | |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 408 | void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, |
| 409 | const HeaderSearchOptions &HSOpts) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 410 | // FIXME: temporary hack: hard-coded paths. |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 411 | AddPath("/usr/local/include", System, true, false, false); |
| 412 | |
| 413 | // Builtin includes use #include_next directives and should be positioned |
| 414 | // just prior C include dirs. |
| 415 | if (HSOpts.UseBuiltinIncludes) { |
| 416 | // Ignore the sys root, we *always* look for clang headers relative to |
| 417 | // supplied path. |
| 418 | llvm::sys::Path P(HSOpts.ResourceDir); |
| 419 | P.appendComponent("include"); |
| 420 | AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true); |
| 421 | } |
| 422 | |
| 423 | // Add dirs specified via 'configure --with-c-include-dirs'. |
Daniel Dunbar | c706468 | 2009-11-12 07:28:29 +0000 | [diff] [blame] | 424 | llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 425 | if (CIncludeDirs != "") { |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 426 | llvm::SmallVector<llvm::StringRef, 5> dirs; |
| 427 | CIncludeDirs.split(dirs, ":"); |
| 428 | for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin(); |
| 429 | i != dirs.end(); |
| 430 | ++i) |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 431 | AddPath(*i, System, false, false, false); |
| 432 | return; |
| 433 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 434 | llvm::Triple::OSType os = triple.getOS(); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 435 | switch (os) { |
| 436 | case llvm::Triple::Win32: |
| 437 | { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 438 | std::string VSDir; |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 439 | std::string WindowsSDKDir; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 440 | if (getVisualStudioDir(VSDir)) { |
| 441 | AddPath(VSDir + "\\VC\\include", System, false, false, false); |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 442 | if (getWindowsSDKDir(WindowsSDKDir)) |
| 443 | AddPath(WindowsSDKDir, System, false, false, false); |
| 444 | else |
| 445 | AddPath(VSDir + "\\VC\\PlatformSDK\\Include", |
| 446 | System, false, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 447 | } |
John Thompson | 9319f02 | 2009-11-23 17:49:27 +0000 | [diff] [blame] | 448 | else { |
| 449 | // Default install paths. |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 450 | AddPath("C:/Program Files/Microsoft Visual Studio 10.0/VC/include", |
| 451 | System, false, false, false); |
John Thompson | 9319f02 | 2009-11-23 17:49:27 +0000 | [diff] [blame] | 452 | AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 453 | System, false, false, false); |
| 454 | AddPath( |
| 455 | "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
| 456 | System, false, false, false); |
| 457 | AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include", |
| 458 | System, false, false, false); |
| 459 | AddPath( |
| 460 | "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include", |
| 461 | System, false, false, false); |
| 462 | // For some clang developers. |
| 463 | AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 464 | System, false, false, false); |
| 465 | AddPath( |
| 466 | "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
| 467 | System, false, false, false); |
| 468 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 469 | } |
| 470 | break; |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 471 | case llvm::Triple::Haiku: |
| 472 | AddPath("/boot/common/include", System, true, false, false); |
| 473 | AddPath("/boot/develop/headers/os", System, true, false, false); |
| 474 | AddPath("/boot/develop/headers/os/app", System, true, false, false); |
| 475 | AddPath("/boot/develop/headers/os/arch", System, true, false, false); |
| 476 | AddPath("/boot/develop/headers/os/device", System, true, false, false); |
| 477 | AddPath("/boot/develop/headers/os/drivers", System, true, false, false); |
| 478 | AddPath("/boot/develop/headers/os/game", System, true, false, false); |
| 479 | AddPath("/boot/develop/headers/os/interface", System, true, false, false); |
| 480 | AddPath("/boot/develop/headers/os/kernel", System, true, false, false); |
| 481 | AddPath("/boot/develop/headers/os/locale", System, true, false, false); |
| 482 | AddPath("/boot/develop/headers/os/mail", System, true, false, false); |
| 483 | AddPath("/boot/develop/headers/os/media", System, true, false, false); |
| 484 | AddPath("/boot/develop/headers/os/midi", System, true, false, false); |
| 485 | AddPath("/boot/develop/headers/os/midi2", System, true, false, false); |
| 486 | AddPath("/boot/develop/headers/os/net", System, true, false, false); |
| 487 | AddPath("/boot/develop/headers/os/storage", System, true, false, false); |
| 488 | AddPath("/boot/develop/headers/os/support", System, true, false, false); |
| 489 | AddPath("/boot/develop/headers/os/translation", |
| 490 | System, true, false, false); |
| 491 | AddPath("/boot/develop/headers/os/add-ons/graphics", |
| 492 | System, true, false, false); |
| 493 | AddPath("/boot/develop/headers/os/add-ons/input_server", |
| 494 | System, true, false, false); |
| 495 | AddPath("/boot/develop/headers/os/add-ons/screen_saver", |
| 496 | System, true, false, false); |
| 497 | AddPath("/boot/develop/headers/os/add-ons/tracker", |
| 498 | System, true, false, false); |
| 499 | AddPath("/boot/develop/headers/os/be_apps/Deskbar", |
| 500 | System, true, false, false); |
| 501 | AddPath("/boot/develop/headers/os/be_apps/NetPositive", |
| 502 | System, true, false, false); |
| 503 | AddPath("/boot/develop/headers/os/be_apps/Tracker", |
| 504 | System, true, false, false); |
| 505 | AddPath("/boot/develop/headers/cpp", System, true, false, false); |
| 506 | AddPath("/boot/develop/headers/cpp/i586-pc-haiku", |
| 507 | System, true, false, false); |
| 508 | AddPath("/boot/develop/headers/3rdparty", System, true, false, false); |
| 509 | AddPath("/boot/develop/headers/bsd", System, true, false, false); |
| 510 | AddPath("/boot/develop/headers/glibc", System, true, false, false); |
| 511 | AddPath("/boot/develop/headers/posix", System, true, false, false); |
| 512 | AddPath("/boot/develop/headers", System, true, false, false); |
| 513 | break; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 514 | case llvm::Triple::MinGW64: |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 515 | case llvm::Triple::MinGW32: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 516 | AddPath("c:/mingw/include", System, true, false, false); |
| 517 | break; |
| 518 | default: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 519 | break; |
| 520 | } |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 521 | |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 522 | AddPath("/usr/include", System, false, false, false); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 525 | void InitHeaderSearch:: |
| 526 | AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) { |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 527 | llvm::Triple::OSType os = triple.getOS(); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 528 | llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT); |
| 529 | if (CxxIncludeRoot != "") { |
| 530 | llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH); |
| 531 | if (CxxIncludeArch == "") |
| 532 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(), |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 533 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, |
| 534 | triple); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 535 | else |
| 536 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH, |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 537 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, |
| 538 | triple); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 539 | return; |
| 540 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 541 | // FIXME: temporary hack: hard-coded paths. |
| 542 | switch (os) { |
| 543 | case llvm::Triple::Cygwin: |
| 544 | AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include", |
| 545 | System, true, false, false); |
| 546 | AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++", |
| 547 | System, true, false, false); |
| 548 | break; |
| 549 | case llvm::Triple::MinGW64: |
| 550 | // Try gcc 4.4.0 |
| 551 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0"); |
| 552 | // Try gcc 4.3.0 |
| 553 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0"); |
| 554 | // Fall through. |
| 555 | case llvm::Triple::MinGW32: |
| 556 | // Try gcc 4.4.0 |
| 557 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); |
| 558 | // Try gcc 4.3.0 |
| 559 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); |
| 560 | break; |
| 561 | case llvm::Triple::Darwin: |
Daniel Dunbar | f2070b3 | 2010-05-28 01:54:31 +0000 | [diff] [blame] | 562 | switch (triple.getArch()) { |
| 563 | default: break; |
| 564 | |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 565 | case llvm::Triple::ppc: |
| 566 | case llvm::Triple::ppc64: |
Douglas Gregor | 616d436 | 2010-05-29 01:21:11 +0000 | [diff] [blame^] | 567 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 568 | "powerpc-apple-darwin10", "", "ppc64", |
| 569 | triple); |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 570 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
| 571 | "powerpc-apple-darwin10", "", "ppc64", |
| 572 | triple); |
| 573 | break; |
| 574 | |
Daniel Dunbar | f2070b3 | 2010-05-28 01:54:31 +0000 | [diff] [blame] | 575 | case llvm::Triple::x86: |
| 576 | case llvm::Triple::x86_64: |
| 577 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 578 | "i686-apple-darwin10", "", "x86_64", triple); |
| 579 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
| 580 | "i686-apple-darwin8", "", "", triple); |
| 581 | break; |
| 582 | |
| 583 | case llvm::Triple::arm: |
| 584 | case llvm::Triple::thumb: |
| 585 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 586 | "arm-apple-darwin10", "v7", "", triple); |
| 587 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 588 | "arm-apple-darwin10", "v6", "", triple); |
| 589 | break; |
| 590 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 591 | break; |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 592 | case llvm::Triple::DragonFly: |
| 593 | AddPath("/usr/include/c++/4.1", System, true, false, false); |
| 594 | break; |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 595 | case llvm::Triple::Linux: |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 596 | //===------------------------------------------------------------------===// |
| 597 | // Debian based distros. |
| 598 | // Note: these distros symlink /usr/include/c++/X.Y.Z -> X.Y |
| 599 | //===------------------------------------------------------------------===// |
| 600 | // Ubuntu 10.04 LTS "Lucid Lynx" -- gcc-4.4.3 |
| 601 | // Ubuntu 9.10 "Karmic Koala" -- gcc-4.4.1 |
| 602 | // Debian 6.0 "squeeze" -- gcc-4.4.2 |
| 603 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
| 604 | "x86_64-linux-gnu", "32", "", triple); |
| 605 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
| 606 | "i486-linux-gnu", "", "64", triple); |
| 607 | // Ubuntu 9.04 "Jaunty Jackalope" -- gcc-4.3.3 |
| 608 | // Ubuntu 8.10 "Intrepid Ibex" -- gcc-4.3.2 |
| 609 | // Debian 5.0 "lenny" -- gcc-4.3.2 |
| 610 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
| 611 | "x86_64-linux-gnu", "32", "", triple); |
| 612 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
| 613 | "i486-linux-gnu", "", "64", triple); |
| 614 | // Ubuntu 8.04.4 LTS "Hardy Heron" -- gcc-4.2.4 |
| 615 | // Ubuntu 8.04.[0-3] LTS "Hardy Heron" -- gcc-4.2.3 |
| 616 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", |
| 617 | "x86_64-linux-gnu", "32", "", triple); |
| 618 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", |
| 619 | "i486-linux-gnu", "", "64", triple); |
| 620 | // Ubuntu 7.10 "Gutsy Gibbon" -- gcc-4.1.3 |
| 621 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1", |
| 622 | "x86_64-linux-gnu", "32", "", triple); |
| 623 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1", |
| 624 | "i486-linux-gnu", "", "64", triple); |
| 625 | |
| 626 | //===------------------------------------------------------------------===// |
| 627 | // Redhat based distros. |
| 628 | //===------------------------------------------------------------------===// |
| 629 | // Fedora 13 |
Chris Lattner | 4336e19 | 2010-05-29 01:01:38 +0000 | [diff] [blame] | 630 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4", |
| 631 | "x86_64-redhat-linux", "32", "", triple); |
| 632 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4", |
| 633 | "i686-redhat-linux","", "", triple); |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 634 | // Fedora 12 |
| 635 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
| 636 | "x86_64-redhat-linux", "32", "", triple); |
| 637 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
| 638 | "i686-redhat-linux","", "", triple); |
| 639 | // Fedora 12 (pre-FEB-2010) |
| 640 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", |
| 641 | "x86_64-redhat-linux", "32", "", triple); |
| 642 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", |
| 643 | "i686-redhat-linux","", "", triple); |
| 644 | // Fedora 11 |
| 645 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
| 646 | "x86_64-redhat-linux", "32", "", triple); |
| 647 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
| 648 | "i586-redhat-linux","", "", triple); |
| 649 | // Fedora 10 |
| 650 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
| 651 | "x86_64-redhat-linux", "32", "", triple); |
| 652 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
| 653 | "i386-redhat-linux","", "", triple); |
| 654 | // Fedora 9 |
| 655 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", |
| 656 | "x86_64-redhat-linux", "32", "", triple); |
| 657 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", |
| 658 | "i386-redhat-linux", "", "", triple); |
| 659 | // Fedora 8 |
| 660 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", |
| 661 | "x86_64-redhat-linux", "", "", triple); |
| 662 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", |
| 663 | "i386-redhat-linux", "", "", triple); |
| 664 | |
| 665 | //===------------------------------------------------------------------===// |
| 666 | |
Benjamin Kramer | 0db3d72 | 2010-01-25 12:20:15 +0000 | [diff] [blame] | 667 | // Exherbo (2010-01-25) |
| 668 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
Torok Edwin | fc4b899 | 2009-12-18 17:29:14 +0000 | [diff] [blame] | 669 | "x86_64-pc-linux-gnu", "32", "", triple); |
Benjamin Kramer | 0db3d72 | 2010-01-25 12:20:15 +0000 | [diff] [blame] | 670 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
Torok Edwin | fc4b899 | 2009-12-18 17:29:14 +0000 | [diff] [blame] | 671 | "i686-pc-linux-gnu", "", "", triple); |
Chris Lattner | ea00f84 | 2010-04-23 15:55:20 +0000 | [diff] [blame] | 672 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 673 | // openSUSE 11.1 32 bit |
| 674 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 675 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 676 | // openSUSE 11.1 64 bit |
| 677 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 678 | "x86_64-suse-linux", "32", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 679 | // openSUSE 11.2 |
| 680 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 681 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 682 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 683 | "x86_64-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 684 | // Arch Linux 2008-06-24 |
| 685 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 686 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 687 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 688 | "x86_64-unknown-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 689 | // Gentoo x86 2009.1 stable |
| 690 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 691 | "/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] | 692 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 693 | // Gentoo x86 2009.0 stable |
| 694 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 695 | "/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] | 696 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 697 | // Gentoo x86 2008.0 stable |
| 698 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 699 | "/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] | 700 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 701 | // Gentoo amd64 stable |
| 702 | AddGnuCPlusPlusIncludePaths( |
| 703 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 704 | "i686-pc-linux-gnu", "", "", triple); |
Eric Christopher | 70d9d41 | 2010-03-03 21:41:50 +0000 | [diff] [blame] | 705 | |
| 706 | // Gentoo amd64 gcc 4.3.2 |
| 707 | AddGnuCPlusPlusIncludePaths( |
| 708 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4", |
| 709 | "x86_64-pc-linux-gnu", "", "", triple); |
| 710 | |
| 711 | // Gentoo amd64 gcc 4.4.3 |
| 712 | AddGnuCPlusPlusIncludePaths( |
| 713 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4", |
| 714 | "x86_64-pc-linux-gnu", "32", "", triple); |
| 715 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 716 | break; |
| 717 | case llvm::Triple::FreeBSD: |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 718 | // FreeBSD 8.0 |
| 719 | // FreeBSD 7.3 |
Nuno Lopes | afe859a | 2010-01-17 00:00:11 +0000 | [diff] [blame] | 720 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 721 | break; |
| 722 | case llvm::Triple::Solaris: |
| 723 | // Solaris - Fall though.. |
| 724 | case llvm::Triple::AuroraUX: |
| 725 | // AuroraUX |
| 726 | AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 727 | "i386-pc-solaris2.11", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 728 | break; |
| 729 | default: |
| 730 | break; |
| 731 | } |
| 732 | } |
| 733 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 734 | void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 735 | const llvm::Triple &triple, |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 736 | const HeaderSearchOptions &HSOpts) { |
| 737 | if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes) |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 738 | AddDefaultCPlusPlusIncludePaths(triple); |
| 739 | |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 740 | AddDefaultCIncludePaths(triple, HSOpts); |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 741 | |
| 742 | // Add the default framework include paths on Darwin. |
| 743 | if (triple.getOS() == llvm::Triple::Darwin) { |
| 744 | AddPath("/System/Library/Frameworks", System, true, false, true); |
| 745 | AddPath("/Library/Frameworks", System, true, false, true); |
| 746 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 749 | /// RemoveDuplicates - If there are duplicate directory entries in the specified |
| 750 | /// search list, remove the later (dead) ones. |
| 751 | static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, |
| 752 | bool Verbose) { |
| 753 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; |
| 754 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; |
| 755 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; |
| 756 | for (unsigned i = 0; i != SearchList.size(); ++i) { |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 757 | unsigned DirToRemove = i; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 759 | const DirectoryLookup &CurEntry = SearchList[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 760 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 761 | if (CurEntry.isNormalDir()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 762 | // 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] | 763 | if (SeenDirs.insert(CurEntry.getDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 764 | continue; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 765 | } else if (CurEntry.isFramework()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 766 | // 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] | 767 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 768 | continue; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 769 | } else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 770 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 771 | // 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] | 772 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 773 | continue; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 774 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 775 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 776 | // If we have a normal #include dir/framework/headermap that is shadowed |
| 777 | // later in the chain by a system include location, we actually want to |
| 778 | // ignore the user's request and drop the user dir... keeping the system |
| 779 | // dir. This is weird, but required to emulate GCC's search path correctly. |
| 780 | // |
| 781 | // Since dupes of system dirs are rare, just rescan to find the original |
| 782 | // that we're nuking instead of using a DenseMap. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 783 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 784 | // Find the dir that this is the same of. |
| 785 | unsigned FirstDir; |
| 786 | for (FirstDir = 0; ; ++FirstDir) { |
| 787 | assert(FirstDir != i && "Didn't find dupe?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 788 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 789 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; |
| 790 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 791 | // 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] | 792 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 793 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 794 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 795 | bool isSame; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 796 | if (CurEntry.isNormalDir()) |
| 797 | isSame = SearchEntry.getDir() == CurEntry.getDir(); |
| 798 | else if (CurEntry.isFramework()) |
| 799 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 800 | else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 801 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 802 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 803 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 805 | if (isSame) |
| 806 | break; |
| 807 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 808 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 809 | // If the first dir in the search path is a non-system dir, zap it |
| 810 | // instead of the system one. |
| 811 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) |
| 812 | DirToRemove = FirstDir; |
| 813 | } |
| 814 | |
| 815 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 816 | llvm::errs() << "ignoring duplicate directory \"" |
| 817 | << CurEntry.getName() << "\"\n"; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 818 | if (DirToRemove != i) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 819 | llvm::errs() << " as it is a non-system directory that duplicates " |
| 820 | << "a system directory\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 821 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 822 | |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 823 | // This is reached if the current entry is a duplicate. Remove the |
| 824 | // DirToRemove (usually the current dir). |
| 825 | SearchList.erase(SearchList.begin()+DirToRemove); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 826 | --i; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | |
| 831 | void InitHeaderSearch::Realize() { |
| 832 | // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. |
| 833 | std::vector<DirectoryLookup> SearchList; |
| 834 | SearchList = IncludeGroup[Angled]; |
| 835 | SearchList.insert(SearchList.end(), IncludeGroup[System].begin(), |
| 836 | IncludeGroup[System].end()); |
| 837 | SearchList.insert(SearchList.end(), IncludeGroup[After].begin(), |
| 838 | IncludeGroup[After].end()); |
| 839 | RemoveDuplicates(SearchList, Verbose); |
| 840 | RemoveDuplicates(IncludeGroup[Quoted], Verbose); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 842 | // Prepend QUOTED list on the search list. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(), |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 844 | IncludeGroup[Quoted].end()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 846 | |
| 847 | bool DontSearchCurDir = false; // TODO: set to true if -I- is set? |
| 848 | Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(), |
| 849 | DontSearchCurDir); |
| 850 | |
| 851 | // If verbose, print the list of directories that will be searched. |
| 852 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 853 | llvm::errs() << "#include \"...\" search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 854 | unsigned QuotedIdx = IncludeGroup[Quoted].size(); |
| 855 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { |
| 856 | if (i == QuotedIdx) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 857 | llvm::errs() << "#include <...> search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 858 | const char *Name = SearchList[i].getName(); |
| 859 | const char *Suffix; |
| 860 | if (SearchList[i].isNormalDir()) |
| 861 | Suffix = ""; |
| 862 | else if (SearchList[i].isFramework()) |
| 863 | Suffix = " (framework directory)"; |
| 864 | else { |
| 865 | assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); |
| 866 | Suffix = " (headermap)"; |
| 867 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 868 | llvm::errs() << " " << Name << Suffix << "\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 869 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 870 | llvm::errs() << "End of search list.\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 871 | } |
| 872 | } |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 873 | |
Daniel Dunbar | 5814e65 | 2009-11-11 21:44:21 +0000 | [diff] [blame] | 874 | void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, |
| 875 | const HeaderSearchOptions &HSOpts, |
| 876 | const LangOptions &Lang, |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 877 | const llvm::Triple &Triple) { |
| 878 | InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); |
| 879 | |
| 880 | // Add the user defined entries. |
| 881 | for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { |
| 882 | const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 883 | Init.AddPath(E.Path, E.Group, false, E.IsUserSupplied, E.IsFramework, |
| 884 | false); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | // Add entries from CPATH and friends. |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 888 | Init.AddDelimitedPaths(HSOpts.EnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 889 | if (Lang.CPlusPlus && Lang.ObjC1) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 890 | Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 891 | else if (Lang.CPlusPlus) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 892 | Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 893 | else if (Lang.ObjC1) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 894 | Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 895 | else |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 896 | Init.AddDelimitedPaths(HSOpts.CEnvIncPath); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 897 | |
Daniel Dunbar | dd35ce9 | 2009-11-07 04:58:12 +0000 | [diff] [blame] | 898 | if (HSOpts.UseStandardIncludes) |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 899 | Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 900 | |
| 901 | Init.Realize(); |
| 902 | } |