<p>I have a Makefile that starts by running a tool before applying the build rules (which this tool writes for me). If this tool, which is a python script, exits with a non-null status code, I want GNU Make to stop right there and not go on with building the program.</p>

<p>Currently, I do something like this (top level, i.e. column 1):</p>

<pre><code>$(info Generating build rules...)
$(shell python collect_sources.py)
include BuildRules.mk
</code></pre>

<p>But this does not stop make if <code>collect_sources.py</code> exits with a status code of 1. This also captures the standard output of <code>collect_sources.py</code> but does not print it out, so I have the feeling I'm looking in the wrong direction.</p>

<p>If at all possible, the solution should even work when a simple MS-DOS shell is the standard system shell.</p>

<p>Any suggestion?</p>

There might be a better way, but I tried the following and it works:
```
```
$(if $(shell if your_command; then echo ok; fi), , $(error your_command failed))
```
```
Here I did assume that
```
your_command
```
does not give any output, but it shouldn't be hard to work around such a situation.
Edit: To make it work with the default Windows shell (and probably any decent shell) you could write
```
your_command && echo ok
```
instead of the
```
if
```
within the
```
shell
```
function. I do not think this is possible for (older) DOS shells. For these you probably want to adapt
```
your_command
```
or write a wrapper script to print something on error (or success).