18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci# Shorthand 48c2ecf20Sopenharmony_ciwarning = $(warning-if,y,$(1)) 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci# Simply expanded variable. 78c2ecf20Sopenharmony_ciX := 1 88c2ecf20Sopenharmony_ciSIMPLE := $(X) 98c2ecf20Sopenharmony_ciX := 2 108c2ecf20Sopenharmony_ci$(warning,SIMPLE = $(SIMPLE)) 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci# Recursively expanded variable. 138c2ecf20Sopenharmony_ciX := 1 148c2ecf20Sopenharmony_ciRECURSIVE = $(X) 158c2ecf20Sopenharmony_ciX := 2 168c2ecf20Sopenharmony_ci$(warning,RECURSIVE = $(RECURSIVE)) 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci# Append something to a simply expanded variable. 198c2ecf20Sopenharmony_ciY := 3 208c2ecf20Sopenharmony_ciSIMPLE += $(Y) 218c2ecf20Sopenharmony_ciY := 4 228c2ecf20Sopenharmony_ci$(warning,SIMPLE = $(SIMPLE)) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci# Append something to a recursively expanded variable. 258c2ecf20Sopenharmony_ciY := 3 268c2ecf20Sopenharmony_ciRECURSIVE += $(Y) 278c2ecf20Sopenharmony_ciY := 4 288c2ecf20Sopenharmony_ci$(warning,RECURSIVE = $(RECURSIVE)) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci# Use += operator to an undefined variable. 318c2ecf20Sopenharmony_ci# This works as a recursively expanded variable. 328c2ecf20Sopenharmony_ciY := 3 338c2ecf20Sopenharmony_ciUNDEFINED_VARIABLE += $(Y) 348c2ecf20Sopenharmony_ciY := 4 358c2ecf20Sopenharmony_ci$(warning,UNDEFINED_VARIABLE = $(UNDEFINED_VARIABLE)) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci# You can use variable references for the lefthand side of assignment statement. 388c2ecf20Sopenharmony_ciX := A 398c2ecf20Sopenharmony_ciY := B 408c2ecf20Sopenharmony_ci$(X)$(Y) := 5 418c2ecf20Sopenharmony_ci$(warning,AB = $(AB)) 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci# User-defined function. 448c2ecf20Sopenharmony_cigreeting = $(1), my name is $(2). 458c2ecf20Sopenharmony_ci$(warning,$(greeting,Hello,John)) 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci# The number of arguments is not checked for user-defined functions. 488c2ecf20Sopenharmony_ci# If some arguments are optional, it is useful to pass fewer parameters. 498c2ecf20Sopenharmony_ci# $(2) will be blank in this case. 508c2ecf20Sopenharmony_ci$(warning,$(greeting,Hello)) 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci# Unreferenced parameters are just ignored. 538c2ecf20Sopenharmony_ci$(warning,$(greeting,Hello,John,ignored,ignored)) 54