Thank you! Shame on me. For some reason, I never figured that r.e. variables are expanded each time, but believed they are just lazily evaluated.
On Wed, 20 May 2020 at 21:57, Paul Smith <[email protected]> wrote: > 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 > >
