cond-token-number.mk revision 1.7 1 1.7 rillig # $NetBSD: cond-token-number.mk,v 1.7 2022/01/02 02:57:39 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for number tokens in .if conditions.
4 1.5 rillig #
5 1.5 rillig # TODO: Add introduction.
6 1.1 rillig
7 1.3 rillig .if 0
8 1.3 rillig . error
9 1.3 rillig .endif
10 1.1 rillig
11 1.3 rillig # Even though -0 is a number and would be accepted by strtod, it is not
12 1.3 rillig # accepted by the condition parser.
13 1.3 rillig #
14 1.3 rillig # See the ch_isdigit call in CondParser_String.
15 1.3 rillig .if -0
16 1.3 rillig . error
17 1.5 rillig .else
18 1.5 rillig . error
19 1.3 rillig .endif
20 1.3 rillig
21 1.3 rillig # Even though +0 is a number and would be accepted by strtod, it is not
22 1.3 rillig # accepted by the condition parser.
23 1.3 rillig #
24 1.3 rillig # See the ch_isdigit call in CondParser_String.
25 1.3 rillig .if +0
26 1.3 rillig . error
27 1.5 rillig .else
28 1.5 rillig . error
29 1.3 rillig .endif
30 1.3 rillig
31 1.3 rillig # Even though -1 is a number and would be accepted by strtod, it is not
32 1.3 rillig # accepted by the condition parser.
33 1.3 rillig #
34 1.3 rillig # See the ch_isdigit call in CondParser_String.
35 1.3 rillig .if !-1
36 1.3 rillig . error
37 1.5 rillig .else
38 1.5 rillig . error
39 1.3 rillig .endif
40 1.3 rillig
41 1.3 rillig # Even though +1 is a number and would be accepted by strtod, it is not
42 1.3 rillig # accepted by the condition parser.
43 1.3 rillig #
44 1.3 rillig # See the ch_isdigit call in CondParser_String.
45 1.3 rillig .if !+1
46 1.3 rillig . error
47 1.5 rillig .else
48 1.5 rillig . error
49 1.3 rillig .endif
50 1.3 rillig
51 1.3 rillig # When the number comes from a variable expression though, it may be signed.
52 1.3 rillig # XXX: This is inconsistent.
53 1.3 rillig .if ${:U+0}
54 1.3 rillig . error
55 1.3 rillig .endif
56 1.3 rillig
57 1.3 rillig # When the number comes from a variable expression though, it may be signed.
58 1.3 rillig # XXX: This is inconsistent.
59 1.3 rillig .if !${:U+1}
60 1.3 rillig . error
61 1.3 rillig .endif
62 1.3 rillig
63 1.4 rillig # Hexadecimal numbers are accepted.
64 1.4 rillig .if 0x0
65 1.4 rillig . error
66 1.4 rillig .endif
67 1.4 rillig .if 0x1
68 1.4 rillig .else
69 1.4 rillig . error
70 1.4 rillig .endif
71 1.4 rillig
72 1.6 rillig # This is not a hexadecimal number, even though it has an x. It is
73 1.6 rillig # interpreted as a string instead. In a plain '.if', such a token evaluates
74 1.6 rillig # to true if it is non-empty. In other '.if' directives, such a token is
75 1.6 rillig # evaluated by either FuncDefined or FuncMake.
76 1.4 rillig .if 3x4
77 1.4 rillig .else
78 1.4 rillig . error
79 1.4 rillig .endif
80 1.4 rillig
81 1.7 rillig # Make can do radix conversion from hex.
82 1.6 rillig HEX= dead
83 1.6 rillig .if 0x${HEX} == 57005
84 1.6 rillig .else
85 1.6 rillig . error
86 1.6 rillig .endif
87 1.6 rillig
88 1.3 rillig # Ensure that parsing continues until here.
89 1.3 rillig .info End of the tests.
90 1.3 rillig
91 1.3 rillig all: # nothing
92