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