directive-for.mk (bmake-20201101) | : | directive-for.mk (bmake-20201117) | ||
---|---|---|---|---|
# $NetBSD: directive-for.mk,v 1.8 2020/10/25 15:49:03 rillig Exp $ | # $NetBSD: directive-for.mk,v 1.9 2020/11/15 20:20:58 rillig Exp $ | |||
# | # | |||
# Tests for the .for directive. | # Tests for the .for directive. | |||
# | ||||
# TODO: Describe naming conventions for the loop variables. | ||||
# .for f in values | ||||
# .for file in values | ||||
# .for _FILE_ in values | ||||
# .for .FILE. in values | ||||
# .for _f_ in values | ||||
# Using the .for loop, lists of values can be produced. | # Using the .for loop, lists of values can be produced. | |||
# In simple cases, the :@var@${var}@ variable modifier can be used to | # In simple cases, the :@var@${var}@ variable modifier can be used to | |||
# reach the same effects. | # reach the same effects. | |||
# | # | |||
.undef NUMBERS | .undef NUMBERS | |||
.for num in 1 2 3 | .for num in 1 2 3 | |||
NUMBERS+= ${num} | NUMBERS+= ${num} | |||
.endfor | .endfor | |||
.if ${NUMBERS} != "1 2 3" | .if ${NUMBERS} != "1 2 3" | |||
. error | . error | |||
.endif | .endif | |||
# The .for loop also works for multiple iteration variables. | # The .for loop also works for multiple iteration variables. | |||
# This is something that the variable modifier :@ cannot do. | ||||
.for name value in VARNAME value NAME2 value2 | .for name value in VARNAME value NAME2 value2 | |||
${name}= ${value} | ${name}= ${value} | |||
.endfor | .endfor | |||
.if ${VARNAME} != "value" || ${NAME2} != "value2" | .if ${VARNAME} != "value" || ${NAME2} != "value2" | |||
. error | . error | |||
.endif | .endif | |||
# The .for loop splits the items at whitespace, taking quotes into account, | # The .for loop splits the items at whitespace, taking quotes into account, | |||
# just like the :M or :S variable modifiers. | # just like the :M or :S variable modifiers. | |||
# | # | |||
# Until 2012-06-03, it had split the items exactly at whitespace, without | # Until 2012-06-03, it had split the items exactly at whitespace, without | |||
# taking the quotes into account. | # taking the quotes into account. This had resulted in 10 words. | |||
# | # | |||
.undef WORDS | .undef WORDS | |||
.for var in one t\ w\ o "three three" 'four four' `five six` | .for var in one t\ w\ o "three three" 'four four' `five six` | |||
WORDS+= counted | WORDS+= counted | |||
.endfor | .endfor | |||
.if ${WORDS:[#]} != 6 | .if ${WORDS:[#]} != 6 | |||
. error | . error | |||
.endif | .endif | |||
# In the body of the .for loop, the iteration variables can be accessed | # In the body of the .for loop, the iteration variables can be accessed | |||
End of changes. 4 change blocks. | ||||
2 lines changed or deleted | 10 lines changed or added |