Exiting from a Makefile based on the state of two shell variables

Viewed 31703

During make checksource, $CROSS_COMPILE should be "whatever". If $CROSS_COMPILE is not set, make should throw an error and exit.

I have the following rule in my Makefile:

.PHONY: checksource

all: checksource default

checksource:
    $(if $(and $(ifeq ($(CROSS_COMPILE), whatever)), $(ifeq ($(VARIABLE),))), \
    ($(shell echo "Error! VARIABLE not defined!") \
     $(shell exit 2)))

Right now if $CROSS_COMPILE is set to whatever and $VARIABLE is undefined, the make doesn't exit.

$CROSS_COMPILE:

$> echo $CROSS_COMPILE
whatever
$>

$VARIABLE is not defined:

$> echo $VARIABLE
$>

I could use a nested ifeq, but I want to make it pretty (and learn a bit more about Makefile operations).

2 Answers
Related