4.6. Error trapping in makefiles

When make invokes a command in a makefile (including your package’s upstream makefiles and debian/rules), it does so using sh. This means that sh’s usual bad error handling properties apply: if you include a miniature script as one of the commands in your makefile you’ll find that if you don’t do anything about it then errors are not detected and make will blithely continue after problems.

Every time you put more than one shell command (this includes using a loop) in a makefile command you must make sure that errors are trapped. For simple compound commands, such as changing directory and then running a program, using && rather than semicolon as a command separator is sufficient. For more complex commands including most loops and conditionals you should include a separate set -e command at the start of every makefile command that’s actually one of these miniature shell scripts.