summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver/Tools.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-09-22 21:41:16 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-09-22 21:41:16 +0000
commit8404eb0badf2911f5afe5039c3887919875dcad5 (patch)
treeb76a16c33c3383324aca2fb7ca2bf6e13a4db595 /clang/lib/Driver/Tools.cpp
parente92e5ee81fe87c036fa41f85a31d4ded35732834 (diff)
downloadbcm5719-llvm-8404eb0badf2911f5afe5039c3887919875dcad5.tar.gz
bcm5719-llvm-8404eb0badf2911f5afe5039c3887919875dcad5.zip
Add support for CPATH and friends.
This moves the existing code for CPATH into the driver and adds the environment lookup and path splitting there. The paths are then passed down to cc1 with -I options (CPATH), added after the normal user-specified include dirs. Language specific paths are passed via -LANG-isystem and the actual filtering is performed in the frontend. I tried to match GCC's behavior as close as possible Fixes PR8971. llvm-svn: 140341
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r--clang/lib/Driver/Tools.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 840e4c27348..c3c07f412f8 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -183,6 +183,38 @@ static void addProfileRT(const ToolChain &TC, const ArgList &Args,
CmdArgs.push_back(Args.MakeArgString(ProfileRT));
}
+static void AddIncludeDirectoryList(const ArgList &Args,
+ ArgStringList &CmdArgs,
+ const char *ArgName,
+ const char *DirList) {
+ if (!DirList)
+ return; // Nothing to do.
+
+ StringRef Dirs(DirList);
+ if (Dirs.empty()) // Empty string should not add '.'.
+ return;
+
+ StringRef::size_type Delim;
+ while ((Delim = Dirs.find(llvm::sys::PathSeparator)) != StringRef::npos) {
+ if (Delim == 0) { // Leading colon.
+ CmdArgs.push_back(ArgName);
+ CmdArgs.push_back(".");
+ } else {
+ CmdArgs.push_back(ArgName);
+ CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim)));
+ }
+ Dirs = Dirs.substr(Delim + 1);
+ }
+
+ if (Dirs.empty()) { // Trailing colon.
+ CmdArgs.push_back(ArgName);
+ CmdArgs.push_back(".");
+ } else { // Add the last path.
+ CmdArgs.push_back(ArgName);
+ CmdArgs.push_back(Args.MakeArgString(Dirs));
+ }
+}
+
void Clang::AddPreprocessingOptions(const Driver &D,
const ArgList &Args,
ArgStringList &CmdArgs,
@@ -391,6 +423,23 @@ void Clang::AddPreprocessingOptions(const Driver &D,
}
Args.AddAllArgs(CmdArgs, options::OPT_fauto_module_import);
+
+ // Parse additional include paths from environment variables.
+ // CPATH - included following the user specified includes (but prior to
+ // builtin and standard includes).
+ AddIncludeDirectoryList(Args, CmdArgs, "-I", ::getenv("CPATH"));
+ // C_INCLUDE_PATH - system includes enabled when compiling C.
+ AddIncludeDirectoryList(Args, CmdArgs, "-c-isystem",
+ ::getenv("C_INCLUDE_PATH"));
+ // CPLUS_INCLUDE_PATH - system includes enabled when compiling C++.
+ AddIncludeDirectoryList(Args, CmdArgs, "-cxx-isystem",
+ ::getenv("CPLUS_INCLUDE_PATH"));
+ // OBJC_INCLUDE_PATH - system includes enabled when compiling ObjC.
+ AddIncludeDirectoryList(Args, CmdArgs, "-objc-isystem",
+ ::getenv("OBJC_INCLUDE_PATH"));
+ // OBJCPLUS_INCLUDE_PATH - system includes enabled when compiling ObjC++.
+ AddIncludeDirectoryList(Args, CmdArgs, "-objcxx-isystem",
+ ::getenv("OBJCPLUS_INCLUDE_PATH"));
}
/// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting.
OpenPOWER on IntegriCloud