blob: ef9129feaff8cb045a6e698d482bde5c366cfd34 [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
Oscar Fuentes2100fe92011-02-03 22:48:20 +000014#ifdef HAVE_CLANG_CONFIG_H
15# include "clang/Config/config.h"
16#endif
17
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000018#include "clang/Frontend/Utils.h"
Nico Weber0fca0222008-08-22 09:25:22 +000019#include "clang/Basic/FileManager.h"
20#include "clang/Basic/LangOptions.h"
Daniel Dunbar63c8b772009-11-07 04:20:50 +000021#include "clang/Frontend/HeaderSearchOptions.h"
22#include "clang/Lex/HeaderSearch.h"
Nico Weber0fca0222008-08-22 09:25:22 +000023#include "llvm/ADT/SmallString.h"
24#include "llvm/ADT/SmallPtrSet.h"
Rafael Espindolaaadd7a42009-11-13 05:13:58 +000025#include "llvm/ADT/SmallVector.h"
Rafael Espindolaf0a2f512009-11-12 05:48:41 +000026#include "llvm/ADT/StringExtras.h"
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000027#include "llvm/ADT/Triple.h"
Benjamin Kramere89ba592009-12-08 12:38:20 +000028#include "llvm/ADT/Twine.h"
Chris Lattnerd57a7ef2009-08-23 22:45:33 +000029#include "llvm/Support/raw_ostream.h"
Chandler Carruthca234192011-11-04 23:49:05 +000030#include "llvm/Support/ErrorHandling.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000031#include "llvm/Support/Path.h"
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +000032#include "llvm/Config/config.h"
Nico Weber0fca0222008-08-22 09:25:22 +000033using namespace clang;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000034using namespace clang::frontend;
35
36namespace {
37
38/// InitHeaderSearch - This class makes it easier to set the search paths of
39/// a HeaderSearch object. InitHeaderSearch stores several search path lists
40/// internally, which can be sent to a HeaderSearch object in one swoop.
41class InitHeaderSearch {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +000042 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
43 typedef std::vector<std::pair<IncludeDirGroup,
44 DirectoryLookup> >::const_iterator path_iterator;
Chris Lattnerebb61642011-06-16 22:56:45 +000045 HeaderSearch &Headers;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000046 bool Verbose;
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000047 std::string IncludeSysroot;
48 bool IsNotEmptyOrRoot;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000049
50public:
51
Chris Lattner5f9e2722011-07-23 10:55:15 +000052 InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
Michael J. Spenceraf6530c2010-12-25 20:09:27 +000053 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
54 IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) {
Chandler Carruthc09265a2010-11-15 07:15:26 +000055 }
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000056
57 /// AddPath - Add the specified path to the specified group list.
Chris Lattner5f9e2722011-07-23 10:55:15 +000058 void AddPath(const Twine &Path, IncludeDirGroup Group,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000059 bool isCXXAware, bool isUserSupplied,
60 bool isFramework, bool IgnoreSysRoot = false);
61
mike-ma6087372010-05-05 17:00:31 +000062 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000063 /// libstdc++.
Chris Lattner5f9e2722011-07-23 10:55:15 +000064 void AddGnuCPlusPlusIncludePaths(StringRef Base,
65 StringRef ArchDir,
66 StringRef Dir32,
67 StringRef Dir64,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000068 const llvm::Triple &triple);
69
Michael J. Spencer06a8dc62010-12-21 16:45:42 +000070 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000071 /// libstdc++.
Chris Lattner5f9e2722011-07-23 10:55:15 +000072 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
73 StringRef Arch,
74 StringRef Version);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000075
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000076 /// AddMinGW64CXXPaths - Add the necessary paths to support
77 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
Chris Lattner5f9e2722011-07-23 10:55:15 +000078 void AddMinGW64CXXPaths(StringRef Base,
79 StringRef Version);
NAKAMURA Takumi9db48462011-03-15 02:32:36 +000080
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000081 // AddDefaultCIncludePaths - Add paths that should always be searched.
mike-m79bc57c2010-05-16 19:03:52 +000082 void AddDefaultCIncludePaths(const llvm::Triple &triple,
83 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000084
85 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
86 // compiling c++.
Douglas Gregord944a9b2011-06-27 15:47:15 +000087 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
88 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000089
90 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
91 /// that e.g. stdio.h is found.
Daniel Dunbara268fc02011-10-11 18:20:10 +000092 void AddDefaultIncludePaths(const LangOptions &Lang,
93 const llvm::Triple &triple,
94 const HeaderSearchOptions &HSOpts);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000095
96 /// Realize - Merges all search path lists into one list and send it to
97 /// HeaderSearch.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +000098 void Realize(const LangOptions &Lang);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000099};
100
Chris Lattnerebb61642011-06-16 22:56:45 +0000101} // end anonymous namespace.
Nico Weber0fca0222008-08-22 09:25:22 +0000102
Chris Lattner5f9e2722011-07-23 10:55:15 +0000103void InitHeaderSearch::AddPath(const Twine &Path,
Benjamin Kramer458fb102009-09-05 09:49:39 +0000104 IncludeDirGroup Group, bool isCXXAware,
105 bool isUserSupplied, bool isFramework,
106 bool IgnoreSysRoot) {
Benjamin Kramere89ba592009-12-08 12:38:20 +0000107 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
Nico Weber0fca0222008-08-22 09:25:22 +0000108 FileManager &FM = Headers.getFileMgr();
Mike Stump1eb44332009-09-09 15:08:12 +0000109
Nico Weber0fca0222008-08-22 09:25:22 +0000110 // Compute the actual path, taking into consideration -isysroot.
Chandler Carruth5853b0f2010-11-15 00:05:18 +0000111 llvm::SmallString<256> MappedPathStorage;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000112 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
Mike Stump1eb44332009-09-09 15:08:12 +0000113
Nico Weber0fca0222008-08-22 09:25:22 +0000114 // Handle isysroot.
Rafael Espindola9a7e09d2011-03-02 21:30:07 +0000115 if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot &&
NAKAMURA Takumi0f0cdab2011-05-02 04:50:10 +0000116#if defined(_WIN32)
117 !MappedPathStr.empty() &&
118 llvm::sys::path::is_separator(MappedPathStr[0]) &&
119#else
Michael J. Spencer256053b2010-12-17 21:22:22 +0000120 llvm::sys::path::is_absolute(MappedPathStr) &&
NAKAMURA Takumi0f0cdab2011-05-02 04:50:10 +0000121#endif
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000122 IsNotEmptyOrRoot) {
Chandler Carruth5619ae52010-11-15 09:28:23 +0000123 MappedPathStorage.clear();
Chandler Carruthc09265a2010-11-15 07:15:26 +0000124 MappedPathStr =
Michael J. Spenceraf6530c2010-12-25 20:09:27 +0000125 (IncludeSysroot + Path).toStringRef(MappedPathStorage);
Nico Weber0fca0222008-08-22 09:25:22 +0000126 }
Mike Stump1eb44332009-09-09 15:08:12 +0000127
Nico Weber0fca0222008-08-22 09:25:22 +0000128 // Compute the DirectoryLookup type.
Chris Lattner9d728512008-10-27 01:19:25 +0000129 SrcMgr::CharacteristicKind Type;
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000130 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000131 Type = SrcMgr::C_User;
Nico Weber0fca0222008-08-22 09:25:22 +0000132 else if (isCXXAware)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000133 Type = SrcMgr::C_System;
Nico Weber0fca0222008-08-22 09:25:22 +0000134 else
Chris Lattner0b9e7362008-09-26 21:18:42 +0000135 Type = SrcMgr::C_ExternCSystem;
Mike Stump1eb44332009-09-09 15:08:12 +0000136
137
Nico Weber0fca0222008-08-22 09:25:22 +0000138 // If the directory exists, add it.
Chris Lattner39b49bc2010-11-23 08:35:12 +0000139 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000140 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type,
141 isUserSupplied, isFramework)));
Nico Weber0fca0222008-08-22 09:25:22 +0000142 return;
143 }
Mike Stump1eb44332009-09-09 15:08:12 +0000144
Nico Weber0fca0222008-08-22 09:25:22 +0000145 // Check to see if this is an apple-style headermap (which are not allowed to
146 // be frameworks).
147 if (!isFramework) {
Chris Lattner39b49bc2010-11-23 08:35:12 +0000148 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
Nico Weber0fca0222008-08-22 09:25:22 +0000149 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
150 // It is a headermap, add it to the search path.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000151 IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type,
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000152 isUserSupplied, Group == IndexHeaderMap)));
Nico Weber0fca0222008-08-22 09:25:22 +0000153 return;
154 }
155 }
156 }
Mike Stump1eb44332009-09-09 15:08:12 +0000157
Nico Weber0fca0222008-08-22 09:25:22 +0000158 if (Verbose)
Chandler Carruthf3721452010-11-15 00:48:13 +0000159 llvm::errs() << "ignoring nonexistent directory \""
160 << MappedPathStr << "\"\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000161}
162
Chris Lattner5f9e2722011-07-23 10:55:15 +0000163void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
164 StringRef ArchDir,
165 StringRef Dir32,
166 StringRef Dir64,
Rafael Espindola31b63be2009-10-14 17:09:44 +0000167 const llvm::Triple &triple) {
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000168 // Add the base dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000169 AddPath(Base, CXXSystem, true, false, false);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000170
171 // Add the multilib dirs
Rafael Espindola31b63be2009-10-14 17:09:44 +0000172 llvm::Triple::ArchType arch = triple.getArch();
173 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola31b63be2009-10-14 17:09:44 +0000174 if (is64bit)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000175 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false);
Rafael Espindola31b63be2009-10-14 17:09:44 +0000176 else
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000177 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false);
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000178
179 // Add the backward dir
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000180 AddPath(Base + "/backward", CXXSystem, true, false, false);
Rafael Espindola2e9f6522009-10-06 01:33:02 +0000181}
Nico Weber0fca0222008-08-22 09:25:22 +0000182
Chris Lattner5f9e2722011-07-23 10:55:15 +0000183void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
184 StringRef Arch,
185 StringRef Version) {
Benjamin Kramerab8ae192010-01-20 16:18:11 +0000186 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000187 CXXSystem, true, false, false);
Chris Lattner8e9006b2010-09-03 16:45:53 +0000188 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000189 CXXSystem, true, false, false);
Benjamin Kramerab8ae192010-01-20 16:18:11 +0000190 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000191 CXXSystem, true, false, false);
Mike Stump620d57a2009-10-12 20:50:45 +0000192}
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +0000193
Chris Lattner5f9e2722011-07-23 10:55:15 +0000194void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
195 StringRef Version) {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000196 // Assumes Base is HeaderSearchOpts' ResourceDir
197 AddPath(Base + "/../../../include/c++/" + Version,
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000198 CXXSystem, true, false, false);
Douglas Gregord944a9b2011-06-27 15:47:15 +0000199 AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000200 CXXSystem, true, false, false);
Douglas Gregord944a9b2011-06-27 15:47:15 +0000201 AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
202 CXXSystem, true, false, false);
203 AddPath(Base + "/../../../include/c++/" + Version + "/backward",
NAKAMURA Takumi9db48462011-03-15 02:32:36 +0000204 CXXSystem, true, false, false);
205}
206
mike-m79bc57c2010-05-16 19:03:52 +0000207void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
208 const HeaderSearchOptions &HSOpts) {
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000209 llvm::Triple::OSType os = triple.getOS();
210
Daniel Dunbara268fc02011-10-11 18:20:10 +0000211 if (HSOpts.UseStandardSystemIncludes) {
212 switch (os) {
213 case llvm::Triple::FreeBSD:
214 case llvm::Triple::NetBSD:
215 break;
216 default:
217 // FIXME: temporary hack: hard-coded paths.
218 AddPath("/usr/local/include", System, true, false, false);
219 break;
220 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000221 }
mike-m79bc57c2010-05-16 19:03:52 +0000222
223 // Builtin includes use #include_next directives and should be positioned
224 // just prior C include dirs.
225 if (HSOpts.UseBuiltinIncludes) {
226 // Ignore the sys root, we *always* look for clang headers relative to
227 // supplied path.
228 llvm::sys::Path P(HSOpts.ResourceDir);
229 P.appendComponent("include");
230 AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true);
231 }
232
Daniel Dunbara268fc02011-10-11 18:20:10 +0000233 // All remaining additions are for system include directories, early exit if
234 // we aren't using them.
235 if (!HSOpts.UseStandardSystemIncludes)
236 return;
237
mike-m79bc57c2010-05-16 19:03:52 +0000238 // Add dirs specified via 'configure --with-c-include-dirs'.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000239 StringRef CIncludeDirs(C_INCLUDE_DIRS);
Daniel Dunbarc7064682009-11-12 07:28:29 +0000240 if (CIncludeDirs != "") {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000241 SmallVector<StringRef, 5> dirs;
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000242 CIncludeDirs.split(dirs, ":");
Chris Lattner5f9e2722011-07-23 10:55:15 +0000243 for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000244 i != dirs.end();
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000245 ++i)
Rafael Espindolaf0a2f512009-11-12 05:48:41 +0000246 AddPath(*i, System, false, false, false);
247 return;
248 }
Benjamin Kramer8e50a962011-02-02 18:59:27 +0000249
Mike Stump43d81762009-10-08 23:29:47 +0000250 switch (os) {
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000251 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000252 case llvm::Triple::Win32:
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000253 llvm_unreachable("Include management is handled in the driver.");
Chandler Carruthca234192011-11-04 23:49:05 +0000254
Chris Lattner86ed3a32010-04-11 19:29:39 +0000255 case llvm::Triple::Haiku:
256 AddPath("/boot/common/include", System, true, false, false);
257 AddPath("/boot/develop/headers/os", System, true, false, false);
258 AddPath("/boot/develop/headers/os/app", System, true, false, false);
259 AddPath("/boot/develop/headers/os/arch", System, true, false, false);
260 AddPath("/boot/develop/headers/os/device", System, true, false, false);
261 AddPath("/boot/develop/headers/os/drivers", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000262 AddPath("/boot/develop/headers/os/game", System, true, false, false);
Chris Lattner86ed3a32010-04-11 19:29:39 +0000263 AddPath("/boot/develop/headers/os/interface", System, true, false, false);
264 AddPath("/boot/develop/headers/os/kernel", System, true, false, false);
265 AddPath("/boot/develop/headers/os/locale", System, true, false, false);
266 AddPath("/boot/develop/headers/os/mail", System, true, false, false);
267 AddPath("/boot/develop/headers/os/media", System, true, false, false);
268 AddPath("/boot/develop/headers/os/midi", System, true, false, false);
269 AddPath("/boot/develop/headers/os/midi2", System, true, false, false);
270 AddPath("/boot/develop/headers/os/net", System, true, false, false);
271 AddPath("/boot/develop/headers/os/storage", System, true, false, false);
272 AddPath("/boot/develop/headers/os/support", System, true, false, false);
273 AddPath("/boot/develop/headers/os/translation",
274 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000275 AddPath("/boot/develop/headers/os/add-ons/graphics",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000276 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000277 AddPath("/boot/develop/headers/os/add-ons/input_server",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000278 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000279 AddPath("/boot/develop/headers/os/add-ons/screen_saver",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000280 System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000281 AddPath("/boot/develop/headers/os/add-ons/tracker",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000282 System, true, false, false);
283 AddPath("/boot/develop/headers/os/be_apps/Deskbar",
284 System, true, false, false);
285 AddPath("/boot/develop/headers/os/be_apps/NetPositive",
286 System, true, false, false);
287 AddPath("/boot/develop/headers/os/be_apps/Tracker",
288 System, true, false, false);
289 AddPath("/boot/develop/headers/cpp", System, true, false, false);
NAKAMURA Takumi125b4cb2011-02-17 08:50:50 +0000290 AddPath("/boot/develop/headers/cpp/i586-pc-haiku",
Chris Lattner86ed3a32010-04-11 19:29:39 +0000291 System, true, false, false);
292 AddPath("/boot/develop/headers/3rdparty", System, true, false, false);
293 AddPath("/boot/develop/headers/bsd", System, true, false, false);
294 AddPath("/boot/develop/headers/glibc", System, true, false, false);
295 AddPath("/boot/develop/headers/posix", System, true, false, false);
296 AddPath("/boot/develop/headers", System, true, false, false);
Eli Friedmana7e68452010-08-22 01:00:03 +0000297 break;
Douglas Gregordca52262011-07-01 22:41:14 +0000298 case llvm::Triple::RTEMS:
299 break;
NAKAMURA Takumi32df0022010-10-11 02:27:37 +0000300 case llvm::Triple::Cygwin:
301 AddPath("/usr/include/w32api", System, true, false, false);
302 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000303 case llvm::Triple::MinGW32: {
304 // mingw-w64 crt include paths
305 llvm::sys::Path P(HSOpts.ResourceDir);
306 P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include
307 AddPath(P.str(), System, true, false, false);
308 P = llvm::sys::Path(HSOpts.ResourceDir);
309 P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include
310 AddPath(P.str(), System, true, false, false);
311 // mingw.org crt include paths
312 P = llvm::sys::Path(HSOpts.ResourceDir);
313 P.appendComponent("../../../include"); // <sysroot>/include
314 AddPath(P.str(), System, true, false, false);
315 AddPath("/mingw/include", System, true, false, false);
316 AddPath("c:/mingw/include", System, true, false, false);
317 }
Mike Stump43d81762009-10-08 23:29:47 +0000318 break;
Douglas Gregord944a9b2011-06-27 15:47:15 +0000319
Mike Stump43d81762009-10-08 23:29:47 +0000320 default:
Mike Stump43d81762009-10-08 23:29:47 +0000321 break;
322 }
John Thompsond3f88342009-10-13 18:51:32 +0000323
Douglas Gregordca52262011-07-01 22:41:14 +0000324 if ( os != llvm::Triple::RTEMS )
325 AddPath("/usr/include", System, false, false, false);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000326}
327
Chris Lattner0e3cc052010-05-05 05:28:39 +0000328void InitHeaderSearch::
Douglas Gregord944a9b2011-06-27 15:47:15 +0000329AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000330 llvm::Triple::OSType os = triple.getOS();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000331 StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000332 if (CxxIncludeRoot != "") {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000333 StringRef CxxIncludeArch(CXX_INCLUDE_ARCH);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000334 if (CxxIncludeArch == "")
335 AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(),
Chris Lattner0e3cc052010-05-05 05:28:39 +0000336 CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR,
337 triple);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000338 else
339 AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH,
Chris Lattner0e3cc052010-05-05 05:28:39 +0000340 CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR,
341 triple);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000342 return;
343 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000344 // 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:
385 // Cygwin-1.7
386 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
387 // g++-4 / Cygwin-1.5
388 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
389 // FIXME: Do we support g++-3.4.4?
390 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4");
391 break;
392 case llvm::Triple::MinGW32:
Douglas Gregord944a9b2011-06-27 15:47:15 +0000393 // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
394 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
395 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
396 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
397 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
Eli Friedmana74ec5c2011-11-28 23:58:55 +0000398 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
Douglas Gregord944a9b2011-06-27 15:47:15 +0000399 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
400 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
Douglas Gregorf732f2b2011-07-05 14:16:05 +0000401 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
Eli Friedmana74ec5c2011-11-28 23:58:55 +0000402 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
Douglas Gregorf732f2b2011-07-05 14:16:05 +0000403 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
Douglas Gregord944a9b2011-06-27 15:47:15 +0000404 // mingw.org C++ include paths
405 AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000406 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000407 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
Daniel Dunbardb57a4c2011-04-19 21:43:27 +0000408 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
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:
434 // Solaris - Fall though..
435 case llvm::Triple::AuroraUX:
436 // AuroraUX
437 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000438 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000439 break;
440 default:
441 break;
442 }
443}
444
Daniel Dunbara268fc02011-10-11 18:20:10 +0000445void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
446 const llvm::Triple &triple,
mike-m79bc57c2010-05-16 19:03:52 +0000447 const HeaderSearchOptions &HSOpts) {
Chandler Carruthca234192011-11-04 23:49:05 +0000448 // NB: This code path is going away. All of the logic is moving into the
449 // driver which has the information necessary to do target-specific
450 // selections of default include paths. Each target which moves there will be
451 // exempted from this logic here until we can delete the entire pile of code.
452 switch (triple.getOS()) {
453 default:
454 break; // Everything else continues to use this routine's logic.
455
Chandler Carruth7d7e9f92011-11-05 20:17:13 +0000456 case llvm::Triple::Linux:
Chandler Carruthca234192011-11-04 23:49:05 +0000457 case llvm::Triple::Win32:
458 return;
459 }
460
Daniel Dunbara268fc02011-10-11 18:20:10 +0000461 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
462 HSOpts.UseStandardSystemIncludes) {
Douglas Gregorbaf41f12011-07-29 20:21:18 +0000463 if (HSOpts.UseLibcxx) {
464 if (triple.isOSDarwin()) {
465 // On Darwin, libc++ may be installed alongside the compiler in
466 // lib/c++/v1.
467 llvm::sys::Path P(HSOpts.ResourceDir);
468 if (!P.isEmpty()) {
469 P.eraseComponent(); // Remove version from foo/lib/clang/version
470 P.eraseComponent(); // Remove clang from foo/lib/clang
471
472 // Get foo/lib/c++/v1
473 P.appendComponent("c++");
474 P.appendComponent("v1");
475 AddPath(P.str(), CXXSystem, true, false, false, true);
476 }
477 }
478
Bob Wilson13c4f212011-06-21 21:12:29 +0000479 AddPath("/usr/include/c++/v1", CXXSystem, true, false, false);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000480 } else {
Douglas Gregord944a9b2011-06-27 15:47:15 +0000481 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
Daniel Dunbara268fc02011-10-11 18:20:10 +0000482 }
Bob Wilson13c4f212011-06-21 21:12:29 +0000483 }
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000484
mike-m79bc57c2010-05-16 19:03:52 +0000485 AddDefaultCIncludePaths(triple, HSOpts);
Daniel Dunbare1665822009-11-07 04:20:39 +0000486
487 // Add the default framework include paths on Darwin.
Daniel Dunbara268fc02011-10-11 18:20:10 +0000488 if (HSOpts.UseStandardSystemIncludes) {
489 if (triple.isOSDarwin()) {
490 AddPath("/System/Library/Frameworks", System, true, false, true);
491 AddPath("/Library/Frameworks", System, true, false, true);
492 }
Daniel Dunbare1665822009-11-07 04:20:39 +0000493 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000494}
495
Nico Weber0fca0222008-08-22 09:25:22 +0000496/// RemoveDuplicates - If there are duplicate directory entries in the specified
Chad Rosiere305e812011-10-10 18:44:24 +0000497/// search list, remove the later (dead) ones. Returns the number of non-system
498/// headers removed, which is used to update NumAngled.
499static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
500 unsigned First, bool Verbose) {
Nico Weber0fca0222008-08-22 09:25:22 +0000501 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
502 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
503 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
Chad Rosiere305e812011-10-10 18:44:24 +0000504 unsigned NonSystemRemoved = 0;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000505 for (unsigned i = First; i != SearchList.size(); ++i) {
Chris Lattner7a739402008-09-26 17:46:45 +0000506 unsigned DirToRemove = i;
Mike Stump1eb44332009-09-09 15:08:12 +0000507
Chris Lattner43eee072009-02-08 01:00:10 +0000508 const DirectoryLookup &CurEntry = SearchList[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000509
Chris Lattner43eee072009-02-08 01:00:10 +0000510 if (CurEntry.isNormalDir()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000511 // If this isn't the first time we've seen this dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000512 if (SeenDirs.insert(CurEntry.getDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000513 continue;
Chris Lattner43eee072009-02-08 01:00:10 +0000514 } else if (CurEntry.isFramework()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000515 // If this isn't the first time we've seen this framework dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000516 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000517 continue;
Nico Weber0fca0222008-08-22 09:25:22 +0000518 } else {
Chris Lattner43eee072009-02-08 01:00:10 +0000519 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
Nico Weber0fca0222008-08-22 09:25:22 +0000520 // If this isn't the first time we've seen this headermap, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000521 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
Nico Weber0fca0222008-08-22 09:25:22 +0000522 continue;
Chris Lattner30f05b52009-02-08 00:55:22 +0000523 }
Mike Stump1eb44332009-09-09 15:08:12 +0000524
Chris Lattner30f05b52009-02-08 00:55:22 +0000525 // If we have a normal #include dir/framework/headermap that is shadowed
526 // later in the chain by a system include location, we actually want to
527 // ignore the user's request and drop the user dir... keeping the system
528 // dir. This is weird, but required to emulate GCC's search path correctly.
529 //
530 // Since dupes of system dirs are rare, just rescan to find the original
531 // that we're nuking instead of using a DenseMap.
Chris Lattner43eee072009-02-08 01:00:10 +0000532 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
Chris Lattner30f05b52009-02-08 00:55:22 +0000533 // Find the dir that this is the same of.
534 unsigned FirstDir;
535 for (FirstDir = 0; ; ++FirstDir) {
536 assert(FirstDir != i && "Didn't find dupe?");
Mike Stump1eb44332009-09-09 15:08:12 +0000537
Chris Lattner43eee072009-02-08 01:00:10 +0000538 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
539
Chris Lattner30f05b52009-02-08 00:55:22 +0000540 // If these are different lookup types, then they can't be the dupe.
Chris Lattner43eee072009-02-08 01:00:10 +0000541 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
Chris Lattner30f05b52009-02-08 00:55:22 +0000542 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000543
Chris Lattner30f05b52009-02-08 00:55:22 +0000544 bool isSame;
Chris Lattner43eee072009-02-08 01:00:10 +0000545 if (CurEntry.isNormalDir())
546 isSame = SearchEntry.getDir() == CurEntry.getDir();
547 else if (CurEntry.isFramework())
548 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
Chris Lattner30f05b52009-02-08 00:55:22 +0000549 else {
Chris Lattner43eee072009-02-08 01:00:10 +0000550 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
551 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
Chris Lattner30f05b52009-02-08 00:55:22 +0000552 }
Mike Stump1eb44332009-09-09 15:08:12 +0000553
Chris Lattner30f05b52009-02-08 00:55:22 +0000554 if (isSame)
555 break;
556 }
Mike Stump1eb44332009-09-09 15:08:12 +0000557
Chris Lattner30f05b52009-02-08 00:55:22 +0000558 // If the first dir in the search path is a non-system dir, zap it
559 // instead of the system one.
560 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
561 DirToRemove = FirstDir;
562 }
563
564 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000565 llvm::errs() << "ignoring duplicate directory \""
566 << CurEntry.getName() << "\"\n";
Chris Lattner30f05b52009-02-08 00:55:22 +0000567 if (DirToRemove != i)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000568 llvm::errs() << " as it is a non-system directory that duplicates "
569 << "a system directory\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000570 }
Chad Rosiere305e812011-10-10 18:44:24 +0000571 if (DirToRemove != i)
572 ++NonSystemRemoved;
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Chris Lattner7a739402008-09-26 17:46:45 +0000574 // This is reached if the current entry is a duplicate. Remove the
575 // DirToRemove (usually the current dir).
576 SearchList.erase(SearchList.begin()+DirToRemove);
Nico Weber0fca0222008-08-22 09:25:22 +0000577 --i;
578 }
Chad Rosiere305e812011-10-10 18:44:24 +0000579 return NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000580}
581
582
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000583void InitHeaderSearch::Realize(const LangOptions &Lang) {
Nico Weber0fca0222008-08-22 09:25:22 +0000584 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
585 std::vector<DirectoryLookup> SearchList;
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000586 SearchList.reserve(IncludePath.size());
Mike Stump1eb44332009-09-09 15:08:12 +0000587
Chris Lattnerebb61642011-06-16 22:56:45 +0000588 // Quoted arguments go first.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000589 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
590 it != ie; ++it) {
591 if (it->first == Quoted)
592 SearchList.push_back(it->second);
593 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000594 // Deduplicate and remember index.
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000595 RemoveDuplicates(SearchList, 0, Verbose);
Chris Lattnerebb61642011-06-16 22:56:45 +0000596 unsigned NumQuoted = SearchList.size();
Mike Stump1eb44332009-09-09 15:08:12 +0000597
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000598 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
599 it != ie; ++it) {
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000600 if (it->first == Angled || it->first == IndexHeaderMap)
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000601 SearchList.push_back(it->second);
602 }
Chris Lattnerebb61642011-06-16 22:56:45 +0000603
604 RemoveDuplicates(SearchList, NumQuoted, Verbose);
605 unsigned NumAngled = SearchList.size();
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000606
607 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
608 it != ie; ++it) {
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000609 if (it->first == System ||
610 (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
Benjamin Kramerc535d972011-09-23 02:25:14 +0000611 (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
Benjamin Kramer47adebe2011-09-22 21:41:16 +0000612 (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
613 (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000614 SearchList.push_back(it->second);
615 }
616
617 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
618 it != ie; ++it) {
619 if (it->first == After)
620 SearchList.push_back(it->second);
621 }
622
Chris Lattner1d7f12b2011-06-16 22:58:10 +0000623 // Remove duplicates across both the Angled and System directories. GCC does
624 // this and failing to remove duplicates across these two groups breaks
625 // #include_next.
Chad Rosiere305e812011-10-10 18:44:24 +0000626 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
627 NumAngled -= NonSystemRemoved;
Nico Weber0fca0222008-08-22 09:25:22 +0000628
629 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
Chris Lattnerebb61642011-06-16 22:56:45 +0000630 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
Nico Weber0fca0222008-08-22 09:25:22 +0000631
632 // If verbose, print the list of directories that will be searched.
633 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000634 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000635 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
Chris Lattnerebb61642011-06-16 22:56:45 +0000636 if (i == NumQuoted)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000637 llvm::errs() << "#include <...> search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000638 const char *Name = SearchList[i].getName();
639 const char *Suffix;
640 if (SearchList[i].isNormalDir())
641 Suffix = "";
642 else if (SearchList[i].isFramework())
643 Suffix = " (framework directory)";
644 else {
645 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
646 Suffix = " (headermap)";
647 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000648 llvm::errs() << " " << Name << Suffix << "\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000649 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000650 llvm::errs() << "End of search list.\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000651 }
652}
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000653
Daniel Dunbar5814e652009-11-11 21:44:21 +0000654void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
655 const HeaderSearchOptions &HSOpts,
656 const LangOptions &Lang,
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000657 const llvm::Triple &Triple) {
658 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
659
660 // Add the user defined entries.
661 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
662 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Chandler Carruthac2bc4d2011-11-05 08:30:29 +0000663 Init.AddPath(E.Path, E.Group, !E.ImplicitExternC, E.IsUserSupplied,
664 E.IsFramework, E.IgnoreSysRoot);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000665 }
666
Daniel Dunbara268fc02011-10-11 18:20:10 +0000667 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000668
Joerg Sonnenberger2df66472011-02-22 00:40:56 +0000669 Init.Realize(Lang);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000670}