InitHeaderSearch.cpp 45 KB

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