I'm trying to check if a variable contains a particular string. I've tried a solution posted here: Makefile : contains string but in my case it does not seem wot work.
@echo $(findstring 2025, $(basename $(<F)))`
returns 2025
, but :
ifeq ($(findstring 2025, $(basename $(<F))),2025)
@echo $(findstring 2025, $(basename $(<F)))
endif
does not return 2025
. Why?
You're using ifeq
and since you don't say that you got a syntax error it must be that this is not in a recipe. ifeq
is a make keyword not a valid shell command, so it can't be in a recipe.
If you check the documentation for automatic variables like $(<F)
you'll find that they are only set in a recipe context. So you can't ever use automatic variables in ifeq
conditionals: they will always be the empty string.