blob: 00a1491412139c4d6ae0e76e41aaea3e085a650e [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"
Chandler Carruth55fc8732012-12-04 09:13:33 +000017#include "clang/Config/config.h" // C_INCLUDE_DIRS
Daniel Dunbar63c8b772009-11-07 04:20:50 +000018#include "clang/Lex/HeaderSearch.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000019#include "clang/Lex/HeaderSearchOptions.h"
Nico Weber0fca0222008-08-22 09:25:22 +000020#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000021#include "llvm/ADT/SmallString.h"
Rafael Espindolaaadd7a42009-11-13 05:13:58 +000022#include "llvm/ADT/SmallVector.h"
Rafael Espindolaf0a2f512009-11-12 05:48:41 +000023#include "llvm/ADT/StringExtras.h"
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000024#include "llvm/ADT/Triple.h"
Benjamin Kramere89ba592009-12-08 12:38:20 +000025#include "llvm/ADT/Twine.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"
Chandler Carruth55fc8732012-12-04 09:13:33 +000028#include "llvm/Support/raw_ostream.h"
Dylan Noblesmith69d3b4f2012-02-01 14:25:28 +000029
Nico Weber0fca0222008-08-22 09:25:22 +000030using namespace clang;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000031using namespace clang::frontend;
32
33namespace {
34
35/// InitHeaderSearch - This class makes it easier to set the search paths of
36/// a HeaderSearch object. InitHeaderSearch stores several search path lists
37/// internally, which can be sent to a HeaderSearch object in one swoop.
38class InitHeaderSearch {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +000039 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
40 typedef std::vector<std::pair<IncludeDirGroup,
41 DirectoryLookup> >::const_iterator path_iterator;
Richard Smithf122a132012-06-13 20:27:03 +000042 std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
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
Richard Smithf122a132012-06-13 20:27:03 +000060 /// AddSystemHeaderPrefix - Add the specified prefix to the system header
61 /// prefix list.
62 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
63 SystemHeaderPrefixes.push_back(std::make_pair(Prefix, IsSystemHeader));
64 }
65
mike-ma6087372010-05-05 17:00:31 +000066 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000067 /// libstdc++.
Chris Lattner5f9e2722011-07-23 10:55:15 +000068 void AddGnuCPlusPlusIncludePaths(StringRef Base,
69 StringRef ArchDir,
70 StringRef Dir32,
71 StringRef Dir64,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000072 const llvm::Triple &triple);
73
Michael J. Spencer06a8dc62010-12-21 16:45:42 +000074 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000075 /// libstdc++.
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +000076 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
77 StringRef Arch,
78 StringRef Version);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000079
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000080 /// AddMinGW64CXXPaths - Add the necessary paths to support
81 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +000082 void AddMinGW64CXXPaths(StringRef Base,
83 StringRef Version);
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000084
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000085 // AddDefaultCIncludePaths - Add paths that should always be searched.
mike-m79bc57c2010-05-16 19:03:52 +000086 void AddDefaultCIncludePaths(const llvm::Triple &triple,
87 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000088
89 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
90 // compiling c++.
Douglas Gregord944a9b2011-06-27 15:47:15 +000091 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
92 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000093
94 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
95 /// that e.g. stdio.h is found.
Daniel Dunbara268fc02011-10-11 18:20:10 +000096 void AddDefaultIncludePaths(const LangOptions &Lang,
97 const llvm::Triple &triple,
98 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000099
100 /// Realize - Merges all search path lists into one list and send it to
101 /// HeaderSearch.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000102 void Realize(const LangOptions &Lang);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +0000103};
104
Chris Lattnerebb61642011-06-16 22:56:45 +0000105} // end anonymous namespace.
Nico Weber0fca0222008-08-22 09:25:22 +0000106
Chris Lattner5f9e2722011-07-23 10:55:15 +0000107void InitHeaderSearch::AddPath(const Twine &Path,
Benjamin Kramer458fb102009-09-05 09:49:39 +0000108 IncludeDirGroup Group, bool isCXXAware,
109 bool isUserSupplied, bool isFramework,
110 bool IgnoreSysRoot) {
Benjamin Kramere89ba592009-12-08 12:38:20 +0000111 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
Nico Weber0fca0222008-08-22 09:25:22 +0000112 FileManager &FM = Headers.getFileMgr();
Mike Stump1eb44332009-09-09 15:08:12 +0000113
Nico Weber0fca0222008-08-22 09:25:22 +0000114 // Compute the actual path, taking into consideration -isysroot.
Dylan Noblesmithf7ccbad2012-02-05 02:13:05 +0000115 SmallString<256> MappedPathStorage;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000116 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
Mike Stump1eb44332009-09-09 15:08:12 +0000117
Nico Weber0fca0222008-08-22 09:25:22 +0000118 // Handle isysroot.
Rafael Espindola9a7e09d2011-03-02 21:30:07 +0000119 if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot &&
NAKAMURA Takumi0f0cdab2011-05-02 04:50:10 +0000120#if defined(_WIN32)
121 !MappedPathStr.empty() &&
122 llvm::sys::path::is_separator(MappedPathStr[0]) &&
123#else
Michael J. Spencer256053b2010-12-17 21:22:22 +0000124 llvm::sys::path::is_absolute(MappedPathStr) &&
NAKAMURA Takumi0f0cdab2011-05-02 04:50:10 +0000125#endif
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000126 IsNotEmptyOrRoot) {
Chandler Carruth5619ae52010-11-15 09:28:23 +0000127 MappedPathStorage.clear();
Chandler Carruthc09265a2010-11-15 07:15:26 +0000128 MappedPathStr =
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000129 (IncludeSysroot + Path).toStringRef(MappedPathStorage);
Nico Weber0fca0222008-08-22 09:25:22 +0000130 }
Mike Stump1eb44332009-09-09 15:08:12 +0000131
Nico Weber0fca0222008-08-22 09:25:22 +0000132 // Compute the DirectoryLookup type.
Chris Lattner9d728512008-10-27 01:19:25 +0000133 SrcMgr::CharacteristicKind Type;
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000134 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000135 Type = SrcMgr::C_User;
Nico Weber0fca0222008-08-22 09:25:22 +0000136 else if (isCXXAware)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000137 Type = SrcMgr::C_System;
Nico Weber0fca0222008-08-22 09:25:22 +0000138 else
Chris Lattner0b9e7362008-09-26 21:18:42 +0000139 Type = SrcMgr::C_ExternCSystem;
Mike Stump1eb44332009-09-09 15:08:12 +0000140
141
Nico Weber0fca0222008-08-22 09:25:22 +0000142 // If the directory exists, add it.
Chris Lattner39b49bc2010-11-23 08:35:12 +0000143 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
Daniel Dunbar1ea6bc02013-01-25 01:50:28 +0000144 IncludePath.push_back(
145 std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
Nico Weber0fca0222008-08-22 09:25:22 +0000146 return;
147 }
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Nico Weber0fca0222008-08-22 09:25:22 +0000149 // Check to see if this is an apple-style headermap (which are not allowed to
150 // be frameworks).
151 if (!isFramework) {
Chris Lattner39b49bc2010-11-23 08:35:12 +0000152 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
Nico Weber0fca0222008-08-22 09:25:22 +0000153 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
154 // It is a headermap, add it to the search path.
Daniel Dunbar1ea6bc02013-01-25 01:50:28 +0000155 IncludePath.push_back(
156 std::make_pair(Group,
157 DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
Nico Weber0fca0222008-08-22 09:25:22 +0000158 return;
159 }
160 }
161 }
Mike Stump1eb44332009-09-09 15:08:12 +0000162
Nico Weber0fca0222008-08-22 09:25:22 +0000163 if (Verbose)
Chandler Carruthf3721452010-11-15 00:48:13 +0000164 llvm::errs() << "ignoring nonexistent directory \""
165 << MappedPathStr << "\"\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000166}
167
Chris Lattner5f9e2722011-07-23 10:55:15 +0000168void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
169 StringRef ArchDir,
170 StringRef Dir32,
171 StringRef Dir64,
Rafael Espindola31b63be2009-10-14 17:09:44 +0000172 const llvm::Triple &triple) {
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000173 // Add the base dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000174 AddPath(Base, CXXSystem, true, false, false);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000175
176 // Add the multilib dirs
Rafael Espindola31b63be2009-10-14 17:09:44 +0000177 llvm::Triple::ArchType arch = triple.getArch();
178 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola31b63be2009-10-14 17:09:44 +0000179 if (is64bit)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000180 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false);
Rafael Espindola31b63be2009-10-14 17:09:44 +0000181 else
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000182 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false);
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000183
184 // Add the backward dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000185 AddPath(Base + "/backward", CXXSystem, true, false, false);
Rafael Espindola2e9f6522009-10-06 01:33:02 +0000186}
Nico Weber0fca0222008-08-22 09:25:22 +0000187
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000188void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000189 StringRef Arch,
190 StringRef Version) {
191 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
192 CXXSystem, true, false, false);
193 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
194 CXXSystem, true, false, false);
195 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
196 CXXSystem, true, false, false);
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000197}
198
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000199void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
200 StringRef Version) {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000201 // Assumes Base is HeaderSearchOpts' ResourceDir
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000202 AddPath(Base + "/../../../include/c++/" + Version,
203 CXXSystem, true, false, false);
204 AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
205 CXXSystem, true, false, false);
206 AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
207 CXXSystem, true, false, false);
208 AddPath(Base + "/../../../include/c++/" + Version + "/backward",
209 CXXSystem, true, false, false);
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000210}
211
mike-m79bc57c2010-05-16 19:03:52 +0000212void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
213 const HeaderSearchOptions &HSOpts) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000214 llvm::Triple::OSType os = triple.getOS();
215
Daniel Dunbara268fc02011-10-11 18:20:10 +0000216 if (HSOpts.UseStandardSystemIncludes) {
217 switch (os) {
218 case llvm::Triple::FreeBSD:
219 case llvm::Triple::NetBSD:
Hans Wennborg9d82a032012-08-02 12:27:08 +0000220 case llvm::Triple::OpenBSD:
Eli Friedman42f74f22012-08-08 23:57:20 +0000221 case llvm::Triple::Bitrig:
Daniel Dunbara268fc02011-10-11 18:20:10 +0000222 break;
223 default:
224 // FIXME: temporary hack: hard-coded paths.
225 AddPath("/usr/local/include", System, true, false, false);
226 break;
227 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000228 }
mike-m79bc57c2010-05-16 19:03:52 +0000229
230 // Builtin includes use #include_next directives and should be positioned
231 // just prior C include dirs.
232 if (HSOpts.UseBuiltinIncludes) {
233 // Ignore the sys root, we *always* look for clang headers relative to
234 // supplied path.
235 llvm::sys::Path P(HSOpts.ResourceDir);
236 P.appendComponent("include");
237 AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true);
238 }
239
Daniel Dunbara268fc02011-10-11 18:20:10 +0000240 // All remaining additions are for system include directories, early exit if
241 // we aren't using them.
242 if (!HSOpts.UseStandardSystemIncludes)
243 return;
244
mike-m79bc57c2010-05-16 19:03:52 +0000245 // Add dirs specified via 'configure --with-c-include-dirs'.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000246 StringRef CIncludeDirs(C_INCLUDE_DIRS);
Daniel Dunbarc7064682009-11-12 07:28:29 +0000247 if (CIncludeDirs != "") {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000248 SmallVector<StringRef, 5> dirs;
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000249 CIncludeDirs.split(dirs, ":");
Chris Lattner5f9e2722011-07-23 10:55:15 +0000250 for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000251 i != dirs.end();
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000252 ++i)
Rafael Espindolaf0a2f512009-11-12 05:48:41 +0000253 AddPath(*i, System, false, false, false);
254 return;
255 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000256
Mike Stump43d81762009-10-08 23:29:47 +0000257 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000258 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000259 case llvm::Triple::Win32:
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000260 llvm_unreachable("Include management is handled in the driver.");
Chandler Carruthca234192011-11-04 23:49:05 +0000261
Chris Lattner86ed3a32010-04-11 19:29:39 +0000262 case llvm::Triple::Haiku:
263 AddPath("/boot/common/include", System, true, false, false);
264 AddPath("/boot/develop/headers/os", System, true, false, false);
265 AddPath("/boot/develop/headers/os/app", System, true, false, false);
266 AddPath("/boot/develop/headers/os/arch", System, true, false, false);
267 AddPath("/boot/develop/headers/os/device", System, true, false, false);
268 AddPath("/boot/develop/headers/os/drivers", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000269 AddPath("/boot/develop/headers/os/game", System, true, false, false);
Chris Lattner86ed3a32010-04-11 19:29:39 +0000270 AddPath("/boot/develop/headers/os/interface", System, true, false, false);
271 AddPath("/boot/develop/headers/os/kernel", System, true, false, false);
272 AddPath("/boot/develop/headers/os/locale", System, true, false, false);
273 AddPath("/boot/develop/headers/os/mail", System, true, false, false);
274 AddPath("/boot/develop/headers/os/media", System, true, false, false);
275 AddPath("/boot/develop/headers/os/midi", System, true, false, false);
276 AddPath("/boot/develop/headers/os/midi2", System, true, false, false);
277 AddPath("/boot/develop/headers/os/net", System, true, false, false);
278 AddPath("/boot/develop/headers/os/storage", System, true, false, false);
279 AddPath("/boot/develop/headers/os/support", System, true, false, false);
280 AddPath("/boot/develop/headers/os/translation",
281 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000282 AddPath("/boot/develop/headers/os/add-ons/graphics",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000283 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000284 AddPath("/boot/develop/headers/os/add-ons/input_server",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000285 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000286 AddPath("/boot/develop/headers/os/add-ons/screen_saver",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000287 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000288 AddPath("/boot/develop/headers/os/add-ons/tracker",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000289 System, true, false, false);
290 AddPath("/boot/develop/headers/os/be_apps/Deskbar",
291 System, true, false, false);
292 AddPath("/boot/develop/headers/os/be_apps/NetPositive",
293 System, true, false, false);
294 AddPath("/boot/develop/headers/os/be_apps/Tracker",
295 System, true, false, false);
296 AddPath("/boot/develop/headers/cpp", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000297 AddPath("/boot/develop/headers/cpp/i586-pc-haiku",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000298 System, true, false, false);
299 AddPath("/boot/develop/headers/3rdparty", System, true, false, false);
300 AddPath("/boot/develop/headers/bsd", System, true, false, false);
301 AddPath("/boot/develop/headers/glibc", System, true, false, false);
302 AddPath("/boot/develop/headers/posix", System, true, false, false);
303 AddPath("/boot/develop/headers", System, true, false, false);
Eli Friedmana7e68452010-08-22 01:00:03 +0000304 break;
Douglas Gregordca52262011-07-01 22:41:14 +0000305 case llvm::Triple::RTEMS:
306 break;
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000307 case llvm::Triple::Cygwin:
308 AddPath("/usr/include/w32api", System, true, false, false);
309 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000310 case llvm::Triple::MinGW32: {
311 // mingw-w64 crt include paths
312 llvm::sys::Path P(HSOpts.ResourceDir);
313 P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include
314 AddPath(P.str(), System, true, false, false);
315 P = llvm::sys::Path(HSOpts.ResourceDir);
316 P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include
317 AddPath(P.str(), System, true, false, false);
318 // mingw.org crt include paths
319 P = llvm::sys::Path(HSOpts.ResourceDir);
320 P.appendComponent("../../../include"); // <sysroot>/include
321 AddPath(P.str(), System, true, false, false);
322 AddPath("/mingw/include", System, true, false, false);
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000323#if defined(_WIN32)
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000324 AddPath("c:/mingw/include", System, true, false, false);
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000325#endif
Douglas Gregord944a9b2011-06-27 15:47:15 +0000326 }
Mike Stump43d81762009-10-08 23:29:47 +0000327 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000328
Mike Stump43d81762009-10-08 23:29:47 +0000329 default:
Mike Stump43d81762009-10-08 23:29:47 +0000330 break;
331 }
John Thompsond3f88342009-10-13 18:51:32 +0000332
Douglas Gregordca52262011-07-01 22:41:14 +0000333 if ( os != llvm::Triple::RTEMS )
334 AddPath("/usr/include", System, false, false, false);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000335}
336
Chris Lattner0e3cc052010-05-05 05:28:39 +0000337void InitHeaderSearch::
Douglas Gregord944a9b2011-06-27 15:47:15 +0000338AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000339 llvm::Triple::OSType os = triple.getOS();
340 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000341
342 if (triple.isOSDarwin()) {
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000343 switch (triple.getArch()) {
344 default: break;
345
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000346 case llvm::Triple::ppc:
Douglas Gregor582c3012010-05-29 01:15:12 +0000347 case llvm::Triple::ppc64:
Douglas Gregor616d4362010-05-29 01:21:11 +0000348 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000349 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor616d4362010-05-29 01:21:11 +0000350 triple);
Douglas Gregor582c3012010-05-29 01:15:12 +0000351 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000352 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor582c3012010-05-29 01:15:12 +0000353 triple);
354 break;
355
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000356 case llvm::Triple::x86:
357 case llvm::Triple::x86_64:
358 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
359 "i686-apple-darwin10", "", "x86_64", triple);
360 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
361 "i686-apple-darwin8", "", "", triple);
362 break;
363
364 case llvm::Triple::arm:
365 case llvm::Triple::thumb:
366 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
367 "arm-apple-darwin10", "v7", "", triple);
368 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
369 "arm-apple-darwin10", "v6", "", triple);
370 break;
371 }
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000372 return;
373 }
374
375 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000376 case llvm::Triple::Linux:
377 case llvm::Triple::Win32:
378 llvm_unreachable("Include management is handled in the driver.");
379
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000380 case llvm::Triple::Cygwin:
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000381 // Cygwin-1.7
382 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
383 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
384 // g++-4 / Cygwin-1.5
385 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000386 break;
387 case llvm::Triple::MinGW32:
Douglas Gregord944a9b2011-06-27 15:47:15 +0000388 // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000389 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
390 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
391 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
392 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
393 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
394 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
395 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
396 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
397 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
398 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
Douglas Gregord944a9b2011-06-27 15:47:15 +0000399 // mingw.org C++ include paths
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000400 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000401#if defined(_WIN32)
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000402 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");
403 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");
404 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");
405 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
406 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
407 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000408#endif
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000409 break;
Chris Lattner7a7ca282010-01-09 05:41:14 +0000410 case llvm::Triple::DragonFly:
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000411 AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false);
Chris Lattner7a7ca282010-01-09 05:41:14 +0000412 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000413 case llvm::Triple::FreeBSD:
mike-mac78b7a2010-05-06 14:11:13 +0000414 // FreeBSD 8.0
415 // FreeBSD 7.3
Nuno Lopesafe859a2010-01-17 00:00:11 +0000416 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000417 break;
Anton Korobeynikovab079412010-08-31 22:39:50 +0000418 case llvm::Triple::NetBSD:
419 AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple);
420 break;
Daniel Dunbar95c04572010-08-01 23:13:54 +0000421 case llvm::Triple::OpenBSD: {
422 std::string t = triple.getTriple();
423 if (t.substr(0, 6) == "x86_64")
424 t.replace(0, 6, "amd64");
425 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
426 t, "", "", triple);
427 break;
428 }
Chris Lattner38e317d2010-07-07 16:01:42 +0000429 case llvm::Triple::Minix:
430 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
431 "", "", "", triple);
432 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000433 case llvm::Triple::Solaris:
David Chisnallb6229592012-02-15 18:24:31 +0000434 AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
435 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000436 // Solaris - Fall though..
437 case llvm::Triple::AuroraUX:
438 // AuroraUX
439 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000440 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000441 break;
442 default:
443 break;
444 }
445}
446
Daniel Dunbara268fc02011-10-11 18:20:10 +0000447void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
448 const llvm::Triple &triple,
mike-m79bc57c2010-05-16 19:03:52 +0000449 const HeaderSearchOptions &HSOpts) {
Chandler Carruthca234192011-11-04 23:49:05 +0000450 // NB: This code path is going away. All of the logic is moving into the
451 // driver which has the information necessary to do target-specific
452 // selections of default include paths. Each target which moves there will be
453 // exempted from this logic here until we can delete the entire pile of code.
454 switch (triple.getOS()) {
455 default:
456 break; // Everything else continues to use this routine's logic.
457
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000458 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000459 case llvm::Triple::Win32:
460 return;
461 }
462
Daniel Dunbara268fc02011-10-11 18:20:10 +0000463 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
464 HSOpts.UseStandardSystemIncludes) {
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000465 if (HSOpts.UseLibcxx) {
466 if (triple.isOSDarwin()) {
467 // On Darwin, libc++ may be installed alongside the compiler in
468 // lib/c++/v1.
469 llvm::sys::Path P(HSOpts.ResourceDir);
470 if (!P.isEmpty()) {
471 P.eraseComponent(); // Remove version from foo/lib/clang/version
472 P.eraseComponent(); // Remove clang from foo/lib/clang
473
474 // Get foo/lib/c++/v1
475 P.appendComponent("c++");
476 P.appendComponent("v1");
477 AddPath(P.str(), CXXSystem, true, false, false, true);
478 }
479 }
David Chisnallb4f0bd62012-03-02 10:49:52 +0000480 // On Solaris, include the support directory for things like xlocale and
481 // fudged system headers.
482 if (triple.getOS() == llvm::Triple::Solaris)
483 AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, true, false,
484 false);
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000485
Bob Wilson13c4f212011-06-21 21:12:29 +0000486 AddPath("/usr/include/c++/v1", CXXSystem, true, false, false);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000487 } else {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000488 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000489 }
Bob Wilson13c4f212011-06-21 21:12:29 +0000490 }
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000491
mike-m79bc57c2010-05-16 19:03:52 +0000492 AddDefaultCIncludePaths(triple, HSOpts);
Daniel Dunbare1665822009-11-07 04:20:39 +0000493
494 // Add the default framework include paths on Darwin.
Daniel Dunbara268fc02011-10-11 18:20:10 +0000495 if (HSOpts.UseStandardSystemIncludes) {
496 if (triple.isOSDarwin()) {
497 AddPath("/System/Library/Frameworks", System, true, false, true);
498 AddPath("/Library/Frameworks", System, true, false, true);
499 }
Daniel Dunbare1665822009-11-07 04:20:39 +0000500 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000501}
502
Nico Weber0fca0222008-08-22 09:25:22 +0000503/// RemoveDuplicates - If there are duplicate directory entries in the specified
Chad Rosiere305e812011-10-10 18:44:24 +0000504/// search list, remove the later (dead) ones. Returns the number of non-system
505/// headers removed, which is used to update NumAngled.
506static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
507 unsigned First, bool Verbose) {
Nico Weber0fca0222008-08-22 09:25:22 +0000508 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
509 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
510 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
Chad Rosiere305e812011-10-10 18:44:24 +0000511 unsigned NonSystemRemoved = 0;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000512 for (unsigned i = First; i != SearchList.size(); ++i) {
Chris Lattner7a739402008-09-26 17:46:45 +0000513 unsigned DirToRemove = i;
Mike Stump1eb44332009-09-09 15:08:12 +0000514
Chris Lattner43eee072009-02-08 01:00:10 +0000515 const DirectoryLookup &CurEntry = SearchList[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000516
Chris Lattner43eee072009-02-08 01:00:10 +0000517 if (CurEntry.isNormalDir()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000518 // If this isn't the first time we've seen this dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000519 if (SeenDirs.insert(CurEntry.getDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000520 continue;
Chris Lattner43eee072009-02-08 01:00:10 +0000521 } else if (CurEntry.isFramework()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000522 // If this isn't the first time we've seen this framework dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000523 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000524 continue;
Nico Weber0fca0222008-08-22 09:25:22 +0000525 } else {
Chris Lattner43eee072009-02-08 01:00:10 +0000526 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
Nico Weber0fca0222008-08-22 09:25:22 +0000527 // If this isn't the first time we've seen this headermap, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000528 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
Nico Weber0fca0222008-08-22 09:25:22 +0000529 continue;
Chris Lattner30f05b52009-02-08 00:55:22 +0000530 }
Mike Stump1eb44332009-09-09 15:08:12 +0000531
Chris Lattner30f05b52009-02-08 00:55:22 +0000532 // If we have a normal #include dir/framework/headermap that is shadowed
533 // later in the chain by a system include location, we actually want to
534 // ignore the user's request and drop the user dir... keeping the system
535 // dir. This is weird, but required to emulate GCC's search path correctly.
536 //
537 // Since dupes of system dirs are rare, just rescan to find the original
538 // that we're nuking instead of using a DenseMap.
Chris Lattner43eee072009-02-08 01:00:10 +0000539 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
Chris Lattner30f05b52009-02-08 00:55:22 +0000540 // Find the dir that this is the same of.
541 unsigned FirstDir;
542 for (FirstDir = 0; ; ++FirstDir) {
543 assert(FirstDir != i && "Didn't find dupe?");
Mike Stump1eb44332009-09-09 15:08:12 +0000544
Chris Lattner43eee072009-02-08 01:00:10 +0000545 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
546
Chris Lattner30f05b52009-02-08 00:55:22 +0000547 // If these are different lookup types, then they can't be the dupe.
Chris Lattner43eee072009-02-08 01:00:10 +0000548 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
Chris Lattner30f05b52009-02-08 00:55:22 +0000549 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000550
Chris Lattner30f05b52009-02-08 00:55:22 +0000551 bool isSame;
Chris Lattner43eee072009-02-08 01:00:10 +0000552 if (CurEntry.isNormalDir())
553 isSame = SearchEntry.getDir() == CurEntry.getDir();
554 else if (CurEntry.isFramework())
555 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
Chris Lattner30f05b52009-02-08 00:55:22 +0000556 else {
Chris Lattner43eee072009-02-08 01:00:10 +0000557 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
558 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
Chris Lattner30f05b52009-02-08 00:55:22 +0000559 }
Mike Stump1eb44332009-09-09 15:08:12 +0000560
Chris Lattner30f05b52009-02-08 00:55:22 +0000561 if (isSame)
562 break;
563 }
Mike Stump1eb44332009-09-09 15:08:12 +0000564
Chris Lattner30f05b52009-02-08 00:55:22 +0000565 // If the first dir in the search path is a non-system dir, zap it
566 // instead of the system one.
567 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
568 DirToRemove = FirstDir;
569 }
570
571 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000572 llvm::errs() << "ignoring duplicate directory \""
573 << CurEntry.getName() << "\"\n";
Chris Lattner30f05b52009-02-08 00:55:22 +0000574 if (DirToRemove != i)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000575 llvm::errs() << " as it is a non-system directory that duplicates "
576 << "a system directory\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000577 }
Chad Rosiere305e812011-10-10 18:44:24 +0000578 if (DirToRemove != i)
579 ++NonSystemRemoved;
Mike Stump1eb44332009-09-09 15:08:12 +0000580
Chris Lattner7a739402008-09-26 17:46:45 +0000581 // This is reached if the current entry is a duplicate. Remove the
582 // DirToRemove (usually the current dir).
583 SearchList.erase(SearchList.begin()+DirToRemove);
Nico Weber0fca0222008-08-22 09:25:22 +0000584 --i;
585 }
Chad Rosiere305e812011-10-10 18:44:24 +0000586 return NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000587}
588
589
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000590void InitHeaderSearch::Realize(const LangOptions &Lang) {
Nico Weber0fca0222008-08-22 09:25:22 +0000591 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
592 std::vector<DirectoryLookup> SearchList;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000593 SearchList.reserve(IncludePath.size());
Mike Stump1eb44332009-09-09 15:08:12 +0000594
Chris Lattnerebb61642011-06-16 22:56:45 +0000595 // Quoted arguments go first.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000596 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
597 it != ie; ++it) {
598 if (it->first == Quoted)
599 SearchList.push_back(it->second);
600 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000601 // Deduplicate and remember index.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000602 RemoveDuplicates(SearchList, 0, Verbose);
Chris Lattnerebb61642011-06-16 22:56:45 +0000603 unsigned NumQuoted = SearchList.size();
Mike Stump1eb44332009-09-09 15:08:12 +0000604
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000605 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
606 it != ie; ++it) {
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000607 if (it->first == Angled || it->first == IndexHeaderMap)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000608 SearchList.push_back(it->second);
609 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000610
611 RemoveDuplicates(SearchList, NumQuoted, Verbose);
612 unsigned NumAngled = SearchList.size();
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000613
614 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
615 it != ie; ++it) {
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000616 if (it->first == System ||
617 (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
Benjamin Kramerc535d972011-09-23 02:25:14 +0000618 (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000619 (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
620 (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000621 SearchList.push_back(it->second);
622 }
623
624 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
625 it != ie; ++it) {
626 if (it->first == After)
627 SearchList.push_back(it->second);
628 }
629
Chris Lattner1d7f12b2011-06-16 22:58:10 +0000630 // Remove duplicates across both the Angled and System directories. GCC does
631 // this and failing to remove duplicates across these two groups breaks
632 // #include_next.
Chad Rosiere305e812011-10-10 18:44:24 +0000633 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
634 NumAngled -= NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000635
636 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
Chris Lattnerebb61642011-06-16 22:56:45 +0000637 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
Nico Weber0fca0222008-08-22 09:25:22 +0000638
Richard Smithf122a132012-06-13 20:27:03 +0000639 Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
640
Nico Weber0fca0222008-08-22 09:25:22 +0000641 // If verbose, print the list of directories that will be searched.
642 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000643 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000644 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
Chris Lattnerebb61642011-06-16 22:56:45 +0000645 if (i == NumQuoted)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000646 llvm::errs() << "#include <...> search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000647 const char *Name = SearchList[i].getName();
648 const char *Suffix;
649 if (SearchList[i].isNormalDir())
650 Suffix = "";
651 else if (SearchList[i].isFramework())
652 Suffix = " (framework directory)";
653 else {
654 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
655 Suffix = " (headermap)";
656 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000657 llvm::errs() << " " << Name << Suffix << "\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000658 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000659 llvm::errs() << "End of search list.\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000660 }
661}
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000662
Daniel Dunbar5814e652009-11-11 21:44:21 +0000663void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
664 const HeaderSearchOptions &HSOpts,
665 const LangOptions &Lang,
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000666 const llvm::Triple &Triple) {
667 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
668
669 // Add the user defined entries.
670 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
671 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Chandler Carruthac2bc4d2011-11-05 08:30:29 +0000672 Init.AddPath(E.Path, E.Group, !E.ImplicitExternC, E.IsUserSupplied,
673 E.IsFramework, E.IgnoreSysRoot);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000674 }
675
Daniel Dunbara268fc02011-10-11 18:20:10 +0000676 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000677
Richard Smithf122a132012-06-13 20:27:03 +0000678 for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
679 Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
680 HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
681
Douglas Gregor2f04f182012-02-02 18:42:48 +0000682 if (HSOpts.UseBuiltinIncludes) {
683 // Set up the builtin include directory in the module map.
684 llvm::sys::Path P(HSOpts.ResourceDir);
685 P.appendComponent("include");
686 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str()))
687 HS.getModuleMap().setBuiltinIncludeDir(Dir);
688 }
689
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000690 Init.Realize(Lang);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000691}