Makefile string comparison #Ifeq
As told in the comment you should wrap FIRST
into quotes: `$(FIRST). Note, the Makefile and Bash has different syntax. Makefile require round quotes around variable, bash - not.
Also please remove extra whitespaces inside ifeq
. Note in some cases command ifeq ( $(FIRST),1 )
may compare with unstriped line and fail because of extra whitespaces: it may compare to '1 '
instead of simple '1'
So makefile will looks like
FIRST = 1
ifeq ($(FIRST),1)
ENABLE_CODE += -D'ENABLE_PROGRAM'
endif
all:
@echo FIRST $(FIRST)
@echo ENABLE_CODE $(ENABLE_CODE)
Prasath
Updated on June 04, 2022Comments
-
Prasath almost 2 years
In one of my projects, I am facing the error below. I have two environments and I'm observing the
ifeq
functionality difference between the two environments.In the first environment, the below code is working fine.
FIRST = 1 ifeq ( ($FIRST),1 ) ENABLE_CODE+= -D'ENABLE_PROGRAM' endif
The same code is not working in the second environment. It only works if I modify the code
ifeq ( ($FIRST),1)
to
ifeq ( ( $FIRST),'1')
Could somebody help me to sort this out?