Debian Codegraph @

tests/Kpreprocess

raw
1 # Simple assignments (with bad formatting, as an additional test)
2
3 simple-recursive=foo
4 simple-immediate:=bar
5 # Should become recursive
6 simple-recursive-2+=baz
7
8 whitespaced = foo
9
10
11 # Simple += test. += should preserve the flavor of the variable (simple vs.
12 # recursive).
13
14 preserve-recursive = foo
15 preserve-recursive += bar
16
17 preserve-immediate := foo
18 preserve-immediate += bar
19
20
21 # Recursive substitution
22
23 recursive = $(foo) $(bar) $($(b-char)a$(z-char))
24 recursive += $(indir)
25
26 foo = abc
27 bar = def
28 baz = ghi
29
30 b-char = b
31 z-char = z
32
33 indir = jkl $(indir-2)
34 indir-2 = mno
35
36
37 # Immediate substitution
38
39 def = foo
40 immediate := $(undef)$(def)$(undef)$(def)
41 def = bar
42 undef = bar
43
44
45 # Function calls
46
47 # Chained function call
48 quote = "$(1)" "$(2)"
49 rev-quote = $(quote,$(2),$(1))
50 surround-rev-quote = $(0) $(rev-quote,$(1),$(2)) $(0)
51 surround-rev-quote-unused-arg = $(surround-rev-quote,$(1),$(2)) $(3)
52 # No value is passed for $(3), so it expands to nothing
53 fn-indir = surround-rev-quote
54 messy-fn-res = $($(fn-indir)-unused-arg, a b (,) , c d )
55
56 # Special characters in function call
57 comma = ,
58 right-paren = )
59 dollar = $
60 left-paren = (
61 fn = "$(1)"
62 special-chars-fn-res = $(fn,$(comma)$(dollar)$(left-paren)foo$(right-paren))
63
64
65 # Variable expansions in various locations (verified by checking how the symbol
66 # prints)
67
68 qaz = QAZ
69 echo = $(1)
70 ignore-first = $(2)
71
72 config PRINT_ME
73 string "$(ENV_1)" if ($(echo,FOO) && $(echo,BAR)) || !$(echo,BAZ) || !(($(qaz)))
74 default "$(echo,"foo")" if "foo $(echo,"bar") baz" = "$(undefined)"
75
76 # Expansion within a symbol token, with deliberate sloppiness
77 config PRINT_$(ignore-first, ,ME)_TOO
78 bool "foo"
79 default FOO$(ignore-first, ,BAR)BAZ$(qaz) if $(qaz)&&$(qaz)FOO&&x$(ignore-first, ,xx)
80
81
82 # Recursive expansion (throws an exception)
83
84 rec-1 = x $(rec-2) y
85 rec-2 = x $(rec-3) y
86 rec-3 = x $(rec-1) y
87
88 # Functions are allowed to reference themselves, but an exception is thrown if
89 # the function seems to be stuck (the recursion gets too deep)
90 safe-fn-rec = $($(1))
91 safe-fn-rec-2 = $(safe-fn-rec,safe-fn-rec-3)
92 safe-fn-rec-3 = foo
93 safe-fn-rec-res = $(safe-fn-rec,safe-fn-rec-2)
94
95 unsafe-fn-rec = $(unsafe-fn-rec,$(1))
96
97
98 # Expansion in the left-hand side of assignments
99
100 dummy-arg-fn = bar
101 lhs-indir-1 = lhs-indir-2
102 lhs-indir-2 = -baz
103 rhs = value
104 # LHS expands to foo-bar-baz
105 foo-$(dummy-arg-fn, ignored argument )$($(lhs-indir-1)) = $(rhs)
106 # Expands to empty string, accepted
107 $(undefined)
108
109 # Variable with a space in its name
110 empty =
111 space = $(empty) $(empty)
112 foo$(space)bar = value
113 space-var-res = $(foo bar)
114
115
116 # Built-in functions
117
118 # Expands to "baz qaz"
119 shell-res = $(shell,false && echo foo bar || echo baz qaz)
120
121 # Warns about output on stderr, expands to nothing
122 shell-stderr-res := $(shell,echo message on stderr >&2)
123
124 # Nested parens in macro call. Should give a single argument. Test it with
125 # $(shell) to get a free argument number check.
126 parens-res = pre-$(shell,echo '(a,$(b-char),(c,d),e)')-post
127
128 # Expands to the current location
129 location-res := $(filename):$(lineno)
130
131 # Adds one warning, expands to nothing
132 $(warning-if,,no warning)
133 $(warning-if,n,no warning)
134 warning-res := $(warning-if,y,a warning)
135
136 # Does not cause an error, expands to nothing
137 error-n-res := $(error-if,n,oops)
138
139 # Causes an error when expanded
140 error-y-res = $(error-if,y,oops)
141
142
143 # Environment variables (for testing Kconfig.env_vars). ENV_1 is already
144 # referenced above.
145 env_ref_1 := xxx $(ENV_2) xxx
146 env_ref_2 := $(shell,echo $(ENV_3))
147 env_ref_3 :=
148 env_ref_3 += $(ENV_4)
149 $(warning-if,$(ENV_5),$(ENV_UNDEFINED))
150 source "$(ENV_6)"
151 env_ref_4 = $(ENV_7) # Never evaluated