Makefile error when using diff for different files

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

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

The first line does not cause problems, because the files are the same. The second line compares different files, and after displaying the differences, I see

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

and the script stops. How can I continue?

+6
source share
2 answers

Make the whole recipe to return an error:

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

You can use echo 'Files differ' instead of exit 0 .

+5
source

Since GNU does state management in Section 5.5, Errors , you can ignore the return status of the command, the prefix command with - :

 diff: * -diff $(TEST)/T4.board $(TEST)/T4.board -diff $(TEST)/T4.board $(TEST)/sample.board 
+7
source

Source: https://habr.com/ru/post/910453/


All Articles