1

Is there a way to force an error in a BSD makefile without using a target? I'm looking for something like

.if ...some condition...
    error bad configuration
.endif

This question is like "How to force an error in a gnumake file", but is for BSD makefiles.

Community
  • 1
  • 1
Mr Fooz
  • 109,094
  • 6
  • 73
  • 101

1 Answers1

4

Yes: use .error (and the variable assignment syntax VARIABLE != some command to assign the output of a shell command to a variable).

SOMEVAR != foo --bar
.if (${SOMEVAR} != "some string")
.error bad configuration
.endif

(The man page, which can be read online here if you don't have it to hand, has full details of the syntax.)

Matthew Slattery
  • 45,290
  • 8
  • 103
  • 119
  • Thanks. Do you know of a solution that works for ancient versions of bsd make that don't support the .error directive? I'm using a Solaris version that silently ignores the directive. – Mr Fooz Sep 15 '11 at 22:20
  • No, I don't - sorry. (I do know that there's a version of BSD make called [bmake](http://www.crufty.net/help/sjg/bmake.html) which claims to be quite portable, if that helps?) – Matthew Slattery Sep 15 '11 at 22:44
  • 1
    I can confirm that `bmake` used to be very compatible with make on FreeBSD (now they are the same, so it is easier) and I used it on Solaris with my `bsdowl` make macros. — https://bitbucket.org/michipili/bsdowl – Michaël Le Barbier Aug 18 '14 at 21:19