Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile failing when using diff on different files

Part of my makefile for my C++ project uses the diff command to compare two files that were output by the recently built code. The issue is that if the files are different, the script you not fail and should continue. There are more files that need to be compared and I need to see them all before the build script should end. For example, something like this,

diff:   *
        diff $(TEST)/T4.board $(TEST)/T4.board
        diff $(TEST)/T4.board $(TEST)/sample.board

The first line causes no issue because the files are the same. The second line compares different files, and once the differences are displayed, I see

Makefile:102: recipe for target `diff' failed
make: *** [diff] Error 1

and the script stops. How can I get it to continue?

like image 650
gsingh2011 Avatar asked Mar 11 '12 17:03

gsingh2011


1 Answers

As the GNU make manual states in section 5.5 "Errors", you can ignore the return status of a command by prefixing the command with -:

diff:   *
    -diff $(TEST)/T4.board $(TEST)/T4.board
    -diff $(TEST)/T4.board $(TEST)/sample.board
like image 190
thiton Avatar answered Sep 28 '22 01:09

thiton