Johannes Ernst
Johannes Ernst

Reputation: 3186

Fail in make (gmake)

I have a bunch of variables in my GNU Makefile, and users might change their values. I'd like the Makefile to fail before it starts executing if some of those values don't make any sense.

For example:

FOODIR=foo
BARDIR=bar

is okay, but if the user sets this to

FOODIR=foo
BARDIR=foo

I'd like the Makefile to fail. I'm looking for the right syntax to do this. Something like:

ifeq ($(FOODIR),$(BARDIR))
    exit 1;
endif

but that doesn't work. What's the best way of doing this?

Upvotes: 1

Views: 249

Answers (1)

MadScientist
MadScientist

Reputation: 100856

Makefiles are not shell scripts; you can't use shell commands like exit.

There is a GNU make function $(error ...) you can use (if your GNU make is recent enough):

ifeq ($(FOODIR),$(BARDIR))
    $(error FOODIR is the same as BARDIR: $(FOODIR))
endif

Upvotes: 3

Related Questions