https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65852
Cary Coutant <ccoutant at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ccoutant at gmail dot com --- Comment #11 from Cary Coutant <ccoutant at gmail dot com> --- According to the comments in mkdeps.c, the "bar\\#foo.h" is actually correct: /* GNU make uses a weird quoting scheme for white space. A space or tab preceded by 2N+1 backslashes represents N backslashes followed by space; a space or tab preceded by 2N backslashes represents N backslashes at the end of a file name; and backslashes in other contexts should not be doubled. */ In this case, the '\' is not doubled, and the '#' is escaped as '\#', giving you the '\\#' sequence. But experimentation with make demonstrates that the scheme described in that comment also works for '#', so I guess that GCC ought to escape it the same way. Then again, the Gnu make manual, in section 4.4.2, says this about Windows filenames: """ Microsoft operating systems (MS-DOS and MS-Windows) use backslashes to separate directories in pathnames, like so: c:\foo\bar\baz.c This is equivalent to the Unix-style c:/foo/bar/baz.c (the c: part is the so-called drive letter). When make runs on these systems, it supports backslashes as well as the Unix-style forward slashes in pathnames. However, this support does not include the wildcard expansion, where backslash is a quote character. Therefore, you must use Unix-style slashes in these cases. """ It does not work the same way for escaping a wildcard character: writing "foo\\\*.h" gives this error: make: *** No rule to make target `foo\\\*.h', needed by `foo.o'. Stop. It works if you have a file literally named "foo\\\*.h", but it's not a wildcard, while writing "foo\\*.h" will match a file named "foo\\bar.h" (so an odd number of backslashes escape the wildcard, but don't escape themselves, while an even number of backslashes remain as is). The whole thing seems horribly messed up in several respects. Still, it seems reasonable to expect GCC to escape a filename containing '#' such that GNU make can un-escape it properly.