blob: 26d0b369609bd9b43b54e48c035ed732eb1be0c2 [file] [log] [blame]
Nick Lewyckydf22c2c2010-07-25 03:12:58 +00001//===--- InitHeaderSearch.cpp - Initialize header search paths ------------===//
Nico Weber0fca0222008-08-22 09:25:22 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the InitHeaderSearch class.
11//
12//===----------------------------------------------------------------------===//
13
Oscar Fuentes2100fe92011-02-03 22:48:20 +000014#ifdef HAVE_CLANG_CONFIG_H
15# include "clang/Config/config.h"
16#endif
17
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000018#include "clang/Frontend/Utils.h"
Nico Weber0fca0222008-08-22 09:25:22 +000019#include "clang/Basic/FileManager.h"
20#include "clang/Basic/LangOptions.h"
Daniel Dunbar63c8b772009-11-07 04:20:50 +000021#include "clang/Frontend/HeaderSearchOptions.h"
22#include "clang/Lex/HeaderSearch.h"
Nico Weber0fca0222008-08-22 09:25:22 +000023#include "llvm/ADT/SmallString.h"
24#include "llvm/ADT/SmallPtrSet.h"
Rafael Espindolaaadd7a42009-11-13 05:13:58 +000025#include "llvm/ADT/SmallVector.h"
Rafael Espindolaf0a2f512009-11-12 05:48:41 +000026#include "llvm/ADT/StringExtras.h"
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000027#include "llvm/ADT/Triple.h"
Benjamin Kramere89ba592009-12-08 12:38:20 +000028#include "llvm/ADT/Twine.h"
Chris Lattnerd57a7ef2009-08-23 22:45:33 +000029#include "llvm/Support/raw_ostream.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000030#include "llvm/Support/Path.h"
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +000031#include "llvm/Config/config.h"
Mike Stump620d57a2009-10-12 20:50:45 +000032#ifdef _MSC_VER
33 #define WIN32_LEAN_AND_MEAN 1
34 #include <windows.h>
35#endif
Nico Weber0fca0222008-08-22 09:25:22 +000036using namespace clang;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000037using namespace clang::frontend;
38
39namespace {
40
41/// InitHeaderSearch - This class makes it easier to set the search paths of
42/// a HeaderSearch object. InitHeaderSearch stores several search path lists
43/// internally, which can be sent to a HeaderSearch object in one swoop.
44class InitHeaderSearch {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +000045 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
46 typedef std::vector<std::pair<IncludeDirGroup,
47 DirectoryLookup> >::const_iterator path_iterator;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000048 HeaderSearch& Headers;
49 bool Verbose;
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000050 std::string IncludeSysroot;
51 bool IsNotEmptyOrRoot;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000052
53public:
54
Chandler Carruthc09265a2010-11-15 07:15:26 +000055 InitHeaderSearch(HeaderSearch &HS, bool verbose, llvm::StringRef sysroot)
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000056 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
57 IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) {
Chandler Carruthc09265a2010-11-15 07:15:26 +000058 }
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000059
60 /// AddPath - Add the specified path to the specified group list.
Benjamin Kramere89ba592009-12-08 12:38:20 +000061 void AddPath(const llvm::Twine &Path, IncludeDirGroup Group,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000062 bool isCXXAware, bool isUserSupplied,
63 bool isFramework, bool IgnoreSysRoot = false);
64
mike-ma6087372010-05-05 17:00:31 +000065 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000066 /// libstdc++.
Benjamin Kramere89ba592009-12-08 12:38:20 +000067 void AddGnuCPlusPlusIncludePaths(llvm::StringRef Base,
68 llvm::StringRef ArchDir,
69 llvm::StringRef Dir32,
70 llvm::StringRef Dir64,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000071 const llvm::Triple &triple);
72
Michael J. Spencer06a8dc62010-12-21 16:45:42 +000073 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000074 /// libstdc++.
Benjamin Kramere89ba592009-12-08 12:38:20 +000075 void AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
76 llvm::StringRef Arch,
77 llvm::StringRef Version);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000078
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000079 /// AddMinGW64CXXPaths - Add the necessary paths to support
80 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
81 void AddMinGW64CXXPaths(llvm::StringRef Base);
82
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000083 /// AddDelimitedPaths - Add a list of paths delimited by the system PATH
84 /// separator. The processing follows that of the CPATH variable for gcc.
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +000085 void AddDelimitedPaths(llvm::StringRef String);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000086
87 // AddDefaultCIncludePaths - Add paths that should always be searched.
mike-m79bc57c2010-05-16 19:03:52 +000088 void AddDefaultCIncludePaths(const llvm::Triple &triple,
89 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000090
91 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
92 // compiling c++.
93 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple);
94
95 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
96 /// that e.g. stdio.h is found.
97 void AddDefaultSystemIncludePaths(const LangOptions &Lang,
Douglas Gregor4c2bcad2010-03-24 20:13:48 +000098 const llvm::Triple &triple,
mike-m79bc57c2010-05-16 19:03:52 +000099 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +0000100
101 /// Realize - Merges all search path lists into one list and send it to
102 /// HeaderSearch.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000103 void Realize(const LangOptions &Lang);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +0000104};
105
106}
Nico Weber0fca0222008-08-22 09:25:22 +0000107
Benjamin Kramere89ba592009-12-08 12:38:20 +0000108void InitHeaderSearch::AddPath(const llvm::Twine &Path,
Benjamin Kramer458fb102009-09-05 09:49:39 +0000109 IncludeDirGroup Group, bool isCXXAware,
110 bool isUserSupplied, bool isFramework,
111 bool IgnoreSysRoot) {
Benjamin Kramere89ba592009-12-08 12:38:20 +0000112 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
Nico Weber0fca0222008-08-22 09:25:22 +0000113 FileManager &FM = Headers.getFileMgr();
Mike Stump1eb44332009-09-09 15:08:12 +0000114
Nico Weber0fca0222008-08-22 09:25:22 +0000115 // Compute the actual path, taking into consideration -isysroot.
Chandler Carruth5853b0f2010-11-15 00:05:18 +0000116 llvm::SmallString<256> MappedPathStorage;
Chandler Carruthf3721452010-11-15 00:48:13 +0000117 llvm::StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
Mike Stump1eb44332009-09-09 15:08:12 +0000118
Nico Weber0fca0222008-08-22 09:25:22 +0000119 // Handle isysroot.
Rafael Espindola9a7e09d2011-03-02 21:30:07 +0000120 if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot &&
Michael J. Spencer256053b2010-12-17 21:22:22 +0000121 llvm::sys::path::is_absolute(MappedPathStr) &&
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000122 IsNotEmptyOrRoot) {
Chandler Carruth5619ae52010-11-15 09:28:23 +0000123 MappedPathStorage.clear();
Chandler Carruthc09265a2010-11-15 07:15:26 +0000124 MappedPathStr =
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000125 (IncludeSysroot + Path).toStringRef(MappedPathStorage);
Nico Weber0fca0222008-08-22 09:25:22 +0000126 }
Mike Stump1eb44332009-09-09 15:08:12 +0000127
Nico Weber0fca0222008-08-22 09:25:22 +0000128 // Compute the DirectoryLookup type.
Chris Lattner9d728512008-10-27 01:19:25 +0000129 SrcMgr::CharacteristicKind Type;
Nico Weber0fca0222008-08-22 09:25:22 +0000130 if (Group == Quoted || Group == Angled)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000131 Type = SrcMgr::C_User;
Nico Weber0fca0222008-08-22 09:25:22 +0000132 else if (isCXXAware)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000133 Type = SrcMgr::C_System;
Nico Weber0fca0222008-08-22 09:25:22 +0000134 else
Chris Lattner0b9e7362008-09-26 21:18:42 +0000135 Type = SrcMgr::C_ExternCSystem;
Mike Stump1eb44332009-09-09 15:08:12 +0000136
137
Nico Weber0fca0222008-08-22 09:25:22 +0000138 // If the directory exists, add it.
Chris Lattner39b49bc2010-11-23 08:35:12 +0000139 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000140 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type,
141 isUserSupplied, isFramework)));
Nico Weber0fca0222008-08-22 09:25:22 +0000142 return;
143 }
Mike Stump1eb44332009-09-09 15:08:12 +0000144
Nico Weber0fca0222008-08-22 09:25:22 +0000145 // Check to see if this is an apple-style headermap (which are not allowed to
146 // be frameworks).
147 if (!isFramework) {
Chris Lattner39b49bc2010-11-23 08:35:12 +0000148 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
Nico Weber0fca0222008-08-22 09:25:22 +0000149 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
150 // It is a headermap, add it to the search path.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000151 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type,
152 isUserSupplied)));
Nico Weber0fca0222008-08-22 09:25:22 +0000153 return;
154 }
155 }
156 }
Mike Stump1eb44332009-09-09 15:08:12 +0000157
Nico Weber0fca0222008-08-22 09:25:22 +0000158 if (Verbose)
Chandler Carruthf3721452010-11-15 00:48:13 +0000159 llvm::errs() << "ignoring nonexistent directory \""
160 << MappedPathStr << "\"\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000161}
162
163
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000164void InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) {
165 if (at.empty()) // Empty string should not add '.' path.
Nico Weber0fca0222008-08-22 09:25:22 +0000166 return;
167
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000168 llvm::StringRef::size_type delim;
169 while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) {
170 if (delim == 0)
Nico Weber0fca0222008-08-22 09:25:22 +0000171 AddPath(".", Angled, false, true, false);
172 else
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000173 AddPath(at.substr(0, delim), Angled, false, true, false);
174 at = at.substr(delim + 1);
Nico Weber0fca0222008-08-22 09:25:22 +0000175 }
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000176
177 if (at.empty())
Nico Weber0fca0222008-08-22 09:25:22 +0000178 AddPath(".", Angled, false, true, false);
179 else
180 AddPath(at, Angled, false, true, false);
181}
182
Benjamin Kramere89ba592009-12-08 12:38:20 +0000183void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base,
184 llvm::StringRef ArchDir,
185 llvm::StringRef Dir32,
186 llvm::StringRef Dir64,
Rafael Espindola31b63be2009-10-14 17:09:44 +0000187 const llvm::Triple &triple) {
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000188 // Add the base dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000189 AddPath(Base, CXXSystem, true, false, false);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000190
191 // Add the multilib dirs
Rafael Espindola31b63be2009-10-14 17:09:44 +0000192 llvm::Triple::ArchType arch = triple.getArch();
193 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola31b63be2009-10-14 17:09:44 +0000194 if (is64bit)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000195 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false);
Rafael Espindola31b63be2009-10-14 17:09:44 +0000196 else
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000197 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false);
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000198
199 // Add the backward dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000200 AddPath(Base + "/backward", CXXSystem, true, false, false);
Rafael Espindola2e9f6522009-10-06 01:33:02 +0000201}
Nico Weber0fca0222008-08-22 09:25:22 +0000202
Benjamin Kramere89ba592009-12-08 12:38:20 +0000203void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
204 llvm::StringRef Arch,
205 llvm::StringRef Version) {
Benjamin Kramerab8ae192010-01-20 16:18:11 +0000206 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000207 CXXSystem, true, false, false);
Chris Lattner8e9006b2010-09-03 16:45:53 +0000208 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000209 CXXSystem, true, false, false);
Benjamin Kramerab8ae192010-01-20 16:18:11 +0000210 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000211 CXXSystem, true, false, false);
Mike Stump620d57a2009-10-12 20:50:45 +0000212}
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +0000213
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000214void InitHeaderSearch::AddMinGW64CXXPaths(llvm::StringRef Base) {
215 AddPath(Base,
216 CXXSystem, true, false, false);
217 AddPath(Base + "/x86_64-w64-mingw32",
218 CXXSystem, true, false, false);
219 AddPath(Base + "/backward",
220 CXXSystem, true, false, false);
221}
222
Mike Stump620d57a2009-10-12 20:50:45 +0000223 // FIXME: This probably should goto to some platform utils place.
224#ifdef _MSC_VER
John Thompson75ee3bd2009-11-21 00:15:52 +0000225
Mike Stump620d57a2009-10-12 20:50:45 +0000226 // Read registry string.
John Thompson75ee3bd2009-11-21 00:15:52 +0000227 // This also supports a means to look for high-versioned keys by use
228 // of a $VERSION placeholder in the key path.
229 // $VERSION in the key path is a placeholder for the version number,
230 // causing the highest value path to be searched for and used.
231 // I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION".
232 // There can be additional characters in the component. Only the numberic
233 // characters are compared.
Benjamin Kramer6cd52162010-01-20 16:21:40 +0000234static bool getSystemRegistryString(const char *keyPath, const char *valueName,
235 char *value, size_t maxLength) {
Mike Stump43d81762009-10-08 23:29:47 +0000236 HKEY hRootKey = NULL;
237 HKEY hKey = NULL;
238 const char* subKey = NULL;
239 DWORD valueType;
240 DWORD valueSize = maxLength - 1;
John Thompson75ee3bd2009-11-21 00:15:52 +0000241 long lResult;
Mike Stump43d81762009-10-08 23:29:47 +0000242 bool returnValue = false;
243 if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) {
244 hRootKey = HKEY_CLASSES_ROOT;
245 subKey = keyPath + 18;
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +0000246 }
Mike Stump43d81762009-10-08 23:29:47 +0000247 else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) {
248 hRootKey = HKEY_USERS;
249 subKey = keyPath + 11;
250 }
251 else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) {
252 hRootKey = HKEY_LOCAL_MACHINE;
253 subKey = keyPath + 19;
254 }
255 else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) {
256 hRootKey = HKEY_CURRENT_USER;
257 subKey = keyPath + 18;
258 }
259 else
260 return(false);
John Thompson75ee3bd2009-11-21 00:15:52 +0000261 const char *placeHolder = strstr(subKey, "$VERSION");
262 char bestName[256];
263 bestName[0] = '\0';
264 // If we have a $VERSION placeholder, do the highest-version search.
265 if (placeHolder) {
266 const char *keyEnd = placeHolder - 1;
267 const char *nextKey = placeHolder;
268 // Find end of previous key.
269 while ((keyEnd > subKey) && (*keyEnd != '\\'))
270 keyEnd--;
271 // Find end of key containing $VERSION.
272 while (*nextKey && (*nextKey != '\\'))
273 nextKey++;
274 size_t partialKeyLength = keyEnd - subKey;
275 char partialKey[256];
276 if (partialKeyLength > sizeof(partialKey))
277 partialKeyLength = sizeof(partialKey);
278 strncpy(partialKey, subKey, partialKeyLength);
279 partialKey[partialKeyLength] = '\0';
280 HKEY hTopKey = NULL;
281 lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey);
282 if (lResult == ERROR_SUCCESS) {
283 char keyName[256];
284 int bestIndex = -1;
285 double bestValue = 0.0;
286 DWORD index, size = sizeof(keyName) - 1;
Nuno Lopes33cc2432009-12-07 17:18:48 +0000287 for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL,
288 NULL, NULL, NULL) == ERROR_SUCCESS; index++) {
289 const char *sp = keyName;
290 while (*sp && !isdigit(*sp))
291 sp++;
292 if (!*sp)
293 continue;
294 const char *ep = sp + 1;
295 while (*ep && (isdigit(*ep) || (*ep == '.')))
296 ep++;
297 char numBuf[32];
298 strncpy(numBuf, sp, sizeof(numBuf) - 1);
299 numBuf[sizeof(numBuf) - 1] = '\0';
300 double value = strtod(numBuf, NULL);
301 if (value > bestValue) {
302 bestIndex = (int)index;
303 bestValue = value;
304 strcpy(bestName, keyName);
305 }
John Thompson75ee3bd2009-11-21 00:15:52 +0000306 size = sizeof(keyName) - 1;
307 }
308 // If we found the highest versioned key, open the key and get the value.
309 if (bestIndex != -1) {
310 // Append rest of key.
311 strncat(bestName, nextKey, sizeof(bestName) - 1);
312 bestName[sizeof(bestName) - 1] = '\0';
313 // Open the chosen key path remainder.
314 lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey);
315 if (lResult == ERROR_SUCCESS) {
316 lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
317 (LPBYTE)value, &valueSize);
318 if (lResult == ERROR_SUCCESS)
319 returnValue = true;
320 RegCloseKey(hKey);
321 }
322 }
323 RegCloseKey(hTopKey);
324 }
325 }
326 else {
327 lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey);
328 if (lResult == ERROR_SUCCESS) {
329 lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
330 (LPBYTE)value, &valueSize);
331 if (lResult == ERROR_SUCCESS)
332 returnValue = true;
333 RegCloseKey(hKey);
334 }
Mike Stump43d81762009-10-08 23:29:47 +0000335 }
336 return(returnValue);
337}
Mike Stump620d57a2009-10-12 20:50:45 +0000338#else // _MSC_VER
339 // Read registry string.
Benjamin Kramer6cd52162010-01-20 16:21:40 +0000340static bool getSystemRegistryString(const char*, const char*, char*, size_t) {
Mike Stump620d57a2009-10-12 20:50:45 +0000341 return(false);
342}
343#endif // _MSC_VER
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +0000344
Mike Stump43d81762009-10-08 23:29:47 +0000345 // Get Visual Studio installation directory.
Benjamin Kramer6cd52162010-01-20 16:21:40 +0000346static bool getVisualStudioDir(std::string &path) {
Michael J. Spencerff58e362010-08-21 21:55:07 +0000347 // First check the environment variables that vsvars32.bat sets.
348 const char* vcinstalldir = getenv("VCINSTALLDIR");
349 if(vcinstalldir) {
350 char *p = const_cast<char *>(strstr(vcinstalldir, "\\VC"));
351 if (p)
352 *p = '\0';
353 path = vcinstalldir;
354 return(true);
355 }
356
John Thompson75ee3bd2009-11-21 00:15:52 +0000357 char vsIDEInstallDir[256];
Douglas Gregor80f93d92010-05-18 05:47:04 +0000358 char vsExpressIDEInstallDir[256];
Michael J. Spencerff58e362010-08-21 21:55:07 +0000359 // Then try the windows registry.
John Thompson75ee3bd2009-11-21 00:15:52 +0000360 bool hasVCDir = getSystemRegistryString(
361 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION",
362 "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1);
Douglas Gregor80f93d92010-05-18 05:47:04 +0000363 bool hasVCExpressDir = getSystemRegistryString(
364 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\$VERSION",
365 "InstallDir", vsExpressIDEInstallDir, sizeof(vsExpressIDEInstallDir) - 1);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000366 // If we have both vc80 and vc90, pick version we were compiled with.
John Thompson75ee3bd2009-11-21 00:15:52 +0000367 if (hasVCDir && vsIDEInstallDir[0]) {
Mike Stump620d57a2009-10-12 20:50:45 +0000368 char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE");
369 if (p)
370 *p = '\0';
371 path = vsIDEInstallDir;
372 return(true);
373 }
Douglas Gregor80f93d92010-05-18 05:47:04 +0000374 else if (hasVCExpressDir && vsExpressIDEInstallDir[0]) {
375 char *p = (char*)strstr(vsExpressIDEInstallDir, "\\Common7\\IDE");
376 if (p)
377 *p = '\0';
378 path = vsExpressIDEInstallDir;
379 return(true);
380 }
Mike Stump620d57a2009-10-12 20:50:45 +0000381 else {
382 // Try the environment.
Douglas Gregor80f93d92010-05-18 05:47:04 +0000383 const char* vs100comntools = getenv("VS100COMNTOOLS");
Mike Stump620d57a2009-10-12 20:50:45 +0000384 const char* vs90comntools = getenv("VS90COMNTOOLS");
385 const char* vs80comntools = getenv("VS80COMNTOOLS");
386 const char* vscomntools = NULL;
Douglas Gregor80f93d92010-05-18 05:47:04 +0000387
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000388 // Try to find the version that we were compiled with
Douglas Gregor80f93d92010-05-18 05:47:04 +0000389 if(false) {}
390 #if (_MSC_VER >= 1600) // VC100
391 else if(vs100comntools) {
392 vscomntools = vs100comntools;
Mike Stump620d57a2009-10-12 20:50:45 +0000393 }
Douglas Gregor80f93d92010-05-18 05:47:04 +0000394 #elif (_MSC_VER == 1500) // VC80
395 else if(vs90comntools) {
396 vscomntools = vs90comntools;
397 }
398 #elif (_MSC_VER == 1400) // VC80
399 else if(vs80comntools) {
400 vscomntools = vs80comntools;
401 }
402 #endif
403 // Otherwise find any version we can
404 else if (vs100comntools)
405 vscomntools = vs100comntools;
Mike Stump620d57a2009-10-12 20:50:45 +0000406 else if (vs90comntools)
Mike Stump43d81762009-10-08 23:29:47 +0000407 vscomntools = vs90comntools;
Mike Stump620d57a2009-10-12 20:50:45 +0000408 else if (vs80comntools)
409 vscomntools = vs80comntools;
Douglas Gregor80f93d92010-05-18 05:47:04 +0000410
Mike Stump620d57a2009-10-12 20:50:45 +0000411 if (vscomntools && *vscomntools) {
Dan Gohmancb421fa2010-04-19 16:39:44 +0000412 char *p = const_cast<char *>(strstr(vscomntools, "\\Common7\\Tools"));
Mike Stump620d57a2009-10-12 20:50:45 +0000413 if (p)
414 *p = '\0';
415 path = vscomntools;
416 return(true);
417 }
418 else
419 return(false);
Mike Stump43d81762009-10-08 23:29:47 +0000420 }
Mike Stump620d57a2009-10-12 20:50:45 +0000421 return(false);
Mike Stump43d81762009-10-08 23:29:47 +0000422}
Mike Stump43d81762009-10-08 23:29:47 +0000423
John Thompson75ee3bd2009-11-21 00:15:52 +0000424 // Get Windows SDK installation directory.
Benjamin Kramer6cd52162010-01-20 16:21:40 +0000425static bool getWindowsSDKDir(std::string &path) {
John Thompson75ee3bd2009-11-21 00:15:52 +0000426 char windowsSDKInstallDir[256];
427 // Try the Windows registry.
428 bool hasSDKDir = getSystemRegistryString(
429 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
430 "InstallationFolder", windowsSDKInstallDir, sizeof(windowsSDKInstallDir) - 1);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000431 // If we have both vc80 and vc90, pick version we were compiled with.
John Thompson75ee3bd2009-11-21 00:15:52 +0000432 if (hasSDKDir && windowsSDKInstallDir[0]) {
433 path = windowsSDKInstallDir;
434 return(true);
435 }
436 return(false);
437}
438
mike-m79bc57c2010-05-16 19:03:52 +0000439void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
440 const HeaderSearchOptions &HSOpts) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000441 llvm::Triple::OSType os = triple.getOS();
442
443 switch (os) {
Roman Divacky63076602011-03-01 18:08:03 +0000444 case llvm::Triple::FreeBSD:
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000445 case llvm::Triple::NetBSD:
446 break;
447 default:
448 // FIXME: temporary hack: hard-coded paths.
449 AddPath("/usr/local/include", System, true, false, false);
450 break;
451 }
mike-m79bc57c2010-05-16 19:03:52 +0000452
453 // Builtin includes use #include_next directives and should be positioned
454 // just prior C include dirs.
455 if (HSOpts.UseBuiltinIncludes) {
456 // Ignore the sys root, we *always* look for clang headers relative to
457 // supplied path.
458 llvm::sys::Path P(HSOpts.ResourceDir);
459 P.appendComponent("include");
460 AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true);
461 }
462
463 // Add dirs specified via 'configure --with-c-include-dirs'.
Daniel Dunbarc7064682009-11-12 07:28:29 +0000464 llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS);
465 if (CIncludeDirs != "") {
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000466 llvm::SmallVector<llvm::StringRef, 5> dirs;
467 CIncludeDirs.split(dirs, ":");
468 for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin();
469 i != dirs.end();
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000470 ++i)
Rafael Espindolaf0a2f512009-11-12 05:48:41 +0000471 AddPath(*i, System, false, false, false);
472 return;
473 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000474
Mike Stump43d81762009-10-08 23:29:47 +0000475 switch (os) {
Daniel Dunbard11ee7f2010-09-09 17:38:18 +0000476 case llvm::Triple::Win32: {
477 std::string VSDir;
478 std::string WindowsSDKDir;
479 if (getVisualStudioDir(VSDir)) {
480 AddPath(VSDir + "\\VC\\include", System, false, false, false);
481 if (getWindowsSDKDir(WindowsSDKDir))
482 AddPath(WindowsSDKDir + "\\include", System, false, false, false);
483 else
484 AddPath(VSDir + "\\VC\\PlatformSDK\\Include",
485 System, false, false, false);
486 } else {
487 // Default install paths.
488 AddPath("C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
489 System, false, false, false);
490 AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
491 System, false, false, false);
492 AddPath(
John Thompson9319f022009-11-23 17:49:27 +0000493 "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
Daniel Dunbard11ee7f2010-09-09 17:38:18 +0000494 System, false, false, false);
495 AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include",
496 System, false, false, false);
497 AddPath(
John Thompson9319f022009-11-23 17:49:27 +0000498 "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include",
Daniel Dunbard11ee7f2010-09-09 17:38:18 +0000499 System, false, false, false);
Mike Stump43d81762009-10-08 23:29:47 +0000500 }
501 break;
Daniel Dunbard11ee7f2010-09-09 17:38:18 +0000502 }
Chris Lattner86ed3a32010-04-11 19:29:39 +0000503 case llvm::Triple::Haiku:
504 AddPath("/boot/common/include", System, true, false, false);
505 AddPath("/boot/develop/headers/os", System, true, false, false);
506 AddPath("/boot/develop/headers/os/app", System, true, false, false);
507 AddPath("/boot/develop/headers/os/arch", System, true, false, false);
508 AddPath("/boot/develop/headers/os/device", System, true, false, false);
509 AddPath("/boot/develop/headers/os/drivers", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000510 AddPath("/boot/develop/headers/os/game", System, true, false, false);
Chris Lattner86ed3a32010-04-11 19:29:39 +0000511 AddPath("/boot/develop/headers/os/interface", System, true, false, false);
512 AddPath("/boot/develop/headers/os/kernel", System, true, false, false);
513 AddPath("/boot/develop/headers/os/locale", System, true, false, false);
514 AddPath("/boot/develop/headers/os/mail", System, true, false, false);
515 AddPath("/boot/develop/headers/os/media", System, true, false, false);
516 AddPath("/boot/develop/headers/os/midi", System, true, false, false);
517 AddPath("/boot/develop/headers/os/midi2", System, true, false, false);
518 AddPath("/boot/develop/headers/os/net", System, true, false, false);
519 AddPath("/boot/develop/headers/os/storage", System, true, false, false);
520 AddPath("/boot/develop/headers/os/support", System, true, false, false);
521 AddPath("/boot/develop/headers/os/translation",
522 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000523 AddPath("/boot/develop/headers/os/add-ons/graphics",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000524 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000525 AddPath("/boot/develop/headers/os/add-ons/input_server",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000526 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000527 AddPath("/boot/develop/headers/os/add-ons/screen_saver",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000528 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000529 AddPath("/boot/develop/headers/os/add-ons/tracker",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000530 System, true, false, false);
531 AddPath("/boot/develop/headers/os/be_apps/Deskbar",
532 System, true, false, false);
533 AddPath("/boot/develop/headers/os/be_apps/NetPositive",
534 System, true, false, false);
535 AddPath("/boot/develop/headers/os/be_apps/Tracker",
536 System, true, false, false);
537 AddPath("/boot/develop/headers/cpp", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000538 AddPath("/boot/develop/headers/cpp/i586-pc-haiku",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000539 System, true, false, false);
540 AddPath("/boot/develop/headers/3rdparty", System, true, false, false);
541 AddPath("/boot/develop/headers/bsd", System, true, false, false);
542 AddPath("/boot/develop/headers/glibc", System, true, false, false);
543 AddPath("/boot/develop/headers/posix", System, true, false, false);
544 AddPath("/boot/develop/headers", System, true, false, false);
Eli Friedmana7e68452010-08-22 01:00:03 +0000545 break;
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000546 case llvm::Triple::Cygwin:
547 AddPath("/usr/include/w32api", System, true, false, false);
548 break;
Mike Stump620d57a2009-10-12 20:50:45 +0000549 case llvm::Triple::MinGW32:
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000550 // FIXME: We should be aware of i686-w64-mingw32.
551 if (triple.getArch() == llvm::Triple::x86_64)
552 AddPath("c:/mingw/x86_64-w64-mingw32/include",
553 System, true, false, false);
Douglas Gregorab0d8bd2011-03-06 18:00:59 +0000554 AddPath("/mingw/include", System, true, false, false);
Mike Stump43d81762009-10-08 23:29:47 +0000555 AddPath("c:/mingw/include", System, true, false, false);
556 break;
557 default:
Mike Stump43d81762009-10-08 23:29:47 +0000558 break;
559 }
John Thompsond3f88342009-10-13 18:51:32 +0000560
John Thompsond3f88342009-10-13 18:51:32 +0000561 AddPath("/usr/include", System, false, false, false);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000562}
563
Chris Lattner0e3cc052010-05-05 05:28:39 +0000564void InitHeaderSearch::
565AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000566 llvm::Triple::OSType os = triple.getOS();
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000567 llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT);
568 if (CxxIncludeRoot != "") {
569 llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH);
570 if (CxxIncludeArch == "")
571 AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(),
Chris Lattner0e3cc052010-05-05 05:28:39 +0000572 CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR,
573 triple);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000574 else
575 AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH,
Chris Lattner0e3cc052010-05-05 05:28:39 +0000576 CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR,
577 triple);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000578 return;
579 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000580 // FIXME: temporary hack: hard-coded paths.
581 switch (os) {
582 case llvm::Triple::Cygwin:
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000583 // Cygwin-1.7
584 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
585 // g++-4 / Cygwin-1.5
586 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
587 // FIXME: Do we support g++-3.4.4?
588 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4");
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000589 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000590 case llvm::Triple::MinGW32:
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000591 // FIXME: We should be aware of i686-w64-mingw32.
592 if (triple.getArch() == llvm::Triple::x86_64) {
593 // mingw-w64-20110207
594 AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.3");
595 // mingw-w64-20101129
596 AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.2");
597 }
Douglas Gregorab0d8bd2011-03-06 18:00:59 +0000598 // Try gcc 4.5.2 (MSYS)
599 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2");
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000600 // Try gcc 4.5.0
601 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000602 // Try gcc 4.4.0
603 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
604 // Try gcc 4.3.0
605 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
606 break;
607 case llvm::Triple::Darwin:
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000608 switch (triple.getArch()) {
609 default: break;
610
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000611 case llvm::Triple::ppc:
Douglas Gregor582c3012010-05-29 01:15:12 +0000612 case llvm::Triple::ppc64:
Douglas Gregor616d4362010-05-29 01:21:11 +0000613 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000614 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor616d4362010-05-29 01:21:11 +0000615 triple);
Douglas Gregor582c3012010-05-29 01:15:12 +0000616 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000617 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor582c3012010-05-29 01:15:12 +0000618 triple);
619 break;
620
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000621 case llvm::Triple::x86:
622 case llvm::Triple::x86_64:
623 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
624 "i686-apple-darwin10", "", "x86_64", triple);
625 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
626 "i686-apple-darwin8", "", "", triple);
627 break;
628
629 case llvm::Triple::arm:
630 case llvm::Triple::thumb:
631 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
632 "arm-apple-darwin10", "v7", "", triple);
633 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
634 "arm-apple-darwin10", "v6", "", triple);
635 break;
636 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000637 break;
Chris Lattner7a7ca282010-01-09 05:41:14 +0000638 case llvm::Triple::DragonFly:
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000639 AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false);
Chris Lattner7a7ca282010-01-09 05:41:14 +0000640 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000641 case llvm::Triple::Linux:
mike-mac78b7a2010-05-06 14:11:13 +0000642 //===------------------------------------------------------------------===//
643 // Debian based distros.
644 // Note: these distros symlink /usr/include/c++/X.Y.Z -> X.Y
645 //===------------------------------------------------------------------===//
Rafael Espindolac12bbe52011-02-15 21:44:06 +0000646 // Ubuntu 10.10 "Maverick Meerkat" -- gcc-4.4.5
Rafael Espindolaadafdba2011-02-15 21:16:43 +0000647 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
648 "i686-linux-gnu", "", "64", triple);
649 // The rest of 10.10 is the same as previous versions.
650
mike-mac78b7a2010-05-06 14:11:13 +0000651 // Ubuntu 10.04 LTS "Lucid Lynx" -- gcc-4.4.3
652 // Ubuntu 9.10 "Karmic Koala" -- gcc-4.4.1
653 // Debian 6.0 "squeeze" -- gcc-4.4.2
654 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
655 "x86_64-linux-gnu", "32", "", triple);
656 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
657 "i486-linux-gnu", "", "64", triple);
Nick Lewyckydb083552011-02-01 21:32:14 +0000658 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
659 "arm-linux-gnueabi", "", "", triple);
mike-mac78b7a2010-05-06 14:11:13 +0000660 // Ubuntu 9.04 "Jaunty Jackalope" -- gcc-4.3.3
661 // Ubuntu 8.10 "Intrepid Ibex" -- gcc-4.3.2
662 // Debian 5.0 "lenny" -- gcc-4.3.2
663 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
664 "x86_64-linux-gnu", "32", "", triple);
665 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
666 "i486-linux-gnu", "", "64", triple);
Rafael Espindolae7d6c2c2010-06-04 14:28:10 +0000667 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
668 "arm-linux-gnueabi", "", "", triple);
mike-mac78b7a2010-05-06 14:11:13 +0000669 // Ubuntu 8.04.4 LTS "Hardy Heron" -- gcc-4.2.4
670 // Ubuntu 8.04.[0-3] LTS "Hardy Heron" -- gcc-4.2.3
671 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2",
672 "x86_64-linux-gnu", "32", "", triple);
673 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2",
674 "i486-linux-gnu", "", "64", triple);
675 // Ubuntu 7.10 "Gutsy Gibbon" -- gcc-4.1.3
676 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1",
677 "x86_64-linux-gnu", "32", "", triple);
678 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1",
679 "i486-linux-gnu", "", "64", triple);
680
681 //===------------------------------------------------------------------===//
682 // Redhat based distros.
683 //===------------------------------------------------------------------===//
Eric Christopher8f1cc072011-04-06 18:22:53 +0000684 // Fedora 15
685 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0",
686 "x86_64-redhat-linux", "32", "", triple);
687 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0",
688 "i686-redhat-linux", "", "", triple);
Rafael Espindola6638b3a2010-11-02 18:39:34 +0000689 // Fedora 14
690 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1",
691 "x86_64-redhat-linux", "32", "", triple);
692 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1",
693 "i686-redhat-linux", "", "", triple);
mike-mac78b7a2010-05-06 14:11:13 +0000694 // Fedora 13
Chris Lattner4336e192010-05-29 01:01:38 +0000695 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4",
696 "x86_64-redhat-linux", "32", "", triple);
697 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4",
698 "i686-redhat-linux","", "", triple);
mike-mac78b7a2010-05-06 14:11:13 +0000699 // Fedora 12
700 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3",
701 "x86_64-redhat-linux", "32", "", triple);
702 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3",
703 "i686-redhat-linux","", "", triple);
704 // Fedora 12 (pre-FEB-2010)
705 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2",
706 "x86_64-redhat-linux", "32", "", triple);
707 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2",
708 "i686-redhat-linux","", "", triple);
709 // Fedora 11
710 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1",
711 "x86_64-redhat-linux", "32", "", triple);
712 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1",
713 "i586-redhat-linux","", "", triple);
714 // Fedora 10
715 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2",
716 "x86_64-redhat-linux", "32", "", triple);
717 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2",
718 "i386-redhat-linux","", "", triple);
719 // Fedora 9
720 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0",
721 "x86_64-redhat-linux", "32", "", triple);
722 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0",
723 "i386-redhat-linux", "", "", triple);
724 // Fedora 8
725 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2",
726 "x86_64-redhat-linux", "", "", triple);
727 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2",
728 "i386-redhat-linux", "", "", triple);
729
730 //===------------------------------------------------------------------===//
731
Benjamin Kramer0db3d722010-01-25 12:20:15 +0000732 // Exherbo (2010-01-25)
733 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3",
Torok Edwinfc4b8992009-12-18 17:29:14 +0000734 "x86_64-pc-linux-gnu", "32", "", triple);
Benjamin Kramer0db3d722010-01-25 12:20:15 +0000735 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3",
Torok Edwinfc4b8992009-12-18 17:29:14 +0000736 "i686-pc-linux-gnu", "", "", triple);
Chris Lattnerea00f842010-04-23 15:55:20 +0000737
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000738 // openSUSE 11.1 32 bit
739 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000740 "i586-suse-linux", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000741 // openSUSE 11.1 64 bit
742 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000743 "x86_64-suse-linux", "32", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000744 // openSUSE 11.2
745 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000746 "i586-suse-linux", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000747 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000748 "x86_64-suse-linux", "", "", triple);
Rafael Espindola9d2c0602010-11-25 18:51:59 +0000749
750 // openSUSE 11.4
751 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5",
752 "i586-suse-linux", "", "", triple);
753 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5",
754 "x86_64-suse-linux", "", "", triple);
755
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000756 // Arch Linux 2008-06-24
757 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000758 "i686-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000759 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000760 "x86_64-unknown-linux-gnu", "", "", triple);
Douglas Gregor53703832011-03-14 15:33:44 +0000761 // Gentoo x86 gcc 4.5.2
762 AddGnuCPlusPlusIncludePaths(
763 "/usr/lib/gcc/i686-pc-linux-gnu/4.5.2/include/g++-v4",
764 "i686-pc-linux-gnu", "", "", triple);
765 // Gentoo x86 gcc 4.4.5
766 AddGnuCPlusPlusIncludePaths(
767 "/usr/lib/gcc/i686-pc-linux-gnu/4.4.5/include/g++-v4",
768 "i686-pc-linux-gnu", "", "", triple);
769 // Gentoo x86 gcc 4.4.4
770 AddGnuCPlusPlusIncludePaths(
771 "/usr/lib/gcc/i686-pc-linux-gnu/4.4.4/include/g++-v4",
772 "i686-pc-linux-gnu", "", "", triple);
773 // Gentoo x86 2010.0 stable
Nuno Lopes0d155a52010-09-11 17:51:45 +0000774 AddGnuCPlusPlusIncludePaths(
775 "/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/g++-v4",
776 "i686-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000777 // Gentoo x86 2009.1 stable
778 AddGnuCPlusPlusIncludePaths(
John Thompson40d1bb62009-11-05 22:03:02 +0000779 "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000780 "i686-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000781 // Gentoo x86 2009.0 stable
782 AddGnuCPlusPlusIncludePaths(
John Thompson40d1bb62009-11-05 22:03:02 +0000783 "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000784 "i686-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000785 // Gentoo x86 2008.0 stable
786 AddGnuCPlusPlusIncludePaths(
John Thompson40d1bb62009-11-05 22:03:02 +0000787 "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000788 "i686-pc-linux-gnu", "", "", triple);
Douglas Gregor53703832011-03-14 15:33:44 +0000789 // Gentoo x86 llvm-gcc trunk
790 AddGnuCPlusPlusIncludePaths(
791 "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1",
792 "i686-pc-linux-gnu", "", "", triple);
Nick Lewycky66935342010-07-24 21:33:13 +0000793
Douglas Gregor53703832011-03-14 15:33:44 +0000794 // Gentoo amd64 gcc 4.5.2
795 AddGnuCPlusPlusIncludePaths(
796 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4",
797 "x86_64-pc-linux-gnu", "32", "", triple);
Chandler Carruthfbfdb202010-11-28 07:20:14 +0000798 // Gentoo amd64 gcc 4.4.5
799 AddGnuCPlusPlusIncludePaths(
800 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include/g++-v4",
801 "x86_64-pc-linux-gnu", "32", "", triple);
Nico Weber8ad8a1c2010-11-16 12:42:55 +0000802 // Gentoo amd64 gcc 4.4.4
803 AddGnuCPlusPlusIncludePaths(
804 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4",
805 "x86_64-pc-linux-gnu", "32", "", triple);
Chandler Carruthfbfdb202010-11-28 07:20:14 +0000806 // Gentoo amd64 gcc 4.4.3
807 AddGnuCPlusPlusIncludePaths(
808 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4",
809 "x86_64-pc-linux-gnu", "32", "", triple);
810 // Gentoo amd64 gcc 4.3.2
811 AddGnuCPlusPlusIncludePaths(
812 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4",
813 "x86_64-pc-linux-gnu", "", "", triple);
814 // Gentoo amd64 stable
815 AddGnuCPlusPlusIncludePaths(
816 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4",
Douglas Gregor53703832011-03-14 15:33:44 +0000817 "x86_64-pc-linux-gnu", "", "", triple);
Nico Weber8ad8a1c2010-11-16 12:42:55 +0000818
Nick Lewycky66935342010-07-24 21:33:13 +0000819 // Gentoo amd64 llvm-gcc trunk
820 AddGnuCPlusPlusIncludePaths(
821 "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1",
822 "x86_64-pc-linux-gnu", "", "", triple);
Chandler Carruthfbfdb202010-11-28 07:20:14 +0000823
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000824 break;
825 case llvm::Triple::FreeBSD:
mike-mac78b7a2010-05-06 14:11:13 +0000826 // FreeBSD 8.0
827 // FreeBSD 7.3
Nuno Lopesafe859a2010-01-17 00:00:11 +0000828 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000829 break;
Anton Korobeynikovab079412010-08-31 22:39:50 +0000830 case llvm::Triple::NetBSD:
831 AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple);
832 break;
Daniel Dunbar95c04572010-08-01 23:13:54 +0000833 case llvm::Triple::OpenBSD: {
834 std::string t = triple.getTriple();
835 if (t.substr(0, 6) == "x86_64")
836 t.replace(0, 6, "amd64");
837 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
838 t, "", "", triple);
839 break;
840 }
Chris Lattner38e317d2010-07-07 16:01:42 +0000841 case llvm::Triple::Minix:
842 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
843 "", "", "", triple);
844 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000845 case llvm::Triple::Solaris:
846 // Solaris - Fall though..
847 case llvm::Triple::AuroraUX:
848 // AuroraUX
849 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000850 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000851 break;
852 default:
853 break;
854 }
855}
856
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000857void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
Douglas Gregor4c2bcad2010-03-24 20:13:48 +0000858 const llvm::Triple &triple,
mike-m79bc57c2010-05-16 19:03:52 +0000859 const HeaderSearchOptions &HSOpts) {
Joerg Sonnenberger0bb208c2011-02-22 15:19:35 +0000860 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes)
861 AddDefaultCPlusPlusIncludePaths(triple);
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000862
mike-m79bc57c2010-05-16 19:03:52 +0000863 AddDefaultCIncludePaths(triple, HSOpts);
Daniel Dunbare1665822009-11-07 04:20:39 +0000864
865 // Add the default framework include paths on Darwin.
866 if (triple.getOS() == llvm::Triple::Darwin) {
867 AddPath("/System/Library/Frameworks", System, true, false, true);
868 AddPath("/Library/Frameworks", System, true, false, true);
869 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000870}
871
Nico Weber0fca0222008-08-22 09:25:22 +0000872/// RemoveDuplicates - If there are duplicate directory entries in the specified
873/// search list, remove the later (dead) ones.
874static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000875 unsigned First, bool Verbose) {
Nico Weber0fca0222008-08-22 09:25:22 +0000876 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
877 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
878 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000879 for (unsigned i = First; i != SearchList.size(); ++i) {
Chris Lattner7a739402008-09-26 17:46:45 +0000880 unsigned DirToRemove = i;
Mike Stump1eb44332009-09-09 15:08:12 +0000881
Chris Lattner43eee072009-02-08 01:00:10 +0000882 const DirectoryLookup &CurEntry = SearchList[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000883
Chris Lattner43eee072009-02-08 01:00:10 +0000884 if (CurEntry.isNormalDir()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000885 // If this isn't the first time we've seen this dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000886 if (SeenDirs.insert(CurEntry.getDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000887 continue;
Chris Lattner43eee072009-02-08 01:00:10 +0000888 } else if (CurEntry.isFramework()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000889 // If this isn't the first time we've seen this framework dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000890 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000891 continue;
Nico Weber0fca0222008-08-22 09:25:22 +0000892 } else {
Chris Lattner43eee072009-02-08 01:00:10 +0000893 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
Nico Weber0fca0222008-08-22 09:25:22 +0000894 // If this isn't the first time we've seen this headermap, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000895 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
Nico Weber0fca0222008-08-22 09:25:22 +0000896 continue;
Chris Lattner30f05b52009-02-08 00:55:22 +0000897 }
Mike Stump1eb44332009-09-09 15:08:12 +0000898
Chris Lattner30f05b52009-02-08 00:55:22 +0000899 // If we have a normal #include dir/framework/headermap that is shadowed
900 // later in the chain by a system include location, we actually want to
901 // ignore the user's request and drop the user dir... keeping the system
902 // dir. This is weird, but required to emulate GCC's search path correctly.
903 //
904 // Since dupes of system dirs are rare, just rescan to find the original
905 // that we're nuking instead of using a DenseMap.
Chris Lattner43eee072009-02-08 01:00:10 +0000906 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
Chris Lattner30f05b52009-02-08 00:55:22 +0000907 // Find the dir that this is the same of.
908 unsigned FirstDir;
909 for (FirstDir = 0; ; ++FirstDir) {
910 assert(FirstDir != i && "Didn't find dupe?");
Mike Stump1eb44332009-09-09 15:08:12 +0000911
Chris Lattner43eee072009-02-08 01:00:10 +0000912 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
913
Chris Lattner30f05b52009-02-08 00:55:22 +0000914 // If these are different lookup types, then they can't be the dupe.
Chris Lattner43eee072009-02-08 01:00:10 +0000915 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
Chris Lattner30f05b52009-02-08 00:55:22 +0000916 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000917
Chris Lattner30f05b52009-02-08 00:55:22 +0000918 bool isSame;
Chris Lattner43eee072009-02-08 01:00:10 +0000919 if (CurEntry.isNormalDir())
920 isSame = SearchEntry.getDir() == CurEntry.getDir();
921 else if (CurEntry.isFramework())
922 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
Chris Lattner30f05b52009-02-08 00:55:22 +0000923 else {
Chris Lattner43eee072009-02-08 01:00:10 +0000924 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
925 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
Chris Lattner30f05b52009-02-08 00:55:22 +0000926 }
Mike Stump1eb44332009-09-09 15:08:12 +0000927
Chris Lattner30f05b52009-02-08 00:55:22 +0000928 if (isSame)
929 break;
930 }
Mike Stump1eb44332009-09-09 15:08:12 +0000931
Chris Lattner30f05b52009-02-08 00:55:22 +0000932 // If the first dir in the search path is a non-system dir, zap it
933 // instead of the system one.
934 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
935 DirToRemove = FirstDir;
936 }
937
938 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000939 llvm::errs() << "ignoring duplicate directory \""
940 << CurEntry.getName() << "\"\n";
Chris Lattner30f05b52009-02-08 00:55:22 +0000941 if (DirToRemove != i)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000942 llvm::errs() << " as it is a non-system directory that duplicates "
943 << "a system directory\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000944 }
Mike Stump1eb44332009-09-09 15:08:12 +0000945
Chris Lattner7a739402008-09-26 17:46:45 +0000946 // This is reached if the current entry is a duplicate. Remove the
947 // DirToRemove (usually the current dir).
948 SearchList.erase(SearchList.begin()+DirToRemove);
Nico Weber0fca0222008-08-22 09:25:22 +0000949 --i;
950 }
951}
952
953
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000954void InitHeaderSearch::Realize(const LangOptions &Lang) {
Nico Weber0fca0222008-08-22 09:25:22 +0000955 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
956 std::vector<DirectoryLookup> SearchList;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000957 SearchList.reserve(IncludePath.size());
Mike Stump1eb44332009-09-09 15:08:12 +0000958
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000959 /* Quoted arguments go first. */
960 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
961 it != ie; ++it) {
962 if (it->first == Quoted)
963 SearchList.push_back(it->second);
964 }
965 /* Deduplicate and remember index */
966 RemoveDuplicates(SearchList, 0, Verbose);
967 unsigned quoted = SearchList.size();
Mike Stump1eb44332009-09-09 15:08:12 +0000968
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000969 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
970 it != ie; ++it) {
971 if (it->first == Angled)
972 SearchList.push_back(it->second);
973 }
974
975 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
976 it != ie; ++it) {
977 if (it->first == System || (Lang.CPlusPlus && it->first == CXXSystem))
978 SearchList.push_back(it->second);
979 }
980
981 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
982 it != ie; ++it) {
983 if (it->first == After)
984 SearchList.push_back(it->second);
985 }
986
987 RemoveDuplicates(SearchList, quoted, Verbose);
Nico Weber0fca0222008-08-22 09:25:22 +0000988
989 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000990 Headers.SetSearchPaths(SearchList, quoted, DontSearchCurDir);
Nico Weber0fca0222008-08-22 09:25:22 +0000991
992 // If verbose, print the list of directories that will be searched.
993 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000994 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000995 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000996 if (i == quoted)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000997 llvm::errs() << "#include <...> search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000998 const char *Name = SearchList[i].getName();
999 const char *Suffix;
1000 if (SearchList[i].isNormalDir())
1001 Suffix = "";
1002 else if (SearchList[i].isFramework())
1003 Suffix = " (framework directory)";
1004 else {
1005 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
1006 Suffix = " (headermap)";
1007 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +00001008 llvm::errs() << " " << Name << Suffix << "\n";
Nico Weber0fca0222008-08-22 09:25:22 +00001009 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +00001010 llvm::errs() << "End of search list.\n";
Nico Weber0fca0222008-08-22 09:25:22 +00001011 }
1012}
Daniel Dunbar63c8b772009-11-07 04:20:50 +00001013
Daniel Dunbar5814e652009-11-11 21:44:21 +00001014void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
1015 const HeaderSearchOptions &HSOpts,
1016 const LangOptions &Lang,
Daniel Dunbar63c8b772009-11-07 04:20:50 +00001017 const llvm::Triple &Triple) {
1018 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
1019
1020 // Add the user defined entries.
1021 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
1022 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Daniel Dunbar1b483e72009-11-17 05:04:15 +00001023 Init.AddPath(E.Path, E.Group, false, E.IsUserSupplied, E.IsFramework,
Chris Lattner23637be2010-08-24 22:27:37 +00001024 !E.IsSysRootRelative);
Daniel Dunbar63c8b772009-11-07 04:20:50 +00001025 }
1026
1027 // Add entries from CPATH and friends.
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +00001028 Init.AddDelimitedPaths(HSOpts.EnvIncPath);
Daniel Dunbarc363cb12009-11-16 22:38:40 +00001029 if (Lang.CPlusPlus && Lang.ObjC1)
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +00001030 Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath);
Daniel Dunbarc363cb12009-11-16 22:38:40 +00001031 else if (Lang.CPlusPlus)
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +00001032 Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath);
Daniel Dunbarc363cb12009-11-16 22:38:40 +00001033 else if (Lang.ObjC1)
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +00001034 Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath);
Daniel Dunbarc363cb12009-11-16 22:38:40 +00001035 else
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +00001036 Init.AddDelimitedPaths(HSOpts.CEnvIncPath);
Daniel Dunbar63c8b772009-11-07 04:20:50 +00001037
Daniel Dunbardd35ce92009-11-07 04:58:12 +00001038 if (HSOpts.UseStandardIncludes)
mike-m79bc57c2010-05-16 19:03:52 +00001039 Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts);
Daniel Dunbar63c8b772009-11-07 04:20:50 +00001040
Joerg Sonnenberger2df66472011-02-22 00:40:56 +00001041 Init.Realize(Lang);
Daniel Dunbar63c8b772009-11-07 04:20:50 +00001042}