Testing if a file exists in makefile target, and quitting if not present
gnu, makefile
Solution
`exit` alone returns the status of the last command executed. In this case, it returns zero, which means everything is ok.
This is, because `||` and `&&` have equal precedence, and the shell interprets the command as if it were written
( test ... || echo ... ) && exit
If you want to signal failure you must exit with a non zero value, e.g. `exit 1`. And if you want to echo and exit, just put the commands in sequence separated by `;`
all: foo
foo:
test -s /opt/local/bin/gsort || { echo "GNU sort does not exist! Exiting..."; exit 1; }
Problem
Is there a way to exit with an error condition if a file does not exist? I am currently doing something like this: ``` all: foo foo: test -s /opt/local/bin/gsort || echo "GNU sort does not exist! Exiting..." && exit ``` Running `make` runs the `all` target, which runs `foo`. The expectation is that if the `test -s` conditional fails, then the `echo/exit` statements are executed. However, even if `/usr/bin/gsort` exists, I get the result of the `echo` statement but the `exit` command does not run. This is the opposite of what I am hoping to accomplish. What is the correct way to do something like the above?