[Top][All Lists]

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

Re: Question about `wildcard` value caching

From: Brian Vandenberg
Subject: Re: Question about `wildcard` value caching
Date: Fri, 21 Dec 2018 18:29:43 -0700

Minimal example:

$ cat makefile
$(shell rm -rf /tmp/blah)
$(shell mkdir -p /tmp/blah)
ASDF = $(info $1 $(wildcard /tmp/blah/*)
$(if ${BLAH},$(info before $(wildcard /tmp/blah/*)))
$(shell touch /tmp/blah/{a,b,c}.txt)
$(info after $(wildcard /tmp/blah/*.txt))

$ make --version
GNU Make 4.1

$ make
after /tmp/blah/a.txt /tmp/blah/b.txt /tmp/blah/c.txt
make: *** No targets.  Stop.

$ make BLAH=
make: *** No targets.  Stop.

Take note: I specified different strings in each wildcard:

$(info before $(wildcard /tmp/blah/*))
$(info after $(wildcard /tmp/blah/*.txt))


On Fri, Nov 30, 2018 at 5:40 AM Gaëtan Harter <address@hidden> wrote:

I tried to use `wildcard` in place of doing `ls` and found some
limitation I did not know about.

I faced the issue that, even with deferred variables, the value of
`wildcard` was cached to the value it has on first evaluation and does
not reflect the last state of the filesystem.

Which makes adding `$(info $(VARIABLE_VALUE))` change the behavior.

In my case, if I do not want to change the original behavior, I need to
do twice `ls` to have the initial and the final state, as I cannot
before running, know the name of the target directory.
It is generated by `scan-build` that uses a dynamic name.
I could move it to a fixed name, but that would be working around
instead of understanding if there is a low level solution.

Also I did not find any reference in the documentation on the behavior
or any way to force re-evaluating `wildcard` and it took me a while to
understand what was happening. Maybe I looked in the wrong place and the
right link would also be a good answer.

### Testing procedure

I tested with make from `ubuntu bionic` and also on another machine
using `arch linux`, so more recent, but do not have the version number.

     make --version
     GNU Make 4.1

In the following test snippet [1], I would imagine that doing

     make and make EVALUATE_WILDCARD=1 would both work

But when doing `make EVALUATE_WILDCARD=1` the last `test -f` uses the
value of the first time where `wildcard` was evaluated.

Any hint on how to force the evaluation again, or a way to do twice this
`ls` without relying on the shell is welcome.
I know I can just use a fixed name, or use the shell but that would be
working around before understanding :)

Thank you in advance.

Best regards,


# I am trying to use `wildcard` as a way to do `ls`.
# This simulate a local use case of `scan-build`.
# The final name '$(OUTDIR)/*/index.html' is not known in advance.
# It is generated by 'scan-build' so not predictable directory name.
# I tried to get the name using `wildcard` but if wildcard
# is used before, the initial value is returned.
# Try running 'make' and 'make EVALUATE_WILCARD=1'

OUTDIR = tmp
OUTPUT_FILE = $(addsuffix /index.html,$(wildcard $(OUTDIR)/*))

# Just be sure about the initial context
# One file in 'tmp/a/index.html'
$(shell rm -rf   $(OUTDIR)/*)
$(shell mkdir -p $(OUTDIR)/a)
$(shell touch    $(OUTDIR)/a/index.html)

$(info Evaluate `wildcard` before creating the new file)

.PHONY: all create clean

all: create
        test -f $(OUTPUT_FILE)

create: clean
        mkdir -p $(OUTDIR)/b/
        touch $(OUTDIR)/b/index.html

        rm -rf $(OUTDIR)/

Bug-make mailing list

reply via email to

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