--- a/src/TranslationUnit.cpp +++ b/src/TranslationUnit.cpp @@ -2256,6 +2256,41 @@ } +// VCC Plus, 2026-11-03: dependency paths are Make syntax, not shell syntax. +// mcpp resolves runtime include aliases to their real application-bundle paths, +// which commonly contain spaces. Preserve those filenames as one prerequisite. +static string +quoteMakeFilename(const string &filename, bool target) +{ + string quoted; + size_t backslashes = 0; + for (string::const_iterator it = filename.begin(); it != filename.end(); ++it) + { + const char c = *it; + if (c == '\\') + { + ++backslashes; + continue; + } + const bool escape = c == ' ' || c == '\t' || c == '#' || c == ':' + || (target && c == '%'); + quoted.append(backslashes * (escape ? 2 : 1), '\\'); + backslashes = 0; + if (c == '$') + quoted += "$$"; + else + { + if (escape) + quoted += '\\'; + quoted += c; + } + } + // A trailing slash must not escape the following target/prerequisite delimiter. + quoted.append(backslashes * 2, '\\'); + return quoted; +} + + void TranslationUnit::writePrerequisites(ostream &out, const string &dependenciesFilename, @@ -2265,9 +2300,10 @@ if (prerequisiteFilenamesSeen.size() == 0) // if no files are depended on return; - out << outputFilename; + // Explicit -MT text keeps its documented Make-expression semantics. + out << (params.prerequisiteRuleTarget.empty() ? quoteMakeFilename(outputFilename, true) : outputFilename); if (!dependenciesFilename.empty()) - out << ' ' << dependenciesFilename; + out << ' ' << quoteMakeFilename(dependenciesFilename, true); out << " :"; for (vector::const_iterator it = prerequisiteFilenamesSeen.begin(); @@ -2276,7 +2312,7 @@ const string &fn = *it; if (!strncmp(fn.c_str(), pkgdatadir.c_str(), pkgdatadir.length())) // exclude system header files continue; - out << ' ' << fn; + out << ' ' << quoteMakeFilename(fn, false); } out << '\n'; --- a/src/Parameters.cpp +++ b/src/Parameters.cpp @@ -339,12 +339,16 @@ return false; if (*p++ != '\"') return false; - const char *f = p; - while (*p != '\"' && *p != '\0') // reach end of quoted string - ++p; + // VCC Plus, 2026-11-03: decode escaped paths in preprocessor markers. + filename.clear(); + while (*p != '\"' && *p != '\0') + { + if (*p == '\\' && (p[1] == '\\' || p[1] == '\"')) + ++p; + filename += *p++; + } if (*p != '\"') return false; - filename.assign(f, size_t(p - f)); return true; } --- a/src/lexer.ll +++ b/src/lexer.ll @@ -71,11 +71,16 @@ */ ^\#\ [0-9]+\ \".*\"[ 0-9]*$ { sscanf(yytext + 2, "%d", &lineno); lineno--; - char *fn = strchr(yytext, '\"') + 1; - char *end = strchr(fn, '\"'); - *end = '\0'; - sourceFilename = fn; - TranslationUnit::instance().addPrerequisiteFilename(fn); + // VCC Plus, 2026-11-03: preserve quoted/backslash path characters. + const char *fn = strchr(yytext, '\"') + 1; + sourceFilename.clear(); + while (*fn && *fn != '\"') + { + if (*fn == '\\' && (fn[1] == '\\' || fn[1] == '\"')) + ++fn; + sourceFilename += *fn++; + } + TranslationUnit::instance().addPrerequisiteFilename(sourceFilename.c_str()); } /* Pragma directive. */ @@ -345,7 +350,11 @@ return false; ++r; while (*r && *r != '\"') + { + if (*r == '\\' && (r[1] == '\\' || r[1] == '\"')) + ++r; ++r; + } if (*r != '\"') return false; ++r; --- a/src/lexer.cc +++ b/src/lexer.cc @@ -944,11 +944,16 @@ #line 73 "lexer.ll" { sscanf(yytext + 2, "%d", &lineno); lineno--; - char *fn = strchr(yytext, '\"') + 1; - char *end = strchr(fn, '\"'); - *end = '\0'; - sourceFilename = fn; - TranslationUnit::instance().addPrerequisiteFilename(fn); + // VCC Plus, 2026-11-03: preserve quoted/backslash path characters. + const char *fn = strchr(yytext, '\"') + 1; + sourceFilename.clear(); + while (*fn && *fn != '\"') + { + if (*fn == '\\' && (fn[1] == '\\' || fn[1] == '\"')) + ++fn; + sourceFilename += *fn++; + } + TranslationUnit::instance().addPrerequisiteFilename(sourceFilename.c_str()); } YY_BREAK /* Pragma directive. */ @@ -2419,7 +2424,11 @@ return false; ++r; while (*r && *r != '\"') + { + if (*r == '\\' && (r[1] == '\\' || r[1] == '\"')) + ++r; ++r; + } if (*r != '\"') return false; ++r;