Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Jul 2023 05:29:00 GMT
From:      Jessica Clarke <jrtc27@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 5d4f8df451aa - main - Makefile.libcompat: Make quoting for CC/CXX/CPP more future-proof
Message-ID:  <202307140529.36E5T0EM002036@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=5d4f8df451aa942701ecfced80516f3584b589d9

commit 5d4f8df451aa942701ecfced80516f3584b589d9
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2023-07-14 04:34:03 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2023-07-14 04:34:03 +0000

    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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Makefile.libcompat b/Makefile.libcompat
index e8d33b905559..b21e27105e99 100644
--- a/Makefile.libcompat
+++ b/Makefile.libcompat
@@ -25,9 +25,9 @@ LIB${_LIBCOMPAT}WMAKEENV+= \
 # Don't rebuild build-tools targets during normal build.
 LIB${_LIBCOMPAT}WMAKEENV+=	BUILD_TOOLS_META=.NOMETA
 .endif
-LIB${_LIBCOMPAT}WMAKEFLAGS+= CC="${XCC} ${LIB${_LIBCOMPAT}CFLAGS:@v@${v:Q}@}" \
-		CXX="${XCXX} ${LIB${_LIBCOMPAT}CXXFLAGS:@v@${v:Q}@} ${LIB${_LIBCOMPAT}CFLAGS:@v@${v:Q}@}" \
-		CPP="${XCPP} ${LIB${_LIBCOMPAT}CFLAGS:@v@${v:Q}@}" \
+LIB${_LIBCOMPAT}WMAKEFLAGS+= CC=${${XCC} ${LIB${_LIBCOMPAT}CFLAGS}:L:Q} \
+		CXX=${${XCXX} ${LIB${_LIBCOMPAT}CXXFLAGS} ${LIB${_LIBCOMPAT}CFLAGS}:L:Q} \
+		CPP=${${XCPP} ${LIB${_LIBCOMPAT}CFLAGS}:L:Q} \
 		DESTDIR=${WORLDTMP} \
 		-DNO_CPU_CFLAGS \
 		MK_BOOT=no \



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202307140529.36E5T0EM002036>