0

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?

4
  • 2
    "" is not the same as empty; so ifneq ($(OUTPUT), ) will yield the correct result; or perhaps less cryptic :OUTPUT="$(shell which ...)". Commented May 28 at 19:04
  • In case that was not clear enough: make does not recognize quote-delimited strings. It interprets the "" in your ifneq statement as two literal characters. Remove them, leaving literally nothing to represent nothing. Commented May 29 at 0:12
  • Use ifneq ($(VAR),) or ifneq "$(VAR)" "" forms. Do not combine them. Commented Jun 5 at 19:16
  • ifdef OUTPUT can be used to do something when the variable is non-empty. Commented Jul 1 at 15:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.