162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci# Shorthand
462306a36Sopenharmony_ciwarning = $(warning-if,y,$(1))
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci# You can not pass commas directly to a function since they are treated as
762306a36Sopenharmony_ci# delimiters. You can use the following trick to do so.
862306a36Sopenharmony_cicomma   := ,
962306a36Sopenharmony_ci$(warning,hello$(comma) world)
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci# Like Make, single quotes, double quotes, spaces are treated verbatim.
1262306a36Sopenharmony_ci# The following prints the text as-is.
1362306a36Sopenharmony_ci$(warning,  ' " '"   ' ''' "'")
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci# Unlike Make, '$' has special meaning only when it is followed by '('.
1662306a36Sopenharmony_ci# No need to escape '$' itself.
1762306a36Sopenharmony_ci$(warning,$)
1862306a36Sopenharmony_ci$(warning,$$)
1962306a36Sopenharmony_ci$ := 1
2062306a36Sopenharmony_ci$(warning,$($))
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci# You need a trick to escape '$' followed by '('
2362306a36Sopenharmony_ci# The following should print "$(X)". It should not be expanded further.
2462306a36Sopenharmony_cidollar := $
2562306a36Sopenharmony_ci$(warning,$(dollar)(X))
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci# You need a trick to treat unbalanced parentheses.
2862306a36Sopenharmony_ci# The following should print "(".
2962306a36Sopenharmony_cileft_paren := (
3062306a36Sopenharmony_ci$(warning,$(left_paren))
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci# A simple expanded should not be expanded multiple times.
3362306a36Sopenharmony_ci# The following should print "$(X)". It should not be expanded further.
3462306a36Sopenharmony_ciY := $(dollar)(X)
3562306a36Sopenharmony_ci$(warning,$(Y))
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci# The following should print "$(X)" as well.
3862306a36Sopenharmony_ciY = $(dollar)(X)
3962306a36Sopenharmony_ci$(warning,$(Y))
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci# The following should print "$(".
4262306a36Sopenharmony_ci# It should not be emit "unterminated reference" error.
4362306a36Sopenharmony_ciunterminated := $(dollar)(
4462306a36Sopenharmony_ci$(warning,$(unterminated))
45