aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-05-19 03:35:57 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-05-19 03:35:57 +0000
commitb5c8f8bddc6007b154b5c40640c4f80e7cb0a6eb (patch)
tree0f86de4b0a1b49639a7b960d8d7a3067d3c07f39
parent12d3b1d98ec4463b733348e9fb8eadd19b365b0b (diff)
Move the options for dependency file generation from DependencyFile.cpp
to clang-cc.cpp. Also, rename CreateDependencyFileGen to AttachDependencyFileGen, and make it take a raw_ostream rather than opening a file itself. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72096 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--tools/clang-cc/DependencyFile.cpp65
-rw-r--r--tools/clang-cc/clang-cc.cpp53
-rw-r--r--tools/clang-cc/clang-cc.h8
3 files changed, 67 insertions, 59 deletions
diff --git a/tools/clang-cc/DependencyFile.cpp b/tools/clang-cc/DependencyFile.cpp
index 34b6ecfcab..3306f82aea 100644
--- a/tools/clang-cc/DependencyFile.cpp
+++ b/tools/clang-cc/DependencyFile.cpp
@@ -34,7 +34,8 @@ class VISIBILITY_HIDDEN DependencyFileCallback : public PPCallbacks {
const Preprocessor *PP;
std::vector<std::string> Targets;
llvm::raw_ostream *OS;
-
+ bool IncludeSystemHeaders;
+ bool PhonyTarget;
private:
bool FileMatchesDepCriteria(const char *Filename,
SrcMgr::CharacteristicKind FileType);
@@ -43,9 +44,11 @@ private:
public:
DependencyFileCallback(const Preprocessor *_PP,
llvm::raw_ostream *_OS,
- const std::vector<std::string> &_Targets)
- : PP(_PP), Targets(_Targets), OS(_OS) {
- }
+ const std::vector<std::string> &_Targets,
+ bool _IncludeSystemHeaders,
+ bool _PhonyTarget)
+ : PP(_PP), Targets(_Targets), OS(_OS),
+ IncludeSystemHeaders(_IncludeSystemHeaders), PhonyTarget(_PhonyTarget) {}
~DependencyFileCallback() {
OutputDependencyFile();
@@ -58,54 +61,18 @@ public:
};
}
-//===----------------------------------------------------------------------===//
-// Dependency file options
-//===----------------------------------------------------------------------===//
-static llvm::cl::opt<std::string>
-DependencyFile("dependency-file",
- llvm::cl::desc("Filename (or -) to write dependency output to"));
-
-static llvm::cl::opt<bool>
-DependenciesIncludeSystemHeaders("sys-header-deps",
- llvm::cl::desc("Include system headers in dependency output"));
-
-static llvm::cl::list<std::string>
-DependencyTargets("MT",
- llvm::cl::desc("Specify target for dependency"));
-
-// FIXME: Implement feature
-static llvm::cl::opt<bool>
-PhonyDependencyTarget("MP",
- llvm::cl::desc("Create phony target for each dependency "
- "(other than main file)"));
-
-bool clang::CreateDependencyFileGen(Preprocessor *PP,
- std::string &ErrStr) {
- ErrStr = "";
- if (DependencyFile.empty())
- return false;
- if (DependencyTargets.empty()) {
- ErrStr = "-dependency-file requires at least one -MT option\n";
- return false;
- }
- std::string ErrMsg;
- llvm::raw_ostream *OS;
- if (DependencyFile == "-") {
- OS = new llvm::raw_stdout_ostream();
- } else {
- OS = new llvm::raw_fd_ostream(DependencyFile.c_str(), false, ErrStr);
- if (!ErrMsg.empty()) {
- ErrStr = "unable to open dependency file: " + ErrMsg;
- return false;
- }
- }
+void clang::AttachDependencyFileGen(Preprocessor *PP, llvm::raw_ostream *OS,
+ std::vector<std::string> &Targets,
+ bool IncludeSystemHeaders,
+ bool PhonyTarget) {
+ assert(!Targets.empty() && "Target required for dependency generation");
DependencyFileCallback *PPDep =
- new DependencyFileCallback(PP, OS, DependencyTargets);
+ new DependencyFileCallback(PP, OS, Targets, IncludeSystemHeaders,
+ PhonyTarget);
PP->setPPCallbacks(PPDep);
- return true;
}
/// FileMatchesDepCriteria - Determine whether the given Filename should be
@@ -115,7 +82,7 @@ bool DependencyFileCallback::FileMatchesDepCriteria(const char *Filename,
if (strcmp("<built-in>", Filename) == 0)
return false;
- if (DependenciesIncludeSystemHeaders)
+ if (IncludeSystemHeaders)
return true;
return FileType == SrcMgr::C_User;
@@ -192,7 +159,7 @@ void DependencyFileCallback::OutputDependencyFile() {
*OS << '\n';
// Create phony targets if requested.
- if (PhonyDependencyTarget) {
+ if (PhonyTarget) {
// Skip the first entry, this is always the input file itself.
for (std::vector<std::string>::iterator I = Files.begin() + 1,
E = Files.end(); I != E; ++I) {
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 669c47815e..bf6bceec54 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -1374,13 +1374,6 @@ public:
if (InitializePreprocessor(*PP, InitOpts))
return 0;
- std::string ErrStr;
- bool DFG = CreateDependencyFileGen(PP.get(), ErrStr);
- if (!DFG && !ErrStr.empty()) {
- fprintf(stderr, "%s", ErrStr.c_str());
- return 0;
- }
-
return PP.take();
}
};
@@ -1527,6 +1520,28 @@ DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
static llvm::cl::opt<bool>
DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
"addition to normal output"));
+
+//===----------------------------------------------------------------------===//
+// Dependency file options
+//===----------------------------------------------------------------------===//
+static llvm::cl::opt<std::string>
+DependencyFile("dependency-file",
+ llvm::cl::desc("Filename (or -) to write dependency output to"));
+
+static llvm::cl::opt<bool>
+DependenciesIncludeSystemHeaders("sys-header-deps",
+ llvm::cl::desc("Include system headers in dependency output"));
+
+static llvm::cl::list<std::string>
+DependencyTargets("MT",
+ llvm::cl::desc("Specify target for dependency"));
+
+// FIXME: Implement feature
+static llvm::cl::opt<bool>
+PhonyDependencyTarget("MP",
+ llvm::cl::desc("Create phony target for each dependency "
+ "(other than main file)"));
+
//===----------------------------------------------------------------------===//
// -dump-build-information Stuff
//===----------------------------------------------------------------------===//
@@ -2133,6 +2148,30 @@ int main(int argc, char **argv) {
if (!PP)
continue;
+ // Handle generating dependencies, if requested
+ if (!DependencyFile.empty()) {
+ llvm::raw_ostream *DependencyOS;
+ if (DependencyTargets.empty()) {
+ // FIXME: Use a proper diagnostic
+ llvm::cerr << "-dependency-file requires at least one -MT option\n";
+ HadErrors = true;
+ continue;
+ }
+ std::string ErrStr;
+ DependencyOS =
+ new llvm::raw_fd_ostream(DependencyFile.c_str(), false, ErrStr);
+ if (!ErrStr.empty()) {
+ // FIXME: Use a proper diagnostic
+ llvm::cerr << "unable to open dependency file: " + ErrStr;
+ HadErrors = true;
+ continue;
+ }
+
+ AttachDependencyFileGen(PP.get(), DependencyOS, DependencyTargets,
+ DependenciesIncludeSystemHeaders,
+ PhonyDependencyTarget);
+ }
+
if (ImplicitIncludePCH.empty() &&
InitializeSourceManager(*PP.get(), InFile))
continue;
diff --git a/tools/clang-cc/clang-cc.h b/tools/clang-cc/clang-cc.h
index 0322d2e905..4ea03f8daa 100644
--- a/tools/clang-cc/clang-cc.h
+++ b/tools/clang-cc/clang-cc.h
@@ -64,9 +64,11 @@ MinimalAction *CreatePrintParserActionsAction(Preprocessor &PP,
/// CheckDiagnostics - Gather the expected diagnostics and check them.
bool CheckDiagnostics(Preprocessor &PP);
-/// CreateDependencyFileGen - Create dependency file generator.
-/// This is only done if either -MD or -MMD has been specified.
-bool CreateDependencyFileGen(Preprocessor *PP, std::string &ErrStr);
+/// AttachDependencyFileGen - Create a dependency file generator, and attach
+/// it to the given preprocessor. This takes ownership of the output stream.
+void AttachDependencyFileGen(Preprocessor *PP, llvm::raw_ostream *OS,
+ std::vector<std::string> &Targets,
+ bool IncludeSystemHeaders, bool PhonyTarget);
/// CacheTokens - Cache tokens for use with PCH. Note that this requires
/// a seekable stream.