Matt X
Matt X

Reputation: 254

Makefile if statement causing some weird behavior

In my makefile, the user supplies an argument called EXEC (make target EXEC=something). I want this to happen:

if EXEC equals "server"
    make the variable NOT equal to "client"
if EXEC equals "client"
    make the variable NOT equal to "server"

I tried doing this:

ifeq ($(EXEC),server)
    NOT := client
endif
ifeq ($(EXEC),client)
    NOT := server
endif

I run this by saying make -f build.mk EXEC=server

the output is:

NOT := client
make[2]: NOT: No such file or directory

Why is this error happening?

Upvotes: 0

Views: 39

Answers (1)

MadScientist
MadScientist

Reputation: 101111

It seems you've indented the variable assignment with a TAB character. That means that line is considered part of the recipe for the previous target.

Since you haven't provided the entire makefile, or at least the section of the makefile before/after this, we can't say more than that.

However, in general in a makefile you should never indent any lines with TAB characters unless they are intended to be a part of a recipe.

Upvotes: 1

Related Questions