Reputation: 126
Consider i have a target consisting of foreach loop in makefile
# variables
CONFIG = 1 2 3
LOG_DIR=CONFIG_$(VAR)
# targets
run:
running application
run_configs:
$(foreach VAR, $(CONFIG), make run CONFIGRATION=$(VAR) logging ; )
build_dir:
mkdir $(LOG_DIR)/
logging: build_dir
cp logdata/* $(LOG_DIR)/.
On running the foreach target
make run_configs
running application with CONFIG=1
making logdata
cp logdata/* CONFIG_/.
The directory expected was CONFIG_1 but built was CONFIG_
I understand the makefile is parsed first so, the variable LOG_DIR is evaluated as CONFIG_ because the foreach variable VAR is null at the time.
I cant find a way to update the LOG_DIR variable every time foreach loop is executed.
Is there a way to achieve this.
Upvotes: 0
Views: 120
Reputation: 100856
Um...? When you invoke the recursive make you're setting the variable CONFIGRATION
:
make run CONFIGRATION=$(VAR)
but when you construct the variable you're using $(VAR)
:
LOG_DIR=CONFIG_$(VAR)
CONFIGRATION
is not the same as VAR
. You need to either pass VAR
to the submake:
make run VAR=$(VAR)
or use CONFIGRATION
when building the variable:
LOG_DIR=CONFIG_$(CONFIGRATION)
Upvotes: 1