Reputation: 3764
I am building a makefile that runs a series of tests and adds the results to a file. In the makefile I have this set up as:
runtests:
rm -f results.txt
cardtest1 > results.txt
cardtest2 >> results.txt
cardtest3 >> results.txt
cardtest4 >> results.txt
unittest1 >> results.txt
unittest2 >> results.txt
unittest3 >> results.txt
unittest4 >> results.txt
Now I am able to run all of the above commands in this or any other order (provided the results.txt file exists for the appends) without problem. However, no matter what test is run after rm -f results.txt when it is in the makefile, it will always generate an error.
flip1 ~/src/dominion-base 161% make all
rm -f results.txt
cardtest1 > results1.txt
make: *** [runtests] Error 1
I have been tinkering with it for an hour (originally had all as >> but realized that an append apparently does not create a file that doesn't exist), and I am really unsure of what exactly is wrong with my makefile.
Upvotes: 0
Views: 1394
Reputation: 101111
The error:
make: *** [runtests] Error 1
means that while make was building the target runtests
, one of the commands that it ran exited with an error code of 1
. In POSIX (and make), any exit code other than 0 is considered a failure; only 0 means that the command succeeded.
So make will examine the exit code of the program it invokes (which is the only thing it has to go on) and if it's not 0 it assumes the command failed, and it stops the build.
In the above I would say that your program cardtest1
is exiting with an exit code of 1. You can test this by running (from your shell command line):
cardtest1
echo $?
because the shell puts the exit code of the just-completed program into the shell variable $?
. If it's not 0, then you need to modify your cardtest1
program to ensure that the exit code is set properly.
Upvotes: 3