blob: 16b5dd25d08f383a3d373ec164194572b04293a3 [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;
Daniel Dunbarf85541c2013-01-29 23:59:43 +000046 bool HasSysroot;
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),
Daniel Dunbarf85541c2013-01-29 23:59:43 +000052 HasSysroot(!(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.
Daniel Dunbaref845542013-01-30 00:19:24 +000056 void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework,
57 bool IgnoreSysRoot = false);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000058
Richard Smithf122a132012-06-13 20:27:03 +000059 /// AddSystemHeaderPrefix - Add the specified prefix to the system header
60 /// prefix list.
61 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
62 SystemHeaderPrefixes.push_back(std::make_pair(Prefix, IsSystemHeader));
63 }
64
mike-ma6087372010-05-05 17:00:31 +000065 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000066 /// libstdc++.
Chris Lattner5f9e2722011-07-23 10:55:15 +000067 void AddGnuCPlusPlusIncludePaths(StringRef Base,
68 StringRef ArchDir,
69 StringRef Dir32,
70 StringRef Dir64,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000071 const llvm::Triple &triple);
72
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 Ballmanb3dcbbd2012-03-25 22:46:17 +000075 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
76 StringRef Arch,
77 StringRef Version);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000078
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000079 /// AddMinGW64CXXPaths - Add the necessary paths to support
80 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +000081 void AddMinGW64CXXPaths(StringRef Base,
82 StringRef Version);
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000083
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000084 // AddDefaultCIncludePaths - Add paths that should always be searched.
mike-m79bc57c2010-05-16 19:03:52 +000085 void AddDefaultCIncludePaths(const llvm::Triple &triple,
86 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000087
88 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
89 // compiling c++.
Douglas Gregord944a9b2011-06-27 15:47:15 +000090 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
91 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000092
93 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
94 /// that e.g. stdio.h is found.
Daniel Dunbara268fc02011-10-11 18:20:10 +000095 void AddDefaultIncludePaths(const LangOptions &Lang,
96 const llvm::Triple &triple,
97 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000098
99 /// Realize - Merges all search path lists into one list and send it to
100 /// HeaderSearch.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000101 void Realize(const LangOptions &Lang);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +0000102};
103
Chris Lattnerebb61642011-06-16 22:56:45 +0000104} // end anonymous namespace.
Nico Weber0fca0222008-08-22 09:25:22 +0000105
Daniel Dunbar49ffaef2013-01-29 23:59:37 +0000106static bool CanPrefixSysroot(StringRef Path) {
107#if defined(_WIN32)
108 return !Path.empty() && llvm::sys::path::is_separator(Path[0]);
109#else
110 return llvm::sys::path::is_absolute(Path);
111#endif
112}
113
Daniel Dunbaref845542013-01-30 00:19:24 +0000114void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
Daniel Dunbar5c4e34c2013-01-25 01:50:39 +0000115 bool isFramework, bool IgnoreSysRoot) {
Benjamin Kramere89ba592009-12-08 12:38:20 +0000116 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
Nico Weber0fca0222008-08-22 09:25:22 +0000117 FileManager &FM = Headers.getFileMgr();
Mike Stump1eb44332009-09-09 15:08:12 +0000118
Nico Weber0fca0222008-08-22 09:25:22 +0000119 // Compute the actual path, taking into consideration -isysroot.
Dylan Noblesmithf7ccbad2012-02-05 02:13:05 +0000120 SmallString<256> MappedPathStorage;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000121 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
Mike Stump1eb44332009-09-09 15:08:12 +0000122
Daniel Dunbarf85541c2013-01-29 23:59:43 +0000123 // Prepend the sysroot, if desired and this is a system header group.
Daniel Dunbarc33c9f72013-01-29 23:59:45 +0000124 if (HasSysroot && !IgnoreSysRoot && CanPrefixSysroot(MappedPathStr)) {
Chandler Carruth5619ae52010-11-15 09:28:23 +0000125 MappedPathStorage.clear();
Daniel Dunbar49ffaef2013-01-29 23:59:37 +0000126 MappedPathStr = (IncludeSysroot + Path).toStringRef(MappedPathStorage);
Nico Weber0fca0222008-08-22 09:25:22 +0000127 }
Mike Stump1eb44332009-09-09 15:08:12 +0000128
Nico Weber0fca0222008-08-22 09:25:22 +0000129 // Compute the DirectoryLookup type.
Chris Lattner9d728512008-10-27 01:19:25 +0000130 SrcMgr::CharacteristicKind Type;
Daniel Dunbaref845542013-01-30 00:19:24 +0000131 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
Chris Lattner0b9e7362008-09-26 21:18:42 +0000132 Type = SrcMgr::C_User;
Daniel Dunbaref845542013-01-30 00:19:24 +0000133 } else if (Group == ExternCSystem) {
Chris Lattner0b9e7362008-09-26 21:18:42 +0000134 Type = SrcMgr::C_ExternCSystem;
Daniel Dunbaref845542013-01-30 00:19:24 +0000135 } else {
136 Type = SrcMgr::C_System;
137 }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Nico Weber0fca0222008-08-22 09:25:22 +0000139 // If the directory exists, add it.
Chris Lattner39b49bc2010-11-23 08:35:12 +0000140 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
Daniel Dunbar1ea6bc02013-01-25 01:50:28 +0000141 IncludePath.push_back(
142 std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
Nico Weber0fca0222008-08-22 09:25:22 +0000143 return;
144 }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Nico Weber0fca0222008-08-22 09:25:22 +0000146 // Check to see if this is an apple-style headermap (which are not allowed to
147 // be frameworks).
148 if (!isFramework) {
Chris Lattner39b49bc2010-11-23 08:35:12 +0000149 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
Nico Weber0fca0222008-08-22 09:25:22 +0000150 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
151 // It is a headermap, add it to the search path.
Daniel Dunbar1ea6bc02013-01-25 01:50:28 +0000152 IncludePath.push_back(
153 std::make_pair(Group,
154 DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
Nico Weber0fca0222008-08-22 09:25:22 +0000155 return;
156 }
157 }
158 }
Mike Stump1eb44332009-09-09 15:08:12 +0000159
Nico Weber0fca0222008-08-22 09:25:22 +0000160 if (Verbose)
Chandler Carruthf3721452010-11-15 00:48:13 +0000161 llvm::errs() << "ignoring nonexistent directory \""
162 << MappedPathStr << "\"\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000163}
164
Chris Lattner5f9e2722011-07-23 10:55:15 +0000165void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
166 StringRef ArchDir,
167 StringRef Dir32,
168 StringRef Dir64,
Rafael Espindola31b63be2009-10-14 17:09:44 +0000169 const llvm::Triple &triple) {
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000170 // Add the base dir
Daniel Dunbaref845542013-01-30 00:19:24 +0000171 AddPath(Base, CXXSystem, false);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000172
173 // Add the multilib dirs
Rafael Espindola31b63be2009-10-14 17:09:44 +0000174 llvm::Triple::ArchType arch = triple.getArch();
175 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola31b63be2009-10-14 17:09:44 +0000176 if (is64bit)
Daniel Dunbaref845542013-01-30 00:19:24 +0000177 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false);
Rafael Espindola31b63be2009-10-14 17:09:44 +0000178 else
Daniel Dunbaref845542013-01-30 00:19:24 +0000179 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false);
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000180
181 // Add the backward dir
Daniel Dunbaref845542013-01-30 00:19:24 +0000182 AddPath(Base + "/backward", CXXSystem, false);
Rafael Espindola2e9f6522009-10-06 01:33:02 +0000183}
Nico Weber0fca0222008-08-22 09:25:22 +0000184
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000185void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000186 StringRef Arch,
187 StringRef Version) {
188 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
Daniel Dunbaref845542013-01-30 00:19:24 +0000189 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000190 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
Daniel Dunbaref845542013-01-30 00:19:24 +0000191 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000192 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
Daniel Dunbaref845542013-01-30 00:19:24 +0000193 CXXSystem, false);
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000194}
195
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000196void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
197 StringRef Version) {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000198 // Assumes Base is HeaderSearchOpts' ResourceDir
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000199 AddPath(Base + "/../../../include/c++/" + Version,
Daniel Dunbaref845542013-01-30 00:19:24 +0000200 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000201 AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
Daniel Dunbaref845542013-01-30 00:19:24 +0000202 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000203 AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
Daniel Dunbaref845542013-01-30 00:19:24 +0000204 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000205 AddPath(Base + "/../../../include/c++/" + Version + "/backward",
Daniel Dunbaref845542013-01-30 00:19:24 +0000206 CXXSystem, false);
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000207}
208
mike-m79bc57c2010-05-16 19:03:52 +0000209void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
210 const HeaderSearchOptions &HSOpts) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000211 llvm::Triple::OSType os = triple.getOS();
212
Daniel Dunbara268fc02011-10-11 18:20:10 +0000213 if (HSOpts.UseStandardSystemIncludes) {
214 switch (os) {
215 case llvm::Triple::FreeBSD:
216 case llvm::Triple::NetBSD:
Hans Wennborg9d82a032012-08-02 12:27:08 +0000217 case llvm::Triple::OpenBSD:
Eli Friedman42f74f22012-08-08 23:57:20 +0000218 case llvm::Triple::Bitrig:
Daniel Dunbara268fc02011-10-11 18:20:10 +0000219 break;
220 default:
221 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbaref845542013-01-30 00:19:24 +0000222 AddPath("/usr/local/include", System, false);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000223 break;
224 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000225 }
mike-m79bc57c2010-05-16 19:03:52 +0000226
227 // Builtin includes use #include_next directives and should be positioned
228 // just prior C include dirs.
229 if (HSOpts.UseBuiltinIncludes) {
230 // Ignore the sys root, we *always* look for clang headers relative to
231 // supplied path.
232 llvm::sys::Path P(HSOpts.ResourceDir);
233 P.appendComponent("include");
Daniel Dunbaref845542013-01-30 00:19:24 +0000234 AddPath(P.str(), ExternCSystem, false, /*IgnoreSysRoot=*/true);
mike-m79bc57c2010-05-16 19:03:52 +0000235 }
236
Daniel Dunbara268fc02011-10-11 18:20:10 +0000237 // All remaining additions are for system include directories, early exit if
238 // we aren't using them.
239 if (!HSOpts.UseStandardSystemIncludes)
240 return;
241
mike-m79bc57c2010-05-16 19:03:52 +0000242 // Add dirs specified via 'configure --with-c-include-dirs'.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000243 StringRef CIncludeDirs(C_INCLUDE_DIRS);
Daniel Dunbarc7064682009-11-12 07:28:29 +0000244 if (CIncludeDirs != "") {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000245 SmallVector<StringRef, 5> dirs;
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000246 CIncludeDirs.split(dirs, ":");
Chris Lattner5f9e2722011-07-23 10:55:15 +0000247 for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000248 i != dirs.end();
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000249 ++i)
Daniel Dunbaref845542013-01-30 00:19:24 +0000250 AddPath(*i, ExternCSystem, false);
Rafael Espindolaf0a2f512009-11-12 05:48:41 +0000251 return;
252 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000253
Mike Stump43d81762009-10-08 23:29:47 +0000254 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000255 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000256 case llvm::Triple::Win32:
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000257 llvm_unreachable("Include management is handled in the driver.");
Chandler Carruthca234192011-11-04 23:49:05 +0000258
Chris Lattner86ed3a32010-04-11 19:29:39 +0000259 case llvm::Triple::Haiku:
Daniel Dunbaref845542013-01-30 00:19:24 +0000260 AddPath("/boot/common/include", System, false);
261 AddPath("/boot/develop/headers/os", System, false);
262 AddPath("/boot/develop/headers/os/app", System, false);
263 AddPath("/boot/develop/headers/os/arch", System, false);
264 AddPath("/boot/develop/headers/os/device", System, false);
265 AddPath("/boot/develop/headers/os/drivers", System, false);
266 AddPath("/boot/develop/headers/os/game", System, false);
267 AddPath("/boot/develop/headers/os/interface", System, false);
268 AddPath("/boot/develop/headers/os/kernel", System, false);
269 AddPath("/boot/develop/headers/os/locale", System, false);
270 AddPath("/boot/develop/headers/os/mail", System, false);
271 AddPath("/boot/develop/headers/os/media", System, false);
272 AddPath("/boot/develop/headers/os/midi", System, false);
273 AddPath("/boot/develop/headers/os/midi2", System, false);
274 AddPath("/boot/develop/headers/os/net", System, false);
275 AddPath("/boot/develop/headers/os/storage", System, false);
276 AddPath("/boot/develop/headers/os/support", System, false);
277 AddPath("/boot/develop/headers/os/translation", System, false);
278 AddPath("/boot/develop/headers/os/add-ons/graphics", System, false);
279 AddPath("/boot/develop/headers/os/add-ons/input_server", System, false);
280 AddPath("/boot/develop/headers/os/add-ons/screen_saver", System, false);
281 AddPath("/boot/develop/headers/os/add-ons/tracker", System, false);
282 AddPath("/boot/develop/headers/os/be_apps/Deskbar", System, false);
283 AddPath("/boot/develop/headers/os/be_apps/NetPositive", System, false);
284 AddPath("/boot/develop/headers/os/be_apps/Tracker", System, false);
285 AddPath("/boot/develop/headers/cpp", System, false);
286 AddPath("/boot/develop/headers/cpp/i586-pc-haiku", System, false);
287 AddPath("/boot/develop/headers/3rdparty", System, false);
288 AddPath("/boot/develop/headers/bsd", System, false);
289 AddPath("/boot/develop/headers/glibc", System, false);
290 AddPath("/boot/develop/headers/posix", System, false);
291 AddPath("/boot/develop/headers", System, false);
Eli Friedmana7e68452010-08-22 01:00:03 +0000292 break;
Douglas Gregordca52262011-07-01 22:41:14 +0000293 case llvm::Triple::RTEMS:
294 break;
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000295 case llvm::Triple::Cygwin:
Daniel Dunbaref845542013-01-30 00:19:24 +0000296 AddPath("/usr/include/w32api", System, false);
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000297 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000298 case llvm::Triple::MinGW32: {
299 // mingw-w64 crt include paths
300 llvm::sys::Path P(HSOpts.ResourceDir);
301 P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include
Daniel Dunbaref845542013-01-30 00:19:24 +0000302 AddPath(P.str(), System, false);
Douglas Gregord944a9b2011-06-27 15:47:15 +0000303 P = llvm::sys::Path(HSOpts.ResourceDir);
304 P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include
Daniel Dunbaref845542013-01-30 00:19:24 +0000305 AddPath(P.str(), System, false);
Douglas Gregord944a9b2011-06-27 15:47:15 +0000306 // mingw.org crt include paths
307 P = llvm::sys::Path(HSOpts.ResourceDir);
308 P.appendComponent("../../../include"); // <sysroot>/include
Daniel Dunbaref845542013-01-30 00:19:24 +0000309 AddPath(P.str(), System, false);
310 AddPath("/mingw/include", System, false);
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000311#if defined(_WIN32)
Daniel Dunbaref845542013-01-30 00:19:24 +0000312 AddPath("c:/mingw/include", System, false);
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000313#endif
Douglas Gregord944a9b2011-06-27 15:47:15 +0000314 }
Mike Stump43d81762009-10-08 23:29:47 +0000315 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000316
Mike Stump43d81762009-10-08 23:29:47 +0000317 default:
Mike Stump43d81762009-10-08 23:29:47 +0000318 break;
319 }
John Thompsond3f88342009-10-13 18:51:32 +0000320
Douglas Gregordca52262011-07-01 22:41:14 +0000321 if ( os != llvm::Triple::RTEMS )
Daniel Dunbaref845542013-01-30 00:19:24 +0000322 AddPath("/usr/include", ExternCSystem, false);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000323}
324
Chris Lattner0e3cc052010-05-05 05:28:39 +0000325void InitHeaderSearch::
Douglas Gregord944a9b2011-06-27 15:47:15 +0000326AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000327 llvm::Triple::OSType os = triple.getOS();
328 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000329
330 if (triple.isOSDarwin()) {
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000331 switch (triple.getArch()) {
332 default: break;
333
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000334 case llvm::Triple::ppc:
Douglas Gregor582c3012010-05-29 01:15:12 +0000335 case llvm::Triple::ppc64:
Douglas Gregor616d4362010-05-29 01:21:11 +0000336 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000337 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor616d4362010-05-29 01:21:11 +0000338 triple);
Douglas Gregor582c3012010-05-29 01:15:12 +0000339 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000340 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor582c3012010-05-29 01:15:12 +0000341 triple);
342 break;
343
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000344 case llvm::Triple::x86:
345 case llvm::Triple::x86_64:
346 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
347 "i686-apple-darwin10", "", "x86_64", triple);
348 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
349 "i686-apple-darwin8", "", "", triple);
350 break;
351
352 case llvm::Triple::arm:
353 case llvm::Triple::thumb:
354 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
355 "arm-apple-darwin10", "v7", "", triple);
356 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
357 "arm-apple-darwin10", "v6", "", triple);
358 break;
359 }
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000360 return;
361 }
362
363 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000364 case llvm::Triple::Linux:
365 case llvm::Triple::Win32:
366 llvm_unreachable("Include management is handled in the driver.");
367
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000368 case llvm::Triple::Cygwin:
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000369 // Cygwin-1.7
370 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
371 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
372 // g++-4 / Cygwin-1.5
373 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000374 break;
375 case llvm::Triple::MinGW32:
Douglas Gregord944a9b2011-06-27 15:47:15 +0000376 // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000377 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
378 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
379 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
380 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
381 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
382 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
383 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
384 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
385 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
386 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
Douglas Gregord944a9b2011-06-27 15:47:15 +0000387 // mingw.org C++ include paths
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000388 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000389#if defined(_WIN32)
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +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");
393 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
394 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
395 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000396#endif
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000397 break;
Chris Lattner7a7ca282010-01-09 05:41:14 +0000398 case llvm::Triple::DragonFly:
Daniel Dunbaref845542013-01-30 00:19:24 +0000399 AddPath("/usr/include/c++/4.1", CXXSystem, false);
Chris Lattner7a7ca282010-01-09 05:41:14 +0000400 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000401 case llvm::Triple::FreeBSD:
mike-mac78b7a2010-05-06 14:11:13 +0000402 // FreeBSD 8.0
403 // FreeBSD 7.3
Nuno Lopesafe859a2010-01-17 00:00:11 +0000404 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000405 break;
Anton Korobeynikovab079412010-08-31 22:39:50 +0000406 case llvm::Triple::NetBSD:
407 AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple);
408 break;
Daniel Dunbar95c04572010-08-01 23:13:54 +0000409 case llvm::Triple::OpenBSD: {
410 std::string t = triple.getTriple();
411 if (t.substr(0, 6) == "x86_64")
412 t.replace(0, 6, "amd64");
413 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
414 t, "", "", triple);
415 break;
416 }
Chris Lattner38e317d2010-07-07 16:01:42 +0000417 case llvm::Triple::Minix:
418 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
419 "", "", "", triple);
420 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000421 case llvm::Triple::Solaris:
David Chisnallb6229592012-02-15 18:24:31 +0000422 AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
423 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000424 // Solaris - Fall though..
425 case llvm::Triple::AuroraUX:
426 // AuroraUX
427 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000428 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000429 break;
430 default:
431 break;
432 }
433}
434
Daniel Dunbara268fc02011-10-11 18:20:10 +0000435void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
436 const llvm::Triple &triple,
mike-m79bc57c2010-05-16 19:03:52 +0000437 const HeaderSearchOptions &HSOpts) {
Chandler Carruthca234192011-11-04 23:49:05 +0000438 // NB: This code path is going away. All of the logic is moving into the
439 // driver which has the information necessary to do target-specific
440 // selections of default include paths. Each target which moves there will be
441 // exempted from this logic here until we can delete the entire pile of code.
442 switch (triple.getOS()) {
443 default:
444 break; // Everything else continues to use this routine's logic.
445
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000446 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000447 case llvm::Triple::Win32:
448 return;
449 }
450
Daniel Dunbara268fc02011-10-11 18:20:10 +0000451 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
452 HSOpts.UseStandardSystemIncludes) {
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000453 if (HSOpts.UseLibcxx) {
454 if (triple.isOSDarwin()) {
455 // On Darwin, libc++ may be installed alongside the compiler in
456 // lib/c++/v1.
457 llvm::sys::Path P(HSOpts.ResourceDir);
458 if (!P.isEmpty()) {
459 P.eraseComponent(); // Remove version from foo/lib/clang/version
460 P.eraseComponent(); // Remove clang from foo/lib/clang
461
462 // Get foo/lib/c++/v1
463 P.appendComponent("c++");
464 P.appendComponent("v1");
Daniel Dunbaref845542013-01-30 00:19:24 +0000465 AddPath(P.str(), CXXSystem, false, true);
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000466 }
467 }
David Chisnallb4f0bd62012-03-02 10:49:52 +0000468 // On Solaris, include the support directory for things like xlocale and
469 // fudged system headers.
470 if (triple.getOS() == llvm::Triple::Solaris)
Daniel Dunbaref845542013-01-30 00:19:24 +0000471 AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, false);
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000472
Daniel Dunbaref845542013-01-30 00:19:24 +0000473 AddPath("/usr/include/c++/v1", CXXSystem, 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()) {
Daniel Dunbaref845542013-01-30 00:19:24 +0000484 AddPath("/System/Library/Frameworks", System, true);
485 AddPath("/Library/Frameworks", System, true);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000486 }
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) {
Daniel Dunbaref845542013-01-30 00:19:24 +0000603 if (it->first == System || it->first == ExternCSystem ||
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000604 (!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
Richard Smithf122a132012-06-13 20:27:03 +0000626 Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
627
Nico Weber0fca0222008-08-22 09:25:22 +0000628 // If verbose, print the list of directories that will be searched.
629 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000630 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000631 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
Chris Lattnerebb61642011-06-16 22:56:45 +0000632 if (i == NumQuoted)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000633 llvm::errs() << "#include <...> search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000634 const char *Name = SearchList[i].getName();
635 const char *Suffix;
636 if (SearchList[i].isNormalDir())
637 Suffix = "";
638 else if (SearchList[i].isFramework())
639 Suffix = " (framework directory)";
640 else {
641 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
642 Suffix = " (headermap)";
643 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000644 llvm::errs() << " " << Name << Suffix << "\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000645 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000646 llvm::errs() << "End of search list.\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000647 }
648}
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000649
Daniel Dunbar5814e652009-11-11 21:44:21 +0000650void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
651 const HeaderSearchOptions &HSOpts,
652 const LangOptions &Lang,
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000653 const llvm::Triple &Triple) {
654 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
655
656 // Add the user defined entries.
657 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
658 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Daniel Dunbaref845542013-01-30 00:19:24 +0000659 Init.AddPath(E.Path, E.Group, E.IsFramework, E.IgnoreSysRoot);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000660 }
661
Daniel Dunbara268fc02011-10-11 18:20:10 +0000662 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000663
Richard Smithf122a132012-06-13 20:27:03 +0000664 for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
665 Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
666 HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
667
Douglas Gregor2f04f182012-02-02 18:42:48 +0000668 if (HSOpts.UseBuiltinIncludes) {
669 // Set up the builtin include directory in the module map.
670 llvm::sys::Path P(HSOpts.ResourceDir);
671 P.appendComponent("include");
672 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str()))
673 HS.getModuleMap().setBuiltinIncludeDir(Dir);
674 }
675
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000676 Init.Realize(Lang);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000677}