I used this post as a basis for how to pass arguments to a make target.
I would like to perform a string comparison on this command line arg, using this post as inspiration for doing string equality comparisons in a makefile.
Update using the suggested answer below:
%:
@:
test:
if [ '$(filter-out $@,$(MAKECMDGOALS))' = hi ]; \
echo "WON"; \
else \
echo "LOST"; \
fi
where I do 8 spaces instead of indents, nothing prints. When I do tabs instead of spaces, I get the following errors:
if [ 'hi' = hi ]; \
echo "WON"; \
else \
echo "LOST"; \
fi
/bin/sh: -c: line 0: syntax error near unexpected token `else'
/bin/sh: -c: line 0: `if [ 'hi' = hi ]; echo "WON"; else echo "LOST"; fi'
make: *** [test] Error 2
Original attempt:
%:
@:
test:
ifeq ($(filter-out $@,$(MAKECMDGOALS)),hi)
echo "WON"
else
echo "LOST"
endif
However, when I run, make test hi
, I get
arg="hi"
ifeq (hi,hi)
/bin/sh: -c: line 0: syntax error near unexpected token `hi,hi'
/bin/sh: -c: line 0: `ifeq (hi,hi)'
make: *** [test] Error 2
What is the unexpected token ?