user6796845
user6796845

Reputation:

Makefile error exit with a message

Is there any way to output a error message when the error happens.Let's go into details,I want to know whether one file content equal to another or not.If not ,make should exit and output a error message.

test:
    cmp --silent tmp/test.txt tmp/test_de.txt ||    (error DecryptFile is different from original)

When tmp/test.txt does not equal to tmp/test_de.txt,the output is:

cmp --silent tmp/test.txt tmp/test_de.txt | (error DecryptFile is different from original)
/bin/sh: 1: error: not found
makefile:38: recipe for target 'test' failed
make: *** [test] Error 127

/bin/sh: 1: error: not found

The result isn't what I want.I just want like this kind of error message:

makefile:38: *** missing separator. Stop.

Upvotes: 8

Views: 22800

Answers (2)

Perhaps the error refers to the GNU Make built-in error function but then you should write $(error....) instead of just (error....) and you cannot use it that way (in a shell command). So you really should use echo and exit as answered by tobatamas. Perhaps you might redirect the echo to stderr (e.g. echo message 2>&1 or echo message > /dev/stderr)

The $(error....) builtin could be (and often is) used with GNU make conditionals.

Upvotes: 5

torbatamas
torbatamas

Reputation: 1296

You can use exit. the ( and ) can enclose more than one command:

cmp --silent tmp/test.txt tmp/test_de.txt || (echo "DecryptFile is different from original"; exit 1)

Upvotes: 16

Related Questions