Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make/unit-tests make(1): add tutorial for the :from=...



details:   https://anonhg.NetBSD.org/src/rev/acb13a4ea053
branches:  trunk
changeset: 941818:acb13a4ea053
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 31 10:18:32 2020 +0000

description:
make(1): add tutorial for the :from=to variable modifier

diffstat:

 usr.bin/make/unit-tests/varmod-sysv.mk |  37 ++++++++++++++++++++++++++++++---
 1 files changed, 33 insertions(+), 4 deletions(-)

diffs (56 lines):

diff -r 1c9d98620929 -r acb13a4ea053 usr.bin/make/unit-tests/varmod-sysv.mk
--- a/usr.bin/make/unit-tests/varmod-sysv.mk    Sat Oct 31 09:57:47 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-sysv.mk    Sat Oct 31 10:18:32 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-sysv.mk,v 1.7 2020/10/31 09:03:36 rillig Exp $
+# $NetBSD: varmod-sysv.mk,v 1.8 2020/10/31 10:18:32 rillig Exp $
 #
 # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix
 # "from" with "to".  It can also use '%' as a wildcard.
@@ -7,10 +7,37 @@
 #
 # See ApplyModifier_SysV.
 
-all:
+# A typical use case for the :from=to modifier is conversion of filename
+# extensions.
+.if ${src.c:L:.c=.o} != "src.o"
+.  error
+.endif
+
+# The modifier applies to each word on its own.
+.if ${one.c two.c three.c:L:.c=.o} != "one.o two.o three.o"
+.  error
+.endif
+
+# Words that don't match the pattern are passed unmodified.
+.if ${src.c src.h:L:.c=.o} != "src.o src.h"
+.  error
+.endif
 
-# The :Q looks like a modifier but isn't.
-# It is part of the replacement string.
+# The :from=to modifier is therefore often combined with the :M modifier.
+.if ${src.c src.h:L:M*.c:.c=.o} != "src.o"
+.  error
+.endif
+
+# Another use case for the :from=to modifier is to append a suffix to each
+# word.  In this case, the "from" string is empty, therefore it always
+# matches.  The same effect can be achieved with the :S,$,teen, modifier.
+.if ${four six seven nine:L:=teen} != "fourteen sixteen seventeen nineteen"
+.  error
+.endif
+
+# When the :from=to modifier is parsed, it lasts until the closing brace
+# or parenthesis.  The :Q in the below expression may look like a modifier
+# but isn't.  It is part of the replacement string.
 .if ${a b c d e:L:%a=x:Q} != "x:Q b c d e"
 .  error
 .endif
@@ -127,3 +154,5 @@
 .if ${x:L:x=${INDIRECT}} != "1:value 2:value 4:\${VALUE}"
 .  error
 .endif
+
+all:



Home | Main Index | Thread Index | Old Index