162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci# Shorthand
462306a36Sopenharmony_ciwarning = $(warning-if,y,$(1))
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci# Simply expanded variable.
762306a36Sopenharmony_ciX := 1
862306a36Sopenharmony_ciSIMPLE := $(X)
962306a36Sopenharmony_ciX := 2
1062306a36Sopenharmony_ci$(warning,SIMPLE = $(SIMPLE))
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci# Recursively expanded variable.
1362306a36Sopenharmony_ciX := 1
1462306a36Sopenharmony_ciRECURSIVE = $(X)
1562306a36Sopenharmony_ciX := 2
1662306a36Sopenharmony_ci$(warning,RECURSIVE = $(RECURSIVE))
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci# Append something to a simply expanded variable.
1962306a36Sopenharmony_ciY := 3
2062306a36Sopenharmony_ciSIMPLE += $(Y)
2162306a36Sopenharmony_ciY := 4
2262306a36Sopenharmony_ci$(warning,SIMPLE = $(SIMPLE))
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci# Append something to a recursively expanded variable.
2562306a36Sopenharmony_ciY := 3
2662306a36Sopenharmony_ciRECURSIVE += $(Y)
2762306a36Sopenharmony_ciY := 4
2862306a36Sopenharmony_ci$(warning,RECURSIVE = $(RECURSIVE))
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci# Use += operator to an undefined variable.
3162306a36Sopenharmony_ci# This works as a recursively expanded variable.
3262306a36Sopenharmony_ciY := 3
3362306a36Sopenharmony_ciUNDEFINED_VARIABLE += $(Y)
3462306a36Sopenharmony_ciY := 4
3562306a36Sopenharmony_ci$(warning,UNDEFINED_VARIABLE = $(UNDEFINED_VARIABLE))
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci# You can use variable references for the lefthand side of assignment statement.
3862306a36Sopenharmony_ciX := A
3962306a36Sopenharmony_ciY := B
4062306a36Sopenharmony_ci$(X)$(Y) := 5
4162306a36Sopenharmony_ci$(warning,AB = $(AB))
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci# User-defined function.
4462306a36Sopenharmony_cigreeting = $(1), my name is $(2).
4562306a36Sopenharmony_ci$(warning,$(greeting,Hello,John))
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci# The number of arguments is not checked for user-defined functions.
4862306a36Sopenharmony_ci# If some arguments are optional, it is useful to pass fewer parameters.
4962306a36Sopenharmony_ci# $(2) will be blank in this case.
5062306a36Sopenharmony_ci$(warning,$(greeting,Hello))
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci# Unreferenced parameters are just ignored.
5362306a36Sopenharmony_ci$(warning,$(greeting,Hello,John,ignored,ignored))
54