help-make
[Top][All Lists]
Advanced

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

Re: Can make restart b/c of generated include while a target is running?


From: Paul Smith
Subject: Re: Can make restart b/c of generated include while a target is running?
Date: Thu, 21 May 2020 00:57:40 -0400

On Wed, 2020-05-20 at 17:45 -0700, Victor Sergienko wrote:
> DIRNAME = dir-$(shell date +%Y-%m-%dT%H-%M-%S)
> first_target:
>     mkdir -p $(DIRNAME)
>     ( do something; echo "done" > $(DIRNAME)/.done ) | tee
> $(DIRNAME)/build.log
> 
> Now I have a log where $(DIRNAME) in the "mkdir -p" line is different
> from $(DIRNAME) used in the following line.

Of course that's easily possible.  The rule expands to this:

  first_target:
          mkdir -p dir-$(shell date +%Y-%m-%dT%H-%M-%S)
          ( do something; echo "done" > \
                dir-$(shell date +%Y-%m-%dT%H-%M-%S)/.done ) | \
            tee dir-$(shell date +%Y-%m-%dT%H-%M-%S)/build.log

Since you are invoking the date function three times, it's not strange
at all that they would not all have identical output, if the clock
changed in between two of them.

You should use simple variable assignment:

  DIRNAME := dir-$(shell date +%Y-%m-%dT%H-%M-%S)

so that the contents of the variable are expanded exactly once, when
the variable is assigned, and henceforth will have the same value
always.

See https://www.gnu.org/software/make/manual/html_node/Flavors.html




reply via email to

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