This is more tricky than it first appears as the strings in question have to make it through make expansion, shell string expansion, interpretation by the command writing the file, and end up making sense to the C compiler.
The values are escaped by converting \ to \\, " to \" and ' to \x27 (as it's impossible to quote a ' in a single-quoted string). Writing the file is now done by printf, which won't try to interpret any of the strings being printed as an option. Its arguments are all single-quoted to prevent the shell from trying to expand them in an unwanted manner.
I'm a bit uneasy about requiring a command-line printf tool, but it seems to be a defined part of the POSIX environment so I assume it's now everywhere that sed, awk, etc are. Certainly for our own CI.
This is more tricky than it first appears as the strings in question have to make it through make expansion, shell string expansion, interpretation by the command writing the file, and end up making sense to the C compiler.
The values are escaped by converting
\
to\\
,"
to\"
and'
to\x27
(as it's impossible to quote a'
in a single-quoted string). Writing the file is now done byprintf
, which won't try to interpret any of the strings being printed as an option. Its arguments are all single-quoted to prevent the shell from trying to expand them in an unwanted manner.Fixes #1527