[Top][All Lists]

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

Question about `wildcard` value caching

From: Gaëtan Harter
Subject: Question about `wildcard` value caching
Date: Fri, 30 Nov 2018 12:51:35 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1


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)/

reply via email to

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