Reputation: 3066
I have the following statement in my makefile for a conditional compilation
ifeq ($<,bar)
@echo dfjhsdfhdfklhsdfhj
endif
The echo never executed and appeared as if it wasn't working correctly so I echoed the values of the if statement and got ifeq (bar,bar)
so thus the correct statement is being put into the if statement but it never evaluates to true and always to false. Why is this happening? Using GNU make on RHEL 6.5
Upvotes: 1
Views: 340
Reputation: 80921
I assume you are using that inside a target rule? And you echoed the values with something like echo ifeq ($<,bar)
on a line in the rule?
Those aren't evaluated in the same context (or at the same time).
The make level ifeq
is evaluated at make parse time (and thus $<
has no value).
The expansion of the echo shell line (for make variable substitution) is evaluated at target processing time a(and thus $<
has a value).
Try using @$(if $(filter-out bar,$<),:,echo dfjhsdfhdfklhsdfhj)
instead.
$(filter-out)
removes any words from its second argument that match the first argument (accepts patterns here too).
$(if)
succeeds if its first argument evaluates to a non-empty string.
So first we $(filter-out)
bar
from $<
and if that leaves us with a non-empty string (meaning there was more in $<
than just bar
) then $(if)
evaluates its second argument, in this case the :
(the "just return true" shell command). If we get an empty string then we know that $<
was equal to bar
and $(if)
evaluates its third argument, in this case your echo.
Upvotes: 2