I am looking for guidance here as I recently encountered an issue when it came to comparisons using ifeq
on variables that originated from a top-level Makefile I have no control over, and it made me wonder if there is a way to sanitize or standardize variables so that I can consistently use the same type of comparison going forward.
This is the problem I ran into, notice the use of "
around values.
my_target:
ifeq ($(strip $(TOP_VAR_1)), "VALUE")
#this comparison yields true
endif
ifeq ($(strip $(TOP_VAR_2)), VALUE)
#this comparison yields true
endif
I was able to get these comparisons to work by trial and error based on GNU's conditional syntax guide, but this took me a great amount of time to do so.
Previous attempts include playing around with strip
and quotation marks on variables and values, yet those still yielded a false equality.
e.g.
my_target:
ifeq ($(strip $(TOP_VAR_1)), VALUE)
#this comparison yields false
endif
ifeq ($(strip $(TOP_VAR_2)), "VALUE")
#this comparison yields false
endif
"
then a simpleTOP_VAR := $(subst ",,$(TOP_VAR))
to canonicalize their format would be enough."VALUE" or
VALUE ``) so I didn't understand what was going on that caused the comparison to fail, thus me attempting to get the values to a "standard" formatmake
, so for two strings to compare equal, you will need to be totally specific otherwise you won't be able to accomodate tomake
s wish of character-by-character equality. I take it that you would be ok with all funny quote characters and spaces removed.