2008-08-22 17:25:22 +08:00
|
|
|
//===--- InitHeaderSearch.cpp - Initialize header search paths ----------*-===//
|
|
|
|
//
|
|
|
|
// 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-03-02 14:16:29 +08:00
|
|
|
#include "clang/Frontend/InitHeaderSearch.h"
|
2008-08-22 17:25:22 +08:00
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/LangOptions.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2009-08-24 06:45:33 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-08-22 17:25:22 +08:00
|
|
|
#include "llvm/System/Path.h"
|
2008-09-05 17:41:20 +08:00
|
|
|
#include "llvm/Config/config.h"
|
2009-03-03 06:20:04 +08:00
|
|
|
#include <cstdio>
|
2009-10-13 04:50:45 +08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define WIN32_LEAN_AND_MEAN 1
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2008-08-22 17:25:22 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2009-09-05 17:49:39 +08:00
|
|
|
void InitHeaderSearch::AddPath(const llvm::StringRef &Path,
|
|
|
|
IncludeDirGroup Group, bool isCXXAware,
|
|
|
|
bool isUserSupplied, bool isFramework,
|
|
|
|
bool IgnoreSysRoot) {
|
2008-08-22 17:25:22 +08:00
|
|
|
assert(!Path.empty() && "can't handle empty path here");
|
|
|
|
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.
|
|
|
|
llvm::SmallString<256> MappedPath;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// Handle isysroot.
|
2009-02-19 14:48:28 +08:00
|
|
|
if (Group == System && !IgnoreSysRoot) {
|
2008-08-22 17:25:22 +08:00
|
|
|
// 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.append(isysroot.begin(), isysroot.end());
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
MappedPath.append(Path.begin(), Path.end());
|
|
|
|
|
|
|
|
// Compute the DirectoryLookup type.
|
2008-10-27 09:19:25 +08:00
|
|
|
SrcMgr::CharacteristicKind Type;
|
2008-08-22 17:25:22 +08:00
|
|
|
if (Group == Quoted || Group == Angled)
|
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.
|
2009-09-05 17:49:39 +08:00
|
|
|
if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) {
|
2008-08-22 17:25:22 +08:00
|
|
|
IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied,
|
|
|
|
isFramework));
|
|
|
|
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) {
|
2009-09-05 17:49:39 +08:00
|
|
|
if (const FileEntry *FE = FM.getFile(MappedPath.str())) {
|
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.
|
|
|
|
IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
if (Verbose)
|
2009-08-20 04:04:03 +08:00
|
|
|
llvm::errs() << "ignoring nonexistent directory \""
|
|
|
|
<< MappedPath.str() << "\"\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InitHeaderSearch::AddEnvVarPaths(const char *Name) {
|
|
|
|
const char* at = getenv(Name);
|
2008-10-05 04:58:18 +08:00
|
|
|
if (!at || *at == 0) // Empty string should not add '.' path.
|
2008-08-22 17:25:22 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
const char* delim = strchr(at, llvm::sys::PathSeparator);
|
|
|
|
while (delim != 0) {
|
|
|
|
if (delim-at == 0)
|
|
|
|
AddPath(".", Angled, false, true, false);
|
|
|
|
else
|
2009-09-05 17:49:39 +08:00
|
|
|
AddPath(llvm::StringRef(at, delim-at), Angled, false, true, false);
|
2008-08-22 17:25:22 +08:00
|
|
|
at = delim + 1;
|
|
|
|
delim = strchr(at, llvm::sys::PathSeparator);
|
|
|
|
}
|
|
|
|
if (*at == 0)
|
|
|
|
AddPath(".", Angled, false, true, false);
|
|
|
|
else
|
|
|
|
AddPath(at, Angled, false, true, false);
|
|
|
|
}
|
|
|
|
|
2009-10-10 04:16:49 +08:00
|
|
|
void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(const std::string &Base,
|
|
|
|
const char *Arch) {
|
|
|
|
AddPath(Base, System, true, false, false);
|
|
|
|
AddPath(Base + "/" + Arch, System, true, false, false);
|
|
|
|
AddPath(Base + "/backward", System, true, false, false);
|
2009-10-06 09:33:02 +08:00
|
|
|
}
|
2008-08-22 17:25:22 +08:00
|
|
|
|
2009-10-13 04:50:45 +08:00
|
|
|
void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(const std::string &Base,
|
|
|
|
const char *Arch,
|
|
|
|
const char *Version) {
|
|
|
|
std::string localBase = Base + "/" + Arch + "/" + Version + "/include";
|
|
|
|
AddPath(localBase, System, true, false, false);
|
|
|
|
AddPath(localBase + "/c++", System, true, false, false);
|
|
|
|
AddPath(localBase + "/c++/backward", System, true, false, false);
|
|
|
|
}
|
2009-10-09 07:29:47 +08:00
|
|
|
|
2009-10-13 04:50:45 +08:00
|
|
|
// FIXME: This probably should goto to some platform utils place.
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
// Read registry string.
|
|
|
|
bool getSystemRegistryString(const char *keyPath, const char *valueName,
|
2009-10-09 07:29:47 +08:00
|
|
|
char *value, size_t maxLength) {
|
|
|
|
HKEY hRootKey = NULL;
|
|
|
|
HKEY hKey = NULL;
|
|
|
|
const char* subKey = NULL;
|
|
|
|
DWORD valueType;
|
|
|
|
DWORD valueSize = maxLength - 1;
|
|
|
|
bool returnValue = false;
|
|
|
|
if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) {
|
|
|
|
hRootKey = HKEY_CLASSES_ROOT;
|
|
|
|
subKey = keyPath + 18;
|
|
|
|
}
|
|
|
|
else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) {
|
|
|
|
hRootKey = HKEY_USERS;
|
|
|
|
subKey = keyPath + 11;
|
|
|
|
}
|
|
|
|
else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) {
|
|
|
|
hRootKey = HKEY_LOCAL_MACHINE;
|
|
|
|
subKey = keyPath + 19;
|
2008-09-05 17:41:20 +08:00
|
|
|
}
|
2009-10-09 07:29:47 +08:00
|
|
|
else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) {
|
|
|
|
hRootKey = HKEY_CURRENT_USER;
|
|
|
|
subKey = keyPath + 18;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return(false);
|
|
|
|
long lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey);
|
|
|
|
if (lResult == ERROR_SUCCESS) {
|
2009-10-13 04:50:45 +08:00
|
|
|
lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
|
|
|
|
(LPBYTE)value, &valueSize);
|
2009-10-09 07:29:47 +08:00
|
|
|
if (lResult == ERROR_SUCCESS)
|
|
|
|
returnValue = true;
|
2009-10-13 04:50:45 +08:00
|
|
|
RegCloseKey(hKey);
|
2009-10-09 07:29:47 +08:00
|
|
|
}
|
|
|
|
return(returnValue);
|
|
|
|
}
|
2009-10-13 04:50:45 +08:00
|
|
|
#else // _MSC_VER
|
|
|
|
// Read registry string.
|
|
|
|
bool getSystemRegistryString(const char *, const char *, char *, size_t) {
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
#endif // _MSC_VER
|
2008-09-05 17:41:20 +08:00
|
|
|
|
2009-10-09 07:29:47 +08:00
|
|
|
// Get Visual Studio installation directory.
|
|
|
|
bool getVisualStudioDir(std::string &path) {
|
2009-10-13 04:50:45 +08:00
|
|
|
// Try the Windows registry first.
|
|
|
|
char vs80IDEInstallDir[256];
|
|
|
|
char vs90IDEInstallDir[256];
|
|
|
|
const char* vsIDEInstallDir = NULL;
|
|
|
|
bool has80 = getSystemRegistryString(
|
2009-10-09 07:29:47 +08:00
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0",
|
2009-10-13 04:50:45 +08:00
|
|
|
"InstallDir", vs80IDEInstallDir, sizeof(vs80IDEInstallDir) - 1);
|
|
|
|
bool has90 = getSystemRegistryString(
|
2009-10-09 07:29:47 +08:00
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0",
|
2009-10-13 04:50:45 +08:00
|
|
|
"InstallDir", vs90IDEInstallDir, sizeof(vs90IDEInstallDir) - 1);
|
2009-10-09 07:29:47 +08:00
|
|
|
// If we have both vc80 and vc90, pick version we were compiled with.
|
|
|
|
if (has80 && has90) {
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#if (_MSC_VER >= 1500) // VC90
|
2009-10-13 04:50:45 +08:00
|
|
|
vsIDEInstallDir = vs90IDEInstallDir;
|
2009-10-09 07:29:47 +08:00
|
|
|
#elif (_MSC_VER == 1400) // VC80
|
2009-10-13 04:50:45 +08:00
|
|
|
vsIDEInstallDir = vs80IDEInstallDir;
|
2009-10-09 07:29:47 +08:00
|
|
|
#else
|
2009-10-13 04:50:45 +08:00
|
|
|
vsIDEInstallDir = vs90IDEInstallDir;
|
2009-10-09 07:29:47 +08:00
|
|
|
#endif
|
|
|
|
#else
|
2009-10-13 04:50:45 +08:00
|
|
|
vsIDEInstallDir = vs90IDEInstallDir;
|
2009-10-09 07:29:47 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (has90)
|
2009-10-13 04:50:45 +08:00
|
|
|
vsIDEInstallDir = vs90IDEInstallDir;
|
2009-10-09 07:29:47 +08:00
|
|
|
else if (has80)
|
2009-10-13 04:50:45 +08:00
|
|
|
vsIDEInstallDir = vs80IDEInstallDir;
|
|
|
|
if (vsIDEInstallDir && *vsIDEInstallDir) {
|
|
|
|
char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE");
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
path = vsIDEInstallDir;
|
|
|
|
return(true);
|
2009-10-09 07:29:47 +08:00
|
|
|
}
|
2009-10-13 04:50:45 +08:00
|
|
|
else {
|
|
|
|
// Try the environment.
|
|
|
|
const char* vs90comntools = getenv("VS90COMNTOOLS");
|
|
|
|
const char* vs80comntools = getenv("VS80COMNTOOLS");
|
|
|
|
const char* vscomntools = NULL;
|
|
|
|
// If we have both vc80 and vc90, pick version we were compiled with.
|
|
|
|
if (vs90comntools && vs80comntools) {
|
|
|
|
#if (_MSC_VER >= 1500) // VC90
|
|
|
|
vscomntools = vs90comntools;
|
|
|
|
#elif (_MSC_VER == 1400) // VC80
|
|
|
|
vscomntools = vs80comntools;
|
|
|
|
#else
|
|
|
|
vscomntools = vs90comntools;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (vs90comntools)
|
|
|
|
vscomntools = vs90comntools;
|
|
|
|
else if (vs80comntools)
|
|
|
|
vscomntools = vs80comntools;
|
|
|
|
if (vscomntools && *vscomntools) {
|
|
|
|
char *p = (char*)strstr(vscomntools, "\\Common7\\Tools");
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
path = vscomntools;
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
return(false);
|
2009-10-09 07:29:47 +08:00
|
|
|
}
|
2009-07-02 02:59:43 +08:00
|
|
|
|
2009-10-09 07:29:47 +08:00
|
|
|
void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
|
2009-10-10 03:42:16 +08:00
|
|
|
const llvm::Triple &triple) {
|
2009-10-09 07:29:47 +08:00
|
|
|
// FIXME: temporary hack: hard-coded paths.
|
|
|
|
llvm::Triple::OSType os = triple.getOS();
|
|
|
|
|
|
|
|
switch (os) {
|
|
|
|
case llvm::Triple::Win32:
|
|
|
|
{
|
2009-10-13 04:50:45 +08:00
|
|
|
std::string VSDir;
|
|
|
|
if (getVisualStudioDir(VSDir)) {
|
|
|
|
AddPath(VSDir + "\\VC\\include", System, false, false, false);
|
|
|
|
AddPath(VSDir + "\\VC\\PlatformSDK\\Include",
|
|
|
|
System, false, false, false);
|
|
|
|
}
|
|
|
|
else {
|
2009-10-09 07:29:47 +08:00
|
|
|
// Default install paths.
|
2009-10-13 04:50:45 +08:00
|
|
|
AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
|
2009-10-09 07:29:47 +08:00
|
|
|
System, false, false, false);
|
2009-10-13 04:50:45 +08:00
|
|
|
AddPath(
|
|
|
|
"C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
|
2009-10-09 07:29:47 +08:00
|
|
|
System, false, false, false);
|
2009-10-13 04:50:45 +08:00
|
|
|
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);
|
|
|
|
}
|
2009-10-09 07:29:47 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case llvm::Triple::Cygwin:
|
|
|
|
if (Lang.CPlusPlus) {
|
2009-10-13 04:50:45 +08:00
|
|
|
AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include",
|
|
|
|
System, false, false, false);
|
|
|
|
AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++",
|
|
|
|
System, false, false, false);
|
2009-10-09 07:29:47 +08:00
|
|
|
}
|
|
|
|
AddPath("/usr/include", System, false, false, false);
|
|
|
|
break;
|
|
|
|
case llvm::Triple::MinGW64:
|
2009-10-13 04:50:45 +08:00
|
|
|
if (Lang.CPlusPlus) { // I'm guessing here.
|
|
|
|
// 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:
|
2009-10-09 07:29:47 +08:00
|
|
|
if (Lang.CPlusPlus) {
|
|
|
|
// Try gcc 4.4.0
|
2009-10-13 04:50:45 +08:00
|
|
|
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
|
2009-10-09 07:29:47 +08:00
|
|
|
// Try gcc 4.3.0
|
2009-10-13 04:50:45 +08:00
|
|
|
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
|
2009-10-09 07:29:47 +08:00
|
|
|
}
|
|
|
|
AddPath("c:/mingw/include", System, true, false, false);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (Lang.CPlusPlus) {
|
|
|
|
switch (os) {
|
|
|
|
case llvm::Triple::Darwin:
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
|
|
|
|
"i686-apple-darwin10");
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
|
|
|
|
"i686-apple-darwin8");
|
|
|
|
break;
|
|
|
|
case llvm::Triple::Linux:
|
|
|
|
// Ubuntu 7.10 - Gutsy Gibbon
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3",
|
|
|
|
"i486-linux-gnu");
|
|
|
|
// Ubuntu 9.04
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3",
|
|
|
|
"x86_64-linux-gnu");
|
|
|
|
// Fedora 8
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2",
|
|
|
|
"i386-redhat-linux");
|
|
|
|
// Fedora 9
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0",
|
|
|
|
"i386-redhat-linux");
|
|
|
|
// Fedora 10
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2",
|
|
|
|
"i386-redhat-linux");
|
|
|
|
// openSUSE 11.1
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
|
|
|
|
"i586-suse-linux");
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
|
|
|
|
"x86_64-suse-linux");
|
|
|
|
// openSUSE 11.2
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
|
|
|
|
"i586-suse-linux");
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
|
|
|
|
"x86_64-suse-linux");
|
|
|
|
// Arch Linux 2008-06-24
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
|
|
|
|
"i686-pc-linux-gnu");
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
|
|
|
|
"x86_64-unknown-linux-gnu");
|
|
|
|
// Gentoo x86 2009.0 stable
|
|
|
|
AddGnuCPlusPlusIncludePaths(
|
|
|
|
"/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4",
|
|
|
|
"i686-pc-linux-gnu");
|
|
|
|
// Gentoo x86 2008.0 stable
|
|
|
|
AddGnuCPlusPlusIncludePaths(
|
|
|
|
"/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4",
|
|
|
|
"i686-pc-linux-gnu");
|
|
|
|
// Ubuntu 8.10
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
|
|
|
|
"i486-pc-linux-gnu");
|
|
|
|
// Gentoo amd64 stable
|
|
|
|
AddGnuCPlusPlusIncludePaths(
|
|
|
|
"/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4",
|
|
|
|
"i686-pc-linux-gnu");
|
|
|
|
break;
|
|
|
|
case llvm::Triple::FreeBSD:
|
|
|
|
// DragonFly
|
|
|
|
AddPath("/usr/include/c++/4.1", System, true, false, false);
|
|
|
|
// FreeBSD
|
|
|
|
AddPath("/usr/include/c++/4.2", System, true, false, false);
|
|
|
|
break;
|
|
|
|
case llvm::Triple::Solaris:
|
|
|
|
// AuroraUX
|
2009-10-12 20:02:47 +08:00
|
|
|
AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
|
2009-10-09 07:29:47 +08:00
|
|
|
"i386-pc-solaris2.11");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-02-26 02:06:37 +08:00
|
|
|
|
2009-10-09 07:29:47 +08:00
|
|
|
AddPath("/usr/local/include", System, false, false, false);
|
2009-08-02 01:10:21 +08:00
|
|
|
|
2009-10-09 07:29:47 +08:00
|
|
|
AddPath("/usr/include", System, false, false, false);
|
|
|
|
AddPath("/System/Library/Frameworks", System, true, false, true);
|
|
|
|
AddPath("/Library/Frameworks", System, true, false, true);
|
|
|
|
break;
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitHeaderSearch::AddDefaultEnvVarPaths(const LangOptions &Lang) {
|
|
|
|
AddEnvVarPaths("CPATH");
|
|
|
|
if (Lang.CPlusPlus && Lang.ObjC1)
|
|
|
|
AddEnvVarPaths("OBJCPLUS_INCLUDE_PATH");
|
|
|
|
else if (Lang.CPlusPlus)
|
|
|
|
AddEnvVarPaths("CPLUS_INCLUDE_PATH");
|
|
|
|
else if (Lang.ObjC1)
|
|
|
|
AddEnvVarPaths("OBJC_INCLUDE_PATH");
|
|
|
|
else
|
|
|
|
AddEnvVarPaths("C_INCLUDE_PATH");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// RemoveDuplicates - If there are duplicate directory entries in the specified
|
|
|
|
/// search list, remove the later (dead) ones.
|
|
|
|
static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
|
|
|
|
bool Verbose) {
|
|
|
|
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
|
|
|
|
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
|
|
|
|
llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
|
|
|
|
for (unsigned i = 0; 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-02-08 09:00:10 +08:00
|
|
|
fprintf(stderr, "ignoring duplicate directory \"%s\"\n",
|
|
|
|
CurEntry.getName());
|
2009-02-08 08:55:22 +08:00
|
|
|
if (DirToRemove != i)
|
|
|
|
fprintf(stderr, " as it is a non-system directory that duplicates"
|
|
|
|
" a system directory\n");
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InitHeaderSearch::Realize() {
|
|
|
|
// Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
|
|
|
|
std::vector<DirectoryLookup> SearchList;
|
|
|
|
SearchList = IncludeGroup[Angled];
|
|
|
|
SearchList.insert(SearchList.end(), IncludeGroup[System].begin(),
|
|
|
|
IncludeGroup[System].end());
|
|
|
|
SearchList.insert(SearchList.end(), IncludeGroup[After].begin(),
|
|
|
|
IncludeGroup[After].end());
|
|
|
|
RemoveDuplicates(SearchList, Verbose);
|
|
|
|
RemoveDuplicates(IncludeGroup[Quoted], Verbose);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// Prepend QUOTED list on the search list.
|
2009-09-09 23:08:12 +08:00
|
|
|
SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(),
|
2008-08-22 17:25:22 +08:00
|
|
|
IncludeGroup[Quoted].end());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
|
|
|
|
bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
|
|
|
|
Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(),
|
|
|
|
DontSearchCurDir);
|
|
|
|
|
|
|
|
// If verbose, print the list of directories that will be searched.
|
|
|
|
if (Verbose) {
|
|
|
|
fprintf(stderr, "#include \"...\" search starts here:\n");
|
|
|
|
unsigned QuotedIdx = IncludeGroup[Quoted].size();
|
|
|
|
for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
|
|
|
|
if (i == QuotedIdx)
|
|
|
|
fprintf(stderr, "#include <...> search starts here:\n");
|
|
|
|
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)";
|
|
|
|
}
|
|
|
|
fprintf(stderr, " %s%s\n", Name, Suffix);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "End of search list.\n");
|
|
|
|
}
|
|
|
|
}
|