xref: /linux/scripts/kconfig/tests/preprocess/variable/Kconfig (revision 3eb66e91a25497065c5322b1268cbc3953642227)
1*2bece88fSMasahiro Yamada# SPDX-License-Identifier: GPL-2.0
2*2bece88fSMasahiro Yamada
3*2bece88fSMasahiro Yamada# Shorthand
4*2bece88fSMasahiro Yamadawarning = $(warning-if,y,$(1))
5*2bece88fSMasahiro Yamada
6*2bece88fSMasahiro Yamada# Simply expanded variable.
7*2bece88fSMasahiro YamadaX := 1
8*2bece88fSMasahiro YamadaSIMPLE := $(X)
9*2bece88fSMasahiro YamadaX := 2
10*2bece88fSMasahiro Yamada$(warning,SIMPLE = $(SIMPLE))
11*2bece88fSMasahiro Yamada
12*2bece88fSMasahiro Yamada# Recursively expanded variable.
13*2bece88fSMasahiro YamadaX := 1
14*2bece88fSMasahiro YamadaRECURSIVE = $(X)
15*2bece88fSMasahiro YamadaX := 2
16*2bece88fSMasahiro Yamada$(warning,RECURSIVE = $(RECURSIVE))
17*2bece88fSMasahiro Yamada
18*2bece88fSMasahiro Yamada# Append something to a simply expanded variable.
19*2bece88fSMasahiro YamadaY := 3
20*2bece88fSMasahiro YamadaSIMPLE += $(Y)
21*2bece88fSMasahiro YamadaY := 4
22*2bece88fSMasahiro Yamada$(warning,SIMPLE = $(SIMPLE))
23*2bece88fSMasahiro Yamada
24*2bece88fSMasahiro Yamada# Append something to a recursively expanded variable.
25*2bece88fSMasahiro YamadaY := 3
26*2bece88fSMasahiro YamadaRECURSIVE += $(Y)
27*2bece88fSMasahiro YamadaY := 4
28*2bece88fSMasahiro Yamada$(warning,RECURSIVE = $(RECURSIVE))
29*2bece88fSMasahiro Yamada
30*2bece88fSMasahiro Yamada# Use += operator to an undefined variable.
31*2bece88fSMasahiro Yamada# This works as a recursively expanded variable.
32*2bece88fSMasahiro YamadaY := 3
33*2bece88fSMasahiro YamadaUNDEFINED_VARIABLE += $(Y)
34*2bece88fSMasahiro YamadaY := 4
35*2bece88fSMasahiro Yamada$(warning,UNDEFINED_VARIABLE = $(UNDEFINED_VARIABLE))
36*2bece88fSMasahiro Yamada
37*2bece88fSMasahiro Yamada# You can use variable references for the lefthand side of assignment statement.
38*2bece88fSMasahiro YamadaX := A
39*2bece88fSMasahiro YamadaY := B
40*2bece88fSMasahiro Yamada$(X)$(Y) := 5
41*2bece88fSMasahiro Yamada$(warning,AB = $(AB))
42*2bece88fSMasahiro Yamada
43*2bece88fSMasahiro Yamada# User-defined function.
44*2bece88fSMasahiro Yamadagreeting = $(1), my name is $(2).
45*2bece88fSMasahiro Yamada$(warning,$(greeting,Hello,John))
46*2bece88fSMasahiro Yamada
47*2bece88fSMasahiro Yamada# The number of arguments is not checked for user-defined functions.
48*2bece88fSMasahiro Yamada# If some arguments are optional, it is useful to pass fewer parameters.
49*2bece88fSMasahiro Yamada# $(2) will be blank in this case.
50*2bece88fSMasahiro Yamada$(warning,$(greeting,Hello))
51*2bece88fSMasahiro Yamada
52*2bece88fSMasahiro Yamada# Unreferenced parameters are just ignored.
53*2bece88fSMasahiro Yamada$(warning,$(greeting,Hello,John,ignored,ignored))
54