Reputation: 57163
In my Makefile, I want to check if a certain file exists, do something, and check again. Using gnu make, I cannot. Here is the simple example:
$(info $(wildcard OK))
$(shell touch OK)
$(info $(wildcard OK))
If I run make
once, I see two empty lines. If I run make
again, both lines are OK
.
I thought, maybe $(eval)
will let me get the updated answer. Alas,
$(eval $$(info $$(wildcard OK)))
produces the same answer, as if make
has some way to predict all wildcard calculations before it starts evaluating other commands.
I need this to satisfy the checks performed by Android NDK: I must generate a prebuilt shared library on the fly.
Upvotes: 0
Views: 416
Reputation: 100876
This cannot work because, for performance, make maintains an internal cache of the directory contents. Currently that cache is only updated when make runs a rule: then the target the rule is defined to create will be added to the cache. In your situation make has no way to know that the filesystem has been modified so it won't update the cache.
You have to use the shell, rather than wildcard
; the shell doesn't know about make's internal caches:
$(info $(wildcard OK))
$(shell touch OK)
$(info $(shell [ -f OK ] && echo OK))
Clearly this is a bogus example but I'm sure your real code is significantly different than this.
The only other alternative is to turn the command you need to run into a rule. But again, since the question bears little relation to what you're really trying to do I can't suggest a solution that would work for that.
Upvotes: 2