I use defineto create a macro. However, in the define constructor, I cannot create a variable. Assigning a variable does not cause an error, but when I try to use it a bit later, its value is empty.
for instance
define JIDL_RULE
$(2):
mkdir -p $(2)
$(3):
mkdir -p $(3)
$(call GENERATED_FILE,$(1),$(2),php): $(1)
$(PHPHOME)/bin/php -f $(JIDL2PHP) -- `pwd`/$$< $(DATADEF_HOME) > $$@
$(call GENERATED_FILE,$(1),$(3),js): $(1)
$(PHPHOME)/bin/php -f $(JIDL2JS) -- `pwd`/$$< $(DATADEF_HOME) > $$@
all:: $(call GENERATED_FILE,$(1),$(2),php) $(call GENERATED_FILE,$(1),$(3),js) $(2) $(3)
clean::
-$(RM) -f $(call GENERATED_FILE,$(1),$(2),php) $(call GENERATED_FILE,$(1),$(3),js)
$(call PHP_RULE, $(call GENERATED_FILE,$(1),$(2),php))
$(call JS_RULE, $(call GENERATED_FILE,$(1),$(3),js))
endef
From the above code, you can see that I am duplicating the lines
$(call GENERATED_FILE,$(1),$(2),php)and $(call GENERATED_FILE,$(1),$(3),js)from several places. So I tried to create two variables as the first two macro statements, for example:
PHP_OUT_FILE := $(call GENERATED_FILE,$(1),$(2),php)
JS_OUT_FILE := $(call GENERATED_FILE,$(1),$(3),js)
But if I try to use them later (still within the definition), for example, $(PHP_OUT_FILE)or $(JS_OUT_FILE), the variables are empty. I would very much like to remove this duplication from my macro. Am I doing it wrong? Is it impossible? Is there any other way to do this?
TEST OF BOTH ANSWERS
, "". , , , , - ( ).
eriktous- , $$ , , $$ $ target. .
Ise Wisteria , , . eval , , , . , , .
makefile,
define TEST
$(eval INNERVAR := Blah $(1))
inner::
echo Using EVAL: INNERVAR = $(INNERVAR)
echo
endef
define TEST2
INNERVAR2 := Blah $(1)
inner::
echo Using double dollar sign: INNERVAR2 = $$(INNERVAR2)
echo
endef
$(eval $(call TEST,TEST_1_A))
$(eval $(call TEST,TEST_1_B))
$(eval $(call TEST2,TEST_2_A))
$(eval $(call TEST2,TEST_2_B))
inner::
echo is that var really private? $(INNERVAR)
echo is that var really private? $(INNERVAR2)
: make echoing , , .
Using EVAL: INNERVAR = Blah TEST_1_A
Using EVAL: INNERVAR = Blah TEST_1_B
Using double dollar sign: INNERVAR2 = Blah TEST_2_B
Using double dollar sign: INNERVAR2 = Blah TEST_2_B
is that var really private? Blah TEST_1_B
is that var really private? Blah TEST_2_B