Reputation: 1044
I'm a newbie in Makefile. And here's what I have currently:
install:
ifeq ($(OS),Windows_NT)
# do something
else
# do something
endif
But make throws this error:
ifeq (Windows_NT)
/bin/sh: -c: line 0: syntax error near unexpected token `Windows_NT'
/bin/sh: -c: line 0: `ifeq (Windows_NT)'
make: *** [install] Error 2
I have no idea how to solve this. Please kindly help me.
Upvotes: 0
Views: 373
Reputation: 99164
The contents of a makefile are in Make syntax, except in a recipe.
$(info hello)
foo:
echo working
echo still working
The $(info ...)
line is a Make function call; the echo
lines are shell commands that comprise the recipe for the foo
rule. The whitespace at the beginning of each shell command is a TAB character, not spaces. That's how Make knows that it is a shell command, to be passed to a shell and not interpreted as Make code.
The conditional you wrote is a Make conditional, you wrote it in Make syntax, but you put TABs at the beginnings of the lines, so Make passes them to a shell, and the shell complains that they are not valid (in its language).
Remove the TABs at the beginnings of the conditional's lines, but retain the TABs at the beginnings of the shell commands:
install:
ifeq ($(OS),Windows_NT)
echo doing something
else
echo doing something else
endif
Upvotes: 3