varmod-range.mk revision 1.6 1 1.6 rillig # $NetBSD: varmod-range.mk,v 1.6 2020/11/01 13:55:31 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for the :range variable modifier, which generates sequences
4 1.2 rillig # of integers from the given range.
5 1.6 rillig #
6 1.6 rillig # See also:
7 1.6 rillig # modword.mk
8 1.1 rillig
9 1.4 rillig # The :range modifier generates a sequence of integers, one number per
10 1.4 rillig # word of the variable expression's value.
11 1.4 rillig .if ${a b c:L:range} != "1 2 3"
12 1.4 rillig . error
13 1.4 rillig .endif
14 1.4 rillig
15 1.4 rillig # To preserve spaces in a word, they can be enclosed in quotes, just like
16 1.4 rillig # everywhere else.
17 1.4 rillig .if ${:U first "the second word" third 4 :range} != "1 2 3 4"
18 1.4 rillig . error
19 1.4 rillig .endif
20 1.4 rillig
21 1.4 rillig # The :range modifier takes the number of words from the value of the
22 1.4 rillig # variable expression. If that expression is undefined, the range is
23 1.4 rillig # undefined as well. This should not come as a surprise.
24 1.4 rillig .if "${:range}" != ""
25 1.4 rillig . error
26 1.4 rillig .endif
27 1.4 rillig
28 1.4 rillig # The :range modifier can be given a parameter, which makes the generated
29 1.4 rillig # range independent from the value or the name of the variable expression.
30 1.4 rillig #
31 1.4 rillig # XXX: As of 2020-09-27, the :range=... modifier does not turn the undefined
32 1.4 rillig # expression into a defined one. This looks like an oversight.
33 1.4 rillig .if "${:range=5}" != ""
34 1.4 rillig . error
35 1.4 rillig .endif
36 1.4 rillig
37 1.5 rillig # Negative ranges don't make sense.
38 1.5 rillig # As of 2020-11-01, they are accepted though, using up all available memory.
39 1.5 rillig #.if "${:range=-1}"
40 1.5 rillig #. error
41 1.5 rillig #.else
42 1.5 rillig #. error
43 1.5 rillig #.endif
44 1.5 rillig
45 1.5 rillig # The :range modifier requires a number as parameter.
46 1.5 rillig # As of 2020-11-01, the parser tries to read the 'x' as a number, fails and
47 1.5 rillig # stops there. It then tries to parse the next modifier at that point,
48 1.5 rillig # which fails with the message "Unknown modifier".
49 1.5 rillig .if "${:U:range=x}Rest" != "Rest"
50 1.5 rillig . error
51 1.5 rillig .else
52 1.5 rillig . error
53 1.5 rillig .endif
54 1.5 rillig
55 1.5 rillig # The upper limit of the range must always be given in decimal.
56 1.5 rillig # This parse error stops at the 'x', trying to parse it as a variable
57 1.5 rillig # modifier.
58 1.5 rillig .if "${:U:range=0x0}Rest" != "Rest"
59 1.5 rillig . error
60 1.5 rillig .else
61 1.5 rillig . error
62 1.5 rillig .endif
63 1.5 rillig
64 1.5 rillig # As of 2020-11-01, numeric overflow is not detected.
65 1.5 rillig # Since strtoul returns ULONG_MAX in such a case, it is interpreted as a
66 1.5 rillig # very large number, consuming all available memory.
67 1.5 rillig #.if "${:U:range=18446744073709551619}Rest" != "Rest"
68 1.5 rillig #. error
69 1.5 rillig #.else
70 1.5 rillig #. error
71 1.5 rillig #.endif
72 1.5 rillig
73 1.5 rillig # modifier name too short
74 1.5 rillig .if "${a b c:L:rang}Rest" != "Rest"
75 1.5 rillig . error
76 1.5 rillig .else
77 1.5 rillig . error
78 1.5 rillig .endif
79 1.5 rillig
80 1.5 rillig # misspelled modifier name
81 1.5 rillig .if "${a b c:L:rango}Rest" != "Rest"
82 1.5 rillig . error
83 1.5 rillig .else
84 1.5 rillig . error
85 1.5 rillig .endif
86 1.5 rillig
87 1.5 rillig # modifier name too long
88 1.5 rillig .if "${a b c:L:ranger}Rest" != "Rest"
89 1.5 rillig . error
90 1.5 rillig .else
91 1.5 rillig . error
92 1.5 rillig .endif
93 1.5 rillig
94 1.1 rillig all:
95