diff options
author | Paul Robinson <paul_robinson@playstation.sony.com> | 2015-04-27 18:14:32 +0000 |
---|---|---|
committer | Paul Robinson <paul_robinson@playstation.sony.com> | 2015-04-27 18:14:32 +0000 |
commit | d7214a7651db3dc153f239fe6f1603d865c64b03 (patch) | |
tree | 5455a579bb7d616c30e7195887f67b6c43f1a0a1 /clang/lib | |
parent | 8fd573e87fd924f67cf0bf0ce021282aa7f81042 (diff) | |
download | bcm5719-llvm-d7214a7651db3dc153f239fe6f1603d865c64b03.tar.gz bcm5719-llvm-d7214a7651db3dc153f239fe6f1603d865c64b03.zip |
Support generating NMake/Jom-style depfiles.
NMake is a Make-like builder that comes with Microsoft Visual Studio.
Jom (https://wiki.qt.io/Jom) is an NMake-compatible build tool.
Dependency files for NMake/Jom need to use double-quotes to wrap
filespecs containing special characters, instead of the backslash
escapes that GNU Make wants.
Adds the -MV option, which specifies to use double-quotes as needed
instead of backslash escapes when writing the dependency file.
Differential Revision: http://reviews.llvm.org/D9260
llvm-svn: 235903
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Frontend/DependencyFile.cpp | 28 |
3 files changed, 26 insertions, 5 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 3053d9bde7d..526968cf41b 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -338,6 +338,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, } Args.AddLastArg(CmdArgs, options::OPT_MP); + Args.AddLastArg(CmdArgs, options::OPT_MV); // Convert all -MQ <target> args to -MT <quoted target> for (arg_iterator it = Args.filtered_begin(options::OPT_MT, diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index da1a088097e..2a80b07beec 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -661,6 +661,8 @@ static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts, Opts.DOTOutputFile = Args.getLastArgValue(OPT_dependency_dot); Opts.ModuleDependencyOutputDir = Args.getLastArgValue(OPT_module_dependency_dir); + if (Args.hasArg(OPT_MV)) + Opts.OutputFormat = DependencyOutputFormat::NMake; } bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 6ea8f5193ef..6bea22ed592 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -150,6 +150,8 @@ class DFGImpl : public PPCallbacks { bool AddMissingHeaderDeps; bool SeenMissingHeader; bool IncludeModuleFiles; + DependencyOutputFormat OutputFormat; + private: bool FileMatchesDepCriteria(const char *Filename, SrcMgr::CharacteristicKind FileType); @@ -162,7 +164,8 @@ public: PhonyTarget(Opts.UsePhonyTargets), AddMissingHeaderDeps(Opts.AddMissingHeaderDeps), SeenMissingHeader(false), - IncludeModuleFiles(Opts.IncludeModuleFiles) {} + IncludeModuleFiles(Opts.IncludeModuleFiles), + OutputFormat(Opts.OutputFormat) {} void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, @@ -290,8 +293,23 @@ void DFGImpl::AddFilename(StringRef Filename) { } /// PrintFilename - GCC escapes spaces, # and $, but apparently not ' or " or -/// other scary characters. -static void PrintFilename(raw_ostream &OS, StringRef Filename) { +/// other scary characters. NMake/Jom has a different set of scary characters, +/// but wraps filespecs in double-quotes to avoid misinterpreting them; +/// https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx for NMake info, +/// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx +/// for Windows file-naming info. +static void PrintFilename(raw_ostream &OS, StringRef Filename, + DependencyOutputFormat OutputFormat) { + if (OutputFormat == DependencyOutputFormat::NMake) { + // Add quotes if needed. These are the characters listed as "special" to + // NMake, that are legal in a Windows filespec, and that could cause + // misinterpretation of the dependency string. + if (Filename.find_first_of(" #${}^!") != StringRef::npos) + OS << '\"' << Filename << '\"'; + else + OS << Filename; + return; + } for (unsigned i = 0, e = Filename.size(); i != e; ++i) { if (Filename[i] == ' ' || Filename[i] == '#') OS << '\\'; @@ -354,7 +372,7 @@ void DFGImpl::OutputDependencyFile() { Columns = 2; } OS << ' '; - PrintFilename(OS, *I); + PrintFilename(OS, *I, OutputFormat); Columns += N + 1; } OS << '\n'; @@ -365,7 +383,7 @@ void DFGImpl::OutputDependencyFile() { for (std::vector<std::string>::iterator I = Files.begin() + 1, E = Files.end(); I != E; ++I) { OS << '\n'; - PrintFilename(OS, *I); + PrintFilename(OS, *I, OutputFormat); OS << ":\n"; } } |