InitHeaderSearch.cpp revision e87e851fcebaf27341858b55fa3f46b9ce23a207
1df22c2cc7703c7df04eadd2e6e59c61f545a5741Nick Lewycky//===--- InitHeaderSearch.cpp - Initialize header search paths ------------===// 20fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 30fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// The LLVM Compiler Infrastructure 40fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 50fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// This file is distributed under the University of Illinois Open Source 60fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// License. See LICENSE.TXT for details. 70fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 80fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber//===----------------------------------------------------------------------===// 90fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 100fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// This file implements the InitHeaderSearch class. 110fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 120fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber//===----------------------------------------------------------------------===// 130fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 142cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar#include "clang/Frontend/Utils.h" 150fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "clang/Basic/FileManager.h" 160fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "clang/Basic/LangOptions.h" 1763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#include "clang/Frontend/HeaderSearchOptions.h" 1863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#include "clang/Lex/HeaderSearch.h" 190fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "llvm/ADT/SmallString.h" 200fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "llvm/ADT/SmallPtrSet.h" 21aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola#include "llvm/ADT/SmallVector.h" 22f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola#include "llvm/ADT/StringExtras.h" 232cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar#include "llvm/ADT/Triple.h" 24e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer#include "llvm/ADT/Twine.h" 25d57a7ef9252964bc6c8471451d7bd395b0520cb8Chris Lattner#include "llvm/Support/raw_ostream.h" 26ca23419b8214654d185d595956e9ddf24984750aChandler Carruth#include "llvm/Support/ErrorHandling.h" 2703013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/Path.h" 2869d3b4f7c9fa818d2536b4f1b220b942ae392128Dylan Noblesmith 29cc8a94565ec2ff459dcee9ef34237fdcdfc69b3fDylan Noblesmith#include "clang/Config/config.h" // C_INCLUDE_DIRS 3069d3b4f7c9fa818d2536b4f1b220b942ae392128Dylan Noblesmith 310fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weberusing namespace clang; 322cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarusing namespace clang::frontend; 332cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 342cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarnamespace { 352cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 362cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar/// InitHeaderSearch - This class makes it easier to set the search paths of 372cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar/// a HeaderSearch object. InitHeaderSearch stores several search path lists 382cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar/// internally, which can be sent to a HeaderSearch object in one swoop. 392cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarclass InitHeaderSearch { 402df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath; 412df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger typedef std::vector<std::pair<IncludeDirGroup, 422df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger DirectoryLookup> >::const_iterator path_iterator; 43ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner HeaderSearch &Headers; 442cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool Verbose; 45af6530c938bfc60902f0dfec1c0808aedbee1663Michael J. Spencer std::string IncludeSysroot; 46af6530c938bfc60902f0dfec1c0808aedbee1663Michael J. Spencer bool IsNotEmptyOrRoot; 472cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 482cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarpublic: 492cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 505f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot) 51af6530c938bfc60902f0dfec1c0808aedbee1663Michael J. Spencer : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot), 52af6530c938bfc60902f0dfec1c0808aedbee1663Michael J. Spencer IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) { 53c09265a5fd94af5dcfd7325d0cb4f04197d65afcChandler Carruth } 542cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 552cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddPath - Add the specified path to the specified group list. 565f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void AddPath(const Twine &Path, IncludeDirGroup Group, 572cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool isCXXAware, bool isUserSupplied, 582cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool isFramework, bool IgnoreSysRoot = false); 592cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 60a608737659d4330d9ae7622bf1a87c33b9d97072mike-m /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu 612cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// libstdc++. 625f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void AddGnuCPlusPlusIncludePaths(StringRef Base, 635f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef ArchDir, 645f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Dir32, 655f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Dir64, 662cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar const llvm::Triple &triple); 672cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 6806a8dc616ec8324694d45cd4d724634a899be9a3Michael J. Spencer /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW 692cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// libstdc++. 705f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void AddMinGWCPlusPlusIncludePaths(StringRef Base, 715f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Arch, 725f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Version); 732cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 749db48467f19d4f0929a5ba40c5e2bd7255dc95f0NAKAMURA Takumi /// AddMinGW64CXXPaths - Add the necessary paths to support 759db48467f19d4f0929a5ba40c5e2bd7255dc95f0NAKAMURA Takumi /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64. 765f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void AddMinGW64CXXPaths(StringRef Base, 775f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Version); 789db48467f19d4f0929a5ba40c5e2bd7255dc95f0NAKAMURA Takumi 792cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar // AddDefaultCIncludePaths - Add paths that should always be searched. 8079bc57c074cb91f574fba19215f95b63dcf6b04bmike-m void AddDefaultCIncludePaths(const llvm::Triple &triple, 8179bc57c074cb91f574fba19215f95b63dcf6b04bmike-m const HeaderSearchOptions &HSOpts); 822cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 832cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when 842cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar // compiling c++. 85d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, 86d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor const HeaderSearchOptions &HSOpts); 872cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 882cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddDefaultSystemIncludePaths - Adds the default system include paths so 892cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// that e.g. stdio.h is found. 90a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar void AddDefaultIncludePaths(const LangOptions &Lang, 91a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar const llvm::Triple &triple, 92a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar const HeaderSearchOptions &HSOpts); 932cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 942cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// Realize - Merges all search path lists into one list and send it to 952cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// HeaderSearch. 962df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger void Realize(const LangOptions &Lang); 972cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar}; 982cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 99ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner} // end anonymous namespace. 1000fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1015f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid InitHeaderSearch::AddPath(const Twine &Path, 102458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer IncludeDirGroup Group, bool isCXXAware, 103458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer bool isUserSupplied, bool isFramework, 104458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer bool IgnoreSysRoot) { 105e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); 1060fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber FileManager &FM = Headers.getFileMgr(); 1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1080fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Compute the actual path, taking into consideration -isysroot. 109f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<256> MappedPathStorage; 1105f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); 1111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1120fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Handle isysroot. 1139a7e09d82f739c8fd1b6c28787397d698515a871Rafael Espindola if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot && 1140f0cdab31a4f71914b7f654501d69d96e9f378daNAKAMURA Takumi#if defined(_WIN32) 1150f0cdab31a4f71914b7f654501d69d96e9f378daNAKAMURA Takumi !MappedPathStr.empty() && 1160f0cdab31a4f71914b7f654501d69d96e9f378daNAKAMURA Takumi llvm::sys::path::is_separator(MappedPathStr[0]) && 1170f0cdab31a4f71914b7f654501d69d96e9f378daNAKAMURA Takumi#else 118256053b31e697fdf0cc48f17d621c82fc3b8dff0Michael J. Spencer llvm::sys::path::is_absolute(MappedPathStr) && 1190f0cdab31a4f71914b7f654501d69d96e9f378daNAKAMURA Takumi#endif 120af6530c938bfc60902f0dfec1c0808aedbee1663Michael J. Spencer IsNotEmptyOrRoot) { 1215619ae5d25dc77410a444c86606d4ec9bae8b921Chandler Carruth MappedPathStorage.clear(); 122c09265a5fd94af5dcfd7325d0cb4f04197d65afcChandler Carruth MappedPathStr = 123af6530c938bfc60902f0dfec1c0808aedbee1663Michael J. Spencer (IncludeSysroot + Path).toStringRef(MappedPathStorage); 1240fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1260fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Compute the DirectoryLookup type. 1279d72851fec9e9c62570a027d42701562bbf29751Chris Lattner SrcMgr::CharacteristicKind Type; 12865e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) 1290b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner Type = SrcMgr::C_User; 1300fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else if (isCXXAware) 1310b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner Type = SrcMgr::C_System; 1320fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else 1330b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner Type = SrcMgr::C_ExternCSystem; 1341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1360fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If the directory exists, add it. 13739b49bcaaddb1049234fca9500c0ac02c088e23dChris Lattner if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) { 1382df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type, 1392df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger isUserSupplied, isFramework))); 1400fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber return; 1410fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1430fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Check to see if this is an apple-style headermap (which are not allowed to 1440fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // be frameworks). 1450fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (!isFramework) { 14639b49bcaaddb1049234fca9500c0ac02c088e23dChris Lattner if (const FileEntry *FE = FM.getFile(MappedPathStr)) { 1470fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { 1480fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // It is a headermap, add it to the search path. 1492df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type, 15065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor isUserSupplied, Group == IndexHeaderMap))); 1510fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber return; 1520fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1530fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1540fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1560fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (Verbose) 157f3721457cd9f364f262e7a2d61edcdad05996e61Chandler Carruth llvm::errs() << "ignoring nonexistent directory \"" 158f3721457cd9f364f262e7a2d61edcdad05996e61Chandler Carruth << MappedPathStr << "\"\n"; 1590fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 1600fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1615f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base, 1625f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef ArchDir, 1635f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Dir32, 1645f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Dir64, 16531b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola const llvm::Triple &triple) { 1666ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola // Add the base dir 1672df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger AddPath(Base, CXXSystem, true, false, false); 168ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola 169ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola // Add the multilib dirs 17031b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola llvm::Triple::ArchType arch = triple.getArch(); 17131b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; 17231b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola if (is64bit) 1732df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false); 17431b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola else 1752df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false); 1766ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola 1776ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola // Add the backward dir 1782df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger AddPath(Base + "/backward", CXXSystem, true, false, false); 1792e9f652d53346bf7e64c8a12a9ff06b004a3e489Rafael Espindola} 1800fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1815f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base, 1825f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Arch, 1835f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Version) { 184ab8ae19ea4285a15ca43123e8e218e401dc5cb5aBenjamin Kramer AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", 1852df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger CXXSystem, true, false, false); 1868e9006bb31184a38b7c4c9d3d3040394652cbd9bChris Lattner AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, 1872df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger CXXSystem, true, false, false); 188ab8ae19ea4285a15ca43123e8e218e401dc5cb5aBenjamin Kramer AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", 1892df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger CXXSystem, true, false, false); 190620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump} 19143d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump 1925f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base, 1935f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Version) { 194d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor // Assumes Base is HeaderSearchOpts' ResourceDir 195d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddPath(Base + "/../../../include/c++/" + Version, 1969db48467f19d4f0929a5ba40c5e2bd7255dc95f0NAKAMURA Takumi CXXSystem, true, false, false); 197d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32", 1989db48467f19d4f0929a5ba40c5e2bd7255dc95f0NAKAMURA Takumi CXXSystem, true, false, false); 199d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32", 200d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor CXXSystem, true, false, false); 201d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddPath(Base + "/../../../include/c++/" + Version + "/backward", 2029db48467f19d4f0929a5ba40c5e2bd7255dc95f0NAKAMURA Takumi CXXSystem, true, false, false); 2039db48467f19d4f0929a5ba40c5e2bd7255dc95f0NAKAMURA Takumi} 2049db48467f19d4f0929a5ba40c5e2bd7255dc95f0NAKAMURA Takumi 20579bc57c074cb91f574fba19215f95b63dcf6b04bmike-mvoid InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, 20679bc57c074cb91f574fba19215f95b63dcf6b04bmike-m const HeaderSearchOptions &HSOpts) { 2078e50a96b387dca7525caa8a6add31420dd82a2cdBenjamin Kramer llvm::Triple::OSType os = triple.getOS(); 2088e50a96b387dca7525caa8a6add31420dd82a2cdBenjamin Kramer 209a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar if (HSOpts.UseStandardSystemIncludes) { 210a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar switch (os) { 211a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar case llvm::Triple::FreeBSD: 212a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar case llvm::Triple::NetBSD: 213a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar break; 214a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar default: 215a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar // FIXME: temporary hack: hard-coded paths. 216a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar AddPath("/usr/local/include", System, true, false, false); 217a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar break; 218a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar } 2198e50a96b387dca7525caa8a6add31420dd82a2cdBenjamin Kramer } 22079bc57c074cb91f574fba19215f95b63dcf6b04bmike-m 22179bc57c074cb91f574fba19215f95b63dcf6b04bmike-m // Builtin includes use #include_next directives and should be positioned 22279bc57c074cb91f574fba19215f95b63dcf6b04bmike-m // just prior C include dirs. 22379bc57c074cb91f574fba19215f95b63dcf6b04bmike-m if (HSOpts.UseBuiltinIncludes) { 22479bc57c074cb91f574fba19215f95b63dcf6b04bmike-m // Ignore the sys root, we *always* look for clang headers relative to 22579bc57c074cb91f574fba19215f95b63dcf6b04bmike-m // supplied path. 22679bc57c074cb91f574fba19215f95b63dcf6b04bmike-m llvm::sys::Path P(HSOpts.ResourceDir); 22779bc57c074cb91f574fba19215f95b63dcf6b04bmike-m P.appendComponent("include"); 22879bc57c074cb91f574fba19215f95b63dcf6b04bmike-m AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true); 22979bc57c074cb91f574fba19215f95b63dcf6b04bmike-m } 23079bc57c074cb91f574fba19215f95b63dcf6b04bmike-m 231a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar // All remaining additions are for system include directories, early exit if 232a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar // we aren't using them. 233a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar if (!HSOpts.UseStandardSystemIncludes) 234a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar return; 235a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar 23679bc57c074cb91f574fba19215f95b63dcf6b04bmike-m // Add dirs specified via 'configure --with-c-include-dirs'. 2375f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef CIncludeDirs(C_INCLUDE_DIRS); 238c706468b1e00bab49ca92eb500a39657f530f828Daniel Dunbar if (CIncludeDirs != "") { 2395f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<StringRef, 5> dirs; 240aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola CIncludeDirs.split(dirs, ":"); 2415f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner for (SmallVectorImpl<StringRef>::iterator i = dirs.begin(); 242aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola i != dirs.end(); 243125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi ++i) 244f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola AddPath(*i, System, false, false, false); 245f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola return; 246f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola } 2478e50a96b387dca7525caa8a6add31420dd82a2cdBenjamin Kramer 24843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump switch (os) { 2497d7e9f963a4977e36efb90fd9c369f33ced1a95aChandler Carruth case llvm::Triple::Linux: 250ca23419b8214654d185d595956e9ddf24984750aChandler Carruth case llvm::Triple::Win32: 2517d7e9f963a4977e36efb90fd9c369f33ced1a95aChandler Carruth llvm_unreachable("Include management is handled in the driver."); 252ca23419b8214654d185d595956e9ddf24984750aChandler Carruth 25386ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner case llvm::Triple::Haiku: 25486ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/common/include", System, true, false, false); 25586ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os", System, true, false, false); 25686ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/app", System, true, false, false); 25786ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/arch", System, true, false, false); 25886ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/device", System, true, false, false); 25986ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/drivers", System, true, false, false); 260125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi AddPath("/boot/develop/headers/os/game", System, true, false, false); 26186ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/interface", System, true, false, false); 26286ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/kernel", System, true, false, false); 26386ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/locale", System, true, false, false); 26486ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/mail", System, true, false, false); 26586ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/media", System, true, false, false); 26686ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/midi", System, true, false, false); 26786ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/midi2", System, true, false, false); 26886ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/net", System, true, false, false); 26986ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/storage", System, true, false, false); 27086ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/support", System, true, false, false); 27186ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/translation", 27286ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner System, true, false, false); 273125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi AddPath("/boot/develop/headers/os/add-ons/graphics", 27486ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner System, true, false, false); 275125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi AddPath("/boot/develop/headers/os/add-ons/input_server", 27686ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner System, true, false, false); 277125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi AddPath("/boot/develop/headers/os/add-ons/screen_saver", 27886ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner System, true, false, false); 279125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi AddPath("/boot/develop/headers/os/add-ons/tracker", 28086ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner System, true, false, false); 28186ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/be_apps/Deskbar", 28286ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner System, true, false, false); 28386ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/be_apps/NetPositive", 28486ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner System, true, false, false); 28586ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/os/be_apps/Tracker", 28686ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner System, true, false, false); 28786ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/cpp", System, true, false, false); 288125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi AddPath("/boot/develop/headers/cpp/i586-pc-haiku", 28986ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner System, true, false, false); 29086ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/3rdparty", System, true, false, false); 29186ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/bsd", System, true, false, false); 29286ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/glibc", System, true, false, false); 29386ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers/posix", System, true, false, false); 29486ed3a326342fa2a8c9d9b5d1d7280c9bad2b007Chris Lattner AddPath("/boot/develop/headers", System, true, false, false); 295a7e6845660f91ec611427e1db842780e1ec12bdbEli Friedman break; 296dca5226598097add5d86d57b227aa31df27f0ba4Douglas Gregor case llvm::Triple::RTEMS: 297dca5226598097add5d86d57b227aa31df27f0ba4Douglas Gregor break; 29832df002017e3e8d86bfd3f7090b341d265676fc9NAKAMURA Takumi case llvm::Triple::Cygwin: 29932df002017e3e8d86bfd3f7090b341d265676fc9NAKAMURA Takumi AddPath("/usr/include/w32api", System, true, false, false); 30032df002017e3e8d86bfd3f7090b341d265676fc9NAKAMURA Takumi break; 301d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor case llvm::Triple::MinGW32: { 302d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor // mingw-w64 crt include paths 303d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor llvm::sys::Path P(HSOpts.ResourceDir); 304d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include 305d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddPath(P.str(), System, true, false, false); 306d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor P = llvm::sys::Path(HSOpts.ResourceDir); 307d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include 308d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddPath(P.str(), System, true, false, false); 309d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor // mingw.org crt include paths 310d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor P = llvm::sys::Path(HSOpts.ResourceDir); 311d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor P.appendComponent("../../../include"); // <sysroot>/include 312d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddPath(P.str(), System, true, false, false); 313d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddPath("/mingw/include", System, true, false, false); 314d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddPath("c:/mingw/include", System, true, false, false); 315d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor } 31643d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump break; 317d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor 31843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump default: 31943d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump break; 3200fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 321d3f88343af2dec3459493fafa22532317321eaf0John Thompson 322dca5226598097add5d86d57b227aa31df27f0ba4Douglas Gregor if ( os != llvm::Triple::RTEMS ) 323dca5226598097add5d86d57b227aa31df27f0ba4Douglas Gregor AddPath("/usr/include", System, false, false, false); 324e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola} 325e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola 3260e3cc05542e62fe89345ce94a73494525ee463e0Chris Lattnervoid InitHeaderSearch:: 327d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas GregorAddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { 328e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola llvm::Triple::OSType os = triple.getOS(); 329e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // FIXME: temporary hack: hard-coded paths. 330db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar 331db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar if (triple.isOSDarwin()) { 332f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar switch (triple.getArch()) { 333f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar default: break; 334f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar 335125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi case llvm::Triple::ppc: 336582c30135dce1857db62e58b916ab0fa5edfb1d6Douglas Gregor case llvm::Triple::ppc64: 337616d4362f01a8f819f9351372c3c4368777d4480Douglas Gregor AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 338125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi "powerpc-apple-darwin10", "", "ppc64", 339616d4362f01a8f819f9351372c3c4368777d4480Douglas Gregor triple); 340582c30135dce1857db62e58b916ab0fa5edfb1d6Douglas Gregor AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", 341125b4cb35536e45201f8f2cb19ee620e3ad67c49NAKAMURA Takumi "powerpc-apple-darwin10", "", "ppc64", 342582c30135dce1857db62e58b916ab0fa5edfb1d6Douglas Gregor triple); 343582c30135dce1857db62e58b916ab0fa5edfb1d6Douglas Gregor break; 344582c30135dce1857db62e58b916ab0fa5edfb1d6Douglas Gregor 345f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar case llvm::Triple::x86: 346f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar case llvm::Triple::x86_64: 347f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 348f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar "i686-apple-darwin10", "", "x86_64", triple); 349f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", 350f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar "i686-apple-darwin8", "", "", triple); 351f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar break; 352f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar 353f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar case llvm::Triple::arm: 354f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar case llvm::Triple::thumb: 355f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 356f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar "arm-apple-darwin10", "v7", "", triple); 357f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 358f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar "arm-apple-darwin10", "v6", "", triple); 359f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar break; 360f2070b374c1d6fc72aa6bdb2f49c1efdc4f6d963Daniel Dunbar } 361db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar return; 362db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar } 363db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar 364db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar switch (os) { 3657d7e9f963a4977e36efb90fd9c369f33ced1a95aChandler Carruth case llvm::Triple::Linux: 3667d7e9f963a4977e36efb90fd9c369f33ced1a95aChandler Carruth case llvm::Triple::Win32: 3677d7e9f963a4977e36efb90fd9c369f33ced1a95aChandler Carruth llvm_unreachable("Include management is handled in the driver."); 3687d7e9f963a4977e36efb90fd9c369f33ced1a95aChandler Carruth 369db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar case llvm::Triple::Cygwin: 370db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar // Cygwin-1.7 371f3c1ca6bced3f79ec6d76f1bcb05c5ae6944ce0bNAKAMURA Takumi AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3"); 372db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4"); 373db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar // g++-4 / Cygwin-1.5 374db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); 375db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar break; 376db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar case llvm::Triple::MinGW32: 377d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32) 378d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0"); 379d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1"); 380d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2"); 381d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3"); 382a74ec5c314178a7e73bbaa7d406eb5079ef8ef26Eli Friedman AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4"); 383d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0"); 384d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1"); 385f732f2b11b136f34aecb95b0a2e72f5f272eb723Douglas Gregor AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2"); 386a74ec5c314178a7e73bbaa7d406eb5079ef8ef26Eli Friedman AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3"); 387f732f2b11b136f34aecb95b0a2e72f5f272eb723Douglas Gregor AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0"); 388d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor // mingw.org C++ include paths 389d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS 390e87e851fcebaf27341858b55fa3f46b9ce23a207Aaron Ballman AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2"); 391e87e851fcebaf27341858b55fa3f46b9ce23a207Aaron Ballman AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1"); 392e87e851fcebaf27341858b55fa3f46b9ce23a207Aaron Ballman AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2"); 393db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0"); 394db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); 395db57a4cdb0a6abf3239f3a794a900ce312c5887bDaniel Dunbar AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); 396e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 3977a7ca281bcf50b34de1ce067d3c55879b81722aeChris Lattner case llvm::Triple::DragonFly: 3982df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false); 3997a7ca281bcf50b34de1ce067d3c55879b81722aeChris Lattner break; 400e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::FreeBSD: 401ac78b7a7af0e67f2f4f45d9d94393c281ff4417bmike-m // FreeBSD 8.0 402ac78b7a7af0e67f2f4f45d9d94393c281ff4417bmike-m // FreeBSD 7.3 403afe859a9a6217f177daf42ebab294a90bfe8a6abNuno Lopes AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple); 404e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 405ab079419ff2e52652be349e949202a2470f8d253Anton Korobeynikov case llvm::Triple::NetBSD: 406ab079419ff2e52652be349e949202a2470f8d253Anton Korobeynikov AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple); 407ab079419ff2e52652be349e949202a2470f8d253Anton Korobeynikov break; 40895c0457054518102af6250e718a13a5b2ee5dbeaDaniel Dunbar case llvm::Triple::OpenBSD: { 40995c0457054518102af6250e718a13a5b2ee5dbeaDaniel Dunbar std::string t = triple.getTriple(); 41095c0457054518102af6250e718a13a5b2ee5dbeaDaniel Dunbar if (t.substr(0, 6) == "x86_64") 41195c0457054518102af6250e718a13a5b2ee5dbeaDaniel Dunbar t.replace(0, 6, "amd64"); 41295c0457054518102af6250e718a13a5b2ee5dbeaDaniel Dunbar AddGnuCPlusPlusIncludePaths("/usr/include/g++", 41395c0457054518102af6250e718a13a5b2ee5dbeaDaniel Dunbar t, "", "", triple); 41495c0457054518102af6250e718a13a5b2ee5dbeaDaniel Dunbar break; 41595c0457054518102af6250e718a13a5b2ee5dbeaDaniel Dunbar } 41638e317d6dce161b249508686cc67eb7176958762Chris Lattner case llvm::Triple::Minix: 41738e317d6dce161b249508686cc67eb7176958762Chris Lattner AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3", 41838e317d6dce161b249508686cc67eb7176958762Chris Lattner "", "", "", triple); 41938e317d6dce161b249508686cc67eb7176958762Chris Lattner break; 420e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::Solaris: 421b622959527c07cc6b68739eac1412f75f0ca77faDavid Chisnall AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/", 422b622959527c07cc6b68739eac1412f75f0ca77faDavid Chisnall "i386-pc-solaris2.11", "", "", triple); 423e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Solaris - Fall though.. 424e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::AuroraUX: 425e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // AuroraUX 426e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", 427ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i386-pc-solaris2.11", "", "", triple); 428e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 429e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola default: 430e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 431e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola } 432e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola} 433e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola 434a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbarvoid InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang, 435a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar const llvm::Triple &triple, 43679bc57c074cb91f574fba19215f95b63dcf6b04bmike-m const HeaderSearchOptions &HSOpts) { 437ca23419b8214654d185d595956e9ddf24984750aChandler Carruth // NB: This code path is going away. All of the logic is moving into the 438ca23419b8214654d185d595956e9ddf24984750aChandler Carruth // driver which has the information necessary to do target-specific 439ca23419b8214654d185d595956e9ddf24984750aChandler Carruth // selections of default include paths. Each target which moves there will be 440ca23419b8214654d185d595956e9ddf24984750aChandler Carruth // exempted from this logic here until we can delete the entire pile of code. 441ca23419b8214654d185d595956e9ddf24984750aChandler Carruth switch (triple.getOS()) { 442ca23419b8214654d185d595956e9ddf24984750aChandler Carruth default: 443ca23419b8214654d185d595956e9ddf24984750aChandler Carruth break; // Everything else continues to use this routine's logic. 444ca23419b8214654d185d595956e9ddf24984750aChandler Carruth 4457d7e9f963a4977e36efb90fd9c369f33ced1a95aChandler Carruth case llvm::Triple::Linux: 446ca23419b8214654d185d595956e9ddf24984750aChandler Carruth case llvm::Triple::Win32: 447ca23419b8214654d185d595956e9ddf24984750aChandler Carruth return; 448ca23419b8214654d185d595956e9ddf24984750aChandler Carruth } 449ca23419b8214654d185d595956e9ddf24984750aChandler Carruth 450a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes && 451a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar HSOpts.UseStandardSystemIncludes) { 452baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor if (HSOpts.UseLibcxx) { 453baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor if (triple.isOSDarwin()) { 454baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor // On Darwin, libc++ may be installed alongside the compiler in 455baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor // lib/c++/v1. 456baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor llvm::sys::Path P(HSOpts.ResourceDir); 457baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor if (!P.isEmpty()) { 458baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor P.eraseComponent(); // Remove version from foo/lib/clang/version 459baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor P.eraseComponent(); // Remove clang from foo/lib/clang 460baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor 461baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor // Get foo/lib/c++/v1 462baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor P.appendComponent("c++"); 463baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor P.appendComponent("v1"); 464baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor AddPath(P.str(), CXXSystem, true, false, false, true); 465baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor } 466baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor } 467b4f0bd6864f33bc2fd8246f1f841d87e60c4ffc8David Chisnall // On Solaris, include the support directory for things like xlocale and 468b4f0bd6864f33bc2fd8246f1f841d87e60c4ffc8David Chisnall // fudged system headers. 469b4f0bd6864f33bc2fd8246f1f841d87e60c4ffc8David Chisnall if (triple.getOS() == llvm::Triple::Solaris) 470b4f0bd6864f33bc2fd8246f1f841d87e60c4ffc8David Chisnall AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, true, false, 471b4f0bd6864f33bc2fd8246f1f841d87e60c4ffc8David Chisnall false); 472baf41f16421a10c8ecd015baa686aa1b965ae5e3Douglas Gregor 47313c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson AddPath("/usr/include/c++/v1", CXXSystem, true, false, false); 474a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar } else { 475d944a9b7a680be2ce74aa9398e0604fdebf0338aDouglas Gregor AddDefaultCPlusPlusIncludePaths(triple, HSOpts); 476a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar } 47713c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson } 4786ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola 47979bc57c074cb91f574fba19215f95b63dcf6b04bmike-m AddDefaultCIncludePaths(triple, HSOpts); 480e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar 481e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar // Add the default framework include paths on Darwin. 482a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar if (HSOpts.UseStandardSystemIncludes) { 483a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar if (triple.isOSDarwin()) { 484a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar AddPath("/System/Library/Frameworks", System, true, false, true); 485a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar AddPath("/Library/Frameworks", System, true, false, true); 486a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar } 487e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar } 488e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola} 489e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola 4900fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber/// RemoveDuplicates - If there are duplicate directory entries in the specified 491e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosier/// search list, remove the later (dead) ones. Returns the number of non-system 492e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosier/// headers removed, which is used to update NumAngled. 493e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosierstatic unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, 494e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosier unsigned First, bool Verbose) { 4950fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; 4960fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; 4970fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; 498e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosier unsigned NonSystemRemoved = 0; 4992df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger for (unsigned i = First; i != SearchList.size(); ++i) { 5007a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner unsigned DirToRemove = i; 5011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50243eee07270bf1966ea7289310066aa670c4b647fChris Lattner const DirectoryLookup &CurEntry = SearchList[i]; 5031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50443eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (CurEntry.isNormalDir()) { 5050fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If this isn't the first time we've seen this dir, remove it. 50643eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SeenDirs.insert(CurEntry.getDir())) 5070fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber continue; 50843eee07270bf1966ea7289310066aa670c4b647fChris Lattner } else if (CurEntry.isFramework()) { 5090fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If this isn't the first time we've seen this framework dir, remove it. 51043eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) 5110fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber continue; 5120fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } else { 51343eee07270bf1966ea7289310066aa670c4b647fChris Lattner assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 5140fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If this isn't the first time we've seen this headermap, remove it. 51543eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) 5160fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber continue; 51730f05b553db067c994966daca37e75324ee7b424Chris Lattner } 5181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51930f05b553db067c994966daca37e75324ee7b424Chris Lattner // If we have a normal #include dir/framework/headermap that is shadowed 52030f05b553db067c994966daca37e75324ee7b424Chris Lattner // later in the chain by a system include location, we actually want to 52130f05b553db067c994966daca37e75324ee7b424Chris Lattner // ignore the user's request and drop the user dir... keeping the system 52230f05b553db067c994966daca37e75324ee7b424Chris Lattner // dir. This is weird, but required to emulate GCC's search path correctly. 52330f05b553db067c994966daca37e75324ee7b424Chris Lattner // 52430f05b553db067c994966daca37e75324ee7b424Chris Lattner // Since dupes of system dirs are rare, just rescan to find the original 52530f05b553db067c994966daca37e75324ee7b424Chris Lattner // that we're nuking instead of using a DenseMap. 52643eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { 52730f05b553db067c994966daca37e75324ee7b424Chris Lattner // Find the dir that this is the same of. 52830f05b553db067c994966daca37e75324ee7b424Chris Lattner unsigned FirstDir; 52930f05b553db067c994966daca37e75324ee7b424Chris Lattner for (FirstDir = 0; ; ++FirstDir) { 53030f05b553db067c994966daca37e75324ee7b424Chris Lattner assert(FirstDir != i && "Didn't find dupe?"); 5311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53243eee07270bf1966ea7289310066aa670c4b647fChris Lattner const DirectoryLookup &SearchEntry = SearchList[FirstDir]; 53343eee07270bf1966ea7289310066aa670c4b647fChris Lattner 53430f05b553db067c994966daca37e75324ee7b424Chris Lattner // If these are different lookup types, then they can't be the dupe. 53543eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SearchEntry.getLookupType() != CurEntry.getLookupType()) 53630f05b553db067c994966daca37e75324ee7b424Chris Lattner continue; 5371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53830f05b553db067c994966daca37e75324ee7b424Chris Lattner bool isSame; 53943eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (CurEntry.isNormalDir()) 54043eee07270bf1966ea7289310066aa670c4b647fChris Lattner isSame = SearchEntry.getDir() == CurEntry.getDir(); 54143eee07270bf1966ea7289310066aa670c4b647fChris Lattner else if (CurEntry.isFramework()) 54243eee07270bf1966ea7289310066aa670c4b647fChris Lattner isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); 54330f05b553db067c994966daca37e75324ee7b424Chris Lattner else { 54443eee07270bf1966ea7289310066aa670c4b647fChris Lattner assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 54543eee07270bf1966ea7289310066aa670c4b647fChris Lattner isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); 54630f05b553db067c994966daca37e75324ee7b424Chris Lattner } 5471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54830f05b553db067c994966daca37e75324ee7b424Chris Lattner if (isSame) 54930f05b553db067c994966daca37e75324ee7b424Chris Lattner break; 55030f05b553db067c994966daca37e75324ee7b424Chris Lattner } 5511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 55230f05b553db067c994966daca37e75324ee7b424Chris Lattner // If the first dir in the search path is a non-system dir, zap it 55330f05b553db067c994966daca37e75324ee7b424Chris Lattner // instead of the system one. 55430f05b553db067c994966daca37e75324ee7b424Chris Lattner if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) 55530f05b553db067c994966daca37e75324ee7b424Chris Lattner DirToRemove = FirstDir; 55630f05b553db067c994966daca37e75324ee7b424Chris Lattner } 55730f05b553db067c994966daca37e75324ee7b424Chris Lattner 55830f05b553db067c994966daca37e75324ee7b424Chris Lattner if (Verbose) { 559e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "ignoring duplicate directory \"" 560e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar << CurEntry.getName() << "\"\n"; 56130f05b553db067c994966daca37e75324ee7b424Chris Lattner if (DirToRemove != i) 562e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << " as it is a non-system directory that duplicates " 563e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar << "a system directory\n"; 5640fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 565e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosier if (DirToRemove != i) 566e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosier ++NonSystemRemoved; 5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5687a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner // This is reached if the current entry is a duplicate. Remove the 5697a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner // DirToRemove (usually the current dir). 5707a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner SearchList.erase(SearchList.begin()+DirToRemove); 5710fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber --i; 5720fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 573e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosier return NonSystemRemoved; 5740fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 5750fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 5760fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 5772df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenbergervoid InitHeaderSearch::Realize(const LangOptions &Lang) { 5780fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. 5790fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber std::vector<DirectoryLookup> SearchList; 5802df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger SearchList.reserve(IncludePath.size()); 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 582ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner // Quoted arguments go first. 5832df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 5842df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger it != ie; ++it) { 5852df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger if (it->first == Quoted) 5862df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger SearchList.push_back(it->second); 5872df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger } 588ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner // Deduplicate and remember index. 5892df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger RemoveDuplicates(SearchList, 0, Verbose); 590ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner unsigned NumQuoted = SearchList.size(); 5912df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger 5922df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 5932df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger it != ie; ++it) { 59465e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor if (it->first == Angled || it->first == IndexHeaderMap) 5952df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger SearchList.push_back(it->second); 5962df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger } 597ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner 598ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner RemoveDuplicates(SearchList, NumQuoted, Verbose); 599ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner unsigned NumAngled = SearchList.size(); 6002df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger 6012df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 6022df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger it != ie; ++it) { 60347adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer if (it->first == System || 60447adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) || 605c535d9730e11ca335790359bfbd4600be71c5410Benjamin Kramer (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) || 60647adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) || 60747adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem)) 6082df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger SearchList.push_back(it->second); 6092df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger } 6102df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger 6112df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); 6122df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger it != ie; ++it) { 6132df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger if (it->first == After) 6142df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger SearchList.push_back(it->second); 6152df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger } 6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6171d7f12b83340610f76a73d21cac391e6feced7aaChris Lattner // Remove duplicates across both the Angled and System directories. GCC does 6181d7f12b83340610f76a73d21cac391e6feced7aaChris Lattner // this and failing to remove duplicates across these two groups breaks 6191d7f12b83340610f76a73d21cac391e6feced7aaChris Lattner // #include_next. 620e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosier unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose); 621e305e81f65d13e6953f623a6b31176ad7041ba20Chad Rosier NumAngled -= NonSystemRemoved; 6220fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 6230fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber bool DontSearchCurDir = false; // TODO: set to true if -I- is set? 624ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir); 6250fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 6260fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If verbose, print the list of directories that will be searched. 6270fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (Verbose) { 628e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "#include \"...\" search starts here:\n"; 6290fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { 630ebb6164bebf2b1e4f439433e751710b506918f62Chris Lattner if (i == NumQuoted) 631e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "#include <...> search starts here:\n"; 6320fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber const char *Name = SearchList[i].getName(); 6330fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber const char *Suffix; 6340fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (SearchList[i].isNormalDir()) 6350fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Suffix = ""; 6360fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else if (SearchList[i].isFramework()) 6370fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Suffix = " (framework directory)"; 6380fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else { 6390fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); 6400fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Suffix = " (headermap)"; 6410fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 642e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << " " << Name << Suffix << "\n"; 6430fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 644e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "End of search list.\n"; 6450fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 6460fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 64763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 6485814e657c9ad9ef6049a2a4af0d2aad248a8a15cDaniel Dunbarvoid clang::ApplyHeaderSearchOptions(HeaderSearch &HS, 6495814e657c9ad9ef6049a2a4af0d2aad248a8a15cDaniel Dunbar const HeaderSearchOptions &HSOpts, 6505814e657c9ad9ef6049a2a4af0d2aad248a8a15cDaniel Dunbar const LangOptions &Lang, 65163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar const llvm::Triple &Triple) { 65263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); 65363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 65463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar // Add the user defined entries. 65563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { 65663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; 657ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth Init.AddPath(E.Path, E.Group, !E.ImplicitExternC, E.IsUserSupplied, 658ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth E.IsFramework, E.IgnoreSysRoot); 65963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar } 66063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 661a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar Init.AddDefaultIncludePaths(Lang, Triple, HSOpts); 66263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 6632f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor if (HSOpts.UseBuiltinIncludes) { 6642f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor // Set up the builtin include directory in the module map. 6652f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor llvm::sys::Path P(HSOpts.ResourceDir); 6662f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor P.appendComponent("include"); 6672f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str())) 6682f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor HS.getModuleMap().setBuiltinIncludeDir(Dir); 6692f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor } 6702f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor 6712df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger Init.Realize(Lang); 67263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar} 673