make & gmake compatible if else statement
Asked Answered
A

1

8

Is there any type of if/else statement compatible with GNU make and Berkley make (freeBSD)?

GNU MAKE:

 ifeq ($(BUILD_TYPE), debug)

berkley make:

.ifdef (BUILD_TYPE)
Amberlyamberoid answered 1/2, 2012 at 12:44 Comment(5)
Note that these two lines does NOT test the same thing!Azoth
its only examples of make & gmake syntax. the questions is above. GNU "ifeq" is ".if" berkley make equivalent. i know this.Amberlyamberoid
Why not use automake and have it handle the conditions for you, portably?Sienese
@Amberlyamberoid FreeBSD's make and GNU make are very different, but bmake (the make used on FreeBSD) is available on Linuces as bmake and on Mac OS X as bsdmake, so it is basically available on each platform running GNU Make. If you like BSD Make, you could find my macros bsdowl useful. Check them out! — bitbucket.org/michipili/bsdowlMcquade
@MichaelGrünewald thanks. seems the time to migrate to clang...Amberlyamberoid
M
9

No. The best you can do is use include files with constructed names, like:

include $(BUILD_TYPE).mk

where BUILD_TYPE will be "debug" or whatever. This is certainly not as powerful as if/else but it can do a limited set of things well, in a portable manner.

In general it's almost impossible to write a portable makefile that uses any feature more sophisticated than the basics provided by POSIX. The makefile syntax is so loose and free-form, and yet the features provided by traditional make and the POSIX standard are so anemic, that most make vendors have created a large number of non-compatible extensions.

Generally when people wonder about this I recommend that they either use automake, which takes care of the tedious work of writing portable makefiles for you, or else they commit to one make or the other and simply require people to build it if they don't have it. GNU make, for sure, will run across a huge variety of platforms... even non-POSIX platforms.

Mimosaceous answered 2/2, 2012 at 5:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.