steffens21 steffens21 - 1 year ago 88
Bash Question

Recursive make loses status code

I have the following makefile structure

$ cat makefile
$(MAKE) -C bar barbaz

$ cat bar/makefile
exit 111

When I make the target foo I would expect the status code 111 but instead I get status code 2:

$ make foo
make -C bar barbaz
make[1]: Entering directory `bar'
exit 111
make[1]: *** [barbaz] Error 111
make[1]: Leaving directory `bar'
make: *** [foo] Error 2

How can I have the outer make fail with "Error 111" instead of "Error 2"?

BTW: I'm using GNU Make 3.81

Kaz Kaz
Answer Source

This is not an issue with recursive make invocation; that is a red herring.

If you simply do this from the shell:

$ make barbaz # in bar directory
exit 111
make[1]: *** [barbaz] Error 111
$ echo $?

Make isn't propagating the exact exit status of the failing recipe.

This is documented here:

"The exit status of make is always one of three values: [...]'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download