Settings

Theme

Cross-make selection: conditional Makefiles supporting both BSD and GNU make

wok.oblomov.eu

3 points by bilog 9 years ago · 1 comment

Reader

wahern 9 years ago

9 out of 10 points for effort. (I have a side hobby playing around with portable makefile constructs myself. ;)

However, none of the native make implementations on OpenBSD, NetBSD, or FreeBSD support $(OS). I just tested OpenBSD 6.0, NetBSD 7.0, and FreeBSD 10.1. AFAICT the only platform with "BSD Make" seems to be Linux. After some head scratching I apt-get installed bmake on Ubuntu and finally found the one implementation that expanded $(OS).

The best, most portable strategy I've found for automatically expanding shell variables is to create a shim Makefile that invokes a sub-Makefile. I don't like this any more than the next person, especially because I like to try write non-recursive makefiles. But it works well.

  .POSIX:
  
  all:
    +make -f Makefile.sub OS="$$(uname -s)" all
  
  .DEFAULT:
    +make -f Makefile.sub OS="$$(uname -s)" $<
If I'm being perfectly honest, I usually just write my rules in GNUmakefile, and in the above substitute "gmake" for "make" and "GNUmakefile" for "Makefile.sub", so that the GNU Make build is automatically invoked on other platforms. I really hate it, but at the end of the day many package maintainers prefer to hack their own makefiles anyhow (much to my chagrin, because half the time they have clear and obvious flaws). The effort might be wasted unless it's a really straight-forward makefile that people won't turn up their noses at. And what matters most is that my actual application code is clean and portable. I would like to move away from my GNU Make habit, though. It's definitely on my bucket list.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection