blob: 46694d985df03bde20d6c81f083ea7c7a15fca20 [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"
John McCall8cfb7202013-04-11 22:55:55 +000027#include "llvm/Support/FileSystem.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000028#include "llvm/Support/Path.h"
Rafael Espindola34392372013-06-11 19:59:07 +000029#include "llvm/Support/PathV1.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000030#include "llvm/Support/raw_ostream.h"
Dylan Noblesmith69d3b4f2012-02-01 14:25:28 +000031
Nico Weber0fca0222008-08-22 09:25:22 +000032using namespace clang;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000033using namespace clang::frontend;
34
35namespace {
36
37/// InitHeaderSearch - This class makes it easier to set the search paths of
38/// a HeaderSearch object. InitHeaderSearch stores several search path lists
39/// internally, which can be sent to a HeaderSearch object in one swoop.
40class InitHeaderSearch {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +000041 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
42 typedef std::vector<std::pair<IncludeDirGroup,
43 DirectoryLookup> >::const_iterator path_iterator;
Richard Smithf122a132012-06-13 20:27:03 +000044 std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
Chris Lattnerebb61642011-06-16 22:56:45 +000045 HeaderSearch &Headers;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000046 bool Verbose;
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000047 std::string IncludeSysroot;
Daniel Dunbarf85541c2013-01-29 23:59:43 +000048 bool HasSysroot;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000049
50public:
51
Chris Lattner5f9e2722011-07-23 10:55:15 +000052 InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000053 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
Daniel Dunbarf85541c2013-01-29 23:59:43 +000054 HasSysroot(!(sysroot.empty() || sysroot == "/")) {
Chandler Carruthc09265a2010-11-15 07:15:26 +000055 }
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000056
Daniel Dunbar9cd90a22013-01-30 01:06:03 +000057 /// AddPath - Add the specified path to the specified group list, prefixing
58 /// the sysroot if used.
59 void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
60
61 /// AddUnmappedPath - Add the specified path to the specified group list,
62 /// without performing any sysroot remapping.
63 void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
64 bool isFramework);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000065
Richard Smithf122a132012-06-13 20:27:03 +000066 /// AddSystemHeaderPrefix - Add the specified prefix to the system header
67 /// prefix list.
68 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
69 SystemHeaderPrefixes.push_back(std::make_pair(Prefix, IsSystemHeader));
70 }
71
mike-ma6087372010-05-05 17:00:31 +000072 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000073 /// libstdc++.
Chris Lattner5f9e2722011-07-23 10:55:15 +000074 void AddGnuCPlusPlusIncludePaths(StringRef Base,
75 StringRef ArchDir,
76 StringRef Dir32,
77 StringRef Dir64,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000078 const llvm::Triple &triple);
79
Michael J. Spencer06a8dc62010-12-21 16:45:42 +000080 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000081 /// libstdc++.
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +000082 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
83 StringRef Arch,
84 StringRef Version);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000085
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000086 /// AddMinGW64CXXPaths - Add the necessary paths to support
87 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +000088 void AddMinGW64CXXPaths(StringRef Base,
89 StringRef Version);
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000090
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000091 // AddDefaultCIncludePaths - Add paths that should always be searched.
mike-m79bc57c2010-05-16 19:03:52 +000092 void AddDefaultCIncludePaths(const llvm::Triple &triple,
93 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000094
95 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
96 // compiling c++.
Douglas Gregord944a9b2011-06-27 15:47:15 +000097 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
98 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000099
100 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
101 /// that e.g. stdio.h is found.
Daniel Dunbara268fc02011-10-11 18:20:10 +0000102 void AddDefaultIncludePaths(const LangOptions &Lang,
103 const llvm::Triple &triple,
104 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +0000105
106 /// Realize - Merges all search path lists into one list and send it to
107 /// HeaderSearch.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000108 void Realize(const LangOptions &Lang);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +0000109};
110
Chris Lattnerebb61642011-06-16 22:56:45 +0000111} // end anonymous namespace.
Nico Weber0fca0222008-08-22 09:25:22 +0000112
Daniel Dunbar49ffaef2013-01-29 23:59:37 +0000113static bool CanPrefixSysroot(StringRef Path) {
114#if defined(_WIN32)
115 return !Path.empty() && llvm::sys::path::is_separator(Path[0]);
116#else
117 return llvm::sys::path::is_absolute(Path);
118#endif
119}
120
Daniel Dunbaref845542013-01-30 00:19:24 +0000121void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
Daniel Dunbar9cd90a22013-01-30 01:06:03 +0000122 bool isFramework) {
123 // Add the path with sysroot prepended, if desired and this is a system header
124 // group.
125 if (HasSysroot) {
126 SmallString<256> MappedPathStorage;
127 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
128 if (CanPrefixSysroot(MappedPathStr)) {
129 AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
130 return;
131 }
132 }
Mike Stump1eb44332009-09-09 15:08:12 +0000133
Daniel Dunbar9cd90a22013-01-30 01:06:03 +0000134 AddUnmappedPath(Path, Group, isFramework);
135}
136
137void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
138 bool isFramework) {
139 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
140
141 FileManager &FM = Headers.getFileMgr();
Dylan Noblesmithf7ccbad2012-02-05 02:13:05 +0000142 SmallString<256> MappedPathStorage;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000143 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
Mike Stump1eb44332009-09-09 15:08:12 +0000144
Nico Weber0fca0222008-08-22 09:25:22 +0000145 // Compute the DirectoryLookup type.
Chris Lattner9d728512008-10-27 01:19:25 +0000146 SrcMgr::CharacteristicKind Type;
Daniel Dunbaref845542013-01-30 00:19:24 +0000147 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
Chris Lattner0b9e7362008-09-26 21:18:42 +0000148 Type = SrcMgr::C_User;
Daniel Dunbaref845542013-01-30 00:19:24 +0000149 } else if (Group == ExternCSystem) {
Chris Lattner0b9e7362008-09-26 21:18:42 +0000150 Type = SrcMgr::C_ExternCSystem;
Daniel Dunbaref845542013-01-30 00:19:24 +0000151 } else {
152 Type = SrcMgr::C_System;
153 }
Mike Stump1eb44332009-09-09 15:08:12 +0000154
Nico Weber0fca0222008-08-22 09:25:22 +0000155 // If the directory exists, add it.
Chris Lattner39b49bc2010-11-23 08:35:12 +0000156 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
Daniel Dunbar1ea6bc02013-01-25 01:50:28 +0000157 IncludePath.push_back(
158 std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
Nico Weber0fca0222008-08-22 09:25:22 +0000159 return;
160 }
Mike Stump1eb44332009-09-09 15:08:12 +0000161
Nico Weber0fca0222008-08-22 09:25:22 +0000162 // Check to see if this is an apple-style headermap (which are not allowed to
163 // be frameworks).
164 if (!isFramework) {
Chris Lattner39b49bc2010-11-23 08:35:12 +0000165 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
Nico Weber0fca0222008-08-22 09:25:22 +0000166 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
167 // It is a headermap, add it to the search path.
Daniel Dunbar1ea6bc02013-01-25 01:50:28 +0000168 IncludePath.push_back(
169 std::make_pair(Group,
170 DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
Nico Weber0fca0222008-08-22 09:25:22 +0000171 return;
172 }
173 }
174 }
Mike Stump1eb44332009-09-09 15:08:12 +0000175
Nico Weber0fca0222008-08-22 09:25:22 +0000176 if (Verbose)
Chandler Carruthf3721452010-11-15 00:48:13 +0000177 llvm::errs() << "ignoring nonexistent directory \""
178 << MappedPathStr << "\"\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000179}
180
Chris Lattner5f9e2722011-07-23 10:55:15 +0000181void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
182 StringRef ArchDir,
183 StringRef Dir32,
184 StringRef Dir64,
Rafael Espindola31b63be2009-10-14 17:09:44 +0000185 const llvm::Triple &triple) {
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000186 // Add the base dir
Daniel Dunbaref845542013-01-30 00:19:24 +0000187 AddPath(Base, CXXSystem, false);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000188
189 // Add the multilib dirs
Rafael Espindola31b63be2009-10-14 17:09:44 +0000190 llvm::Triple::ArchType arch = triple.getArch();
191 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola31b63be2009-10-14 17:09:44 +0000192 if (is64bit)
Daniel Dunbaref845542013-01-30 00:19:24 +0000193 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false);
Rafael Espindola31b63be2009-10-14 17:09:44 +0000194 else
Daniel Dunbaref845542013-01-30 00:19:24 +0000195 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false);
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000196
197 // Add the backward dir
Daniel Dunbaref845542013-01-30 00:19:24 +0000198 AddPath(Base + "/backward", CXXSystem, false);
Rafael Espindola2e9f6522009-10-06 01:33:02 +0000199}
Nico Weber0fca0222008-08-22 09:25:22 +0000200
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000201void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000202 StringRef Arch,
203 StringRef Version) {
204 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
Daniel Dunbaref845542013-01-30 00:19:24 +0000205 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000206 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
Daniel Dunbaref845542013-01-30 00:19:24 +0000207 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000208 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
Daniel Dunbaref845542013-01-30 00:19:24 +0000209 CXXSystem, false);
Aaron Ballmanb3656d32012-03-25 15:47:41 +0000210}
211
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000212void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
213 StringRef Version) {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000214 // Assumes Base is HeaderSearchOpts' ResourceDir
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000215 AddPath(Base + "/../../../include/c++/" + Version,
Daniel Dunbaref845542013-01-30 00:19:24 +0000216 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000217 AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
Daniel Dunbaref845542013-01-30 00:19:24 +0000218 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000219 AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
Daniel Dunbaref845542013-01-30 00:19:24 +0000220 CXXSystem, false);
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000221 AddPath(Base + "/../../../include/c++/" + Version + "/backward",
Daniel Dunbaref845542013-01-30 00:19:24 +0000222 CXXSystem, false);
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000223}
224
mike-m79bc57c2010-05-16 19:03:52 +0000225void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
226 const HeaderSearchOptions &HSOpts) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000227 llvm::Triple::OSType os = triple.getOS();
228
Daniel Dunbara268fc02011-10-11 18:20:10 +0000229 if (HSOpts.UseStandardSystemIncludes) {
230 switch (os) {
231 case llvm::Triple::FreeBSD:
232 case llvm::Triple::NetBSD:
Hans Wennborg9d82a032012-08-02 12:27:08 +0000233 case llvm::Triple::OpenBSD:
Eli Friedman42f74f22012-08-08 23:57:20 +0000234 case llvm::Triple::Bitrig:
Daniel Dunbara268fc02011-10-11 18:20:10 +0000235 break;
236 default:
237 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbaref845542013-01-30 00:19:24 +0000238 AddPath("/usr/local/include", System, false);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000239 break;
240 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000241 }
mike-m79bc57c2010-05-16 19:03:52 +0000242
243 // Builtin includes use #include_next directives and should be positioned
244 // just prior C include dirs.
245 if (HSOpts.UseBuiltinIncludes) {
246 // Ignore the sys root, we *always* look for clang headers relative to
247 // supplied path.
248 llvm::sys::Path P(HSOpts.ResourceDir);
249 P.appendComponent("include");
Daniel Dunbar9cd90a22013-01-30 01:06:03 +0000250 AddUnmappedPath(P.str(), ExternCSystem, false);
mike-m79bc57c2010-05-16 19:03:52 +0000251 }
252
Daniel Dunbara268fc02011-10-11 18:20:10 +0000253 // All remaining additions are for system include directories, early exit if
254 // we aren't using them.
255 if (!HSOpts.UseStandardSystemIncludes)
256 return;
257
mike-m79bc57c2010-05-16 19:03:52 +0000258 // Add dirs specified via 'configure --with-c-include-dirs'.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000259 StringRef CIncludeDirs(C_INCLUDE_DIRS);
Daniel Dunbarc7064682009-11-12 07:28:29 +0000260 if (CIncludeDirs != "") {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000261 SmallVector<StringRef, 5> dirs;
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000262 CIncludeDirs.split(dirs, ":");
Chris Lattner5f9e2722011-07-23 10:55:15 +0000263 for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000264 i != dirs.end();
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000265 ++i)
Daniel Dunbaref845542013-01-30 00:19:24 +0000266 AddPath(*i, ExternCSystem, false);
Rafael Espindolaf0a2f512009-11-12 05:48:41 +0000267 return;
268 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000269
Mike Stump43d81762009-10-08 23:29:47 +0000270 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000271 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000272 case llvm::Triple::Win32:
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000273 llvm_unreachable("Include management is handled in the driver.");
Chandler Carruthca234192011-11-04 23:49:05 +0000274
Chris Lattner86ed3a32010-04-11 19:29:39 +0000275 case llvm::Triple::Haiku:
Daniel Dunbaref845542013-01-30 00:19:24 +0000276 AddPath("/boot/common/include", System, false);
277 AddPath("/boot/develop/headers/os", System, false);
278 AddPath("/boot/develop/headers/os/app", System, false);
279 AddPath("/boot/develop/headers/os/arch", System, false);
280 AddPath("/boot/develop/headers/os/device", System, false);
281 AddPath("/boot/develop/headers/os/drivers", System, false);
282 AddPath("/boot/develop/headers/os/game", System, false);
283 AddPath("/boot/develop/headers/os/interface", System, false);
284 AddPath("/boot/develop/headers/os/kernel", System, false);
285 AddPath("/boot/develop/headers/os/locale", System, false);
286 AddPath("/boot/develop/headers/os/mail", System, false);
287 AddPath("/boot/develop/headers/os/media", System, false);
288 AddPath("/boot/develop/headers/os/midi", System, false);
289 AddPath("/boot/develop/headers/os/midi2", System, false);
290 AddPath("/boot/develop/headers/os/net", System, false);
291 AddPath("/boot/develop/headers/os/storage", System, false);
292 AddPath("/boot/develop/headers/os/support", System, false);
293 AddPath("/boot/develop/headers/os/translation", System, false);
294 AddPath("/boot/develop/headers/os/add-ons/graphics", System, false);
295 AddPath("/boot/develop/headers/os/add-ons/input_server", System, false);
296 AddPath("/boot/develop/headers/os/add-ons/screen_saver", System, false);
297 AddPath("/boot/develop/headers/os/add-ons/tracker", System, false);
298 AddPath("/boot/develop/headers/os/be_apps/Deskbar", System, false);
299 AddPath("/boot/develop/headers/os/be_apps/NetPositive", System, false);
300 AddPath("/boot/develop/headers/os/be_apps/Tracker", System, false);
301 AddPath("/boot/develop/headers/cpp", System, false);
302 AddPath("/boot/develop/headers/cpp/i586-pc-haiku", System, false);
303 AddPath("/boot/develop/headers/3rdparty", System, false);
304 AddPath("/boot/develop/headers/bsd", System, false);
305 AddPath("/boot/develop/headers/glibc", System, false);
306 AddPath("/boot/develop/headers/posix", System, false);
307 AddPath("/boot/develop/headers", System, false);
Eli Friedmana7e68452010-08-22 01:00:03 +0000308 break;
Douglas Gregordca52262011-07-01 22:41:14 +0000309 case llvm::Triple::RTEMS:
310 break;
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000311 case llvm::Triple::Cygwin:
Daniel Dunbaref845542013-01-30 00:19:24 +0000312 AddPath("/usr/include/w32api", System, false);
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000313 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000314 case llvm::Triple::MinGW32: {
315 // mingw-w64 crt include paths
316 llvm::sys::Path P(HSOpts.ResourceDir);
317 P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include
Daniel Dunbaref845542013-01-30 00:19:24 +0000318 AddPath(P.str(), System, false);
Douglas Gregord944a9b2011-06-27 15:47:15 +0000319 P = llvm::sys::Path(HSOpts.ResourceDir);
320 P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include
Daniel Dunbaref845542013-01-30 00:19:24 +0000321 AddPath(P.str(), System, false);
Douglas Gregord944a9b2011-06-27 15:47:15 +0000322 // mingw.org crt include paths
323 P = llvm::sys::Path(HSOpts.ResourceDir);
324 P.appendComponent("../../../include"); // <sysroot>/include
Daniel Dunbaref845542013-01-30 00:19:24 +0000325 AddPath(P.str(), System, false);
326 AddPath("/mingw/include", System, false);
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000327#if defined(_WIN32)
Daniel Dunbaref845542013-01-30 00:19:24 +0000328 AddPath("c:/mingw/include", System, false);
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000329#endif
Douglas Gregord944a9b2011-06-27 15:47:15 +0000330 }
Mike Stump43d81762009-10-08 23:29:47 +0000331 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000332
Mike Stump43d81762009-10-08 23:29:47 +0000333 default:
Mike Stump43d81762009-10-08 23:29:47 +0000334 break;
335 }
John Thompsond3f88342009-10-13 18:51:32 +0000336
Douglas Gregordca52262011-07-01 22:41:14 +0000337 if ( os != llvm::Triple::RTEMS )
Daniel Dunbaref845542013-01-30 00:19:24 +0000338 AddPath("/usr/include", ExternCSystem, false);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000339}
340
Chris Lattner0e3cc052010-05-05 05:28:39 +0000341void InitHeaderSearch::
Douglas Gregord944a9b2011-06-27 15:47:15 +0000342AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000343 llvm::Triple::OSType os = triple.getOS();
344 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000345
346 if (triple.isOSDarwin()) {
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000347 switch (triple.getArch()) {
348 default: break;
349
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000350 case llvm::Triple::ppc:
Douglas Gregor582c3012010-05-29 01:15:12 +0000351 case llvm::Triple::ppc64:
Douglas Gregor616d4362010-05-29 01:21:11 +0000352 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000353 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor616d4362010-05-29 01:21:11 +0000354 triple);
Douglas Gregor582c3012010-05-29 01:15:12 +0000355 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000356 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor582c3012010-05-29 01:15:12 +0000357 triple);
358 break;
359
Daniel Dunbarf2070b32010-05-28 01:54:31 +0000360 case llvm::Triple::x86:
361 case llvm::Triple::x86_64:
362 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
363 "i686-apple-darwin10", "", "x86_64", triple);
364 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
365 "i686-apple-darwin8", "", "", triple);
366 break;
367
368 case llvm::Triple::arm:
369 case llvm::Triple::thumb:
370 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
371 "arm-apple-darwin10", "v7", "", triple);
372 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
373 "arm-apple-darwin10", "v6", "", triple);
374 break;
375 }
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000376 return;
377 }
378
379 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000380 case llvm::Triple::Linux:
381 case llvm::Triple::Win32:
382 llvm_unreachable("Include management is handled in the driver.");
383
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000384 case llvm::Triple::Cygwin:
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000385 // Cygwin-1.7
386 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
387 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
388 // g++-4 / Cygwin-1.5
389 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000390 break;
391 case llvm::Triple::MinGW32:
Douglas Gregord944a9b2011-06-27 15:47:15 +0000392 // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000393 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
394 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
395 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
396 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
397 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
398 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
399 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
400 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
401 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
402 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
Douglas Gregord944a9b2011-06-27 15:47:15 +0000403 // mingw.org C++ include paths
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000404 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000405#if defined(_WIN32)
Aaron Ballmanb3dcbbd2012-03-25 22:46:17 +0000406 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");
407 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");
408 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");
409 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
410 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
411 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
NAKAMURA Takumi1696bc22012-09-13 05:53:23 +0000412#endif
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000413 break;
Chris Lattner7a7ca282010-01-09 05:41:14 +0000414 case llvm::Triple::DragonFly:
John McCall8cfb7202013-04-11 22:55:55 +0000415 if (llvm::sys::fs::exists("/usr/lib/gcc47"))
416 AddPath("/usr/include/c++/4.7", CXXSystem, false);
417 else
418 AddPath("/usr/include/c++/4.4", CXXSystem, false);
Chris Lattner7a7ca282010-01-09 05:41:14 +0000419 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000420 case llvm::Triple::FreeBSD:
mike-mac78b7a2010-05-06 14:11:13 +0000421 // FreeBSD 8.0
422 // FreeBSD 7.3
Nuno Lopesafe859a2010-01-17 00:00:11 +0000423 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000424 break;
Daniel Dunbar95c04572010-08-01 23:13:54 +0000425 case llvm::Triple::OpenBSD: {
426 std::string t = triple.getTriple();
427 if (t.substr(0, 6) == "x86_64")
428 t.replace(0, 6, "amd64");
429 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
430 t, "", "", triple);
431 break;
432 }
Chris Lattner38e317d2010-07-07 16:01:42 +0000433 case llvm::Triple::Minix:
434 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
435 "", "", "", triple);
436 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000437 case llvm::Triple::Solaris:
David Chisnallb6229592012-02-15 18:24:31 +0000438 AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
439 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000440 // Solaris - Fall though..
441 case llvm::Triple::AuroraUX:
442 // AuroraUX
443 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000444 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000445 break;
446 default:
447 break;
448 }
449}
450
Daniel Dunbara268fc02011-10-11 18:20:10 +0000451void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
452 const llvm::Triple &triple,
mike-m79bc57c2010-05-16 19:03:52 +0000453 const HeaderSearchOptions &HSOpts) {
Chandler Carruthca234192011-11-04 23:49:05 +0000454 // NB: This code path is going away. All of the logic is moving into the
455 // driver which has the information necessary to do target-specific
456 // selections of default include paths. Each target which moves there will be
457 // exempted from this logic here until we can delete the entire pile of code.
458 switch (triple.getOS()) {
459 default:
460 break; // Everything else continues to use this routine's logic.
461
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000462 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000463 case llvm::Triple::Win32:
464 return;
465 }
466
Daniel Dunbara268fc02011-10-11 18:20:10 +0000467 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
468 HSOpts.UseStandardSystemIncludes) {
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000469 if (HSOpts.UseLibcxx) {
470 if (triple.isOSDarwin()) {
471 // On Darwin, libc++ may be installed alongside the compiler in
472 // lib/c++/v1.
473 llvm::sys::Path P(HSOpts.ResourceDir);
474 if (!P.isEmpty()) {
475 P.eraseComponent(); // Remove version from foo/lib/clang/version
476 P.eraseComponent(); // Remove clang from foo/lib/clang
477
478 // Get foo/lib/c++/v1
479 P.appendComponent("c++");
480 P.appendComponent("v1");
Daniel Dunbar9cd90a22013-01-30 01:06:03 +0000481 AddUnmappedPath(P.str(), CXXSystem, false);
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000482 }
483 }
David Chisnallb4f0bd62012-03-02 10:49:52 +0000484 // On Solaris, include the support directory for things like xlocale and
485 // fudged system headers.
486 if (triple.getOS() == llvm::Triple::Solaris)
Daniel Dunbaref845542013-01-30 00:19:24 +0000487 AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, false);
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000488
Daniel Dunbaref845542013-01-30 00:19:24 +0000489 AddPath("/usr/include/c++/v1", CXXSystem, false);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000490 } else {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000491 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000492 }
Bob Wilson13c4f212011-06-21 21:12:29 +0000493 }
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000494
mike-m79bc57c2010-05-16 19:03:52 +0000495 AddDefaultCIncludePaths(triple, HSOpts);
Daniel Dunbare1665822009-11-07 04:20:39 +0000496
497 // Add the default framework include paths on Darwin.
Daniel Dunbara268fc02011-10-11 18:20:10 +0000498 if (HSOpts.UseStandardSystemIncludes) {
499 if (triple.isOSDarwin()) {
Daniel Dunbaref845542013-01-30 00:19:24 +0000500 AddPath("/System/Library/Frameworks", System, true);
501 AddPath("/Library/Frameworks", System, true);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000502 }
Daniel Dunbare1665822009-11-07 04:20:39 +0000503 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000504}
505
Nico Weber0fca0222008-08-22 09:25:22 +0000506/// RemoveDuplicates - If there are duplicate directory entries in the specified
Chad Rosiere305e812011-10-10 18:44:24 +0000507/// search list, remove the later (dead) ones. Returns the number of non-system
508/// headers removed, which is used to update NumAngled.
509static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
510 unsigned First, bool Verbose) {
Nico Weber0fca0222008-08-22 09:25:22 +0000511 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
512 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
513 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
Chad Rosiere305e812011-10-10 18:44:24 +0000514 unsigned NonSystemRemoved = 0;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000515 for (unsigned i = First; i != SearchList.size(); ++i) {
Chris Lattner7a739402008-09-26 17:46:45 +0000516 unsigned DirToRemove = i;
Mike Stump1eb44332009-09-09 15:08:12 +0000517
Chris Lattner43eee072009-02-08 01:00:10 +0000518 const DirectoryLookup &CurEntry = SearchList[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Chris Lattner43eee072009-02-08 01:00:10 +0000520 if (CurEntry.isNormalDir()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000521 // If this isn't the first time we've seen this dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000522 if (SeenDirs.insert(CurEntry.getDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000523 continue;
Chris Lattner43eee072009-02-08 01:00:10 +0000524 } else if (CurEntry.isFramework()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000525 // If this isn't the first time we've seen this framework dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000526 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000527 continue;
Nico Weber0fca0222008-08-22 09:25:22 +0000528 } else {
Chris Lattner43eee072009-02-08 01:00:10 +0000529 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
Nico Weber0fca0222008-08-22 09:25:22 +0000530 // If this isn't the first time we've seen this headermap, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000531 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
Nico Weber0fca0222008-08-22 09:25:22 +0000532 continue;
Chris Lattner30f05b52009-02-08 00:55:22 +0000533 }
Mike Stump1eb44332009-09-09 15:08:12 +0000534
Chris Lattner30f05b52009-02-08 00:55:22 +0000535 // If we have a normal #include dir/framework/headermap that is shadowed
536 // later in the chain by a system include location, we actually want to
537 // ignore the user's request and drop the user dir... keeping the system
538 // dir. This is weird, but required to emulate GCC's search path correctly.
539 //
540 // Since dupes of system dirs are rare, just rescan to find the original
541 // that we're nuking instead of using a DenseMap.
Chris Lattner43eee072009-02-08 01:00:10 +0000542 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
Chris Lattner30f05b52009-02-08 00:55:22 +0000543 // Find the dir that this is the same of.
544 unsigned FirstDir;
545 for (FirstDir = 0; ; ++FirstDir) {
546 assert(FirstDir != i && "Didn't find dupe?");
Mike Stump1eb44332009-09-09 15:08:12 +0000547
Chris Lattner43eee072009-02-08 01:00:10 +0000548 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
549
Chris Lattner30f05b52009-02-08 00:55:22 +0000550 // If these are different lookup types, then they can't be the dupe.
Chris Lattner43eee072009-02-08 01:00:10 +0000551 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
Chris Lattner30f05b52009-02-08 00:55:22 +0000552 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000553
Chris Lattner30f05b52009-02-08 00:55:22 +0000554 bool isSame;
Chris Lattner43eee072009-02-08 01:00:10 +0000555 if (CurEntry.isNormalDir())
556 isSame = SearchEntry.getDir() == CurEntry.getDir();
557 else if (CurEntry.isFramework())
558 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
Chris Lattner30f05b52009-02-08 00:55:22 +0000559 else {
Chris Lattner43eee072009-02-08 01:00:10 +0000560 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
561 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
Chris Lattner30f05b52009-02-08 00:55:22 +0000562 }
Mike Stump1eb44332009-09-09 15:08:12 +0000563
Chris Lattner30f05b52009-02-08 00:55:22 +0000564 if (isSame)
565 break;
566 }
Mike Stump1eb44332009-09-09 15:08:12 +0000567
Chris Lattner30f05b52009-02-08 00:55:22 +0000568 // If the first dir in the search path is a non-system dir, zap it
569 // instead of the system one.
570 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
571 DirToRemove = FirstDir;
572 }
573
574 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000575 llvm::errs() << "ignoring duplicate directory \""
576 << CurEntry.getName() << "\"\n";
Chris Lattner30f05b52009-02-08 00:55:22 +0000577 if (DirToRemove != i)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000578 llvm::errs() << " as it is a non-system directory that duplicates "
579 << "a system directory\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000580 }
Chad Rosiere305e812011-10-10 18:44:24 +0000581 if (DirToRemove != i)
582 ++NonSystemRemoved;
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Chris Lattner7a739402008-09-26 17:46:45 +0000584 // This is reached if the current entry is a duplicate. Remove the
585 // DirToRemove (usually the current dir).
586 SearchList.erase(SearchList.begin()+DirToRemove);
Nico Weber0fca0222008-08-22 09:25:22 +0000587 --i;
588 }
Chad Rosiere305e812011-10-10 18:44:24 +0000589 return NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000590}
591
592
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000593void InitHeaderSearch::Realize(const LangOptions &Lang) {
Nico Weber0fca0222008-08-22 09:25:22 +0000594 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
595 std::vector<DirectoryLookup> SearchList;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000596 SearchList.reserve(IncludePath.size());
Mike Stump1eb44332009-09-09 15:08:12 +0000597
Chris Lattnerebb61642011-06-16 22:56:45 +0000598 // Quoted arguments go first.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000599 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
600 it != ie; ++it) {
601 if (it->first == Quoted)
602 SearchList.push_back(it->second);
603 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000604 // Deduplicate and remember index.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000605 RemoveDuplicates(SearchList, 0, Verbose);
Chris Lattnerebb61642011-06-16 22:56:45 +0000606 unsigned NumQuoted = SearchList.size();
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000608 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
609 it != ie; ++it) {
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000610 if (it->first == Angled || it->first == IndexHeaderMap)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000611 SearchList.push_back(it->second);
612 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000613
614 RemoveDuplicates(SearchList, NumQuoted, Verbose);
615 unsigned NumAngled = SearchList.size();
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000616
617 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
618 it != ie; ++it) {
Daniel Dunbaref845542013-01-30 00:19:24 +0000619 if (it->first == System || it->first == ExternCSystem ||
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000620 (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
Benjamin Kramerc535d972011-09-23 02:25:14 +0000621 (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000622 (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
623 (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000624 SearchList.push_back(it->second);
625 }
626
627 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
628 it != ie; ++it) {
629 if (it->first == After)
630 SearchList.push_back(it->second);
631 }
632
Chris Lattner1d7f12b2011-06-16 22:58:10 +0000633 // Remove duplicates across both the Angled and System directories. GCC does
634 // this and failing to remove duplicates across these two groups breaks
635 // #include_next.
Chad Rosiere305e812011-10-10 18:44:24 +0000636 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
637 NumAngled -= NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000638
639 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
Chris Lattnerebb61642011-06-16 22:56:45 +0000640 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
Nico Weber0fca0222008-08-22 09:25:22 +0000641
Richard Smithf122a132012-06-13 20:27:03 +0000642 Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
643
Nico Weber0fca0222008-08-22 09:25:22 +0000644 // If verbose, print the list of directories that will be searched.
645 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000646 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000647 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
Chris Lattnerebb61642011-06-16 22:56:45 +0000648 if (i == NumQuoted)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000649 llvm::errs() << "#include <...> search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000650 const char *Name = SearchList[i].getName();
651 const char *Suffix;
652 if (SearchList[i].isNormalDir())
653 Suffix = "";
654 else if (SearchList[i].isFramework())
655 Suffix = " (framework directory)";
656 else {
657 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
658 Suffix = " (headermap)";
659 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000660 llvm::errs() << " " << Name << Suffix << "\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000661 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000662 llvm::errs() << "End of search list.\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000663 }
664}
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000665
Daniel Dunbar5814e652009-11-11 21:44:21 +0000666void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
667 const HeaderSearchOptions &HSOpts,
668 const LangOptions &Lang,
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000669 const llvm::Triple &Triple) {
670 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
671
672 // Add the user defined entries.
673 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
674 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Daniel Dunbar9cd90a22013-01-30 01:06:03 +0000675 if (E.IgnoreSysRoot) {
676 Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework);
677 } else {
678 Init.AddPath(E.Path, E.Group, E.IsFramework);
679 }
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000680 }
681
Daniel Dunbara268fc02011-10-11 18:20:10 +0000682 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000683
Richard Smithf122a132012-06-13 20:27:03 +0000684 for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
685 Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
686 HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
687
Douglas Gregor2f04f182012-02-02 18:42:48 +0000688 if (HSOpts.UseBuiltinIncludes) {
689 // Set up the builtin include directory in the module map.
690 llvm::sys::Path P(HSOpts.ResourceDir);
691 P.appendComponent("include");
692 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str()))
693 HS.getModuleMap().setBuiltinIncludeDir(Dir);
694 }
695
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000696 Init.Realize(Lang);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000697}