I am trying to generate an error in a Makefile when a string is not found in the output of a shell command. The shell command depends on a parameter, therefore the whole thing is in a defined function. Here is a minimalist example:
define check_in_abcdefg
$(eval TMP := $(shell echo abcdefg))
$(if $(findstring $(1),$(TMP)),,$(error $(1) not in $(TMP)))
endef
$(call check_in_abcdefg,def)
all:
@echo Hello, world!
I would like this Makefile to output Hello, world!
in this case, but I'd like it to output xyz not in abcdefg
if I replace the call line with this one:
$(call check_in_abcdefg,xyz)
The problem is that with the def
check I have this output:
Makefile:6: *** missing separator. Stop.
Where line 6 is $(call check_in_abcdefg,def)
Why does the syntax check fail when the $(if ...)
condition is true since it's actually empty ?
Note that the echo command in the dummy target all
is correctly preceded by a tab, not four spaces. I am running GNU make 4.1.90 built for Windows32
, and it seems not to happen for newer version of GNU make
. I am looking for any answer that could help me make it work with GNU make 4.1.90
GNU make 4.2
and it seems to work. I have no idea why this would fail with the version 4.1.90 and unfortunately it's this one which is globally deployed in my context. – Timtrue
. That problem seems to get fixed if something is specified, for exemple :$(if $(findstring $(1), $(TMP), $(errror $(1) is in $(TMP)), $(error $(1) is not in $(TMP)))
works. Hope this can help – Hollyolmake
stops at the error, but if you put an info instead if fails :$(if $(findstring $(1),$(TMP)),$(info OK),$(error $(1) not in $(TMP)))
. This displaysOK
followed by*** missing separator. Stop.
– Tim