The Dude
The Dude

Reputation: 53

Makefile, conditional and wildcard with variables

I'm having troubles with my makefile. I want to have a "master" target which automatically processes a variety of dirs and copies them in a specific location. But somehow the ifneq condition with the wildcard is not working properly, giving me always the same result regardless of the condition being satisfied or not.

I'm trying with:

# Basically the same thing for all targets
% :
ifeq ($(wildcard $(TOP)/flow/$@),)
    $(error Directory $(TOP)/flow/$@ not found. Aborting. Debug: $(wildcard $(TOP)/flow/$@))
else
    $(error Directory $(TOP)/flow/$@ found!. Debug: $(wildcard $(TOP)/flow/$@))
endif

As an example, in $(TOP)/flow exists a directory core but not pwr. The Make target proceed as if they both exist.

➜  work ✗ make core
Makefile:20: *** Directory TOPFOLDER/flow/core found!. Debug: TOPFOLDER/flow/core.  Stop.
➜  work ✗ make pwr 
Makefile:20: *** Directory TOPFOLDER/flow/pwr found!. Debug: .  Stop.

Why is this so? Can't see what I'm doing wrong here.

Thank you for the help!

Upvotes: 0

Views: 440

Answers (1)

tripleee
tripleee

Reputation: 189457

The variable $@ is empty at the time the ifeq is evaluated.

Probably use a run-time check instead:

% :
    test -d $(TOP)/flow/$@/

Upvotes: 1

Related Questions