I have a bit more complex Makefile with dynamically generated targets like this:
COMPONENTS = foo bar lipsum
define TEST_template =
.PHONY: test-$(1)
test-$(1):
@echo test
endef
$(foreach cmpnt,$(COMPONENTS),$(eval $(call TEST_template,$(cmpnt))))
But now I'd like to add a target-specific variable to this target. With non-dynamic targets this works nicely:
test: VAR_ONE=1
test:
@echo "VAR_ONE=$(VAR_ONE)"
But combining these two is not working
COMPONENTS = foo bar lipsum
define TEST_template =
.PHONY: test2-$(1)
test2-$(1): VAR_ONE=1
test2-$(1):
@echo "test - VAR_ONE=$(VAR_ONE)"
endef
$(foreach cmpnt,$(COMPONENTS),$(eval $(call TEST_template,$(cmpnt))))
Now running make test2-foo returns test - VAR_ONE=, so it seems the variable is not being set.
Is this even possible? I've been trying to achieve this for a couple of days now but I couldn't find anything.