Ram
Ram

Reputation: 822

makefile conditional

TOUCHFILE=.touch
NM = meow
.PHONY: extract
extract: $(TOUCHFILE)
$(TOUCHFILE): $(ARCHIVE) Makefile
   ifeq ($(wildcard TOUCHFILE),)
   rm -rf $NM
   touch $(TOUCHFILE)
   else
       @echo "nice going";

Shouldnt the above work? first time when I dont have the .touch, it removes the dir and creates .touch. next time I run with extract, it should echo nice going correct? I see everytime make removes the meow directory and does rest of stuff.

Upvotes: 0

Views: 323

Answers (1)

Beta
Beta

Reputation: 99084

Note that a Make if-then-else must be terminated with endif, and the directives must not be preceded by TABs, since they are not commands. (Also note that your wildcard expression is wrong -- it searches for "TOUCHFILE", not ".touch"):

$(TOUCHFILE): $(ARCHIVE) Makefile
ifeq ($(wildcard $(TOUCHFILE)),)
    rm -rf $NM
    touch $(TOUCHFILE)
else
    @echo "nice going";
endif

Upvotes: 2

Related Questions