In a makefile I need to check, whether a program rocq exists in the system. If it exists assign one value to the variable, otherwise assign another value.
I created the following code:
OUTPUT=$(shell which rocq 2>/dev/null)
ifneq ($(OUTPUT), "")
COQC=rocq c
else
COQC=coqc
endif
COQC := $(COQC)" -R . Mendelson"
all:
@echo [$(COQC)]
@echo [$(OUTPUT)]
I get the following output:
[rocq c -R . Mendelson]
[]
Surprisingly, $(OUTPUT) is empty, but the yes-branch was executed. COQC was assigned to "rocq c".
What am I doing wrong?
ifneq ($(OUTPUT), )will yield the correct result; or perhaps less cryptic :OUTPUT="$(shell which ...)".makedoes not recognize quote-delimited strings. It interprets the""in yourifneqstatement as two literal characters. Remove them, leaving literally nothing to represent nothing.ifneq ($(VAR),)orifneq "$(VAR)" ""forms. Do not combine them.ifdef OUTPUTcan be used to do something when the variable is non-empty.