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