On Wed, Sep 30, 2009 at 11:20 PM, Paul Smith
<address@hidden> wrote:
On Wed, 2009-09-30 at 18:05 +0900, Aditya Kher wrote:
> folks,
> I would like to re-evaluate or rather re-calculate variable value
> during making of target
>
> something like below:
>
> %gmake all RUN_COUNT=4
>
>
> Makefile:
> all:
> ${MAKE} run${RUN_COUNT}
>
> #add code for
> # 1. RUN_COUNT = RUN_COUNT -1
> # 2. re-evaluate "all" target after updating RUN_COUNT
> pre-requisite
This kind of thing is not possible in GNU make. Makefiles are not
procedural languages; they don't start at the top of the makefile and
run rules until they're done, at the bottom.
You can do it with the shell:
all:
for i in `seq 1 $(RUN_COUNT)`; do \
$(MAKE) run$$i || exit $$?; \
done
Not perfect (doesn't obey make's -k option for example) but it will
work. Another option is something like this:
TARGETS := $(addprefix run,$(shell seq 1 $(RUN_COUNT)))
all: $(TARGETS)
run%: %.txt
....
this does all the work in a single instance of make, instead of invoking
sub-makes.