0

In GNU's make is it possible to print a custom error message instead of GNU's default one, possibly with the line number as well? I am fine with make's default behavior in all other scenarios.

Here is an example:

requirements.txt:
    ls requirements.txt || echo "Download requirements.txt." && false

This works; but it is not DRY especially since you see GNU's internal error message as well:

% make
Download requirements.txt.
make: *** [Makefile:10: requirements.txt] Error 1

I would like to just print:

Makefile 10: Please download requirements.txt.

(I am trying to use make for my Dockerfile - not sure if that is a bad idea!)

4
  • 1
    You don't need ls requirements.txt. The recipe will run when requirements.txt is missing. But I don't know how can discard make's error message. – uzsolt May 30 '20 at 15:12
  • Yeah @uzsolt, I am doing that for printing this error message actually. Any other cool ideas that can just print this message would work ;-). – Nishant May 30 '20 at 15:20
  • 1
    A pattern like "%:" will match everything, but I think you are taking DRY rather too far. A rule like file1 requirements.txt file2:\n\t@echo Please download $@ >&2 ; exit 1 means you only need to list the files that need to be downloaded. Is this DRY enough for you? – icarus May 30 '20 at 19:16
  • @icarus, thanks for the pointer. Yes, I think it is not a good thing to do in this case; will try to see some examples of how people use Makefiles with docker. – Nishant May 31 '20 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.