8

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.

2 Answers2

14

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)
torbatamas
  • 1,236
  • 1
  • 11
  • 21
4

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.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • By the way ,what does `echo message > /dev/stderr` mean? After I redirect to stderr,what can I do using `/dev/stderr`. –  May 19 '17 at 06:09