Makefile.libcompat: Make quoting for CC/CXX/CPP more future-proof
authorJessica Clarke <jrtc27@FreeBSD.org>
Fri, 14 Jul 2023 04:34:03 +0000 (05:34 +0100)
committerJessica Clarke <jrtc27@FreeBSD.org>
Fri, 14 Jul 2023 04:34:03 +0000 (05:34 +0100)
commit5d4f8df451aa942701ecfced80516f3584b589d9
treebcff2d87a8947e7f58ef1a8ebf7157ed5b650421
parent0a5e35a7b1811308bcb2aa2e6c7e7bd49dfc9770
Makefile.libcompat: Make quoting for CC/CXX/CPP more future-proof

bmake's :Q is for quoting outside of double quotes, but here is inside
double quotes, and as a result it ends up quoting characters that don't
have a special meaning inside double quotes. On the surface this would
seem harmless, but POSIX sh has a strange behaviour (differing from
outside double quotes) that, inside double quotes, a backslash before a
character that never has a special meaning inside double quotes is
passed through. As a result, should LIB${_LIBCOMPAT}CFLAGS contain
something like -DFOO\(x\)=x, we would form "... -DFOO\\\(x\\\)=x ...",
which would be parsed as -DFOO\\(x\\)=x, since the parentheses are never
special inside double quotes (but the backslash itself is), not the
original -DFOO\(x\)=x as intended.

Instead, construct the whole string as a bmake expression and use :Q on
that, without the manual double quotes around everything. Note that the
:L modifier lets you treat an expression like a variable expansion and
apply modifiers to it, i.e. ${expr:L:...} is the same as tmp=expr
${tmp:...} (in essence, ignoring possible differences due to deferred
substitution).

Improves: 537f945fc89f ("Makefile.libcompat: Quote CFLAGS and CXXFLAGS for sub-make")
Makefile.libcompat