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