Reputation: 311
I am trying to get if else syntax working in Makefile
TYPE=src
RTL=src
program_%:
ifeq ($(TYPE),$(RTL))
echo "RTL"
else
echo "Test"
endif
Here is the command line
$make -f test.make prog_src
and I get the following in the output
echo "RTL"
RTL
However, when i change the if statement such that instead of hard-coded variables I do something like
program_%:
ifeq ($(TYPE),$*)
echo "RTL"
else
echo "Test"
endif
and run as follows
$make -f test.make prog_src
I get the wrong clause evaluated
echo "Test"
Test
Upvotes: 0
Views: 261
Reputation: 6984
remove the whitespaces in the condition
ifeq ($(TYPE),$(RTL))
No; this is not possible ifeq
is evaluated in the context of the makefile and $*
is not expanded there. You can try $(if ...)
but checking equality is not directly possible:
program_%:
@echo $(if $(filter ${TYPE},$*),"RTL","Test")
"Context of makefile" means that if*
sees only global make variables. Special variables like $*
are available in the rule context only.
complex rules are possible by
define complex_rule_A
@echo "complex_rule_A"
@echo "done"
endef
define complex_rule_B
@echo "complex_rule_B"
@echo "failed"
endef
program_%:
$(if $(filter ${TYPE},$*),$(call complex_rule_A),$(call complex_rule_B))
When ${TYPE}
can be enumerated, a more clean solution might be
program_%: .program_${TYPE}_%
:
.program_RTL_%:
echo else
.program_RTL_RTL:
echo RTL
Upvotes: 2