summaryrefslogtreecommitdiffstats
path: root/lib/Frontend/InitHeaderSearch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Frontend/InitHeaderSearch.cpp')
-rw-r--r--lib/Frontend/InitHeaderSearch.cpp230
1 files changed, 135 insertions, 95 deletions
diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp
index df91713..4855b62 100644
--- a/lib/Frontend/InitHeaderSearch.cpp
+++ b/lib/Frontend/InitHeaderSearch.cpp
@@ -11,6 +11,10 @@
//
//===----------------------------------------------------------------------===//
+#ifdef HAVE_CLANG_CONFIG_H
+# include "clang/Config/config.h"
+#endif
+
#include "clang/Frontend/Utils.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangOptions.h"
@@ -23,7 +27,7 @@
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/System/Path.h"
+#include "llvm/Support/Path.h"
#include "llvm/Config/config.h"
#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN 1
@@ -41,13 +45,15 @@ class InitHeaderSearch {
std::vector<DirectoryLookup> IncludeGroup[4];
HeaderSearch& Headers;
bool Verbose;
- std::string isysroot;
+ std::string IncludeSysroot;
+ bool IsNotEmptyOrRoot;
public:
- InitHeaderSearch(HeaderSearch &HS,
- bool verbose = false, const std::string &iSysroot = "")
- : Headers(HS), Verbose(verbose), isysroot(iSysroot) {}
+ InitHeaderSearch(HeaderSearch &HS, bool verbose, llvm::StringRef sysroot)
+ : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
+ IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) {
+ }
/// AddPath - Add the specified path to the specified group list.
void AddPath(const llvm::Twine &Path, IncludeDirGroup Group,
@@ -62,7 +68,7 @@ public:
llvm::StringRef Dir64,
const llvm::Triple &triple);
- /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to suport a MinGW
+ /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
/// libstdc++.
void AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
llvm::StringRef Arch,
@@ -101,19 +107,18 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
FileManager &FM = Headers.getFileMgr();
// Compute the actual path, taking into consideration -isysroot.
- llvm::SmallString<256> MappedPathStr;
- llvm::raw_svector_ostream MappedPath(MappedPathStr);
+ llvm::SmallString<256> MappedPathStorage;
+ llvm::StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
// Handle isysroot.
- if (Group == System && !IgnoreSysRoot) {
- // FIXME: Portability. This should be a sys::Path interface, this doesn't
- // handle things like C:\ right, nor win32 \\network\device\blah.
- if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present.
- MappedPath << isysroot;
+ if (Group == System && !IgnoreSysRoot &&
+ llvm::sys::path::is_absolute(MappedPathStr) &&
+ IsNotEmptyOrRoot) {
+ MappedPathStorage.clear();
+ MappedPathStr =
+ (IncludeSysroot + Path).toStringRef(MappedPathStorage);
}
- Path.print(MappedPath);
-
// Compute the DirectoryLookup type.
SrcMgr::CharacteristicKind Type;
if (Group == Quoted || Group == Angled)
@@ -125,7 +130,7 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
// If the directory exists, add it.
- if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) {
+ if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied,
isFramework));
return;
@@ -134,7 +139,7 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
// Check to see if this is an apple-style headermap (which are not allowed to
// be frameworks).
if (!isFramework) {
- if (const FileEntry *FE = FM.getFile(MappedPath.str())) {
+ if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
// It is a headermap, add it to the search path.
IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied));
@@ -145,7 +150,7 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
if (Verbose)
llvm::errs() << "ignoring nonexistent directory \""
- << MappedPath.str() << "\"\n";
+ << MappedPathStr << "\"\n";
}
@@ -191,8 +196,6 @@ void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base,
void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
llvm::StringRef Arch,
llvm::StringRef Version) {
- AddPath(Base + "/" + Arch + "/" + Version + "/include",
- System, true, false, false);
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
System, true, false, false);
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
@@ -344,7 +347,7 @@ static bool getVisualStudioDir(std::string &path) {
bool hasVCExpressDir = getSystemRegistryString(
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\$VERSION",
"InstallDir", vsExpressIDEInstallDir, sizeof(vsExpressIDEInstallDir) - 1);
- // If we have both vc80 and vc90, pick version we were compiled with.
+ // If we have both vc80 and vc90, pick version we were compiled with.
if (hasVCDir && vsIDEInstallDir[0]) {
char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE");
if (p)
@@ -366,7 +369,7 @@ static bool getVisualStudioDir(std::string &path) {
const char* vs80comntools = getenv("VS80COMNTOOLS");
const char* vscomntools = NULL;
- // Try to find the version that we were compiled with
+ // Try to find the version that we were compiled with
if(false) {}
#if (_MSC_VER >= 1600) // VC100
else if(vs100comntools) {
@@ -409,7 +412,7 @@ static bool getWindowsSDKDir(std::string &path) {
bool hasSDKDir = getSystemRegistryString(
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
"InstallationFolder", windowsSDKInstallDir, sizeof(windowsSDKInstallDir) - 1);
- // If we have both vc80 and vc90, pick version we were compiled with.
+ // If we have both vc80 and vc90, pick version we were compiled with.
if (hasSDKDir && windowsSDKInstallDir[0]) {
path = windowsSDKInstallDir;
return(true);
@@ -419,8 +422,16 @@ static bool getWindowsSDKDir(std::string &path) {
void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts) {
- // FIXME: temporary hack: hard-coded paths.
- AddPath("/usr/local/include", System, true, false, false);
+ llvm::Triple::OSType os = triple.getOS();
+
+ switch (os) {
+ case llvm::Triple::NetBSD:
+ break;
+ default:
+ // FIXME: temporary hack: hard-coded paths.
+ AddPath("/usr/local/include", System, true, false, false);
+ break;
+ }
// Builtin includes use #include_next directives and should be positioned
// just prior C include dirs.
@@ -439,47 +450,39 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
CIncludeDirs.split(dirs, ":");
for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin();
i != dirs.end();
- ++i)
+ ++i)
AddPath(*i, System, false, false, false);
return;
}
- llvm::Triple::OSType os = triple.getOS();
+
switch (os) {
- case llvm::Triple::Win32:
- {
- std::string VSDir;
- std::string WindowsSDKDir;
- if (getVisualStudioDir(VSDir)) {
- AddPath(VSDir + "\\VC\\include", System, false, false, false);
- if (getWindowsSDKDir(WindowsSDKDir))
- AddPath(WindowsSDKDir + "\\include", System, false, false, false);
- else
- AddPath(VSDir + "\\VC\\PlatformSDK\\Include",
- System, false, false, false);
- }
- else {
- // Default install paths.
- AddPath("C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
- System, false, false, false);
- AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
- System, false, false, false);
- AddPath(
+ case llvm::Triple::Win32: {
+ std::string VSDir;
+ std::string WindowsSDKDir;
+ if (getVisualStudioDir(VSDir)) {
+ AddPath(VSDir + "\\VC\\include", System, false, false, false);
+ if (getWindowsSDKDir(WindowsSDKDir))
+ AddPath(WindowsSDKDir + "\\include", System, false, false, false);
+ else
+ AddPath(VSDir + "\\VC\\PlatformSDK\\Include",
+ System, false, false, false);
+ } else {
+ // Default install paths.
+ AddPath("C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
+ System, false, false, false);
+ AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
+ System, false, false, false);
+ AddPath(
"C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
- System, false, false, false);
- AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include",
- System, false, false, false);
- AddPath(
+ System, false, false, false);
+ AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include",
+ System, false, false, false);
+ AddPath(
"C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include",
- System, false, false, false);
- // For some clang developers.
- AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include",
- System, false, false, false);
- AddPath(
- "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
- System, false, false, false);
- }
+ System, false, false, false);
}
break;
+ }
case llvm::Triple::Haiku:
AddPath("/boot/common/include", System, true, false, false);
AddPath("/boot/develop/headers/os", System, true, false, false);
@@ -487,7 +490,7 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
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);
- AddPath("/boot/develop/headers/os/game", System, true, false, false);
+ AddPath("/boot/develop/headers/os/game", System, true, false, false);
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);
@@ -500,13 +503,13 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
AddPath("/boot/develop/headers/os/support", System, true, false, false);
AddPath("/boot/develop/headers/os/translation",
System, true, false, false);
- AddPath("/boot/develop/headers/os/add-ons/graphics",
+ AddPath("/boot/develop/headers/os/add-ons/graphics",
System, true, false, false);
- AddPath("/boot/develop/headers/os/add-ons/input_server",
+ AddPath("/boot/develop/headers/os/add-ons/input_server",
System, true, false, false);
- AddPath("/boot/develop/headers/os/add-ons/screen_saver",
+ AddPath("/boot/develop/headers/os/add-ons/screen_saver",
System, true, false, false);
- AddPath("/boot/develop/headers/os/add-ons/tracker",
+ AddPath("/boot/develop/headers/os/add-ons/tracker",
System, true, false, false);
AddPath("/boot/develop/headers/os/be_apps/Deskbar",
System, true, false, false);
@@ -515,7 +518,7 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
AddPath("/boot/develop/headers/os/be_apps/Tracker",
System, true, false, false);
AddPath("/boot/develop/headers/cpp", System, true, false, false);
- AddPath("/boot/develop/headers/cpp/i586-pc-haiku",
+ AddPath("/boot/develop/headers/cpp/i586-pc-haiku",
System, true, false, false);
AddPath("/boot/develop/headers/3rdparty", System, true, false, false);
AddPath("/boot/develop/headers/bsd", System, true, false, false);
@@ -523,7 +526,9 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
AddPath("/boot/develop/headers/posix", System, true, false, false);
AddPath("/boot/develop/headers", System, true, false, false);
break;
- case llvm::Triple::MinGW64:
+ case llvm::Triple::Cygwin:
+ AddPath("/usr/include/w32api", System, true, false, false);
+ break;
case llvm::Triple::MinGW32:
AddPath("c:/mingw/include", System, true, false, false);
break;
@@ -553,24 +558,24 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
// FIXME: temporary hack: hard-coded paths.
switch (os) {
case llvm::Triple::Cygwin:
- AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include",
- System, true, false, false);
- AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++",
- System, true, false, false);
- AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/i686-pc-cygwin",
- System, true, false, false);
+ // Cygwin-1.7
+ 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");
+ // FIXME: Do we support g++-3.4.4?
+ AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4");
break;
- case llvm::Triple::MinGW64:
- // Try gcc 4.5.0
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.5.0");
- // Try gcc 4.4.0
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0");
- // Try gcc 4.3.0
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0");
- // Fall through.
case llvm::Triple::MinGW32:
- // Try gcc 4.5.0
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
+ // mingw-w64-20110207
+ AddPath("c:/MinGW/include/c++/4.5.3", System, true, false, false);
+ AddPath("c:/MinGW/include/c++/4.5.3/x86_64-w64-mingw32", System, true, false, false);
+ AddPath("c:/MinGW/include/c++/4.5.3/backward", System, true, false, false);
+ // mingw-w64-20101129
+ AddPath("c:/MinGW/include/c++/4.5.2", System, true, false, false);
+ AddPath("c:/MinGW/include/c++/4.5.2/x86_64-w64-mingw32", System, true, false, false);
+ AddPath("c:/MinGW/include/c++/4.5.2/backward", System, true, false, false);
+ // Try gcc 4.5.0
+ AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
// Try gcc 4.4.0
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
// Try gcc 4.3.0
@@ -580,13 +585,13 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
switch (triple.getArch()) {
default: break;
- case llvm::Triple::ppc:
+ case llvm::Triple::ppc:
case llvm::Triple::ppc64:
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
- "powerpc-apple-darwin10", "", "ppc64",
+ "powerpc-apple-darwin10", "", "ppc64",
triple);
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
- "powerpc-apple-darwin10", "", "ppc64",
+ "powerpc-apple-darwin10", "", "ppc64",
triple);
break;
@@ -615,6 +620,11 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
// Debian based distros.
// Note: these distros symlink /usr/include/c++/X.Y.Z -> X.Y
//===------------------------------------------------------------------===//
+ // Ubuntu 10.10 "Maverick Meerkat" -- gcc-4.4.5
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
+ "i686-linux-gnu", "", "64", triple);
+ // The rest of 10.10 is the same as previous versions.
+
// Ubuntu 10.04 LTS "Lucid Lynx" -- gcc-4.4.3
// Ubuntu 9.10 "Karmic Koala" -- gcc-4.4.1
// Debian 6.0 "squeeze" -- gcc-4.4.2
@@ -622,6 +632,8 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
"x86_64-linux-gnu", "32", "", triple);
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
"i486-linux-gnu", "", "64", triple);
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
+ "arm-linux-gnueabi", "", "", triple);
// Ubuntu 9.04 "Jaunty Jackalope" -- gcc-4.3.3
// Ubuntu 8.10 "Intrepid Ibex" -- gcc-4.3.2
// Debian 5.0 "lenny" -- gcc-4.3.2
@@ -646,6 +658,11 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
//===------------------------------------------------------------------===//
// Redhat based distros.
//===------------------------------------------------------------------===//
+ // Fedora 14
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1",
+ "x86_64-redhat-linux", "32", "", triple);
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1",
+ "i686-redhat-linux", "", "", triple);
// Fedora 13
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4",
"x86_64-redhat-linux", "32", "", triple);
@@ -701,11 +718,22 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
"i586-suse-linux", "", "", triple);
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
"x86_64-suse-linux", "", "", triple);
+
+ // openSUSE 11.4
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5",
+ "i586-suse-linux", "", "", triple);
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5",
+ "x86_64-suse-linux", "", "", triple);
+
// Arch Linux 2008-06-24
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
"i686-pc-linux-gnu", "", "", triple);
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
"x86_64-unknown-linux-gnu", "", "", triple);
+ // Gentoo x86 2010.0 stable
+ AddGnuCPlusPlusIncludePaths(
+ "/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/g++-v4",
+ "i686-pc-linux-gnu", "", "", triple);
// Gentoo x86 2009.1 stable
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4",
@@ -718,26 +746,33 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4",
"i686-pc-linux-gnu", "", "", triple);
- // Gentoo amd64 stable
+
+ // Gentoo amd64 gcc 4.4.5
AddGnuCPlusPlusIncludePaths(
- "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4",
- "i686-pc-linux-gnu", "", "", triple);
-
- // Gentoo amd64 gcc 4.3.2
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include/g++-v4",
+ "x86_64-pc-linux-gnu", "32", "", triple);
+ // Gentoo amd64 gcc 4.4.4
AddGnuCPlusPlusIncludePaths(
- "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4",
- "x86_64-pc-linux-gnu", "", "", triple);
-
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4",
+ "x86_64-pc-linux-gnu", "32", "", triple);
// Gentoo amd64 gcc 4.4.3
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4",
"x86_64-pc-linux-gnu", "32", "", triple);
+ // Gentoo amd64 gcc 4.3.2
+ AddGnuCPlusPlusIncludePaths(
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4",
+ "x86_64-pc-linux-gnu", "", "", triple);
+ // Gentoo amd64 stable
+ AddGnuCPlusPlusIncludePaths(
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4",
+ "i686-pc-linux-gnu", "", "", triple);
// Gentoo amd64 llvm-gcc trunk
AddGnuCPlusPlusIncludePaths(
"/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1",
"x86_64-pc-linux-gnu", "", "", triple);
-
+
break;
case llvm::Triple::FreeBSD:
// FreeBSD 8.0
@@ -774,8 +809,13 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts) {
- if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes)
- AddDefaultCPlusPlusIncludePaths(triple);
+ if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes) {
+ if (!HSOpts.CXXSystemIncludes.empty()) {
+ for (unsigned i = 0, e = HSOpts.CXXSystemIncludes.size(); i != e; ++i)
+ AddPath(HSOpts.CXXSystemIncludes[i], System, true, false, false);
+ } else
+ AddDefaultCPlusPlusIncludePaths(triple);
+ }
AddDefaultCIncludePaths(triple, HSOpts);
OpenPOWER on IntegriCloud