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