Reputation: 5551
I'm having a problem with conditional statements in make. Existing questions on SO only work on the highest level in the Makefile.
Here's what I have:
.PHONY: all
all: bar/*.o
bar/%.o: foo/%.cc
ifeq (,$(wildcard $(@D)))
@echo $(wildcard $(@D))
endif
There are two empty files under foo
, a.cc
and b.cc
. The folder bar
exists.
Here's the output:
PS C:\Users\cbrown2\Src> mingw32-make
bar
bar
It enters the ifeq
statement, even though $(wildcard $(@D))
gives bar
.
What gives?
Upvotes: 0
Views: 205
Reputation: 28945
You cannot use conditionals this way. When make evaluates your conditional automatic variables don't have a value yet. So make will see:
bar/%.o: foo/%.cc
@echo $(wildcard $(@D))
because $(@D)
expands as the empty string. And when make will pass the recipe to the shell it will first expand $(@D)
which, this time, has a value: bar
.
One side note that has nothing to do with your problem: when bar
does not contain all object files yet,
all: bar/*.o
will not do what you probably want. What you probably want is:
SRC := $(wildcard foo/*.cc)
OBJ := $(patsubst foo/%.cc,bar/%.o,$(SRC))
all: $(OBJ)
Upvotes: 1