blob: 3f7e6825140cfa64063667284bb701b3a8bac67a [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"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000027#include "llvm/Support/Path.h"
Dylan Noblesmith69d3b4f2012-02-01 14:25:28 +000028
Dylan Noblesmithcc8a9452012-02-14 15:54:49 +000029#include "clang/Config/config.h" // C_INCLUDE_DIRS
Dylan Noblesmith69d3b4f2012-02-01 14:25:28 +000030
Nico Weber0fca0222008-08-22 09:25:22 +000031using namespace clang;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000032using namespace clang::frontend;
33
34namespace {
35
36/// InitHeaderSearch - This class makes it easier to set the search paths of
37/// a HeaderSearch object. InitHeaderSearch stores several search path lists
38/// internally, which can be sent to a HeaderSearch object in one swoop.
39class InitHeaderSearch {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +000040 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
41 typedef std::vector<std::pair<IncludeDirGroup,
42 DirectoryLookup> >::const_iterator path_iterator;
Chris Lattnerebb61642011-06-16 22:56:45 +000043 HeaderSearch &Headers;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000044 bool Verbose;
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000045 std::string IncludeSysroot;
46 bool IsNotEmptyOrRoot;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000047
48public:
49
Chris Lattner5f9e2722011-07-23 10:55:15 +000050 InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000051 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
52 IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) {
Chandler Carruthc09265a2010-11-15 07:15:26 +000053 }
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000054
55 /// AddPath - Add the specified path to the specified group list.
Chris Lattner5f9e2722011-07-23 10:55:15 +000056 void AddPath(const Twine &Path, IncludeDirGroup Group,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000057 bool isCXXAware, bool isUserSupplied,
58 bool isFramework, bool IgnoreSysRoot = false);
59
mike-ma6087372010-05-05 17:00:31 +000060 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000061 /// libstdc++.
Chris Lattner5f9e2722011-07-23 10:55:15 +000062 void AddGnuCPlusPlusIncludePaths(StringRef Base,
63 StringRef ArchDir,
64 StringRef Dir32,
65 StringRef Dir64,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000066 const llvm::Triple &triple);
67
Michael J. Spencer06a8dc62010-12-21 16:45:42 +000068 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000069 /// libstdc++.
Chris Lattner5f9e2722011-07-23 10:55:15 +000070 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
71 StringRef Arch,
72 StringRef Version);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000073
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000074 /// AddMinGW64CXXPaths - Add the necessary paths to support
75 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
Chris Lattner5f9e2722011-07-23 10:55:15 +000076 void AddMinGW64CXXPaths(StringRef Base,
77 StringRef Version);
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000078
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000079 // AddDefaultCIncludePaths - Add paths that should always be searched.
mike-m79bc57c2010-05-16 19:03:52 +000080 void AddDefaultCIncludePaths(const llvm::Triple &triple,
81 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000082
83 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
84 // compiling c++.
Douglas Gregord944a9b2011-06-27 15:47:15 +000085 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
86 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000087
88 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
89 /// that e.g. stdio.h is found.
Daniel Dunbara268fc02011-10-11 18:20:10 +000090 void AddDefaultIncludePaths(const LangOptions &Lang,
91 const llvm::Triple &triple,
92 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000093
94 /// Realize - Merges all search path lists into one list and send it to
95 /// HeaderSearch.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +000096 void Realize(const LangOptions &Lang);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000097};
98
Chris Lattnerebb61642011-06-16 22:56:45 +000099} // end anonymous namespace.
Nico Weber0fca0222008-08-22 09:25:22 +0000100
Chris Lattner5f9e2722011-07-23 10:55:15 +0000101void InitHeaderSearch::AddPath(const Twine &Path,
Benjamin Kramer458fb102009-09-05 09:49:39 +0000102 IncludeDirGroup Group, bool isCXXAware,
103 bool isUserSupplied, bool isFramework,
104 bool IgnoreSysRoot) {
Benjamin Kramere89ba592009-12-08 12:38:20 +0000105 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
Nico Weber0fca0222008-08-22 09:25:22 +0000106 FileManager &FM = Headers.getFileMgr();
Mike Stump1eb44332009-09-09 15:08:12 +0000107
Nico Weber0fca0222008-08-22 09:25:22 +0000108 // Compute the actual path, taking into consideration -isysroot.
Dylan Noblesmithf7ccbad2012-02-05 02:13:05 +0000109 SmallString<256> MappedPathStorage;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000110 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
Mike Stump1eb44332009-09-09 15:08:12 +0000111
Nico Weber0fca0222008-08-22 09:25:22 +0000112 // Handle isysroot.
Rafael Espindola9a7e09d2011-03-02 21:30:07 +0000113 if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot &&
NAKAMURA Takumi0f0cdab2011-05-02 04:50:10 +0000114#if defined(_WIN32)
115 !MappedPathStr.empty() &&
116 llvm::sys::path::is_separator(MappedPathStr[0]) &&
117#else
Michael J. Spencer256053b2010-12-17 21:22:22 +0000118 llvm::sys::path::is_absolute(MappedPathStr) &&
NAKAMURA Takumi0f0cdab2011-05-02 04:50:10 +0000119#endif
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000120 IsNotEmptyOrRoot) {
Chandler Carruth5619ae52010-11-15 09:28:23 +0000121 MappedPathStorage.clear();
Chandler Carruthc09265a2010-11-15 07:15:26 +0000122 MappedPathStr =
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000123 (IncludeSysroot + Path).toStringRef(MappedPathStorage);
Nico Weber0fca0222008-08-22 09:25:22 +0000124 }
Mike Stump1eb44332009-09-09 15:08:12 +0000125
Nico Weber0fca0222008-08-22 09:25:22 +0000126 // Compute the DirectoryLookup type.
Chris Lattner9d728512008-10-27 01:19:25 +0000127 SrcMgr::CharacteristicKind Type;
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000128 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000129 Type = SrcMgr::C_User;
Nico Weber0fca0222008-08-22 09:25:22 +0000130 else if (isCXXAware)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000131 Type = SrcMgr::C_System;
Nico Weber0fca0222008-08-22 09:25:22 +0000132 else
Chris Lattner0b9e7362008-09-26 21:18:42 +0000133 Type = SrcMgr::C_ExternCSystem;
Mike Stump1eb44332009-09-09 15:08:12 +0000134
135
Nico Weber0fca0222008-08-22 09:25:22 +0000136 // If the directory exists, add it.
Chris Lattner39b49bc2010-11-23 08:35:12 +0000137 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000138 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type,
139 isUserSupplied, isFramework)));
Nico Weber0fca0222008-08-22 09:25:22 +0000140 return;
141 }
Mike Stump1eb44332009-09-09 15:08:12 +0000142
Nico Weber0fca0222008-08-22 09:25:22 +0000143 // Check to see if this is an apple-style headermap (which are not allowed to
144 // be frameworks).
145 if (!isFramework) {
Chris Lattner39b49bc2010-11-23 08:35:12 +0000146 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
Nico Weber0fca0222008-08-22 09:25:22 +0000147 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
148 // It is a headermap, add it to the search path.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000149 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type,
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000150 isUserSupplied, Group == IndexHeaderMap)));
Nico Weber0fca0222008-08-22 09:25:22 +0000151 return;
152 }
153 }
154 }
Mike Stump1eb44332009-09-09 15:08:12 +0000155
Nico Weber0fca0222008-08-22 09:25:22 +0000156 if (Verbose)
Chandler Carruthf3721452010-11-15 00:48:13 +0000157 llvm::errs() << "ignoring nonexistent directory \""
158 << MappedPathStr << "\"\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000159}
160
Chris Lattner5f9e2722011-07-23 10:55:15 +0000161void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
162 StringRef ArchDir,
163 StringRef Dir32,
164 StringRef Dir64,
Rafael Espindola31b63be2009-10-14 17:09:44 +0000165 const llvm::Triple &triple) {
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000166 // Add the base dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000167 AddPath(Base, CXXSystem, true, false, false);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000168
169 // Add the multilib dirs
Rafael Espindola31b63be2009-10-14 17:09:44 +0000170 llvm::Triple::ArchType arch = triple.getArch();
171 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola31b63be2009-10-14 17:09:44 +0000172 if (is64bit)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000173 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false);
Rafael Espindola31b63be2009-10-14 17:09:44 +0000174 else
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000175 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false);
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000176
177 // Add the backward dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000178 AddPath(Base + "/backward", CXXSystem, true, false, false);
Rafael Espindola2e9f6522009-10-06 01:33:02 +0000179}
Nico Weber0fca0222008-08-22 09:25:22 +0000180
Chris Lattner5f9e2722011-07-23 10:55:15 +0000181void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
182 StringRef Arch,
183 StringRef Version) {
Benjamin Kramerab8ae192010-01-20 16:18:11 +0000184 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000185 CXXSystem, true, false, false);
Chris Lattner8e9006b2010-09-03 16:45:53 +0000186 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000187 CXXSystem, true, false, false);
Benjamin Kramerab8ae192010-01-20 16:18:11 +0000188 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000189 CXXSystem, true, false, false);
Mike Stump620d57a2009-10-12 20:50:45 +0000190}
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +0000191
Chris Lattner5f9e2722011-07-23 10:55:15 +0000192void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
193 StringRef Version) {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000194 // Assumes Base is HeaderSearchOpts' ResourceDir
195 AddPath(Base + "/../../../include/c++/" + Version,
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000196 CXXSystem, true, false, false);
Douglas Gregord944a9b2011-06-27 15:47:15 +0000197 AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000198 CXXSystem, true, false, false);
Douglas Gregord944a9b2011-06-27 15:47:15 +0000199 AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
200 CXXSystem, true, false, false);
201 AddPath(Base + "/../../../include/c++/" + Version + "/backward",
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000202 CXXSystem, true, false, false);
203}
204
mike-m79bc57c2010-05-16 19:03:52 +0000205void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
206 const HeaderSearchOptions &HSOpts) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000207 llvm::Triple::OSType os = triple.getOS();
208
Daniel Dunbara268fc02011-10-11 18:20:10 +0000209 if (HSOpts.UseStandardSystemIncludes) {
210 switch (os) {
211 case llvm::Triple::FreeBSD:
212 case llvm::Triple::NetBSD:
213 break;
214 default:
215 // FIXME: temporary hack: hard-coded paths.
216 AddPath("/usr/local/include", System, true, false, false);
217 break;
218 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000219 }
mike-m79bc57c2010-05-16 19:03:52 +0000220
221 // Builtin includes use #include_next directives and should be positioned
222 // just prior C include dirs.
223 if (HSOpts.UseBuiltinIncludes) {
224 // Ignore the sys root, we *always* look for clang headers relative to
225 // supplied path.
226 llvm::sys::Path P(HSOpts.ResourceDir);
227 P.appendComponent("include");
228 AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true);
229 }
230
Daniel Dunbara268fc02011-10-11 18:20:10 +0000231 // All remaining additions are for system include directories, early exit if
232 // we aren't using them.
233 if (!HSOpts.UseStandardSystemIncludes)
234 return;
235
mike-m79bc57c2010-05-16 19:03:52 +0000236 // Add dirs specified via 'configure --with-c-include-dirs'.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000237 StringRef CIncludeDirs(C_INCLUDE_DIRS);
Daniel Dunbarc7064682009-11-12 07:28:29 +0000238 if (CIncludeDirs != "") {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000239 SmallVector<StringRef, 5> dirs;
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000240 CIncludeDirs.split(dirs, ":");
Chris Lattner5f9e2722011-07-23 10:55:15 +0000241 for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000242 i != dirs.end();
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000243 ++i)
Rafael Espindolaf0a2f512009-11-12 05:48:41 +0000244 AddPath(*i, System, false, false, false);
245 return;
246 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000247
Mike Stump43d81762009-10-08 23:29:47 +0000248 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000249 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000250 case llvm::Triple::Win32:
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000251 llvm_unreachable("Include management is handled in the driver.");
Chandler Carruthca234192011-11-04 23:49:05 +0000252
Chris Lattner86ed3a32010-04-11 19:29:39 +0000253 case llvm::Triple::Haiku:
254 AddPath("/boot/common/include", System, true, false, false);
255 AddPath("/boot/develop/headers/os", System, true, false, false);
256 AddPath("/boot/develop/headers/os/app", System, true, false, false);
257 AddPath("/boot/develop/headers/os/arch", System, true, false, false);
258 AddPath("/boot/develop/headers/os/device", System, true, false, false);
259 AddPath("/boot/develop/headers/os/drivers", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000260 AddPath("/boot/develop/headers/os/game", System, true, false, false);
Chris Lattner86ed3a32010-04-11 19:29:39 +0000261 AddPath("/boot/develop/headers/os/interface", System, true, false, false);
262 AddPath("/boot/develop/headers/os/kernel", System, true, false, false);
263 AddPath("/boot/develop/headers/os/locale", System, true, false, false);
264 AddPath("/boot/develop/headers/os/mail", System, true, false, false);
265 AddPath("/boot/develop/headers/os/media", System, true, false, false);
266 AddPath("/boot/develop/headers/os/midi", System, true, false, false);
267 AddPath("/boot/develop/headers/os/midi2", System, true, false, false);
268 AddPath("/boot/develop/headers/os/net", System, true, false, false);
269 AddPath("/boot/develop/headers/os/storage", System, true, false, false);
270 AddPath("/boot/develop/headers/os/support", System, true, false, false);
271 AddPath("/boot/develop/headers/os/translation",
272 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000273 AddPath("/boot/develop/headers/os/add-ons/graphics",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000274 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000275 AddPath("/boot/develop/headers/os/add-ons/input_server",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000276 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000277 AddPath("/boot/develop/headers/os/add-ons/screen_saver",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000278 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000279 AddPath("/boot/develop/headers/os/add-ons/tracker",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000280 System, true, false, false);
281 AddPath("/boot/develop/headers/os/be_apps/Deskbar",
282 System, true, false, false);
283 AddPath("/boot/develop/headers/os/be_apps/NetPositive",
284 System, true, false, false);
285 AddPath("/boot/develop/headers/os/be_apps/Tracker",
286 System, true, false, false);
287 AddPath("/boot/develop/headers/cpp", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000288 AddPath("/boot/develop/headers/cpp/i586-pc-haiku",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000289 System, true, false, false);
290 AddPath("/boot/develop/headers/3rdparty", System, true, false, false);
291 AddPath("/boot/develop/headers/bsd", System, true, false, false);
292 AddPath("/boot/develop/headers/glibc", System, true, false, false);
293 AddPath("/boot/develop/headers/posix", System, true, false, false);
294 AddPath("/boot/develop/headers", System, true, false, false);
Eli Friedmana7e68452010-08-22 01:00:03 +0000295 break;
Douglas Gregordca52262011-07-01 22:41:14 +0000296 case llvm::Triple::RTEMS:
297 break;
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000298 case llvm::Triple::Cygwin:
299 AddPath("/usr/include/w32api", System, true, false, false);
300 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000301 case llvm::Triple::MinGW32: {
302 // mingw-w64 crt include paths
303 llvm::sys::Path P(HSOpts.ResourceDir);
304 P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include
305 AddPath(P.str(), System, true, false, false);
306 P = llvm::sys::Path(HSOpts.ResourceDir);
307 P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include
308 AddPath(P.str(), System, true, false, false);
309 // mingw.org crt include paths
310 P = llvm::sys::Path(HSOpts.ResourceDir);
311 P.appendComponent("../../../include"); // <sysroot>/include
312 AddPath(P.str(), System, true, false, false);
313 AddPath("/mingw/include", System, true, false, false);
314 AddPath("c:/mingw/include", System, true, false, false);
315 }
Mike Stump43d81762009-10-08 23:29:47 +0000316 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000317
Mike Stump43d81762009-10-08 23:29:47 +0000318 default:
Mike Stump43d81762009-10-08 23:29:47 +0000319 break;
320 }
John Thompsond3f88342009-10-13 18:51:32 +0000321
Douglas Gregordca52262011-07-01 22:41:14 +0000322 if ( os != llvm::Triple::RTEMS )
323 AddPath("/usr/include", System, false, false, false);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000324}
325
Chris Lattner0e3cc052010-05-05 05:28:39 +0000326void InitHeaderSearch::
Douglas Gregord944a9b2011-06-27 15:47:15 +0000327AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000328 llvm::Triple::OSType os = triple.getOS();
329 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000330
331 if (triple.isOSDarwin()) {
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000332 switch (triple.getArch()) {
333 default: break;
334
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000335 case llvm::Triple::ppc:
Douglas Gregor582c3012010-05-29 01:15:12 +0000336 case llvm::Triple::ppc64:
Douglas Gregor616d4362010-05-29 01:21:11 +0000337 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000338 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor616d4362010-05-29 01:21:11 +0000339 triple);
Douglas Gregor582c3012010-05-29 01:15:12 +0000340 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000341 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor582c3012010-05-29 01:15:12 +0000342 triple);
343 break;
344
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000345 case llvm::Triple::x86:
346 case llvm::Triple::x86_64:
347 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
348 "i686-apple-darwin10", "", "x86_64", triple);
349 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
350 "i686-apple-darwin8", "", "", triple);
351 break;
352
353 case llvm::Triple::arm:
354 case llvm::Triple::thumb:
355 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
356 "arm-apple-darwin10", "v7", "", triple);
357 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
358 "arm-apple-darwin10", "v6", "", triple);
359 break;
360 }
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000361 return;
362 }
363
364 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000365 case llvm::Triple::Linux:
366 case llvm::Triple::Win32:
367 llvm_unreachable("Include management is handled in the driver.");
368
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000369 case llvm::Triple::Cygwin:
370 // Cygwin-1.7
NAKAMURA Takumif3c1ca62012-01-21 14:46:07 +0000371 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000372 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
373 // g++-4 / Cygwin-1.5
374 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000375 break;
376 case llvm::Triple::MinGW32:
Douglas Gregord944a9b2011-06-27 15:47:15 +0000377 // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
378 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
379 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
380 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
381 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
Eli Friedmana74ec5c2011-11-28 23:58:55 +0000382 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
Douglas Gregord944a9b2011-06-27 15:47:15 +0000383 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
384 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
Douglas Gregorf732f2b2011-07-05 14:16:05 +0000385 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
Eli Friedmana74ec5c2011-11-28 23:58:55 +0000386 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
Douglas Gregorf732f2b2011-07-05 14:16:05 +0000387 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
Douglas Gregord944a9b2011-06-27 15:47:15 +0000388 // mingw.org C++ include paths
389 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
Aaron Ballmane87e8512012-03-15 14:31:30 +0000390 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");
391 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");
392 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000393 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000394 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000395 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000396 break;
Chris Lattner7a7ca282010-01-09 05:41:14 +0000397 case llvm::Triple::DragonFly:
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000398 AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false);
Chris Lattner7a7ca282010-01-09 05:41:14 +0000399 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000400 case llvm::Triple::FreeBSD:
mike-mac78b7a2010-05-06 14:11:13 +0000401 // FreeBSD 8.0
402 // FreeBSD 7.3
Nuno Lopesafe859a2010-01-17 00:00:11 +0000403 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000404 break;
Anton Korobeynikovab079412010-08-31 22:39:50 +0000405 case llvm::Triple::NetBSD:
406 AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple);
407 break;
Daniel Dunbar95c04572010-08-01 23:13:54 +0000408 case llvm::Triple::OpenBSD: {
409 std::string t = triple.getTriple();
410 if (t.substr(0, 6) == "x86_64")
411 t.replace(0, 6, "amd64");
412 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
413 t, "", "", triple);
414 break;
415 }
Chris Lattner38e317d2010-07-07 16:01:42 +0000416 case llvm::Triple::Minix:
417 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
418 "", "", "", triple);
419 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000420 case llvm::Triple::Solaris:
David Chisnallb6229592012-02-15 18:24:31 +0000421 AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
422 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000423 // Solaris - Fall though..
424 case llvm::Triple::AuroraUX:
425 // AuroraUX
426 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000427 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000428 break;
429 default:
430 break;
431 }
432}
433
Daniel Dunbara268fc02011-10-11 18:20:10 +0000434void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
435 const llvm::Triple &triple,
mike-m79bc57c2010-05-16 19:03:52 +0000436 const HeaderSearchOptions &HSOpts) {
Chandler Carruthca234192011-11-04 23:49:05 +0000437 // NB: This code path is going away. All of the logic is moving into the
438 // driver which has the information necessary to do target-specific
439 // selections of default include paths. Each target which moves there will be
440 // exempted from this logic here until we can delete the entire pile of code.
441 switch (triple.getOS()) {
442 default:
443 break; // Everything else continues to use this routine's logic.
444
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000445 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000446 case llvm::Triple::Win32:
447 return;
448 }
449
Daniel Dunbara268fc02011-10-11 18:20:10 +0000450 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
451 HSOpts.UseStandardSystemIncludes) {
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000452 if (HSOpts.UseLibcxx) {
453 if (triple.isOSDarwin()) {
454 // On Darwin, libc++ may be installed alongside the compiler in
455 // lib/c++/v1.
456 llvm::sys::Path P(HSOpts.ResourceDir);
457 if (!P.isEmpty()) {
458 P.eraseComponent(); // Remove version from foo/lib/clang/version
459 P.eraseComponent(); // Remove clang from foo/lib/clang
460
461 // Get foo/lib/c++/v1
462 P.appendComponent("c++");
463 P.appendComponent("v1");
464 AddPath(P.str(), CXXSystem, true, false, false, true);
465 }
466 }
David Chisnallb4f0bd62012-03-02 10:49:52 +0000467 // On Solaris, include the support directory for things like xlocale and
468 // fudged system headers.
469 if (triple.getOS() == llvm::Triple::Solaris)
470 AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, true, false,
471 false);
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000472
Bob Wilson13c4f212011-06-21 21:12:29 +0000473 AddPath("/usr/include/c++/v1", CXXSystem, true, false, false);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000474 } else {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000475 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000476 }
Bob Wilson13c4f212011-06-21 21:12:29 +0000477 }
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000478
mike-m79bc57c2010-05-16 19:03:52 +0000479 AddDefaultCIncludePaths(triple, HSOpts);
Daniel Dunbare1665822009-11-07 04:20:39 +0000480
481 // Add the default framework include paths on Darwin.
Daniel Dunbara268fc02011-10-11 18:20:10 +0000482 if (HSOpts.UseStandardSystemIncludes) {
483 if (triple.isOSDarwin()) {
484 AddPath("/System/Library/Frameworks", System, true, false, true);
485 AddPath("/Library/Frameworks", System, true, false, true);
486 }
Daniel Dunbare1665822009-11-07 04:20:39 +0000487 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000488}
489
Nico Weber0fca0222008-08-22 09:25:22 +0000490/// RemoveDuplicates - If there are duplicate directory entries in the specified
Chad Rosiere305e812011-10-10 18:44:24 +0000491/// search list, remove the later (dead) ones. Returns the number of non-system
492/// headers removed, which is used to update NumAngled.
493static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
494 unsigned First, bool Verbose) {
Nico Weber0fca0222008-08-22 09:25:22 +0000495 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
496 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
497 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
Chad Rosiere305e812011-10-10 18:44:24 +0000498 unsigned NonSystemRemoved = 0;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000499 for (unsigned i = First; i != SearchList.size(); ++i) {
Chris Lattner7a739402008-09-26 17:46:45 +0000500 unsigned DirToRemove = i;
Mike Stump1eb44332009-09-09 15:08:12 +0000501
Chris Lattner43eee072009-02-08 01:00:10 +0000502 const DirectoryLookup &CurEntry = SearchList[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000503
Chris Lattner43eee072009-02-08 01:00:10 +0000504 if (CurEntry.isNormalDir()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000505 // If this isn't the first time we've seen this dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000506 if (SeenDirs.insert(CurEntry.getDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000507 continue;
Chris Lattner43eee072009-02-08 01:00:10 +0000508 } else if (CurEntry.isFramework()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000509 // If this isn't the first time we've seen this framework dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000510 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000511 continue;
Nico Weber0fca0222008-08-22 09:25:22 +0000512 } else {
Chris Lattner43eee072009-02-08 01:00:10 +0000513 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
Nico Weber0fca0222008-08-22 09:25:22 +0000514 // If this isn't the first time we've seen this headermap, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000515 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
Nico Weber0fca0222008-08-22 09:25:22 +0000516 continue;
Chris Lattner30f05b52009-02-08 00:55:22 +0000517 }
Mike Stump1eb44332009-09-09 15:08:12 +0000518
Chris Lattner30f05b52009-02-08 00:55:22 +0000519 // If we have a normal #include dir/framework/headermap that is shadowed
520 // later in the chain by a system include location, we actually want to
521 // ignore the user's request and drop the user dir... keeping the system
522 // dir. This is weird, but required to emulate GCC's search path correctly.
523 //
524 // Since dupes of system dirs are rare, just rescan to find the original
525 // that we're nuking instead of using a DenseMap.
Chris Lattner43eee072009-02-08 01:00:10 +0000526 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
Chris Lattner30f05b52009-02-08 00:55:22 +0000527 // Find the dir that this is the same of.
528 unsigned FirstDir;
529 for (FirstDir = 0; ; ++FirstDir) {
530 assert(FirstDir != i && "Didn't find dupe?");
Mike Stump1eb44332009-09-09 15:08:12 +0000531
Chris Lattner43eee072009-02-08 01:00:10 +0000532 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
533
Chris Lattner30f05b52009-02-08 00:55:22 +0000534 // If these are different lookup types, then they can't be the dupe.
Chris Lattner43eee072009-02-08 01:00:10 +0000535 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
Chris Lattner30f05b52009-02-08 00:55:22 +0000536 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000537
Chris Lattner30f05b52009-02-08 00:55:22 +0000538 bool isSame;
Chris Lattner43eee072009-02-08 01:00:10 +0000539 if (CurEntry.isNormalDir())
540 isSame = SearchEntry.getDir() == CurEntry.getDir();
541 else if (CurEntry.isFramework())
542 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
Chris Lattner30f05b52009-02-08 00:55:22 +0000543 else {
Chris Lattner43eee072009-02-08 01:00:10 +0000544 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
545 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
Chris Lattner30f05b52009-02-08 00:55:22 +0000546 }
Mike Stump1eb44332009-09-09 15:08:12 +0000547
Chris Lattner30f05b52009-02-08 00:55:22 +0000548 if (isSame)
549 break;
550 }
Mike Stump1eb44332009-09-09 15:08:12 +0000551
Chris Lattner30f05b52009-02-08 00:55:22 +0000552 // If the first dir in the search path is a non-system dir, zap it
553 // instead of the system one.
554 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
555 DirToRemove = FirstDir;
556 }
557
558 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000559 llvm::errs() << "ignoring duplicate directory \""
560 << CurEntry.getName() << "\"\n";
Chris Lattner30f05b52009-02-08 00:55:22 +0000561 if (DirToRemove != i)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000562 llvm::errs() << " as it is a non-system directory that duplicates "
563 << "a system directory\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000564 }
Chad Rosiere305e812011-10-10 18:44:24 +0000565 if (DirToRemove != i)
566 ++NonSystemRemoved;
Mike Stump1eb44332009-09-09 15:08:12 +0000567
Chris Lattner7a739402008-09-26 17:46:45 +0000568 // This is reached if the current entry is a duplicate. Remove the
569 // DirToRemove (usually the current dir).
570 SearchList.erase(SearchList.begin()+DirToRemove);
Nico Weber0fca0222008-08-22 09:25:22 +0000571 --i;
572 }
Chad Rosiere305e812011-10-10 18:44:24 +0000573 return NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000574}
575
576
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000577void InitHeaderSearch::Realize(const LangOptions &Lang) {
Nico Weber0fca0222008-08-22 09:25:22 +0000578 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
579 std::vector<DirectoryLookup> SearchList;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000580 SearchList.reserve(IncludePath.size());
Mike Stump1eb44332009-09-09 15:08:12 +0000581
Chris Lattnerebb61642011-06-16 22:56:45 +0000582 // Quoted arguments go first.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000583 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
584 it != ie; ++it) {
585 if (it->first == Quoted)
586 SearchList.push_back(it->second);
587 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000588 // Deduplicate and remember index.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000589 RemoveDuplicates(SearchList, 0, Verbose);
Chris Lattnerebb61642011-06-16 22:56:45 +0000590 unsigned NumQuoted = SearchList.size();
Mike Stump1eb44332009-09-09 15:08:12 +0000591
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000592 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
593 it != ie; ++it) {
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000594 if (it->first == Angled || it->first == IndexHeaderMap)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000595 SearchList.push_back(it->second);
596 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000597
598 RemoveDuplicates(SearchList, NumQuoted, Verbose);
599 unsigned NumAngled = SearchList.size();
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000600
601 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
602 it != ie; ++it) {
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000603 if (it->first == System ||
604 (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
Benjamin Kramerc535d972011-09-23 02:25:14 +0000605 (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000606 (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
607 (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000608 SearchList.push_back(it->second);
609 }
610
611 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
612 it != ie; ++it) {
613 if (it->first == After)
614 SearchList.push_back(it->second);
615 }
616
Chris Lattner1d7f12b2011-06-16 22:58:10 +0000617 // Remove duplicates across both the Angled and System directories. GCC does
618 // this and failing to remove duplicates across these two groups breaks
619 // #include_next.
Chad Rosiere305e812011-10-10 18:44:24 +0000620 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
621 NumAngled -= NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000622
623 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
Chris Lattnerebb61642011-06-16 22:56:45 +0000624 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
Nico Weber0fca0222008-08-22 09:25:22 +0000625
626 // If verbose, print the list of directories that will be searched.
627 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000628 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000629 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
Chris Lattnerebb61642011-06-16 22:56:45 +0000630 if (i == NumQuoted)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000631 llvm::errs() << "#include <...> search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000632 const char *Name = SearchList[i].getName();
633 const char *Suffix;
634 if (SearchList[i].isNormalDir())
635 Suffix = "";
636 else if (SearchList[i].isFramework())
637 Suffix = " (framework directory)";
638 else {
639 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
640 Suffix = " (headermap)";
641 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000642 llvm::errs() << " " << Name << Suffix << "\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000643 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000644 llvm::errs() << "End of search list.\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000645 }
646}
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000647
Daniel Dunbar5814e652009-11-11 21:44:21 +0000648void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
649 const HeaderSearchOptions &HSOpts,
650 const LangOptions &Lang,
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000651 const llvm::Triple &Triple) {
652 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
653
654 // Add the user defined entries.
655 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
656 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Chandler Carruthac2bc4d2011-11-05 08:30:29 +0000657 Init.AddPath(E.Path, E.Group, !E.ImplicitExternC, E.IsUserSupplied,
658 E.IsFramework, E.IgnoreSysRoot);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000659 }
660
Daniel Dunbara268fc02011-10-11 18:20:10 +0000661 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000662
Douglas Gregor2f04f182012-02-02 18:42:48 +0000663 if (HSOpts.UseBuiltinIncludes) {
664 // Set up the builtin include directory in the module map.
665 llvm::sys::Path P(HSOpts.ResourceDir);
666 P.appendComponent("include");
667 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str()))
668 HS.getModuleMap().setBuiltinIncludeDir(Dir);
669 }
670
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000671 Init.Realize(Lang);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000672}