Build system: don't use supposedly local variable inside macro
authorThomas Miedema <thomasmiedema@gmail.com>
Thu, 28 May 2015 16:59:29 +0000 (18:59 +0200)
committerThomas Miedema <thomasmiedema@gmail.com>
Sat, 30 May 2015 15:03:46 +0000 (17:03 +0200)
There is no support for local variables inside `make` macros (defined
using the `define` keyword), see
[wiki:Building/Architecture/Idiom/Macros].

In this case `make show VALUE=INPLACE_WRAPPER` would print some bogus
value ("inplace/bin/mkUserGuidePart" actually, from the last BUILD_DIRS
entry in ghc.mk that calls shell-wrapper), and using that variable
somewhere might be a bug.

Test Plan:
I checked the rules directory with the following crude regexp, and this
seems the be the only real offender.

    grep -P '^[^ $#\t][^$]*[^+]=' rules/*

What it is supposed to do (from right to left):
  * look for variable assignments
  * but not updates (+=)
  * where the variable name doesn't contain any dollar signs
  * and the line doesn't start with whitespace or a comment

[skip ci]

Differential Revision: https://phabricator.haskell.org/D918

rules/shell-wrapper.mk

index 6b84072..dac9016 100644 (file)
@@ -26,18 +26,18 @@ ifeq "$$($1_$2_WANT_INPLACE_WRAPPER)" "YES"
 $1_$2_INPLACE_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
 
 ifeq "$$($1_$2_TOPDIR)" "YES"
-INPLACE_WRAPPER = $$(INPLACE_LIB)/$$($1_$2_INPLACE_SHELL_WRAPPER_NAME)
+$1_$2_INPLACE_WRAPPER = $$(INPLACE_LIB)/$$($1_$2_INPLACE_SHELL_WRAPPER_NAME)
 else
-INPLACE_WRAPPER = $$(INPLACE_BIN)/$$($1_$2_INPLACE_SHELL_WRAPPER_NAME)
+$1_$2_INPLACE_WRAPPER = $$(INPLACE_BIN)/$$($1_$2_INPLACE_SHELL_WRAPPER_NAME)
 endif
 
-all_$1_$2 : $$(INPLACE_WRAPPER)
+all_$1_$2 : $$($1_$2_INPLACE_WRAPPER)
 
-$$(INPLACE_WRAPPER): WRAPPER=$$@
+$$($1_$2_INPLACE_WRAPPER): WRAPPER=$$@
 ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
-$$(INPLACE_WRAPPER): $$($1_$2_SHELL_WRAPPER_NAME)
+$$($1_$2_INPLACE_WRAPPER): $$($1_$2_SHELL_WRAPPER_NAME)
 endif
-$$(INPLACE_WRAPPER): $$($1_$2_INPLACE)
+$$($1_$2_INPLACE_WRAPPER): $$($1_$2_INPLACE)
        $$(call removeFiles,                                                    $$@)
        echo '#!$$(SHELL)'                                                   >> $$@
        echo 'executablename="$$(TOP)/$$<"'                                  >> $$@