Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

equivalent of pipefail in GNU make?

Tags:

Say I have the following files:

buggy_program:

#!/bin/sh echo "wops, some bug made me exit with failure" exit 1 

Makefile:

file.gz:     buggy_program | gzip -9 -c >$@ 

Now if I type make, GNU make will happily build file.gz even though buggy_program exited with non-zero status.

In bash I could do set -o pipefail to make a pipeline exit with failure if at least one program in the pipeline exits with failure. Is there a similar method in GNU make? Or some workaround that doesn't involve temporary files? (The reason for gzipping here is precisely to avoid a huge temporary file.)

like image 548
unhammer Avatar asked Apr 15 '14 09:04

unhammer


2 Answers

Try this

SHELL=/bin/bash -o pipefail  file.gz:     buggy_program | gzip -9 -c >$@ 
like image 149
Quanlong Avatar answered Oct 03 '22 04:10

Quanlong


You could do:

SHELL=/bin/bash  .DELETE_ON_ERROR: file.gz:     set -o pipefail; buggy_program | gzip -9 -c >$@ 

but this only work with bash.

like image 38
manlio Avatar answered Oct 03 '22 04:10

manlio