If your python script exits with a non-zero code, make
will detect this and tell you that an error occurred. So you don't need to do anything more.
Example, if I have a program foo.py
that does this:
print 'running foo'
exit(1)
And a Makefile
like this:
foo:
python foo.py
And I run make foo
, I get the output:
python foo.py
running foo
make: *** [foo] Error 1
So it detected the error.
If on the other hand, what you want to do is record the return value of a command in a Makefile, you can use the $?
variable, which stores the last return value of a command.
A couple things to note:
- the dollar sign has to be escaped in a Makefile, so it becomes
$$?
in the command
- since each command in a Makefile is run in a separate shell, you must capture the output in the same subshell as the command you're running (i.e. make the output capture part of the same line as the command you care about)
Example:
build:
python mySample.py ; echo $$? > output
After running make
, you will have a file named output
that contains the return value of mySample.py
.