12bece88fSMasahiro Yamada# SPDX-License-Identifier: GPL-2.0
22bece88fSMasahiro Yamada
32bece88fSMasahiro Yamada# Shorthand
42bece88fSMasahiro Yamadawarning = $(warning-if,y,$(1))
52bece88fSMasahiro Yamada
62bece88fSMasahiro Yamada# You can not pass commas directly to a function since they are treated as
72bece88fSMasahiro Yamada# delimiters. You can use the following trick to do so.
82bece88fSMasahiro Yamadacomma   := ,
92bece88fSMasahiro Yamada$(warning,hello$(comma) world)
102bece88fSMasahiro Yamada
112bece88fSMasahiro Yamada# Like Make, single quotes, double quotes, spaces are treated verbatim.
122bece88fSMasahiro Yamada# The following prints the text as-is.
132bece88fSMasahiro Yamada$(warning,  ' " '"   ' ''' "'")
142bece88fSMasahiro Yamada
152bece88fSMasahiro Yamada# Unlike Make, '$' has special meaning only when it is followed by '('.
162bece88fSMasahiro Yamada# No need to escape '$' itself.
172bece88fSMasahiro Yamada$(warning,$)
182bece88fSMasahiro Yamada$(warning,$$)
192bece88fSMasahiro Yamada$ := 1
202bece88fSMasahiro Yamada$(warning,$($))
212bece88fSMasahiro Yamada
222bece88fSMasahiro Yamada# You need a trick to escape '$' followed by '('
232bece88fSMasahiro Yamada# The following should print "$(X)". It should not be expanded further.
242bece88fSMasahiro Yamadadollar := $
252bece88fSMasahiro Yamada$(warning,$(dollar)(X))
262bece88fSMasahiro Yamada
272bece88fSMasahiro Yamada# You need a trick to treat unbalanced parentheses.
282bece88fSMasahiro Yamada# The following should print "(".
292bece88fSMasahiro Yamadaleft_paren := (
302bece88fSMasahiro Yamada$(warning,$(left_paren))
312bece88fSMasahiro Yamada
322bece88fSMasahiro Yamada# A simple expanded should not be expanded multiple times.
332bece88fSMasahiro Yamada# The following should print "$(X)". It should not be expanded further.
342bece88fSMasahiro YamadaY := $(dollar)(X)
352bece88fSMasahiro Yamada$(warning,$(Y))
362bece88fSMasahiro Yamada
372bece88fSMasahiro Yamada# The following should print "$(X)" as well.
382bece88fSMasahiro YamadaY = $(dollar)(X)
392bece88fSMasahiro Yamada$(warning,$(Y))
402bece88fSMasahiro Yamada
412bece88fSMasahiro Yamada# The following should print "$(".
422bece88fSMasahiro Yamada# It should not be emit "unterminated reference" error.
432bece88fSMasahiro Yamadaunterminated := $(dollar)(
442bece88fSMasahiro Yamada$(warning,$(unterminated))
45