help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re-calculate variable values


From: Aditya Kher
Subject: Re: Re-calculate variable values
Date: Thu, 1 Oct 2009 00:15:00 +0900

paul,
thanks for the note.
I do understand the difference between Makefile and say, a procedural script.
I had forgotten to mention that I did try the for loop in shell but did not like it much - for the same reasons that you mention.
So I was thinking of taking advantage of ability in Make that it "automatically re-makes target if the pre-requisite is newer than target".
The only stumbling block as I said is ability on "How to keep newing the target". This I am not able to do. May be manipulating an environment variable
from within Make would help. Thanks again.

aditya

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.




--
----
Aditya Kher
email: address@hidden
Web:   http://www.kher.org
----


reply via email to

[Prev in Thread] Current Thread [Next in Thread]