FreeBSD make does not support "ifdef" directives
My FreeBSD
- 11.0
and can make
not be found to parse directives ifdef
. For example:
ifdef VERBOSE
Q :=
else
Q := @
endif
make
will complain:
make: "/root/Project/powermon/Makefile" line 13: Need an operator
make: "/root/Project/powermon/Makefile" line 15: Need an operator
make: "/root/Project/powermon/Makefile" line 17: Need an operator
My current solution uses gmake
. So, does any make
port FreeBSD
support processing ifdef
?
source to share
BSD make uses different syntax and has different functions than GNU make. The snippet shown should look like this BSD:
.ifdef VERBOSE
Q :=
.else
Q := @
.endif
You basically have three options:
- If your software is specifically for BSD, write your Makefile in BSD to do the syntax. man make (1) contains a complete manual for FreeBSD
make
. - Write a portable Makefile. This would only use the most basic functionality
make
that is implemented by every known toolmake
(for example, don't use any template rules, etc.). This can be tedious, and there are other tools to help manage this by creating a Makefile, for examplecmake
or the GNU autotools. - write a GNU make Makefile (it might be a good idea to name it
GNUmakefile
, so it is never interpreted bymake
anything other than GNU make), and rely on GNU make to be available almost everywhere. For FreeBSD, this would mean setting the appropriate port.
If you go with the third option, you can add a "wrapper" Makefile
like eg. this is:
GNUMAKE?= gmake
all:
${GNUMAKE} $@
.DEFAULT:
${GNUMAKE} $@
.PHONY: all
Typing make
in BSD will cause BSD to make that file and call accordingly gmake
. On the GNU system (where make
is GNU make), this file will be ignored if present GNUmakefile
- GNU make prefers that only Makefile
.
source to share