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" |
Chris Lattner | d57a7ef | 2009-08-23 22:45:33 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 25 | #include "llvm/System/Path.h" |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 26 | #include "llvm/Config/config.h" |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 27 | #include <cstdio> |
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. |
| 53 | void AddPath(const llvm::StringRef &Path, IncludeDirGroup Group, |
| 54 | bool isCXXAware, bool isUserSupplied, |
| 55 | bool isFramework, bool IgnoreSysRoot = false); |
| 56 | |
| 57 | /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to suport a gnu |
| 58 | /// libstdc++. |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 59 | void AddGnuCPlusPlusIncludePaths(const std::string &Base, |
| 60 | const char *ArchDir, |
| 61 | const char *Dir32, |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 62 | const char *Dir64, |
| 63 | const llvm::Triple &triple); |
| 64 | |
| 65 | /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to suport a MinGW |
| 66 | /// libstdc++. |
| 67 | void AddMinGWCPlusPlusIncludePaths(const std::string &Base, |
| 68 | const char *Arch, |
| 69 | const char *Version); |
| 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. |
| 73 | void AddDelimitedPaths(const char *String); |
| 74 | |
| 75 | // AddDefaultCIncludePaths - Add paths that should always be searched. |
| 76 | void AddDefaultCIncludePaths(const llvm::Triple &triple); |
| 77 | |
| 78 | // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when |
| 79 | // compiling c++. |
| 80 | void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple); |
| 81 | |
| 82 | /// AddDefaultSystemIncludePaths - Adds the default system include paths so |
| 83 | /// that e.g. stdio.h is found. |
| 84 | void AddDefaultSystemIncludePaths(const LangOptions &Lang, |
| 85 | const llvm::Triple &triple); |
| 86 | |
| 87 | /// Realize - Merges all search path lists into one list and send it to |
| 88 | /// HeaderSearch. |
| 89 | void Realize(); |
| 90 | }; |
| 91 | |
| 92 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 93 | |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 94 | void InitHeaderSearch::AddPath(const llvm::StringRef &Path, |
| 95 | IncludeDirGroup Group, bool isCXXAware, |
| 96 | bool isUserSupplied, bool isFramework, |
| 97 | bool IgnoreSysRoot) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 98 | assert(!Path.empty() && "can't handle empty path here"); |
| 99 | FileManager &FM = Headers.getFileMgr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 101 | // Compute the actual path, taking into consideration -isysroot. |
| 102 | llvm::SmallString<256> MappedPath; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 104 | // Handle isysroot. |
Chris Lattner | 6858dd3 | 2009-02-19 06:48:28 +0000 | [diff] [blame] | 105 | if (Group == System && !IgnoreSysRoot) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 106 | // FIXME: Portability. This should be a sys::Path interface, this doesn't |
| 107 | // handle things like C:\ right, nor win32 \\network\device\blah. |
| 108 | if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present. |
| 109 | MappedPath.append(isysroot.begin(), isysroot.end()); |
| 110 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 112 | MappedPath.append(Path.begin(), Path.end()); |
| 113 | |
| 114 | // Compute the DirectoryLookup type. |
Chris Lattner | 9d72851 | 2008-10-27 01:19:25 +0000 | [diff] [blame] | 115 | SrcMgr::CharacteristicKind Type; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 116 | if (Group == Quoted || Group == Angled) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 117 | Type = SrcMgr::C_User; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 118 | else if (isCXXAware) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 119 | Type = SrcMgr::C_System; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 120 | else |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 121 | Type = SrcMgr::C_ExternCSystem; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 | |
| 123 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 124 | // If the directory exists, add it. |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 125 | if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 126 | IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied, |
| 127 | isFramework)); |
| 128 | return; |
| 129 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 130 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 131 | // Check to see if this is an apple-style headermap (which are not allowed to |
| 132 | // be frameworks). |
| 133 | if (!isFramework) { |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 134 | if (const FileEntry *FE = FM.getFile(MappedPath.str())) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 135 | if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { |
| 136 | // It is a headermap, add it to the search path. |
| 137 | IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied)); |
| 138 | return; |
| 139 | } |
| 140 | } |
| 141 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 143 | if (Verbose) |
Daniel Dunbar | 7765934 | 2009-08-19 20:04:03 +0000 | [diff] [blame] | 144 | llvm::errs() << "ignoring nonexistent directory \"" |
| 145 | << MappedPath.str() << "\"\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 149 | void InitHeaderSearch::AddDelimitedPaths(const char *at) { |
| 150 | if (*at == 0) // Empty string should not add '.' path. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 151 | return; |
| 152 | |
| 153 | const char* delim = strchr(at, llvm::sys::PathSeparator); |
| 154 | while (delim != 0) { |
| 155 | if (delim-at == 0) |
| 156 | AddPath(".", Angled, false, true, false); |
| 157 | else |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 158 | AddPath(llvm::StringRef(at, delim-at), Angled, false, true, false); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 159 | at = delim + 1; |
| 160 | delim = strchr(at, llvm::sys::PathSeparator); |
| 161 | } |
| 162 | if (*at == 0) |
| 163 | AddPath(".", Angled, false, true, false); |
| 164 | else |
| 165 | AddPath(at, Angled, false, true, false); |
| 166 | } |
| 167 | |
Mike Stump | ec05766 | 2009-10-09 20:16:49 +0000 | [diff] [blame] | 168 | void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(const std::string &Base, |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 169 | const char *ArchDir, |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 170 | const char *Dir32, |
| 171 | const char *Dir64, |
| 172 | const llvm::Triple &triple) { |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 173 | // Add the common dirs |
| 174 | AddPath(Base, System, true, false, false); |
| 175 | AddPath(Base + "/backward", System, true, false, false); |
| 176 | |
| 177 | // Add the multilib dirs |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 178 | llvm::Triple::ArchType arch = triple.getArch(); |
| 179 | bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 180 | if (is64bit) |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 181 | AddPath(Base + "/" + ArchDir + "/" + Dir64, System, true, false, false); |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 182 | else |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 183 | AddPath(Base + "/" + ArchDir + "/" + Dir32, System, true, false, false); |
Rafael Espindola | 2e9f652 | 2009-10-06 01:33:02 +0000 | [diff] [blame] | 184 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 185 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 186 | void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(const std::string &Base, |
| 187 | const char *Arch, |
| 188 | const char *Version) { |
Daniel Dunbar | 5c5758b | 2009-11-07 04:20:25 +0000 | [diff] [blame] | 189 | std::string localBase = Base + "/" + Arch + "/" + Version + "/include"; |
| 190 | AddPath(localBase, System, true, false, false); |
| 191 | AddPath(localBase + "/c++", System, true, false, false); |
| 192 | AddPath(localBase + "/c++/backward", System, true, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 193 | } |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 194 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 195 | // FIXME: This probably should goto to some platform utils place. |
| 196 | #ifdef _MSC_VER |
| 197 | // Read registry string. |
| 198 | bool getSystemRegistryString(const char *keyPath, const char *valueName, |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 199 | char *value, size_t maxLength) { |
| 200 | HKEY hRootKey = NULL; |
| 201 | HKEY hKey = NULL; |
| 202 | const char* subKey = NULL; |
| 203 | DWORD valueType; |
| 204 | DWORD valueSize = maxLength - 1; |
| 205 | bool returnValue = false; |
| 206 | if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { |
| 207 | hRootKey = HKEY_CLASSES_ROOT; |
| 208 | subKey = keyPath + 18; |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 209 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 210 | else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { |
| 211 | hRootKey = HKEY_USERS; |
| 212 | subKey = keyPath + 11; |
| 213 | } |
| 214 | else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { |
| 215 | hRootKey = HKEY_LOCAL_MACHINE; |
| 216 | subKey = keyPath + 19; |
| 217 | } |
| 218 | else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { |
| 219 | hRootKey = HKEY_CURRENT_USER; |
| 220 | subKey = keyPath + 18; |
| 221 | } |
| 222 | else |
| 223 | return(false); |
| 224 | long lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); |
| 225 | if (lResult == ERROR_SUCCESS) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 226 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 227 | (LPBYTE)value, &valueSize); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 228 | if (lResult == ERROR_SUCCESS) |
| 229 | returnValue = true; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 230 | RegCloseKey(hKey); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 231 | } |
| 232 | return(returnValue); |
| 233 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 234 | #else // _MSC_VER |
| 235 | // Read registry string. |
| 236 | bool getSystemRegistryString(const char *, const char *, char *, size_t) { |
| 237 | return(false); |
| 238 | } |
| 239 | #endif // _MSC_VER |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 240 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 241 | // Get Visual Studio installation directory. |
| 242 | bool getVisualStudioDir(std::string &path) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 243 | // Try the Windows registry first. |
| 244 | char vs80IDEInstallDir[256]; |
| 245 | char vs90IDEInstallDir[256]; |
| 246 | const char* vsIDEInstallDir = NULL; |
| 247 | bool has80 = getSystemRegistryString( |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 248 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0", |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 249 | "InstallDir", vs80IDEInstallDir, sizeof(vs80IDEInstallDir) - 1); |
| 250 | bool has90 = getSystemRegistryString( |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 251 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0", |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 252 | "InstallDir", vs90IDEInstallDir, sizeof(vs90IDEInstallDir) - 1); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 253 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 254 | if (has80 && has90) { |
| 255 | #ifdef _MSC_VER |
| 256 | #if (_MSC_VER >= 1500) // VC90 |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 257 | vsIDEInstallDir = vs90IDEInstallDir; |
| 258 | #elif (_MSC_VER == 1400) // VC80 |
| 259 | vsIDEInstallDir = vs80IDEInstallDir; |
| 260 | #else |
| 261 | vsIDEInstallDir = vs90IDEInstallDir; |
| 262 | #endif |
| 263 | #else |
| 264 | vsIDEInstallDir = vs90IDEInstallDir; |
| 265 | #endif |
| 266 | } |
| 267 | else if (has90) |
| 268 | vsIDEInstallDir = vs90IDEInstallDir; |
| 269 | else if (has80) |
| 270 | vsIDEInstallDir = vs80IDEInstallDir; |
| 271 | if (vsIDEInstallDir && *vsIDEInstallDir) { |
| 272 | char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); |
| 273 | if (p) |
| 274 | *p = '\0'; |
| 275 | path = vsIDEInstallDir; |
| 276 | return(true); |
| 277 | } |
| 278 | else { |
| 279 | // Try the environment. |
| 280 | const char* vs90comntools = getenv("VS90COMNTOOLS"); |
| 281 | const char* vs80comntools = getenv("VS80COMNTOOLS"); |
| 282 | const char* vscomntools = NULL; |
| 283 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 284 | if (vs90comntools && vs80comntools) { |
| 285 | #if (_MSC_VER >= 1500) // VC90 |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 286 | vscomntools = vs90comntools; |
| 287 | #elif (_MSC_VER == 1400) // VC80 |
| 288 | vscomntools = vs80comntools; |
| 289 | #else |
| 290 | vscomntools = vs90comntools; |
| 291 | #endif |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 292 | } |
| 293 | else if (vs90comntools) |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 294 | vscomntools = vs90comntools; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 295 | else if (vs80comntools) |
| 296 | vscomntools = vs80comntools; |
| 297 | if (vscomntools && *vscomntools) { |
| 298 | char *p = (char*)strstr(vscomntools, "\\Common7\\Tools"); |
| 299 | if (p) |
| 300 | *p = '\0'; |
| 301 | path = vscomntools; |
| 302 | return(true); |
| 303 | } |
| 304 | else |
| 305 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 306 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 307 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 308 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 309 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 310 | void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 311 | // FIXME: temporary hack: hard-coded paths. |
Daniel Dunbar | c706468 | 2009-11-12 07:28:29 +0000 | [diff] [blame] | 312 | llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 313 | if (CIncludeDirs != "") { |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 314 | llvm::SmallVector<llvm::StringRef, 5> dirs; |
| 315 | CIncludeDirs.split(dirs, ":"); |
| 316 | for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin(); |
| 317 | i != dirs.end(); |
| 318 | ++i) |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 319 | AddPath(*i, System, false, false, false); |
| 320 | return; |
| 321 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 322 | llvm::Triple::OSType os = triple.getOS(); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 323 | switch (os) { |
| 324 | case llvm::Triple::Win32: |
| 325 | { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 326 | std::string VSDir; |
| 327 | if (getVisualStudioDir(VSDir)) { |
| 328 | AddPath(VSDir + "\\VC\\include", System, false, false, false); |
| 329 | AddPath(VSDir + "\\VC\\PlatformSDK\\Include", |
| 330 | System, false, false, false); |
| 331 | } |
| 332 | else { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 333 | // Default install paths. |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 334 | AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 335 | System, false, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 336 | AddPath( |
| 337 | "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 338 | System, false, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 339 | AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include", |
| 340 | System, false, false, false); |
| 341 | AddPath( |
| 342 | "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include", |
| 343 | System, false, false, false); |
| 344 | // For some clang developers. |
| 345 | AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 346 | System, false, false, false); |
| 347 | AddPath( |
| 348 | "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
| 349 | System, false, false, false); |
| 350 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 351 | } |
| 352 | break; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 353 | case llvm::Triple::MinGW64: |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 354 | case llvm::Triple::MinGW32: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 355 | AddPath("c:/mingw/include", System, true, false, false); |
| 356 | break; |
| 357 | default: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 358 | break; |
| 359 | } |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 360 | |
| 361 | AddPath("/usr/local/include", System, false, false, false); |
| 362 | AddPath("/usr/include", System, false, false, false); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) { |
| 366 | llvm::Triple::OSType os = triple.getOS(); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 367 | llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT); |
| 368 | if (CxxIncludeRoot != "") { |
| 369 | llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH); |
| 370 | if (CxxIncludeArch == "") |
| 371 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(), |
| 372 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple); |
| 373 | else |
| 374 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH, |
| 375 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple); |
| 376 | return; |
| 377 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 378 | // FIXME: temporary hack: hard-coded paths. |
| 379 | switch (os) { |
| 380 | case llvm::Triple::Cygwin: |
| 381 | AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include", |
| 382 | System, true, false, false); |
| 383 | AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++", |
| 384 | System, true, false, false); |
| 385 | break; |
| 386 | case llvm::Triple::MinGW64: |
| 387 | // Try gcc 4.4.0 |
| 388 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0"); |
| 389 | // Try gcc 4.3.0 |
| 390 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0"); |
| 391 | // Fall through. |
| 392 | case llvm::Triple::MinGW32: |
| 393 | // Try gcc 4.4.0 |
| 394 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); |
| 395 | // Try gcc 4.3.0 |
| 396 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); |
| 397 | break; |
| 398 | case llvm::Triple::Darwin: |
| 399 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 400 | "i686-apple-darwin10", "", "x86_64", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 401 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 402 | "i686-apple-darwin8", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 403 | break; |
| 404 | case llvm::Triple::Linux: |
| 405 | // Ubuntu 7.10 - Gutsy Gibbon |
| 406 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 407 | "i486-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 408 | // Ubuntu 9.04 |
| 409 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 410 | "x86_64-linux-gnu","32", "", triple); |
Sebastian Redl | 5114eca | 2009-11-05 17:44:49 +0000 | [diff] [blame] | 411 | // Ubuntu 9.10 |
| 412 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 413 | "x86_64-linux-gnu", "32", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 414 | // Fedora 8 |
| 415 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 416 | "i386-redhat-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 417 | // Fedora 9 |
| 418 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 419 | "i386-redhat-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 420 | // Fedora 10 |
| 421 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 422 | "i386-redhat-linux","", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 423 | // openSUSE 11.1 32 bit |
| 424 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 425 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 426 | // openSUSE 11.1 64 bit |
| 427 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 428 | "x86_64-suse-linux", "32", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 429 | // openSUSE 11.2 |
| 430 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 431 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 432 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 433 | "x86_64-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 434 | // Arch Linux 2008-06-24 |
| 435 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 436 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 437 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 438 | "x86_64-unknown-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 439 | // Gentoo x86 2009.1 stable |
| 440 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 441 | "/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] | 442 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 443 | // Gentoo x86 2009.0 stable |
| 444 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 445 | "/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] | 446 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 447 | // Gentoo x86 2008.0 stable |
| 448 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 449 | "/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] | 450 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 451 | // Ubuntu 8.10 |
| 452 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 453 | "i486-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 454 | // Ubuntu 9.04 |
| 455 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 456 | "i486-linux-gnu","", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 457 | // Gentoo amd64 stable |
| 458 | AddGnuCPlusPlusIncludePaths( |
| 459 | "/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] | 460 | "i686-pc-linux-gnu", "", "", triple); |
Benjamin Kramer | 5d7a188 | 2009-10-30 12:57:13 +0000 | [diff] [blame] | 461 | // Exherbo (2009-10-26) |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 462 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", |
| 463 | "x86_64-pc-linux-gnu", "32", "", triple); |
| 464 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", |
| 465 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 466 | break; |
| 467 | case llvm::Triple::FreeBSD: |
| 468 | // DragonFly |
| 469 | AddPath("/usr/include/c++/4.1", System, true, false, false); |
| 470 | // FreeBSD |
| 471 | AddPath("/usr/include/c++/4.2", System, true, false, false); |
| 472 | break; |
| 473 | case llvm::Triple::Solaris: |
| 474 | // Solaris - Fall though.. |
| 475 | case llvm::Triple::AuroraUX: |
| 476 | // AuroraUX |
| 477 | AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 478 | "i386-pc-solaris2.11", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 479 | break; |
| 480 | default: |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 485 | void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, |
| 486 | const llvm::Triple &triple) { |
| 487 | AddDefaultCIncludePaths(triple); |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 488 | |
| 489 | // Add the default framework include paths on Darwin. |
| 490 | if (triple.getOS() == llvm::Triple::Darwin) { |
| 491 | AddPath("/System/Library/Frameworks", System, true, false, true); |
| 492 | AddPath("/Library/Frameworks", System, true, false, true); |
| 493 | } |
| 494 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 495 | if (Lang.CPlusPlus) |
| 496 | AddDefaultCPlusPlusIncludePaths(triple); |
| 497 | } |
| 498 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 499 | /// RemoveDuplicates - If there are duplicate directory entries in the specified |
| 500 | /// search list, remove the later (dead) ones. |
| 501 | static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, |
| 502 | bool Verbose) { |
| 503 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; |
| 504 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; |
| 505 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; |
| 506 | for (unsigned i = 0; i != SearchList.size(); ++i) { |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 507 | unsigned DirToRemove = i; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 508 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 509 | const DirectoryLookup &CurEntry = SearchList[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 510 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 511 | if (CurEntry.isNormalDir()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 512 | // 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] | 513 | if (SeenDirs.insert(CurEntry.getDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 514 | continue; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 515 | } else if (CurEntry.isFramework()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 516 | // 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] | 517 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 518 | continue; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 519 | } else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 520 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 521 | // 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] | 522 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 523 | continue; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 524 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 526 | // If we have a normal #include dir/framework/headermap that is shadowed |
| 527 | // later in the chain by a system include location, we actually want to |
| 528 | // ignore the user's request and drop the user dir... keeping the system |
| 529 | // dir. This is weird, but required to emulate GCC's search path correctly. |
| 530 | // |
| 531 | // Since dupes of system dirs are rare, just rescan to find the original |
| 532 | // that we're nuking instead of using a DenseMap. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 533 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 534 | // Find the dir that this is the same of. |
| 535 | unsigned FirstDir; |
| 536 | for (FirstDir = 0; ; ++FirstDir) { |
| 537 | assert(FirstDir != i && "Didn't find dupe?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 539 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; |
| 540 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 541 | // 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] | 542 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 543 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 545 | bool isSame; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 546 | if (CurEntry.isNormalDir()) |
| 547 | isSame = SearchEntry.getDir() == CurEntry.getDir(); |
| 548 | else if (CurEntry.isFramework()) |
| 549 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 550 | else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 551 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 552 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 553 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 555 | if (isSame) |
| 556 | break; |
| 557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 558 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 559 | // If the first dir in the search path is a non-system dir, zap it |
| 560 | // instead of the system one. |
| 561 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) |
| 562 | DirToRemove = FirstDir; |
| 563 | } |
| 564 | |
| 565 | if (Verbose) { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 566 | fprintf(stderr, "ignoring duplicate directory \"%s\"\n", |
| 567 | CurEntry.getName()); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 568 | if (DirToRemove != i) |
| 569 | fprintf(stderr, " as it is a non-system directory that duplicates" |
| 570 | " a system directory\n"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 571 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 572 | |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 573 | // This is reached if the current entry is a duplicate. Remove the |
| 574 | // DirToRemove (usually the current dir). |
| 575 | SearchList.erase(SearchList.begin()+DirToRemove); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 576 | --i; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | |
| 581 | void InitHeaderSearch::Realize() { |
| 582 | // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. |
| 583 | std::vector<DirectoryLookup> SearchList; |
| 584 | SearchList = IncludeGroup[Angled]; |
| 585 | SearchList.insert(SearchList.end(), IncludeGroup[System].begin(), |
| 586 | IncludeGroup[System].end()); |
| 587 | SearchList.insert(SearchList.end(), IncludeGroup[After].begin(), |
| 588 | IncludeGroup[After].end()); |
| 589 | RemoveDuplicates(SearchList, Verbose); |
| 590 | RemoveDuplicates(IncludeGroup[Quoted], Verbose); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 591 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 592 | // Prepend QUOTED list on the search list. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(), |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 594 | IncludeGroup[Quoted].end()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 595 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 596 | |
| 597 | bool DontSearchCurDir = false; // TODO: set to true if -I- is set? |
| 598 | Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(), |
| 599 | DontSearchCurDir); |
| 600 | |
| 601 | // If verbose, print the list of directories that will be searched. |
| 602 | if (Verbose) { |
| 603 | fprintf(stderr, "#include \"...\" search starts here:\n"); |
| 604 | unsigned QuotedIdx = IncludeGroup[Quoted].size(); |
| 605 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { |
| 606 | if (i == QuotedIdx) |
| 607 | fprintf(stderr, "#include <...> search starts here:\n"); |
| 608 | const char *Name = SearchList[i].getName(); |
| 609 | const char *Suffix; |
| 610 | if (SearchList[i].isNormalDir()) |
| 611 | Suffix = ""; |
| 612 | else if (SearchList[i].isFramework()) |
| 613 | Suffix = " (framework directory)"; |
| 614 | else { |
| 615 | assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); |
| 616 | Suffix = " (headermap)"; |
| 617 | } |
| 618 | fprintf(stderr, " %s%s\n", Name, Suffix); |
| 619 | } |
| 620 | fprintf(stderr, "End of search list.\n"); |
| 621 | } |
| 622 | } |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 623 | |
Daniel Dunbar | 5814e65 | 2009-11-11 21:44:21 +0000 | [diff] [blame] | 624 | void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, |
| 625 | const HeaderSearchOptions &HSOpts, |
| 626 | const LangOptions &Lang, |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 627 | const llvm::Triple &Triple) { |
| 628 | InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); |
| 629 | |
| 630 | // Add the user defined entries. |
| 631 | for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { |
| 632 | const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; |
| 633 | Init.AddPath(E.Path, E.Group, E.IsCXXAware, E.IsUserSupplied, E.IsFramework, |
| 634 | E.IgnoreSysRoot); |
| 635 | } |
| 636 | |
| 637 | // Add entries from CPATH and friends. |
| 638 | Init.AddDelimitedPaths(HSOpts.EnvIncPath.c_str()); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame^] | 639 | if (Lang.CPlusPlus && Lang.ObjC1) |
| 640 | Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath.c_str()); |
| 641 | else if (Lang.CPlusPlus) |
| 642 | Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath.c_str()); |
| 643 | else if (Lang.ObjC1) |
| 644 | Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath.c_str()); |
| 645 | else |
| 646 | Init.AddDelimitedPaths(HSOpts.CEnvIncPath.c_str()); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 647 | |
| 648 | if (!HSOpts.BuiltinIncludePath.empty()) { |
| 649 | // Ignore the sys root, we *always* look for clang headers relative to |
| 650 | // supplied path. |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 651 | Init.AddPath(HSOpts.BuiltinIncludePath, System, |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 652 | false, false, false, /*IgnoreSysRoot=*/ true); |
| 653 | } |
| 654 | |
Daniel Dunbar | dd35ce9 | 2009-11-07 04:58:12 +0000 | [diff] [blame] | 655 | if (HSOpts.UseStandardIncludes) |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 656 | Init.AddDefaultSystemIncludePaths(Lang, Triple); |
| 657 | |
| 658 | Init.Realize(); |
| 659 | } |