1 # $NetBSD: directive-for.mk,v 1.2 2020/09/02 22:58:59 rillig Exp $
3 # Tests for the .for directive.
5 # Using the .for loop, lists of values can be produced.
6 # In simple cases, the :@var@${var}@ variable modifier can be used to
7 # reach the same effects.
13 .if ${NUMBERS} != "1 2 3"
17 # The .for loop also works for multiple iteration variables.
18 .for name value in VARNAME value NAME2 value2
21 .if ${VARNAME} != "value" || ${NAME2} != "value2"
25 # The .for loop splits the items at whitespace, taking quotes into account,
26 # just like the :M or :S variable modifiers.
28 # Until 2012-06-03, it had split the items exactly at whitespace, without
29 # taking the quotes into account.
32 .for var in one t\ w\ o "three three" 'four four' `five six`
39 # In the body of the .for loop, the iteration variables can be accessed
40 # like normal variables, even though they are not really variables.
42 # Instead, the expression ${var} is transformed into ${:U1}, ${:U2} and so
43 # on, before the loop body is evaluated.
45 # A notable effect of this implementation technique is that the .for
46 # iteration variables and the normal global variables live in separate
47 # namespaces and do not influence each other.
51 .for var var2 in 1 2 3 4
53 .if ${var} != "value before"
54 . warning After the .for loop, var must still have its original value.
56 .if ${var2} != "value before"
57 . warning After the .for loop, var2 must still have its original value.
60 # Everything from the paragraph above also applies if the loop body is
61 # empty, even if there is no actual iteration since the loop items are
66 .for var var2 in ${:U}
68 .if ${var} != "value before"
69 . warning After the .for loop, var must still have its original value.
71 .if ${var2} != "value before"
72 . warning After the .for loop, var2 must still have its original value.
75 # Until 2008-12-21, the values of the iteration variables were simply
76 # inserted as plain text and then parsed as usual, which made it possible
77 # to achieve all kinds of strange effects.
79 # Before that date, the .for loop expanded to:
81 # Since that date, the .for loop expands to:
82 # EXPANSION${:U+}= value
87 EXPANSION${plus}= value
89 .if ${EXPANSION} != "before"
90 . error This must be a make from before 2009.
92 .if ${EXPANSION+} != "value"
93 . error This must be a make from before 2009.