Reputation: 102346
I have the following in my GNU makefile:
# Undefined Behavior Sanitizer (Clang 3.2 and GCC 4.8 and above)
UBSAN = 0
ifeq ($(findstring ubsan,$(MAKECMDGOALS)),ubsan)
UBSAN = 1
CXXFLAGS += -fsanitize=undefined
endif # UBsan
# Address Sanitizer (Clang 3.2 and GCC 4.8 and above)
ASAN = 0
ifeq ($(findstring asan,$(MAKECMDGOALS)),asan)
ASAN = 1
CXXFLAGS += -fsanitize=address
endif # Asan
# Effectively a NOR
ifneq ($(shell echo $$($(ASAN) * $(UBSAN))),0)
$(error Asan and UBsan are mutually exclusive. Specify only one of them)
endif
The idea is to detect make ubsan asan
(or user overrides to CFLAGS
and CXXFLAGS
), and error out if both are specified.
Unfortunately, its firing with no command targets:
$ make
/bin/sh: 1: 0: not found
GNUmakefile:64: *** Asan and UBsan are mutually exclusive. Specify only one of them. Stop.
I also tried quoting the "0"
with the same result: ifneq ($(shell echo $$($(ASAN) * $(UBSAN))),"0")
.
How do I compare two integral values in a makefile?
Upvotes: 0
Views: 263
Reputation: 81012
Your problem is a simple typo.
You left out one (
/)
in the arithmetic expansion in the $(shell)
command.
Your shell command is echo $(0 * 0)
which the shell sees as a command substitution not arithmetic expansion and then tries to run 0 <expansion of all files in the current directory> 0
. Which is why you get the /bin/sh: 1: 0: not found
error message.
Add the missing (
/)
and your problem goes away.
ifneq ($(shell echo $$(($(ASAN) * $(UBSAN)))),0)
That being said I wouldn't bother using the shell for this at all (it is expensive).
All you are trying to test, in this case, is that $(ASAN)
and $(UBSAN)
are not both 1
. So just assert that.
ifeq ($(ASAN)$(UBSAN),11)
$(error Asan and UBsan are mutually exclusive. Specify only one of them)
endif
If you want to be safer about manual assignment of some other value (e.g. make ASAN=11
or something) then you could do something more like:
ifeq ($(filter-out 1,$(ASAN))$(filter-out 1,$(UBSAN)),)
$(error Asan and UBsan are mutually exclusive. Specify only one of them)
endif
Upvotes: 1