2010-07-25 11:12:58 +08:00
|
|
|
//===--- InitHeaderSearch.cpp - Initialize header search paths ------------===//
|
2008-08-22 17:25:22 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the InitHeaderSearch class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-11-10 07:02:47 +08:00
|
|
|
#include "clang/Frontend/Utils.h"
|
2008-08-22 17:25:22 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/LangOptions.h"
|
2009-11-07 12:20:50 +08:00
|
|
|
#include "clang/Frontend/HeaderSearchOptions.h"
|
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
2008-08-22 17:25:22 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2009-11-13 13:13:58 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-11-12 13:48:41 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2009-11-10 07:02:47 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2009-12-08 20:38:20 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2009-08-24 06:45:33 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-11-05 07:49:05 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-11-30 02:12:39 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-02-01 22:25:28 +08:00
|
|
|
|
2012-02-14 23:54:49 +08:00
|
|
|
#include "clang/Config/config.h" // C_INCLUDE_DIRS
|
2012-02-01 22:25:28 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
using namespace clang;
|
2009-11-10 07:02:47 +08:00
|
|
|
using namespace clang::frontend;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// InitHeaderSearch - This class makes it easier to set the search paths of
|
|
|
|
/// a HeaderSearch object. InitHeaderSearch stores several search path lists
|
|
|
|
/// internally, which can be sent to a HeaderSearch object in one swoop.
|
|
|
|
class InitHeaderSearch {
|
2011-02-22 08:40:56 +08:00
|
|
|
std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
|
|
|
|
typedef std::vector<std::pair<IncludeDirGroup,
|
|
|
|
DirectoryLookup> >::const_iterator path_iterator;
|
2012-06-14 04:27:03 +08:00
|
|
|
std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
|
2011-06-17 06:56:45 +08:00
|
|
|
HeaderSearch &Headers;
|
2009-11-10 07:02:47 +08:00
|
|
|
bool Verbose;
|
2010-12-26 04:09:27 +08:00
|
|
|
std::string IncludeSysroot;
|
|
|
|
bool IsNotEmptyOrRoot;
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
|
2010-12-26 04:09:27 +08:00
|
|
|
: Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
|
|
|
|
IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) {
|
2010-11-15 15:15:26 +08:00
|
|
|
}
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
/// AddPath - Add the specified path to the specified group list.
|
2011-07-23 18:55:15 +08:00
|
|
|
void AddPath(const Twine &Path, IncludeDirGroup Group,
|
2009-11-10 07:02:47 +08:00
|
|
|
bool isCXXAware, bool isUserSupplied,
|
|
|
|
bool isFramework, bool IgnoreSysRoot = false);
|
|
|
|
|
2012-06-14 04:27:03 +08:00
|
|
|
/// AddSystemHeaderPrefix - Add the specified prefix to the system header
|
|
|
|
/// prefix list.
|
|
|
|
void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
|
|
|
|
SystemHeaderPrefixes.push_back(std::make_pair(Prefix, IsSystemHeader));
|
|
|
|
}
|
|
|
|
|
2010-05-06 01:00:31 +08:00
|
|
|
/// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
|
2009-11-10 07:02:47 +08:00
|
|
|
/// libstdc++.
|
2011-07-23 18:55:15 +08:00
|
|
|
void AddGnuCPlusPlusIncludePaths(StringRef Base,
|
|
|
|
StringRef ArchDir,
|
|
|
|
StringRef Dir32,
|
|
|
|
StringRef Dir64,
|
2009-11-10 07:02:47 +08:00
|
|
|
const llvm::Triple &triple);
|
|
|
|
|
2010-12-22 00:45:42 +08:00
|
|
|
/// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
|
2009-11-10 07:02:47 +08:00
|
|
|
/// libstdc++.
|
2012-03-26 06:46:17 +08:00
|
|
|
void AddMinGWCPlusPlusIncludePaths(StringRef Base,
|
|
|
|
StringRef Arch,
|
|
|
|
StringRef Version);
|
2009-11-10 07:02:47 +08:00
|
|
|
|
2011-03-15 10:32:36 +08:00
|
|
|
/// AddMinGW64CXXPaths - Add the necessary paths to support
|
|
|
|
/// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
|
2012-03-26 06:46:17 +08:00
|
|
|
void AddMinGW64CXXPaths(StringRef Base,
|
|
|
|
StringRef Version);
|
2011-03-15 10:32:36 +08:00
|
|
|
|
2009-11-10 07:02:47 +08:00
|
|
|
// AddDefaultCIncludePaths - Add paths that should always be searched.
|
2010-05-17 03:03:52 +08:00
|
|
|
void AddDefaultCIncludePaths(const llvm::Triple &triple,
|
|
|
|
const HeaderSearchOptions &HSOpts);
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
// AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
|
|
|
|
// compiling c++.
|
2011-06-27 23:47:15 +08:00
|
|
|
void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
|
|
|
|
const HeaderSearchOptions &HSOpts);
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
/// AddDefaultSystemIncludePaths - Adds the default system include paths so
|
|
|
|
/// that e.g. stdio.h is found.
|
2011-10-12 02:20:10 +08:00
|
|
|
void AddDefaultIncludePaths(const LangOptions &Lang,
|
|
|
|
const llvm::Triple &triple,
|
|
|
|
const HeaderSearchOptions &HSOpts);
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
/// Realize - Merges all search path lists into one list and send it to
|
|
|
|
/// HeaderSearch.
|
2011-02-22 08:40:56 +08:00
|
|
|
void Realize(const LangOptions &Lang);
|
2009-11-10 07:02:47 +08:00
|
|
|
};
|
|
|
|
|
2011-06-17 06:56:45 +08:00
|
|
|
} // end anonymous namespace.
|
2008-08-22 17:25:22 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void InitHeaderSearch::AddPath(const Twine &Path,
|
2009-09-05 17:49:39 +08:00
|
|
|
IncludeDirGroup Group, bool isCXXAware,
|
|
|
|
bool isUserSupplied, bool isFramework,
|
|
|
|
bool IgnoreSysRoot) {
|
2009-12-08 20:38:20 +08:00
|
|
|
assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
|
2008-08-22 17:25:22 +08:00
|
|
|
FileManager &FM = Headers.getFileMgr();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// Compute the actual path, taking into consideration -isysroot.
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> MappedPathStorage;
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// Handle isysroot.
|
2011-03-03 05:30:07 +08:00
|
|
|
if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot &&
|
2011-05-02 12:50:10 +08:00
|
|
|
#if defined(_WIN32)
|
|
|
|
!MappedPathStr.empty() &&
|
|
|
|
llvm::sys::path::is_separator(MappedPathStr[0]) &&
|
|
|
|
#else
|
2010-12-18 05:22:22 +08:00
|
|
|
llvm::sys::path::is_absolute(MappedPathStr) &&
|
2011-05-02 12:50:10 +08:00
|
|
|
#endif
|
2010-12-26 04:09:27 +08:00
|
|
|
IsNotEmptyOrRoot) {
|
2010-11-15 17:28:23 +08:00
|
|
|
MappedPathStorage.clear();
|
2010-11-15 15:15:26 +08:00
|
|
|
MappedPathStr =
|
2010-12-26 04:09:27 +08:00
|
|
|
(IncludeSysroot + Path).toStringRef(MappedPathStorage);
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// Compute the DirectoryLookup type.
|
2008-10-27 09:19:25 +08:00
|
|
|
SrcMgr::CharacteristicKind Type;
|
2011-07-28 12:45:53 +08:00
|
|
|
if (Group == Quoted || Group == Angled || Group == IndexHeaderMap)
|
2008-09-27 05:18:42 +08:00
|
|
|
Type = SrcMgr::C_User;
|
2008-08-22 17:25:22 +08:00
|
|
|
else if (isCXXAware)
|
2008-09-27 05:18:42 +08:00
|
|
|
Type = SrcMgr::C_System;
|
2008-08-22 17:25:22 +08:00
|
|
|
else
|
2008-09-27 05:18:42 +08:00
|
|
|
Type = SrcMgr::C_ExternCSystem;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// If the directory exists, add it.
|
2010-11-23 16:35:12 +08:00
|
|
|
if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
|
2011-02-22 08:40:56 +08:00
|
|
|
IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type,
|
|
|
|
isUserSupplied, isFramework)));
|
2008-08-22 17:25:22 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// Check to see if this is an apple-style headermap (which are not allowed to
|
|
|
|
// be frameworks).
|
|
|
|
if (!isFramework) {
|
2010-11-23 16:35:12 +08:00
|
|
|
if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
|
2008-08-22 17:25:22 +08:00
|
|
|
if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
|
|
|
|
// It is a headermap, add it to the search path.
|
2011-02-22 08:40:56 +08:00
|
|
|
IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type,
|
2011-07-28 12:45:53 +08:00
|
|
|
isUserSupplied, Group == IndexHeaderMap)));
|
2008-08-22 17:25:22 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
if (Verbose)
|
2010-11-15 08:48:13 +08:00
|
|
|
llvm::errs() << "ignoring nonexistent directory \""
|
|
|
|
<< MappedPathStr << "\"\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
|
|
|
|
StringRef ArchDir,
|
|
|
|
StringRef Dir32,
|
|
|
|
StringRef Dir64,
|
2009-10-15 01:09:44 +08:00
|
|
|
const llvm::Triple &triple) {
|
2009-11-24 00:31:19 +08:00
|
|
|
// Add the base dir
|
2011-02-22 08:40:56 +08:00
|
|
|
AddPath(Base, CXXSystem, true, false, false);
|
2009-11-17 03:49:37 +08:00
|
|
|
|
|
|
|
// Add the multilib dirs
|
2009-10-15 01:09:44 +08:00
|
|
|
llvm::Triple::ArchType arch = triple.getArch();
|
|
|
|
bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
|
|
|
|
if (is64bit)
|
2011-02-22 08:40:56 +08:00
|
|
|
AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false);
|
2009-10-15 01:09:44 +08:00
|
|
|
else
|
2011-02-22 08:40:56 +08:00
|
|
|
AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false);
|
2009-11-24 00:31:19 +08:00
|
|
|
|
|
|
|
// Add the backward dir
|
2011-02-22 08:40:56 +08:00
|
|
|
AddPath(Base + "/backward", CXXSystem, true, false, false);
|
2009-10-06 09:33:02 +08:00
|
|
|
}
|
2008-08-22 17:25:22 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
|
2012-03-26 06:46:17 +08:00
|
|
|
StringRef Arch,
|
|
|
|
StringRef Version) {
|
|
|
|
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
|
|
|
|
CXXSystem, true, false, false);
|
|
|
|
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
|
|
|
|
CXXSystem, true, false, false);
|
|
|
|
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
|
|
|
|
CXXSystem, true, false, false);
|
2009-10-13 04:50:45 +08:00
|
|
|
}
|
2009-10-09 07:29:47 +08:00
|
|
|
|
2012-03-26 06:46:17 +08:00
|
|
|
void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
|
|
|
|
StringRef Version) {
|
2011-06-27 23:47:15 +08:00
|
|
|
// Assumes Base is HeaderSearchOpts' ResourceDir
|
2012-03-26 06:46:17 +08:00
|
|
|
AddPath(Base + "/../../../include/c++/" + Version,
|
|
|
|
CXXSystem, true, false, false);
|
|
|
|
AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
|
|
|
|
CXXSystem, true, false, false);
|
|
|
|
AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
|
|
|
|
CXXSystem, true, false, false);
|
|
|
|
AddPath(Base + "/../../../include/c++/" + Version + "/backward",
|
|
|
|
CXXSystem, true, false, false);
|
2011-03-15 10:32:36 +08:00
|
|
|
}
|
|
|
|
|
2010-05-17 03:03:52 +08:00
|
|
|
void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
|
|
|
|
const HeaderSearchOptions &HSOpts) {
|
2011-02-03 02:59:27 +08:00
|
|
|
llvm::Triple::OSType os = triple.getOS();
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
if (HSOpts.UseStandardSystemIncludes) {
|
|
|
|
switch (os) {
|
|
|
|
case llvm::Triple::FreeBSD:
|
|
|
|
case llvm::Triple::NetBSD:
|
2012-08-02 20:27:08 +08:00
|
|
|
case llvm::Triple::OpenBSD:
|
2012-08-09 07:57:20 +08:00
|
|
|
case llvm::Triple::Bitrig:
|
2011-10-12 02:20:10 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// FIXME: temporary hack: hard-coded paths.
|
|
|
|
AddPath("/usr/local/include", System, true, false, false);
|
|
|
|
break;
|
|
|
|
}
|
2011-02-03 02:59:27 +08:00
|
|
|
}
|
2010-05-17 03:03:52 +08:00
|
|
|
|
|
|
|
// Builtin includes use #include_next directives and should be positioned
|
|
|
|
// just prior C include dirs.
|
|
|
|
if (HSOpts.UseBuiltinIncludes) {
|
|
|
|
// Ignore the sys root, we *always* look for clang headers relative to
|
|
|
|
// supplied path.
|
|
|
|
llvm::sys::Path P(HSOpts.ResourceDir);
|
|
|
|
P.appendComponent("include");
|
|
|
|
AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true);
|
|
|
|
}
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
// All remaining additions are for system include directories, early exit if
|
|
|
|
// we aren't using them.
|
|
|
|
if (!HSOpts.UseStandardSystemIncludes)
|
|
|
|
return;
|
|
|
|
|
2010-05-17 03:03:52 +08:00
|
|
|
// Add dirs specified via 'configure --with-c-include-dirs'.
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef CIncludeDirs(C_INCLUDE_DIRS);
|
2009-11-12 15:28:29 +08:00
|
|
|
if (CIncludeDirs != "") {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<StringRef, 5> dirs;
|
2009-11-13 13:13:58 +08:00
|
|
|
CIncludeDirs.split(dirs, ":");
|
2011-07-23 18:55:15 +08:00
|
|
|
for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
|
2009-11-13 13:13:58 +08:00
|
|
|
i != dirs.end();
|
2011-02-17 16:50:50 +08:00
|
|
|
++i)
|
2009-11-12 13:48:41 +08:00
|
|
|
AddPath(*i, System, false, false, false);
|
|
|
|
return;
|
|
|
|
}
|
2011-02-03 02:59:27 +08:00
|
|
|
|
2009-10-09 07:29:47 +08:00
|
|
|
switch (os) {
|
2011-11-06 04:17:13 +08:00
|
|
|
case llvm::Triple::Linux:
|
2011-11-05 07:49:05 +08:00
|
|
|
case llvm::Triple::Win32:
|
2011-11-06 04:17:13 +08:00
|
|
|
llvm_unreachable("Include management is handled in the driver.");
|
2011-11-05 07:49:05 +08:00
|
|
|
|
2010-04-12 03:29:39 +08:00
|
|
|
case llvm::Triple::Haiku:
|
|
|
|
AddPath("/boot/common/include", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/app", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/arch", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/device", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/drivers", System, true, false, false);
|
2011-02-17 16:50:50 +08:00
|
|
|
AddPath("/boot/develop/headers/os/game", System, true, false, false);
|
2010-04-12 03:29:39 +08:00
|
|
|
AddPath("/boot/develop/headers/os/interface", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/kernel", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/locale", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/mail", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/media", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/midi", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/midi2", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/net", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/storage", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/support", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/translation",
|
|
|
|
System, true, false, false);
|
2011-02-17 16:50:50 +08:00
|
|
|
AddPath("/boot/develop/headers/os/add-ons/graphics",
|
2010-04-12 03:29:39 +08:00
|
|
|
System, true, false, false);
|
2011-02-17 16:50:50 +08:00
|
|
|
AddPath("/boot/develop/headers/os/add-ons/input_server",
|
2010-04-12 03:29:39 +08:00
|
|
|
System, true, false, false);
|
2011-02-17 16:50:50 +08:00
|
|
|
AddPath("/boot/develop/headers/os/add-ons/screen_saver",
|
2010-04-12 03:29:39 +08:00
|
|
|
System, true, false, false);
|
2011-02-17 16:50:50 +08:00
|
|
|
AddPath("/boot/develop/headers/os/add-ons/tracker",
|
2010-04-12 03:29:39 +08:00
|
|
|
System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/be_apps/Deskbar",
|
|
|
|
System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/be_apps/NetPositive",
|
|
|
|
System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/os/be_apps/Tracker",
|
|
|
|
System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/cpp", System, true, false, false);
|
2011-02-17 16:50:50 +08:00
|
|
|
AddPath("/boot/develop/headers/cpp/i586-pc-haiku",
|
2010-04-12 03:29:39 +08:00
|
|
|
System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/3rdparty", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/bsd", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/glibc", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers/posix", System, true, false, false);
|
|
|
|
AddPath("/boot/develop/headers", System, true, false, false);
|
2010-08-22 09:00:03 +08:00
|
|
|
break;
|
2011-07-02 06:41:14 +08:00
|
|
|
case llvm::Triple::RTEMS:
|
|
|
|
break;
|
2010-10-11 10:27:37 +08:00
|
|
|
case llvm::Triple::Cygwin:
|
|
|
|
AddPath("/usr/include/w32api", System, true, false, false);
|
|
|
|
break;
|
2011-06-27 23:47:15 +08:00
|
|
|
case llvm::Triple::MinGW32: {
|
|
|
|
// mingw-w64 crt include paths
|
|
|
|
llvm::sys::Path P(HSOpts.ResourceDir);
|
|
|
|
P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include
|
|
|
|
AddPath(P.str(), System, true, false, false);
|
|
|
|
P = llvm::sys::Path(HSOpts.ResourceDir);
|
|
|
|
P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include
|
|
|
|
AddPath(P.str(), System, true, false, false);
|
|
|
|
// mingw.org crt include paths
|
|
|
|
P = llvm::sys::Path(HSOpts.ResourceDir);
|
|
|
|
P.appendComponent("../../../include"); // <sysroot>/include
|
|
|
|
AddPath(P.str(), System, true, false, false);
|
|
|
|
AddPath("/mingw/include", System, true, false, false);
|
2012-09-13 13:53:23 +08:00
|
|
|
#if defined(_WIN32)
|
2012-03-26 06:46:17 +08:00
|
|
|
AddPath("c:/mingw/include", System, true, false, false);
|
2012-09-13 13:53:23 +08:00
|
|
|
#endif
|
2011-06-27 23:47:15 +08:00
|
|
|
}
|
2009-10-09 07:29:47 +08:00
|
|
|
break;
|
2011-06-27 23:47:15 +08:00
|
|
|
|
2009-10-09 07:29:47 +08:00
|
|
|
default:
|
|
|
|
break;
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
2009-10-14 02:51:32 +08:00
|
|
|
|
2011-07-02 06:41:14 +08:00
|
|
|
if ( os != llvm::Triple::RTEMS )
|
|
|
|
AddPath("/usr/include", System, false, false, false);
|
2009-10-27 22:47:31 +08:00
|
|
|
}
|
|
|
|
|
2010-05-05 13:28:39 +08:00
|
|
|
void InitHeaderSearch::
|
2011-06-27 23:47:15 +08:00
|
|
|
AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
|
2009-10-27 22:47:31 +08:00
|
|
|
llvm::Triple::OSType os = triple.getOS();
|
|
|
|
// FIXME: temporary hack: hard-coded paths.
|
2011-04-20 05:43:27 +08:00
|
|
|
|
|
|
|
if (triple.isOSDarwin()) {
|
2010-05-28 09:54:31 +08:00
|
|
|
switch (triple.getArch()) {
|
|
|
|
default: break;
|
|
|
|
|
2011-02-17 16:50:50 +08:00
|
|
|
case llvm::Triple::ppc:
|
2010-05-29 09:15:12 +08:00
|
|
|
case llvm::Triple::ppc64:
|
2010-05-29 09:21:11 +08:00
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
|
2011-02-17 16:50:50 +08:00
|
|
|
"powerpc-apple-darwin10", "", "ppc64",
|
2010-05-29 09:21:11 +08:00
|
|
|
triple);
|
2010-05-29 09:15:12 +08:00
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
|
2011-02-17 16:50:50 +08:00
|
|
|
"powerpc-apple-darwin10", "", "ppc64",
|
2010-05-29 09:15:12 +08:00
|
|
|
triple);
|
|
|
|
break;
|
|
|
|
|
2010-05-28 09:54:31 +08:00
|
|
|
case llvm::Triple::x86:
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
|
|
|
|
"i686-apple-darwin10", "", "x86_64", triple);
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
|
|
|
|
"i686-apple-darwin8", "", "", triple);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
case llvm::Triple::thumb:
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
|
|
|
|
"arm-apple-darwin10", "v7", "", triple);
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
|
|
|
|
"arm-apple-darwin10", "v6", "", triple);
|
|
|
|
break;
|
|
|
|
}
|
2011-04-20 05:43:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (os) {
|
2011-11-06 04:17:13 +08:00
|
|
|
case llvm::Triple::Linux:
|
|
|
|
case llvm::Triple::Win32:
|
|
|
|
llvm_unreachable("Include management is handled in the driver.");
|
|
|
|
|
2011-04-20 05:43:27 +08:00
|
|
|
case llvm::Triple::Cygwin:
|
2012-03-26 06:46:17 +08:00
|
|
|
// Cygwin-1.7
|
|
|
|
AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
|
|
|
|
AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
|
|
|
|
// g++-4 / Cygwin-1.5
|
|
|
|
AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
|
2011-04-20 05:43:27 +08:00
|
|
|
break;
|
|
|
|
case llvm::Triple::MinGW32:
|
2011-06-27 23:47:15 +08:00
|
|
|
// mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
|
2012-03-26 06:46:17 +08:00
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
|
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
|
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
|
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
|
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
|
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
|
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
|
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
|
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
|
|
|
|
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
|
2011-06-27 23:47:15 +08:00
|
|
|
// mingw.org C++ include paths
|
2012-03-26 06:46:17 +08:00
|
|
|
AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
|
2012-09-13 13:53:23 +08:00
|
|
|
#if defined(_WIN32)
|
2012-03-26 06:46:17 +08:00
|
|
|
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");
|
|
|
|
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");
|
|
|
|
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");
|
|
|
|
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
|
|
|
|
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
|
|
|
|
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
|
2012-09-13 13:53:23 +08:00
|
|
|
#endif
|
2009-10-27 22:47:31 +08:00
|
|
|
break;
|
2010-01-09 13:41:14 +08:00
|
|
|
case llvm::Triple::DragonFly:
|
2011-02-22 08:40:56 +08:00
|
|
|
AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false);
|
2009-10-27 22:47:31 +08:00
|
|
|
break;
|
|
|
|
case llvm::Triple::FreeBSD:
|
2010-05-06 22:11:13 +08:00
|
|
|
// FreeBSD 8.0
|
|
|
|
// FreeBSD 7.3
|
2010-01-17 08:00:11 +08:00
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple);
|
2009-10-27 22:47:31 +08:00
|
|
|
break;
|
2010-09-01 06:39:50 +08:00
|
|
|
case llvm::Triple::NetBSD:
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple);
|
|
|
|
break;
|
2010-08-02 07:13:54 +08:00
|
|
|
case llvm::Triple::OpenBSD: {
|
|
|
|
std::string t = triple.getTriple();
|
|
|
|
if (t.substr(0, 6) == "x86_64")
|
|
|
|
t.replace(0, 6, "amd64");
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/g++",
|
|
|
|
t, "", "", triple);
|
|
|
|
break;
|
|
|
|
}
|
2010-07-08 00:01:42 +08:00
|
|
|
case llvm::Triple::Minix:
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
|
|
|
|
"", "", "", triple);
|
|
|
|
break;
|
2009-10-27 22:47:31 +08:00
|
|
|
case llvm::Triple::Solaris:
|
2012-02-16 02:24:31 +08:00
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
|
|
|
|
"i386-pc-solaris2.11", "", "", triple);
|
2009-10-27 22:47:31 +08:00
|
|
|
// Solaris - Fall though..
|
|
|
|
case llvm::Triple::AuroraUX:
|
|
|
|
// AuroraUX
|
|
|
|
AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
|
2009-11-17 03:49:37 +08:00
|
|
|
"i386-pc-solaris2.11", "", "", triple);
|
2009-10-27 22:47:31 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
|
|
|
|
const llvm::Triple &triple,
|
2010-05-17 03:03:52 +08:00
|
|
|
const HeaderSearchOptions &HSOpts) {
|
2011-11-05 07:49:05 +08:00
|
|
|
// NB: This code path is going away. All of the logic is moving into the
|
|
|
|
// driver which has the information necessary to do target-specific
|
|
|
|
// selections of default include paths. Each target which moves there will be
|
|
|
|
// exempted from this logic here until we can delete the entire pile of code.
|
|
|
|
switch (triple.getOS()) {
|
|
|
|
default:
|
|
|
|
break; // Everything else continues to use this routine's logic.
|
|
|
|
|
2011-11-06 04:17:13 +08:00
|
|
|
case llvm::Triple::Linux:
|
2011-11-05 07:49:05 +08:00
|
|
|
case llvm::Triple::Win32:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
|
|
|
|
HSOpts.UseStandardSystemIncludes) {
|
2011-07-30 04:21:18 +08:00
|
|
|
if (HSOpts.UseLibcxx) {
|
|
|
|
if (triple.isOSDarwin()) {
|
|
|
|
// On Darwin, libc++ may be installed alongside the compiler in
|
|
|
|
// lib/c++/v1.
|
|
|
|
llvm::sys::Path P(HSOpts.ResourceDir);
|
|
|
|
if (!P.isEmpty()) {
|
|
|
|
P.eraseComponent(); // Remove version from foo/lib/clang/version
|
|
|
|
P.eraseComponent(); // Remove clang from foo/lib/clang
|
|
|
|
|
|
|
|
// Get foo/lib/c++/v1
|
|
|
|
P.appendComponent("c++");
|
|
|
|
P.appendComponent("v1");
|
|
|
|
AddPath(P.str(), CXXSystem, true, false, false, true);
|
|
|
|
}
|
|
|
|
}
|
2012-03-02 18:49:52 +08:00
|
|
|
// On Solaris, include the support directory for things like xlocale and
|
|
|
|
// fudged system headers.
|
|
|
|
if (triple.getOS() == llvm::Triple::Solaris)
|
|
|
|
AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, true, false,
|
|
|
|
false);
|
2011-07-30 04:21:18 +08:00
|
|
|
|
2011-06-22 05:12:29 +08:00
|
|
|
AddPath("/usr/include/c++/v1", CXXSystem, true, false, false);
|
2011-10-12 02:20:10 +08:00
|
|
|
} else {
|
2011-06-27 23:47:15 +08:00
|
|
|
AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
|
2011-10-12 02:20:10 +08:00
|
|
|
}
|
2011-06-22 05:12:29 +08:00
|
|
|
}
|
2009-11-24 00:31:19 +08:00
|
|
|
|
2010-05-17 03:03:52 +08:00
|
|
|
AddDefaultCIncludePaths(triple, HSOpts);
|
2009-11-07 12:20:39 +08:00
|
|
|
|
|
|
|
// Add the default framework include paths on Darwin.
|
2011-10-12 02:20:10 +08:00
|
|
|
if (HSOpts.UseStandardSystemIncludes) {
|
|
|
|
if (triple.isOSDarwin()) {
|
|
|
|
AddPath("/System/Library/Frameworks", System, true, false, true);
|
|
|
|
AddPath("/Library/Frameworks", System, true, false, true);
|
|
|
|
}
|
2009-11-07 12:20:39 +08:00
|
|
|
}
|
2009-10-27 22:47:31 +08:00
|
|
|
}
|
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
/// RemoveDuplicates - If there are duplicate directory entries in the specified
|
2011-10-11 02:44:24 +08:00
|
|
|
/// search list, remove the later (dead) ones. Returns the number of non-system
|
|
|
|
/// headers removed, which is used to update NumAngled.
|
|
|
|
static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
|
|
|
|
unsigned First, bool Verbose) {
|
2008-08-22 17:25:22 +08:00
|
|
|
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
|
|
|
|
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
|
|
|
|
llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
|
2011-10-11 02:44:24 +08:00
|
|
|
unsigned NonSystemRemoved = 0;
|
2011-02-22 08:40:56 +08:00
|
|
|
for (unsigned i = First; i != SearchList.size(); ++i) {
|
2008-09-27 01:46:45 +08:00
|
|
|
unsigned DirToRemove = i;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 09:00:10 +08:00
|
|
|
const DirectoryLookup &CurEntry = SearchList[i];
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 09:00:10 +08:00
|
|
|
if (CurEntry.isNormalDir()) {
|
2008-08-22 17:25:22 +08:00
|
|
|
// If this isn't the first time we've seen this dir, remove it.
|
2009-02-08 09:00:10 +08:00
|
|
|
if (SeenDirs.insert(CurEntry.getDir()))
|
2008-08-22 17:25:22 +08:00
|
|
|
continue;
|
2009-02-08 09:00:10 +08:00
|
|
|
} else if (CurEntry.isFramework()) {
|
2008-08-22 17:25:22 +08:00
|
|
|
// If this isn't the first time we've seen this framework dir, remove it.
|
2009-02-08 09:00:10 +08:00
|
|
|
if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
|
2008-08-22 17:25:22 +08:00
|
|
|
continue;
|
|
|
|
} else {
|
2009-02-08 09:00:10 +08:00
|
|
|
assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
|
2008-08-22 17:25:22 +08:00
|
|
|
// If this isn't the first time we've seen this headermap, remove it.
|
2009-02-08 09:00:10 +08:00
|
|
|
if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
|
2008-08-22 17:25:22 +08:00
|
|
|
continue;
|
2009-02-08 08:55:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
// If we have a normal #include dir/framework/headermap that is shadowed
|
|
|
|
// later in the chain by a system include location, we actually want to
|
|
|
|
// ignore the user's request and drop the user dir... keeping the system
|
|
|
|
// dir. This is weird, but required to emulate GCC's search path correctly.
|
|
|
|
//
|
|
|
|
// Since dupes of system dirs are rare, just rescan to find the original
|
|
|
|
// that we're nuking instead of using a DenseMap.
|
2009-02-08 09:00:10 +08:00
|
|
|
if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
|
2009-02-08 08:55:22 +08:00
|
|
|
// Find the dir that this is the same of.
|
|
|
|
unsigned FirstDir;
|
|
|
|
for (FirstDir = 0; ; ++FirstDir) {
|
|
|
|
assert(FirstDir != i && "Didn't find dupe?");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 09:00:10 +08:00
|
|
|
const DirectoryLookup &SearchEntry = SearchList[FirstDir];
|
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
// If these are different lookup types, then they can't be the dupe.
|
2009-02-08 09:00:10 +08:00
|
|
|
if (SearchEntry.getLookupType() != CurEntry.getLookupType())
|
2009-02-08 08:55:22 +08:00
|
|
|
continue;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
bool isSame;
|
2009-02-08 09:00:10 +08:00
|
|
|
if (CurEntry.isNormalDir())
|
|
|
|
isSame = SearchEntry.getDir() == CurEntry.getDir();
|
|
|
|
else if (CurEntry.isFramework())
|
|
|
|
isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
|
2009-02-08 08:55:22 +08:00
|
|
|
else {
|
2009-02-08 09:00:10 +08:00
|
|
|
assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
|
|
|
|
isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
|
2009-02-08 08:55:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
if (isSame)
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
// If the first dir in the search path is a non-system dir, zap it
|
|
|
|
// instead of the system one.
|
|
|
|
if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
|
|
|
|
DirToRemove = FirstDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Verbose) {
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << "ignoring duplicate directory \""
|
|
|
|
<< CurEntry.getName() << "\"\n";
|
2009-02-08 08:55:22 +08:00
|
|
|
if (DirToRemove != i)
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << " as it is a non-system directory that duplicates "
|
|
|
|
<< "a system directory\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
2011-10-11 02:44:24 +08:00
|
|
|
if (DirToRemove != i)
|
|
|
|
++NonSystemRemoved;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-09-27 01:46:45 +08:00
|
|
|
// This is reached if the current entry is a duplicate. Remove the
|
|
|
|
// DirToRemove (usually the current dir).
|
|
|
|
SearchList.erase(SearchList.begin()+DirToRemove);
|
2008-08-22 17:25:22 +08:00
|
|
|
--i;
|
|
|
|
}
|
2011-10-11 02:44:24 +08:00
|
|
|
return NonSystemRemoved;
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-22 08:40:56 +08:00
|
|
|
void InitHeaderSearch::Realize(const LangOptions &Lang) {
|
2008-08-22 17:25:22 +08:00
|
|
|
// Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
|
|
|
|
std::vector<DirectoryLookup> SearchList;
|
2011-02-22 08:40:56 +08:00
|
|
|
SearchList.reserve(IncludePath.size());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-06-17 06:56:45 +08:00
|
|
|
// Quoted arguments go first.
|
2011-02-22 08:40:56 +08:00
|
|
|
for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
|
|
|
|
it != ie; ++it) {
|
|
|
|
if (it->first == Quoted)
|
|
|
|
SearchList.push_back(it->second);
|
|
|
|
}
|
2011-06-17 06:56:45 +08:00
|
|
|
// Deduplicate and remember index.
|
2011-02-22 08:40:56 +08:00
|
|
|
RemoveDuplicates(SearchList, 0, Verbose);
|
2011-06-17 06:56:45 +08:00
|
|
|
unsigned NumQuoted = SearchList.size();
|
2011-02-22 08:40:56 +08:00
|
|
|
|
|
|
|
for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
|
|
|
|
it != ie; ++it) {
|
2011-07-28 12:45:53 +08:00
|
|
|
if (it->first == Angled || it->first == IndexHeaderMap)
|
2011-02-22 08:40:56 +08:00
|
|
|
SearchList.push_back(it->second);
|
|
|
|
}
|
2011-06-17 06:56:45 +08:00
|
|
|
|
|
|
|
RemoveDuplicates(SearchList, NumQuoted, Verbose);
|
|
|
|
unsigned NumAngled = SearchList.size();
|
2011-02-22 08:40:56 +08:00
|
|
|
|
|
|
|
for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
|
|
|
|
it != ie; ++it) {
|
2011-09-23 05:41:16 +08:00
|
|
|
if (it->first == System ||
|
|
|
|
(!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
|
2011-09-23 10:25:14 +08:00
|
|
|
(/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
|
2011-09-23 05:41:16 +08:00
|
|
|
(Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
|
|
|
|
(Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
|
2011-02-22 08:40:56 +08:00
|
|
|
SearchList.push_back(it->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
|
|
|
|
it != ie; ++it) {
|
|
|
|
if (it->first == After)
|
|
|
|
SearchList.push_back(it->second);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-06-17 06:58:10 +08:00
|
|
|
// Remove duplicates across both the Angled and System directories. GCC does
|
|
|
|
// this and failing to remove duplicates across these two groups breaks
|
|
|
|
// #include_next.
|
2011-10-11 02:44:24 +08:00
|
|
|
unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
|
|
|
|
NumAngled -= NonSystemRemoved;
|
2008-08-22 17:25:22 +08:00
|
|
|
|
|
|
|
bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
|
2011-06-17 06:56:45 +08:00
|
|
|
Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
|
2008-08-22 17:25:22 +08:00
|
|
|
|
2012-06-14 04:27:03 +08:00
|
|
|
Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
|
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// If verbose, print the list of directories that will be searched.
|
|
|
|
if (Verbose) {
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << "#include \"...\" search starts here:\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
|
2011-06-17 06:56:45 +08:00
|
|
|
if (i == NumQuoted)
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << "#include <...> search starts here:\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
const char *Name = SearchList[i].getName();
|
|
|
|
const char *Suffix;
|
|
|
|
if (SearchList[i].isNormalDir())
|
|
|
|
Suffix = "";
|
|
|
|
else if (SearchList[i].isFramework())
|
|
|
|
Suffix = " (framework directory)";
|
|
|
|
else {
|
|
|
|
assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
|
|
|
|
Suffix = " (headermap)";
|
|
|
|
}
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << " " << Name << Suffix << "\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << "End of search list.\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
|
|
|
}
|
2009-11-07 12:20:50 +08:00
|
|
|
|
2009-11-12 05:44:21 +08:00
|
|
|
void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
|
|
|
|
const HeaderSearchOptions &HSOpts,
|
|
|
|
const LangOptions &Lang,
|
2009-11-07 12:20:50 +08:00
|
|
|
const llvm::Triple &Triple) {
|
|
|
|
InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
|
|
|
|
|
|
|
|
// Add the user defined entries.
|
|
|
|
for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
|
|
|
|
const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
|
2011-11-05 16:30:29 +08:00
|
|
|
Init.AddPath(E.Path, E.Group, !E.ImplicitExternC, E.IsUserSupplied,
|
|
|
|
E.IsFramework, E.IgnoreSysRoot);
|
2009-11-07 12:20:50 +08:00
|
|
|
}
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
|
2009-11-07 12:20:50 +08:00
|
|
|
|
2012-06-14 04:27:03 +08:00
|
|
|
for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
|
|
|
|
Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
|
|
|
|
HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
|
|
|
|
|
2012-02-03 02:42:48 +08:00
|
|
|
if (HSOpts.UseBuiltinIncludes) {
|
|
|
|
// Set up the builtin include directory in the module map.
|
|
|
|
llvm::sys::Path P(HSOpts.ResourceDir);
|
|
|
|
P.appendComponent("include");
|
|
|
|
if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P.str()))
|
|
|
|
HS.getModuleMap().setBuiltinIncludeDir(Dir);
|
|
|
|
}
|
|
|
|
|
2011-02-22 08:40:56 +08:00
|
|
|
Init.Realize(Lang);
|
2009-11-07 12:20:50 +08:00
|
|
|
}
|