I have the following Makefile
~/w/i/craft-api git:develop ❯❯❯ cat Makefile ⏎ ✱ ◼
test:
echo "TODO: write tests"
generate-toc:
if ! [ -x "$(command -v doctoc)" ]; then
echo "Missing doctoc. Run 'npm install doctoc -g' first"
else
doctoc ./README.md
fi
I'm encountering this error
~/w/i/craft-api git:develop ❯❯❯ make generate-toc ✱ ◼
if ! [ -x "" ]; then
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [generate-toc] Error 2
What is incorrect in my Makefile syntax / usage?
Adding line-continuing backslashes doesn't appear to fix the issue:
~/w/i/craft-api git:develop ❯❯❯ cat Makefile ⏎ ✱ ◼
test:
echo "TODO: write tests"
generate-toc:
if ! [ -x "$(command -v doctoc)" ]; then \
echo "Missing doctoc. Run 'npm install doctoc -g' first" \
else \
doctoc ./README.md \
fi
~/w/i/craft-api git:develop ❯❯❯ make generate-toc ✱ ◼
if ! [ -x "" ]; then \
echo "Missing doctoc. Run 'npm install doctoc -g' first" \
else \
doctoc ./README.md \
fi
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [generate-toc] Error 2
The lines of the makefile following the ifneq are obeyed if the two arguments do not match; otherwise they are ignored. The ifdef directive begins the conditional, and specifies the condition. It contains single argument. If the given argument is true then condition becomes true.
= defines a recursively-expanded variable. := defines a simply-expanded variable.
The eval function is very special: it allows you to define new makefile constructs that are not constant; which are the result of evaluating other variables and functions. The argument to the eval function is expanded, then the results of that expansion are parsed as makefile syntax.
Every line is treated as a separate command and is passed to a different shell instance. You can use \
continuations to combine all of the lines so make knows to pass them as one long string to a single shell. This removes the newlines so you also need to add ;
at the end of each command.
if ! [ -x "$$(command -v doctoc)" ]; then \
echo "Missing doctoc. Run 'npm install doctoc -g' first"; \
else \
doctoc ./README.md; \
fi
You'll also want to escape the $
, otherwise make will interpret it rather than the shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With