Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/share/mk bsd.subdir.mk: replace obscure indirection with dir...



details:   https://anonhg.NetBSD.org/src/rev/908d3a7d8e04
branches:  trunk
changeset: 368427:908d3a7d8e04
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 10 21:32:09 2022 +0000

description:
bsd.subdir.mk: replace obscure indirection with direct condition

Since 2008, when make generates the body of a .for loop, it does not
copy the items as raw strings but as expressions of the form ${:U...}.
This prevents syntactical changes from code injection in the body of the
.for loop.

Since then, using .for loop variables in conditions works.  Since the
same time, the variable assignment operator '+=' doesn't need to be
protected by a leading space anymore.  Even if the item from the .for
loop is 'libc++', the trailing '+' is not parsed as part of the variable
assignment operator, and it never had been parsed this way.  The space
probably has been cargo cult programming.  The only ambiguous case had
been in a variable assignment, when the variable name ended with a
variable from the .for loop, and the assignment operator was '='.  Only
in this case could the parser be tricked into parsing the variable
assignment as 'libc+ +=' instead of the intended 'libc++ ='.

diffstat:

 share/mk/bsd.subdir.mk |  11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diffs (29 lines):

diff -r dce399cbdbb3 -r 908d3a7d8e04 share/mk/bsd.subdir.mk
--- a/share/mk/bsd.subdir.mk    Sun Jul 10 21:16:57 2022 +0000
+++ b/share/mk/bsd.subdir.mk    Sun Jul 10 21:32:09 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: bsd.subdir.mk,v 1.55 2022/07/10 21:16:57 rillig Exp $
+#      $NetBSD: bsd.subdir.mk,v 1.56 2022/07/10 21:32:09 rillig Exp $
 #      @(#)bsd.subdir.mk       8.1 (Berkeley) 6/8/93
 
 .include <bsd.init.mk>
@@ -27,16 +27,13 @@
 __RECURSETARG= ${TARGETS}
 .endif
 
-# for obscure reasons, we can't do a simple .if ${dir} == ".WAIT"
-# but have to assign to __TARGDIR first.
 .for targ in ${__RECURSETARG}
 .for dir in ${__REALSUBDIR}
-__TARGDIR := ${dir}
-.if ${__TARGDIR} == ".WAIT"
-SUBDIR_${targ} += .WAIT
+.if ${dir} == ".WAIT"
+SUBDIR_${targ}+= .WAIT
 .elif !commands(${targ}-${dir})
 ${targ}-${dir}: .PHONY .MAKE __recurse
-SUBDIR_${targ} += ${targ}-${dir}
+SUBDIR_${targ}+= ${targ}-${dir}
 .endif
 .endfor
 subdir-${targ}: .PHONY ${SUBDIR_${targ}}



Home | Main Index | Thread Index | Old Index