blob: 216927e22f05e8baae11e8c8d44a50a6b8ace6cb [file] [log] [blame]
Nick Lewyckydf22c2c2010-07-25 03:12:58 +00001//===--- InitHeaderSearch.cpp - Initialize header search paths ------------===//
Nico Weber0fca0222008-08-22 09:25:22 +00002//
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
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000014#include "clang/Frontend/Utils.h"
Nico Weber0fca0222008-08-22 09:25:22 +000015#include "clang/Basic/FileManager.h"
16#include "clang/Basic/LangOptions.h"
Daniel Dunbar63c8b772009-11-07 04:20:50 +000017#include "clang/Frontend/HeaderSearchOptions.h"
18#include "clang/Lex/HeaderSearch.h"
Nico Weber0fca0222008-08-22 09:25:22 +000019#include "llvm/ADT/SmallString.h"
20#include "llvm/ADT/SmallPtrSet.h"
Rafael Espindolaaadd7a42009-11-13 05:13:58 +000021#include "llvm/ADT/SmallVector.h"
Rafael Espindolaf0a2f512009-11-12 05:48:41 +000022#include "llvm/ADT/StringExtras.h"
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000023#include "llvm/ADT/Triple.h"
Benjamin Kramere89ba592009-12-08 12:38:20 +000024#include "llvm/ADT/Twine.h"
Chris Lattnerd57a7ef2009-08-23 22:45:33 +000025#include "llvm/Support/raw_ostream.h"
Chandler Carruthca234192011-11-04 23:49:05 +000026#include "llvm/Support/ErrorHandling.h"
Aaron Ballmanb3656d32012-03-25 15:47:41 +000027#include "llvm/Support/FileSystem.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000028#include "llvm/Support/Path.h"
Aaron Ballmanb3656d32012-03-25 15:47:41 +000029#include "llvm/Support/Regex.h"
Dylan Noblesmith69d3b4f2012-02-01 14:25:28 +000030
Dylan Noblesmithcc8a9452012-02-14 15:54:49 +000031#include "clang/Config/config.h" // C_INCLUDE_DIRS
Dylan Noblesmith69d3b4f2012-02-01 14:25:28 +000032
Nico Weber0fca0222008-08-22 09:25:22 +000033using namespace clang;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000034using namespace clang::frontend;
35
36namespace {
37
38/// InitHeaderSearch - This class makes it easier to set the search paths of
39/// a HeaderSearch object. InitHeaderSearch stores several search path lists
40/// internally, which can be sent to a HeaderSearch object in one swoop.
41class InitHeaderSearch {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +000042 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
43 typedef std::vector<std::pair<IncludeDirGroup,
44 DirectoryLookup> >::const_iterator path_iterator;
Chris Lattnerebb61642011-06-16 22:56:45 +000045 HeaderSearch &Headers;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000046 bool Verbose;
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000047 std::string IncludeSysroot;
48 bool IsNotEmptyOrRoot;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000049
50public:
51
Chris Lattner5f9e2722011-07-23 10:55:15 +000052 InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000053 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
54 IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) {
Chandler Carruthc09265a2010-11-15 07:15:26 +000055 }
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000056
57 /// AddPath - Add the specified path to the specified group list.
Chris Lattner5f9e2722011-07-23 10:55:15 +000058 void AddPath(const Twine &Path, IncludeDirGroup Group,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000059 bool isCXXAware, bool isUserSupplied,
60 bool isFramework, bool IgnoreSysRoot = false);
61
mike-ma6087372010-05-05 17:00:31 +000062 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000063 /// libstdc++.
Chris Lattner5f9e2722011-07-23 10:55:15 +000064 void AddGnuCPlusPlusIncludePaths(StringRef Base,
65 StringRef ArchDir,
66 StringRef Dir32,
67 StringRef Dir64,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000068 const llvm::Triple &triple);
Aaron Ballmanb3656d32012-03-25 15:47:41 +000069
70 /// AddMinGWCIncludePaths - Add MinGW paths that should always be searched
71 void AddMinGWCIncludePaths(StringRef Base);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000072
Michael J. Spencer06a8dc62010-12-21 16:45:42 +000073 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000074 /// libstdc++.
Aaron Ballmanb3656d32012-03-25 15:47:41 +000075 void AddMinGWCPlusPlusIncludePaths(StringRef Base, StringRef Arch);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000076
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000077 /// AddMinGW64CXXPaths - Add the necessary paths to support
78 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
Aaron Ballmanb3656d32012-03-25 15:47:41 +000079 void AddMinGW64CXXPaths(StringRef Base);
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000080
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000081 // AddDefaultCIncludePaths - Add paths that should always be searched.
mike-m79bc57c2010-05-16 19:03:52 +000082 void AddDefaultCIncludePaths(const llvm::Triple &triple,
83 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000084
85 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
86 // compiling c++.
Douglas Gregord944a9b2011-06-27 15:47:15 +000087 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
88 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000089
90 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
91 /// that e.g. stdio.h is found.
Daniel Dunbara268fc02011-10-11 18:20:10 +000092 void AddDefaultIncludePaths(const LangOptions &Lang,
93 const llvm::Triple &triple,
94 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000095
96 /// Realize - Merges all search path lists into one list and send it to
97 /// HeaderSearch.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +000098 void Realize(const LangOptions &Lang);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000099};
100
Chris Lattnerebb61642011-06-16 22:56:45 +0000101} // end anonymous namespace.
Nico Weber0fca0222008-08-22 09:25:22 +0000102
Chris Lattner5f9e2722011-07-23 10:55:15 +0000103void InitHeaderSearch::AddPath(const Twine &Path,
Benjamin Kramer458fb102009-09-05 09:49:39 +0000104 IncludeDirGroup Group, bool isCXXAware,
105 bool isUserSupplied, bool isFramework,
106 bool IgnoreSysRoot) {
Benjamin Kramere89ba592009-12-08 12:38:20 +0000107 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
Nico Weber0fca0222008-08-22 09:25:22 +0000108 FileManager &FM = Headers.getFileMgr();
Mike Stump1eb44332009-09-09 15:08:12 +0000109
Nico Weber0fca0222008-08-22 09:25:22 +0000110 // Compute the actual path, taking into consideration -isysroot.
Dylan Noblesmithf7ccbad2012-02-05 02:13:05 +0000111 SmallString<256> MappedPathStorage;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000112 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
Mike Stump1eb44332009-09-09 15:08:12 +0000113
Nico Weber0fca0222008-08-22 09:25:22 +0000114 // Handle isysroot.
Rafael Espindola9a7e09d2011-03-02 21:30:07 +0000115 if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot &&
NAKAMURA Takumi0f0cdab2011-05-02 04:50:10 +0000116#if defined(_WIN32)
117 !MappedPathStr.empty() &&
118 llvm::sys::path::is_separator(MappedPathStr[0]) &&
119#else
Michael J. Spencer256053b2010-12-17 21:22:22 +0000120 llvm::sys::path::is_absolute(MappedPathStr) &&
NAKAMURA Takumi0f0cdab2011-05-02 04:50:10 +0000121#endif
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000122 IsNotEmptyOrRoot) {
Chandler Carruth5619ae52010-11-15 09:28:23 +0000123 MappedPathStorage.clear();
Chandler Carruthc09265a2010-11-15 07:15:26 +0000124 MappedPathStr =
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000125 (IncludeSysroot + Path).toStringRef(MappedPathStorage);
Nico Weber0fca0222008-08-22 09:25:22 +0000126 }
Mike Stump1eb44332009-09-09 15:08:12 +0000127
Nico Weber0fca0222008-08-22 09:25:22 +0000128 // Compute the DirectoryLookup type.
Chris Lattner9d728512008-10-27 01:19:25 +0000129 SrcMgr::CharacteristicKind Type;
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000130 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000131 Type = SrcMgr::C_User;
Nico Weber0fca0222008-08-22 09:25:22 +0000132 else if (isCXXAware)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000133 Type = SrcMgr::C_System;
Nico Weber0fca0222008-08-22 09:25:22 +0000134 else
Chris Lattner0b9e7362008-09-26 21:18:42 +0000135 Type = SrcMgr::C_ExternCSystem;
Mike Stump1eb44332009-09-09 15:08:12 +0000136
137
Nico Weber0fca0222008-08-22 09:25:22 +0000138 // If the directory exists, add it.
Chris Lattner39b49bc2010-11-23 08:35:12 +0000139 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000140 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type,
141 isUserSupplied, isFramework)));
Nico Weber0fca0222008-08-22 09:25:22 +0000142 return;
143 }
Mike Stump1eb44332009-09-09 15:08:12 +0000144
Nico Weber0fca0222008-08-22 09:25:22 +0000145 // Check to see if this is an apple-style headermap (which are not allowed to
146 // be frameworks).
147 if (!isFramework) {
Chris Lattner39b49bc2010-11-23 08:35:12 +0000148 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
Nico Weber0fca0222008-08-22 09:25:22 +0000149 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
150 // It is a headermap, add it to the search path.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000151 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type,
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000152 isUserSupplied, Group == IndexHeaderMap)));
Nico Weber0fca0222008-08-22 09:25:22 +0000153 return;
154 }
155 }
156 }
Mike Stump1eb44332009-09-09 15:08:12 +0000157
Nico Weber0fca0222008-08-22 09:25:22 +0000158 if (Verbose)
Chandler Carruthf3721452010-11-15 00:48:13 +0000159 llvm::errs() << "ignoring nonexistent directory \""
160 << MappedPathStr << "\"\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000161}
162
Chris Lattner5f9e2722011-07-23 10:55:15 +0000163void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
164 StringRef ArchDir,
165 StringRef Dir32,
166 StringRef Dir64,
Rafael Espindola31b63be2009-10-14 17:09:44 +0000167 const llvm::Triple &triple) {
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000168 // Add the base dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000169 AddPath(Base, CXXSystem, true, false, false);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000170
171 // Add the multilib dirs
Rafael Espindola31b63be2009-10-14 17:09:44 +0000172 llvm::Triple::ArchType arch = triple.getArch();
173 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola31b63be2009-10-14 17:09:44 +0000174 if (is64bit)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000175 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false);
Rafael Espindola31b63be2009-10-14 17:09:44 +0000176 else
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000177 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false);
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000178
179 // Add the backward dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000180 AddPath(Base + "/backward", CXXSystem, true, false, false);
Rafael Espindola2e9f6522009-10-06 01:33:02 +0000181}
Nico Weber0fca0222008-08-22 09:25:22 +0000182
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000183void InitHeaderSearch::AddMinGWCIncludePaths(StringRef Base) {
184 // match directories of the forms x.x and x.x.x where x can be 1 or 2 digits
185 llvm::Regex Regex("[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?$");
186 llvm::error_code EC;
187 for (llvm::sys::fs::directory_iterator I(Base + "/lib/gcc/mingw32", EC), E;
188 I != E && !EC; I.increment(EC)) {
189 llvm::sys::fs::file_status status;
190 if (!I->status(status) && is_directory(status) && Regex.match(I->path())) {
191 AddPath(I->path() + "/include", System, true, false, false);
192 AddPath(Base + "/" + "include", System, true, false, false);
193 AddPath(I->path() + "/include-fixed", System, true, false, false);
194 }
195 }
Mike Stump620d57a2009-10-12 20:50:45 +0000196}
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +0000197
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000198void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
199 StringRef Arch) {
200 // match directories of the forms x.x and x.x.x where x can be 1 or 2 digits
201 llvm::Regex Regex("[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?$");
202 llvm::error_code EC;
203 for (llvm::sys::fs::directory_iterator I(Base + "/" + Arch, EC), E;
204 I != E && !EC; I.increment(EC)) {
205 llvm::sys::fs::file_status status;
206 if (!I->status(status) && is_directory(status) && Regex.match(I->path())) {
207 const std::string &P = I->path();
208 AddPath(P + "/include/c++", CXXSystem, true, false, false);
209 AddPath(P + "/include/c++/" + Arch, CXXSystem, true, false, false);
210 AddPath(P + "/include/c++/backward", CXXSystem, true, false, false);
211 }
212 }
213}
214
215void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base) {
216 // match directories of the forms x.x and x.x.x where x can be 1 or 2 digits
217 llvm::Regex Regex("[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?$");
218 llvm::error_code EC;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000219 // Assumes Base is HeaderSearchOpts' ResourceDir
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000220 llvm::Twine Path = Base + "/../../../include/c++/";
221 for (llvm::sys::fs::directory_iterator I(Path, EC), E;
222 I != E && !EC; I.increment(EC)) {
223 llvm::sys::fs::file_status status;
224 if (!I->status(status) && is_directory(status) && Regex.match(I->path())) {
225 AddPath(I->path(), CXXSystem, true, false, false);
226 AddPath(I->path() + "/x86_64-w64-mingw32", CXXSystem, true, false, false);
227 AddPath(I->path() + "/i686-w64-mingw32", CXXSystem, true, false, false);
228 AddPath(I->path() + "/backward", CXXSystem, true, false, false);
229 }
230 }
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000231}
232
mike-m79bc57c2010-05-16 19:03:52 +0000233void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
234 const HeaderSearchOptions &HSOpts) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000235 llvm::Triple::OSType os = triple.getOS();
236
Daniel Dunbara268fc02011-10-11 18:20:10 +0000237 if (HSOpts.UseStandardSystemIncludes) {
238 switch (os) {
239 case llvm::Triple::FreeBSD:
240 case llvm::Triple::NetBSD:
241 break;
242 default:
243 // FIXME: temporary hack: hard-coded paths.
244 AddPath("/usr/local/include", System, true, false, false);
245 break;
246 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000247 }
mike-m79bc57c2010-05-16 19:03:52 +0000248
249 // Builtin includes use #include_next directives and should be positioned
250 // just prior C include dirs.
251 if (HSOpts.UseBuiltinIncludes) {
252 // Ignore the sys root, we *always* look for clang headers relative to
253 // supplied path.
254 llvm::sys::Path P(HSOpts.ResourceDir);
255 P.appendComponent("include");
256 AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true);
257 }
258
Daniel Dunbara268fc02011-10-11 18:20:10 +0000259 // All remaining additions are for system include directories, early exit if
260 // we aren't using them.
261 if (!HSOpts.UseStandardSystemIncludes)
262 return;
263
mike-m79bc57c2010-05-16 19:03:52 +0000264 // Add dirs specified via 'configure --with-c-include-dirs'.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000265 StringRef CIncludeDirs(C_INCLUDE_DIRS);
Daniel Dunbarc7064682009-11-12 07:28:29 +0000266 if (CIncludeDirs != "") {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000267 SmallVector<StringRef, 5> dirs;
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000268 CIncludeDirs.split(dirs, ":");
Chris Lattner5f9e2722011-07-23 10:55:15 +0000269 for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000270 i != dirs.end();
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000271 ++i)
Rafael Espindolaf0a2f512009-11-12 05:48:41 +0000272 AddPath(*i, System, false, false, false);
273 return;
274 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000275
Mike Stump43d81762009-10-08 23:29:47 +0000276 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000277 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000278 case llvm::Triple::Win32:
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000279 llvm_unreachable("Include management is handled in the driver.");
Chandler Carruthca234192011-11-04 23:49:05 +0000280
Chris Lattner86ed3a32010-04-11 19:29:39 +0000281 case llvm::Triple::Haiku:
282 AddPath("/boot/common/include", System, true, false, false);
283 AddPath("/boot/develop/headers/os", System, true, false, false);
284 AddPath("/boot/develop/headers/os/app", System, true, false, false);
285 AddPath("/boot/develop/headers/os/arch", System, true, false, false);
286 AddPath("/boot/develop/headers/os/device", System, true, false, false);
287 AddPath("/boot/develop/headers/os/drivers", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000288 AddPath("/boot/develop/headers/os/game", System, true, false, false);
Chris Lattner86ed3a32010-04-11 19:29:39 +0000289 AddPath("/boot/develop/headers/os/interface", System, true, false, false);
290 AddPath("/boot/develop/headers/os/kernel", System, true, false, false);
291 AddPath("/boot/develop/headers/os/locale", System, true, false, false);
292 AddPath("/boot/develop/headers/os/mail", System, true, false, false);
293 AddPath("/boot/develop/headers/os/media", System, true, false, false);
294 AddPath("/boot/develop/headers/os/midi", System, true, false, false);
295 AddPath("/boot/develop/headers/os/midi2", System, true, false, false);
296 AddPath("/boot/develop/headers/os/net", System, true, false, false);
297 AddPath("/boot/develop/headers/os/storage", System, true, false, false);
298 AddPath("/boot/develop/headers/os/support", System, true, false, false);
299 AddPath("/boot/develop/headers/os/translation",
300 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000301 AddPath("/boot/develop/headers/os/add-ons/graphics",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000302 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000303 AddPath("/boot/develop/headers/os/add-ons/input_server",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000304 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000305 AddPath("/boot/develop/headers/os/add-ons/screen_saver",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000306 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000307 AddPath("/boot/develop/headers/os/add-ons/tracker",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000308 System, true, false, false);
309 AddPath("/boot/develop/headers/os/be_apps/Deskbar",
310 System, true, false, false);
311 AddPath("/boot/develop/headers/os/be_apps/NetPositive",
312 System, true, false, false);
313 AddPath("/boot/develop/headers/os/be_apps/Tracker",
314 System, true, false, false);
315 AddPath("/boot/develop/headers/cpp", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000316 AddPath("/boot/develop/headers/cpp/i586-pc-haiku",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000317 System, true, false, false);
318 AddPath("/boot/develop/headers/3rdparty", System, true, false, false);
319 AddPath("/boot/develop/headers/bsd", System, true, false, false);
320 AddPath("/boot/develop/headers/glibc", System, true, false, false);
321 AddPath("/boot/develop/headers/posix", System, true, false, false);
322 AddPath("/boot/develop/headers", System, true, false, false);
Eli Friedmana7e68452010-08-22 01:00:03 +0000323 break;
Douglas Gregordca52262011-07-01 22:41:14 +0000324 case llvm::Triple::RTEMS:
325 break;
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000326 case llvm::Triple::Cygwin:
327 AddPath("/usr/include/w32api", System, true, false, false);
328 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000329 case llvm::Triple::MinGW32: {
330 // mingw-w64 crt include paths
331 llvm::sys::Path P(HSOpts.ResourceDir);
332 P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include
333 AddPath(P.str(), System, true, false, false);
334 P = llvm::sys::Path(HSOpts.ResourceDir);
335 P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include
336 AddPath(P.str(), System, true, false, false);
337 // mingw.org crt include paths
338 P = llvm::sys::Path(HSOpts.ResourceDir);
339 P.appendComponent("../../../include"); // <sysroot>/include
340 AddPath(P.str(), System, true, false, false);
341 AddPath("/mingw/include", System, true, false, false);
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000342 AddMinGWCIncludePaths("c:/mingw");
Douglas Gregord944a9b2011-06-27 15:47:15 +0000343 }
Mike Stump43d81762009-10-08 23:29:47 +0000344 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000345
Mike Stump43d81762009-10-08 23:29:47 +0000346 default:
Mike Stump43d81762009-10-08 23:29:47 +0000347 break;
348 }
John Thompsond3f88342009-10-13 18:51:32 +0000349
Douglas Gregordca52262011-07-01 22:41:14 +0000350 if ( os != llvm::Triple::RTEMS )
351 AddPath("/usr/include", System, false, false, false);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000352}
353
Chris Lattner0e3cc052010-05-05 05:28:39 +0000354void InitHeaderSearch::
Douglas Gregord944a9b2011-06-27 15:47:15 +0000355AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000356 llvm::Triple::OSType os = triple.getOS();
357 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000358
359 if (triple.isOSDarwin()) {
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000360 switch (triple.getArch()) {
361 default: break;
362
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000363 case llvm::Triple::ppc:
Douglas Gregor582c3012010-05-29 01:15:12 +0000364 case llvm::Triple::ppc64:
Douglas Gregor616d4362010-05-29 01:21:11 +0000365 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000366 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor616d4362010-05-29 01:21:11 +0000367 triple);
Douglas Gregor582c3012010-05-29 01:15:12 +0000368 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000369 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor582c3012010-05-29 01:15:12 +0000370 triple);
371 break;
372
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000373 case llvm::Triple::x86:
374 case llvm::Triple::x86_64:
375 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
376 "i686-apple-darwin10", "", "x86_64", triple);
377 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
378 "i686-apple-darwin8", "", "", triple);
379 break;
380
381 case llvm::Triple::arm:
382 case llvm::Triple::thumb:
383 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
384 "arm-apple-darwin10", "v7", "", triple);
385 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
386 "arm-apple-darwin10", "v6", "", triple);
387 break;
388 }
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000389 return;
390 }
391
392 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000393 case llvm::Triple::Linux:
394 case llvm::Triple::Win32:
395 llvm_unreachable("Include management is handled in the driver.");
396
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000397 case llvm::Triple::Cygwin:
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000398 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000399 break;
400 case llvm::Triple::MinGW32:
Douglas Gregord944a9b2011-06-27 15:47:15 +0000401 // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000402 AddMinGW64CXXPaths(HSOpts.ResourceDir);
Douglas Gregord944a9b2011-06-27 15:47:15 +0000403 // mingw.org C++ include paths
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000404 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32"); //MSYS
405 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32");
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000406 break;
Chris Lattner7a7ca282010-01-09 05:41:14 +0000407 case llvm::Triple::DragonFly:
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000408 AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false);
Chris Lattner7a7ca282010-01-09 05:41:14 +0000409 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000410 case llvm::Triple::FreeBSD:
mike-mac78b7a2010-05-06 14:11:13 +0000411 // FreeBSD 8.0
412 // FreeBSD 7.3
Nuno Lopesafe859a2010-01-17 00:00:11 +0000413 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000414 break;
Anton Korobeynikovab079412010-08-31 22:39:50 +0000415 case llvm::Triple::NetBSD:
416 AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple);
417 break;
Daniel Dunbar95c04572010-08-01 23:13:54 +0000418 case llvm::Triple::OpenBSD: {
419 std::string t = triple.getTriple();
420 if (t.substr(0, 6) == "x86_64")
421 t.replace(0, 6, "amd64");
422 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
423 t, "", "", triple);
424 break;
425 }
Chris Lattner38e317d2010-07-07 16:01:42 +0000426 case llvm::Triple::Minix:
427 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
428 "", "", "", triple);
429 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000430 case llvm::Triple::Solaris:
David Chisnallb6229592012-02-15 18:24:31 +0000431 AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
432 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000433 // Solaris - Fall though..
434 case llvm::Triple::AuroraUX:
435 // AuroraUX
436 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000437 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000438 break;
439 default:
440 break;
441 }
442}
443
Daniel Dunbara268fc02011-10-11 18:20:10 +0000444void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
445 const llvm::Triple &triple,
mike-m79bc57c2010-05-16 19:03:52 +0000446 const HeaderSearchOptions &HSOpts) {
Chandler Carruthca234192011-11-04 23:49:05 +0000447 // NB: This code path is going away. All of the logic is moving into the
448 // driver which has the information necessary to do target-specific
449 // selections of default include paths. Each target which moves there will be
450 // exempted from this logic here until we can delete the entire pile of code.
451 switch (triple.getOS()) {
452 default:
453 break; // Everything else continues to use this routine's logic.
454
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000455 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000456 case llvm::Triple::Win32:
457 return;
458 }
459
Daniel Dunbara268fc02011-10-11 18:20:10 +0000460 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
461 HSOpts.UseStandardSystemIncludes) {
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000462 if (HSOpts.UseLibcxx) {
463 if (triple.isOSDarwin()) {
464 // On Darwin, libc++ may be installed alongside the compiler in
465 // lib/c++/v1.
466 llvm::sys::Path P(HSOpts.ResourceDir);
467 if (!P.isEmpty()) {
468 P.eraseComponent(); // Remove version from foo/lib/clang/version
469 P.eraseComponent(); // Remove clang from foo/lib/clang
470
471 // Get foo/lib/c++/v1
472 P.appendComponent("c++");
473 P.appendComponent("v1");
474 AddPath(P.str(), CXXSystem, true, false, false, true);
475 }
476 }
David Chisnallb4f0bd62012-03-02 10:49:52 +0000477 // On Solaris, include the support directory for things like xlocale and
478 // fudged system headers.
479 if (triple.getOS() == llvm::Triple::Solaris)
480 AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, true, false,
481 false);
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000482
Bob Wilson13c4f212011-06-21 21:12:29 +0000483 AddPath("/usr/include/c++/v1", CXXSystem, true, false, false);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000484 } else {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000485 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000486 }
Bob Wilson13c4f212011-06-21 21:12:29 +0000487 }
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000488
mike-m79bc57c2010-05-16 19:03:52 +0000489 AddDefaultCIncludePaths(triple, HSOpts);
Daniel Dunbare1665822009-11-07 04:20:39 +0000490
491 // Add the default framework include paths on Darwin.
Daniel Dunbara268fc02011-10-11 18:20:10 +0000492 if (HSOpts.UseStandardSystemIncludes) {
493 if (triple.isOSDarwin()) {
494 AddPath("/System/Library/Frameworks", System, true, false, true);
495 AddPath("/Library/Frameworks", System, true, false, true);
496 }
Daniel Dunbare1665822009-11-07 04:20:39 +0000497 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000498}
499
Nico Weber0fca0222008-08-22 09:25:22 +0000500/// RemoveDuplicates - If there are duplicate directory entries in the specified
Chad Rosiere305e812011-10-10 18:44:24 +0000501/// search list, remove the later (dead) ones. Returns the number of non-system
502/// headers removed, which is used to update NumAngled.
503static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
504 unsigned First, bool Verbose) {
Nico Weber0fca0222008-08-22 09:25:22 +0000505 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
506 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
507 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
Chad Rosiere305e812011-10-10 18:44:24 +0000508 unsigned NonSystemRemoved = 0;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000509 for (unsigned i = First; i != SearchList.size(); ++i) {
Chris Lattner7a739402008-09-26 17:46:45 +0000510 unsigned DirToRemove = i;
Mike Stump1eb44332009-09-09 15:08:12 +0000511
Chris Lattner43eee072009-02-08 01:00:10 +0000512 const DirectoryLookup &CurEntry = SearchList[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000513
Chris Lattner43eee072009-02-08 01:00:10 +0000514 if (CurEntry.isNormalDir()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000515 // If this isn't the first time we've seen this dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000516 if (SeenDirs.insert(CurEntry.getDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000517 continue;
Chris Lattner43eee072009-02-08 01:00:10 +0000518 } else if (CurEntry.isFramework()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000519 // If this isn't the first time we've seen this framework dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000520 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000521 continue;
Nico Weber0fca0222008-08-22 09:25:22 +0000522 } else {
Chris Lattner43eee072009-02-08 01:00:10 +0000523 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
Nico Weber0fca0222008-08-22 09:25:22 +0000524 // If this isn't the first time we've seen this headermap, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000525 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
Nico Weber0fca0222008-08-22 09:25:22 +0000526 continue;
Chris Lattner30f05b52009-02-08 00:55:22 +0000527 }
Mike Stump1eb44332009-09-09 15:08:12 +0000528
Chris Lattner30f05b52009-02-08 00:55:22 +0000529 // If we have a normal #include dir/framework/headermap that is shadowed
530 // later in the chain by a system include location, we actually want to
531 // ignore the user's request and drop the user dir... keeping the system
532 // dir. This is weird, but required to emulate GCC's search path correctly.
533 //
534 // Since dupes of system dirs are rare, just rescan to find the original
535 // that we're nuking instead of using a DenseMap.
Chris Lattner43eee072009-02-08 01:00:10 +0000536 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
Chris Lattner30f05b52009-02-08 00:55:22 +0000537 // Find the dir that this is the same of.
538 unsigned FirstDir;
539 for (FirstDir = 0; ; ++FirstDir) {
540 assert(FirstDir != i && "Didn't find dupe?");
Mike Stump1eb44332009-09-09 15:08:12 +0000541
Chris Lattner43eee072009-02-08 01:00:10 +0000542 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
543
Chris Lattner30f05b52009-02-08 00:55:22 +0000544 // If these are different lookup types, then they can't be the dupe.
Chris Lattner43eee072009-02-08 01:00:10 +0000545 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
Chris Lattner30f05b52009-02-08 00:55:22 +0000546 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000547
Chris Lattner30f05b52009-02-08 00:55:22 +0000548 bool isSame;
Chris Lattner43eee072009-02-08 01:00:10 +0000549 if (CurEntry.isNormalDir())
550 isSame = SearchEntry.getDir() == CurEntry.getDir();
551 else if (CurEntry.isFramework())
552 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
Chris Lattner30f05b52009-02-08 00:55:22 +0000553 else {
Chris Lattner43eee072009-02-08 01:00:10 +0000554 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
555 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
Chris Lattner30f05b52009-02-08 00:55:22 +0000556 }
Mike Stump1eb44332009-09-09 15:08:12 +0000557
Chris Lattner30f05b52009-02-08 00:55:22 +0000558 if (isSame)
559 break;
560 }
Mike Stump1eb44332009-09-09 15:08:12 +0000561
Chris Lattner30f05b52009-02-08 00:55:22 +0000562 // If the first dir in the search path is a non-system dir, zap it
563 // instead of the system one.
564 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
565 DirToRemove = FirstDir;
566 }
567
568 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000569 llvm::errs() << "ignoring duplicate directory \""
570 << CurEntry.getName() << "\"\n";
Chris Lattner30f05b52009-02-08 00:55:22 +0000571 if (DirToRemove != i)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000572 llvm::errs() << " as it is a non-system directory that duplicates "
573 << "a system directory\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000574 }
Chad Rosiere305e812011-10-10 18:44:24 +0000575 if (DirToRemove != i)
576 ++NonSystemRemoved;
Mike Stump1eb44332009-09-09 15:08:12 +0000577
Chris Lattner7a739402008-09-26 17:46:45 +0000578 // This is reached if the current entry is a duplicate. Remove the
579 // DirToRemove (usually the current dir).
580 SearchList.erase(SearchList.begin()+DirToRemove);
Nico Weber0fca0222008-08-22 09:25:22 +0000581 --i;
582 }
Chad Rosiere305e812011-10-10 18:44:24 +0000583 return NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000584}
585
586
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000587void InitHeaderSearch::Realize(const LangOptions &Lang) {
Nico Weber0fca0222008-08-22 09:25:22 +0000588 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
589 std::vector<DirectoryLookup> SearchList;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000590 SearchList.reserve(IncludePath.size());
Mike Stump1eb44332009-09-09 15:08:12 +0000591
Chris Lattnerebb61642011-06-16 22:56:45 +0000592 // Quoted arguments go first.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000593 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
594 it != ie; ++it) {
595 if (it->first == Quoted)
596 SearchList.push_back(it->second);
597 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000598 // Deduplicate and remember index.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000599 RemoveDuplicates(SearchList, 0, Verbose);
Chris Lattnerebb61642011-06-16 22:56:45 +0000600 unsigned NumQuoted = SearchList.size();
Mike Stump1eb44332009-09-09 15:08:12 +0000601
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000602 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
603 it != ie; ++it) {
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000604 if (it->first == Angled || it->first == IndexHeaderMap)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000605 SearchList.push_back(it->second);
606 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000607
608 RemoveDuplicates(SearchList, NumQuoted, Verbose);
609 unsigned NumAngled = SearchList.size();
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000610
611 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
612 it != ie; ++it) {
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000613 if (it->first == System ||
614 (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
Benjamin Kramerc535d972011-09-23 02:25:14 +0000615 (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000616 (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
617 (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000618 SearchList.push_back(it->second);
619 }
620
621 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
622 it != ie; ++it) {
623 if (it->first == After)
624 SearchList.push_back(it->second);
625 }
626
Chris Lattner1d7f12b2011-06-16 22:58:10 +0000627 // Remove duplicates across both the Angled and System directories. GCC does
628 // this and failing to remove duplicates across these two groups breaks
629 // #include_next.
Chad Rosiere305e812011-10-10 18:44:24 +0000630 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
631 NumAngled -= NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000632
633 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
Chris Lattnerebb61642011-06-16 22:56:45 +0000634 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
Nico Weber0fca0222008-08-22 09:25:22 +0000635
636 // If verbose, print the list of directories that will be searched.
637 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000638 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000639 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
Chris Lattnerebb61642011-06-16 22:56:45 +0000640 if (i == NumQuoted)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000641 llvm::errs() << "#include <...> search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000642 const char *Name = SearchList[i].getName();
643 const char *Suffix;
644 if (SearchList[i].isNormalDir())
645 Suffix = "";
646 else if (SearchList[i].isFramework())
647 Suffix = " (framework directory)";
648 else {
649 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
650 Suffix = " (headermap)";
651 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000652 llvm::errs() << " " << Name << Suffix << "\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000653 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000654 llvm::errs() << "End of search list.\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000655 }
656}
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000657
Daniel Dunbar5814e652009-11-11 21:44:21 +0000658void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
659 const HeaderSearchOptions &HSOpts,
660 const LangOptions &Lang,
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000661 const llvm::Triple &Triple) {
662 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
663
664 // Add the user defined entries.
665 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
666 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Chandler Carruthac2bc4d2011-11-05 08:30:29 +0000667 Init.AddPath(E.Path, E.Group, !E.ImplicitExternC, E.IsUserSupplied,
668 E.IsFramework, E.IgnoreSysRoot);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000669 }
670
Daniel Dunbara268fc02011-10-11 18:20:10 +0000671 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000672
Douglas Gregor2f04f182012-02-02 18:42:48 +0000673 if (HSOpts.UseBuiltinIncludes) {
674 // Set up the builtin include directory in the module map.
675 llvm::sys::Path P(HSOpts.ResourceDir);
676 P.appendComponent("include");
677 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str()))
678 HS.getModuleMap().setBuiltinIncludeDir(Dir);
679 }
680
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000681 Init.Realize(Lang);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000682}