0

I am trying to get an optional dependency in GNU make. I tried to use $(wildcard) but am getting un-expected output:

test.mk:

a:
        @echo "a"
b: $(wildcard a)
        @echo "b"
        @touch a

expected output:

$ make -f ./test.mk b
b
$ make -f ./test.mk b
a
b

actual output:

$ make -f ./test.mk b
b
$ make -f ./test.mk b
b

What am I missing about $(wildcard) ?

3

1 Answer 1

1

You're not missing anything about $(wildcard ...). It's just that file a already exists when you run make b for the second time, so make doesn't need to make it and so isn't going to run its recipe.

If you add:

.PHONY: a

to the makefile then target a will be made, if required, regardless of the existence of such a file and give the behaviour you expect, but it's not clear from your post if this would really capture your objective.

1
  • ah, that is obvious with hindsight. Thanks !
    – mathieu
    Commented Aug 10, 2016 at 14:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.