Search code examples
cygwinc-preprocessorllvm-clanggnu-make

Why does clang -MM output a Windows-style absolute path with a colon, which is invalid for make rule syntax?


Regarding the MM flag:

Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies of the main source file. The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from -include or -imacros command line options.

The version of clang I'm using is part of the Android NDK and as such uses Windows-style paths, rather than Cygwin-style paths. Using the -MM flag, clang is outputting the name of an included files as an absolute, Windows-style path which has a colon after the drive letter, thus breaking the syntax that Cywgin's GNU Make is expecting.

I could adjust the paths after clang outputs it and before make uses it, but this seems like a hack, as the -MM flag is not producing appropriate output (a valid make rule). Is there a flag or environment variable to correct this behavior?


Solution

  • Some variants of make do support unescaped colons in Windows-style absolute paths as part of a make rule, but the GNU make in Cygwin does not - which is a known fact. The output from clang is not invalid for other variants of make (MSYS for MinGW) which support this behavior. Without replacing or modifying either tool, escaping the colons is a necessary processing step.