4

I want to run diff in a makefile and catch the output,

test:
     diff a b > tmp

but diff returns non-zero if it catches any differences.

Make interprets the non-zero return code as an error, and even if I ignore the error using -diff, it still prints a warning.

makefile:7: recipe for target 'test' failed
make: [test] Error 1 (ignored)

Can I make it shut up?

John Lawrence Aspden
  • 17,124
  • 11
  • 67
  • 110
  • 1
    put a '-' in front of the command that you want to ignore. Change `diff a b > tmp` to `-diff a b > tmp`. https://www.gnu.org/software/make/manual/make.html#Errors – shrewmouse Sep 16 '19 at 17:38

1 Answers1

7

You need to make sure your recipe returns 0 (success) even if the diff command doesn't. Something like:

test:
        diff a b > tmp || true
MadScientist
  • 92,819
  • 9
  • 109
  • 136