diff mbox

[2,of,7] infra: add comment describing single/double dollar-sign rules

Message ID 32d9759c21dfe0792ff0.1399822726@argentina
State Superseded
Headers show

Commit Message

Thomas De Schampheleire May 11, 2014, 3:38 p.m. UTC
As the rules with respect to variable and function references and the need
for single or double dollar signs are not trivial, add a comment in
pkg-generic.mk describing them.

Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>

---
 package/pkg-generic.mk |  13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

Comments

Yann E. MORIN May 11, 2014, 8:42 p.m. UTC | #1
Thomas, All,

On 2014-05-11 17:38 +0200, Thomas De Schampheleire spake thusly:
> As the rules with respect to variable and function references and the need
> for single or double dollar signs are not trivial, add a comment in
> pkg-generic.mk describing them.
> 
> Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
> 
> ---
>  package/pkg-generic.mk |  13 +++++++++++++
>  1 files changed, 13 insertions(+), 0 deletions(-)
> 
> diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
> --- a/package/pkg-generic.mk
> +++ b/package/pkg-generic.mk
> @@ -250,6 +250,19 @@ endif
>  #  argument 3 is the uppercase package name, without the HOST_ prefix
>  #             for host packages
>  #  argument 4 is the type (target or host)
> +#
> +# Note about variable and function references: inside all blocks that are
> +# evaluated with $(eval), which includes all 'inner-xxx-package' blocks,

Here I'd say something like:

    ... evaluated with $(eval) [either directly or indirectly], ...

We want these rules to apply even to functions called from inside an
evaluated function, right?

Regards,
Yann E. MORIN.

> +# specific rules apply with respect to variable and function references.
> +# Numbered variables (parameters to the block) can be referenced with a single
> +# dollar sign: $(1), $(2), $(3), etc. All other variables should be referenced
> +# with a double dollar sign: $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all
> +# make functions should be referenced with a double dollar sign: $$(subst),
> +# $$(call), $$(filter-out), etc.
> +# These rules ensure that these variables and functions are only expanded during
> +# the $(eval) step, and not earlier. Otherwise, unintuitive and undesired
> +# behavior occurs with respect to these variables and functions.
> +#
>  ################################################################################
>  
>  define inner-generic-package
Thomas De Schampheleire May 12, 2014, 11:55 a.m. UTC | #2
Hi Yann,

On Sun, May 11, 2014 at 10:42 PM, Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> Thomas, All,
>
> On 2014-05-11 17:38 +0200, Thomas De Schampheleire spake thusly:
>> As the rules with respect to variable and function references and the need
>> for single or double dollar signs are not trivial, add a comment in
>> pkg-generic.mk describing them.
>>
>> Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
>>
>> ---
>>  package/pkg-generic.mk |  13 +++++++++++++
>>  1 files changed, 13 insertions(+), 0 deletions(-)
>>
>> diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
>> --- a/package/pkg-generic.mk
>> +++ b/package/pkg-generic.mk
>> @@ -250,6 +250,19 @@ endif
>>  #  argument 3 is the uppercase package name, without the HOST_ prefix
>>  #             for host packages
>>  #  argument 4 is the type (target or host)
>> +#
>> +# Note about variable and function references: inside all blocks that are
>> +# evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
>
> Here I'd say something like:
>
>     ... evaluated with $(eval) [either directly or indirectly], ...
>
> We want these rules to apply even to functions called from inside an
> evaluated function, right?
>

No, I don't think this is true. The big problem is that most functions
can be called both within as outside of an evaluated block. When it is
not evaluated, then the double dollar signs cause incorrect behavior.

Take the following test program (which you can play with to test out
different combinations)

FOO = bar

func = something-$(FOO)-$(1)

define block
▸‐‐‐‐‐‐‐X = $(1)
▸‐‐‐‐‐‐‐Y = $$(FOO)

target:
▸‐‐‐‐‐‐‐@echo X=$$(X) Y=$$(Y) Z=$(call func,else)
endef


all:
▸‐‐‐‐‐‐‐@echo Z=$(call func,else)

$(eval $(call block,hello))


If you change 'func' to use $$(FOO) instead of $(FOO), then the 'all'
target will have output
/bin/sh: 1: FOO: not found
Z=something--else

instead of
Z=something-bar-else

Best regards,
Thomas
diff mbox

Patch

diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -250,6 +250,19 @@  endif
 #  argument 3 is the uppercase package name, without the HOST_ prefix
 #             for host packages
 #  argument 4 is the type (target or host)
+#
+# Note about variable and function references: inside all blocks that are
+# evaluated with $(eval), which includes all 'inner-xxx-package' blocks,
+# specific rules apply with respect to variable and function references.
+# Numbered variables (parameters to the block) can be referenced with a single
+# dollar sign: $(1), $(2), $(3), etc. All other variables should be referenced
+# with a double dollar sign: $$(TARGET_DIR), $$($(2)_VERSION), etc. Also all
+# make functions should be referenced with a double dollar sign: $$(subst),
+# $$(call), $$(filter-out), etc.
+# These rules ensure that these variables and functions are only expanded during
+# the $(eval) step, and not earlier. Otherwise, unintuitive and undesired
+# behavior occurs with respect to these variables and functions.
+#
 ################################################################################
 
 define inner-generic-package