diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Frontend/InitHeaderSearch.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Frontend/InitHeaderSearch.cpp | 233 |
1 files changed, 136 insertions, 97 deletions
diff --git a/contrib/llvm/tools/clang/lib/Frontend/InitHeaderSearch.cpp b/contrib/llvm/tools/clang/lib/Frontend/InitHeaderSearch.cpp index cd2fef8..69199e2 100644 --- a/contrib/llvm/tools/clang/lib/Frontend/InitHeaderSearch.cpp +++ b/contrib/llvm/tools/clang/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" @@ -24,7 +28,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 @@ -45,13 +49,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, @@ -66,7 +72,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, @@ -105,19 +111,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) @@ -129,7 +134,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; @@ -138,7 +143,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)); @@ -149,7 +154,7 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path, if (Verbose) llvm::errs() << "ignoring nonexistent directory \"" - << MappedPath.str() << "\"\n"; + << MappedPathStr << "\"\n"; } @@ -195,8 +200,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, @@ -348,7 +351,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) @@ -370,7 +373,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) { @@ -413,7 +416,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); @@ -423,10 +426,17 @@ static bool getWindowsSDKDir(std::string &path) { void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { - // FIXME: temporary hack: hard-coded paths. -#ifndef __FreeBSD__ - AddPath(CLANG_PREFIX "/usr/local/include", System, true, false, false); -#endif + llvm::Triple::OSType os = triple.getOS(); + + switch (os) { + case llvm::Triple::FreeBSD: + 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. @@ -445,47 +455,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); @@ -493,7 +495,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); @@ -506,13 +508,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); @@ -521,7 +523,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); @@ -529,7 +531,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; @@ -563,24 +567,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 @@ -590,13 +594,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; @@ -625,6 +629,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 @@ -632,6 +641,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 @@ -656,6 +667,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); @@ -711,11 +727,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", @@ -728,26 +755,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 @@ -787,8 +821,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); |