On Wed, Nov 30, 2016 at 06:49:21PM -0800, William Ahern wrote:
On Wed, Nov 23, 2016 at 11:59:46PM +0100, mathieu stumpf guntz wrote:
Ok, thank you William, I'll go with `!=` for now and possibly investigate in
way to make it even more portable later.
FWIW, this construct,
DATE = date
V = $(shell $(DATE))$(DATE:sh)
test:
@printf "%s\n" "$(V)"
worked on all the systems I tried, including
- Solaris Make (Solaris 11.3)
- bmake (FreeBSD 10.2)
- OpenBSD Make (OpenBSD 6.0)
- NetBSD Make (NetBSD 7.0)
- GNU Make 4.1 (Ubuntu Xenial)
- GNU Make 3.81 (OS X 10.10)
I played around with this a little more and got pretty far. The following
code should work on all the above (bugs notwithstanding). It will
automatically guess SOFLAGS if it's not defined from the command-line. It
uses several different techniques for conditional evaluation, plus the above
trick for shell substitution.
true_or_false.true = true
true_or_false. = false
OS.is_aix.aix = true
OS.is_aix = $(true_or_false.$(OS.is_aix.$(OS)))
OS.is_darwin.darwin = true
OS.is_darwin = $(true_or_false.$(OS.is_darwin.$(OS)))
OS.is_freebsd.freebsd = true
OS.is_freebsd = $(true_or_false.$(OS.is_freebsd.$(OS)))
OS.is_linux.linux = true
OS.is_linux = $(true_or_false.$(OS.is_linux.$(OS)))
OS.is_netbsd.netbsd = true
OS.is_netbsd = $(true_or_false.$(OS.is_netbsd.$(OS)))
OS.is_openbsd.openbsd = true
OS.is_openbsd = $(true_or_false.$(OS.is_openbsd.$(OS)))
OS.is_sunos.sunos = true
OS.is_sunos = $(true_or_false.$(OS.is_sunos.$(OS)))
OS.is_sun = $(OS.is_sunos)
OS.is_bsd = $(OS.is_freebsd:false=$(OS.is_openbsd:false=$(OS.is_netbsd)))
OS.exec = uname -s | tr 'A-Z' 'a-z'
OS.guess = $(shell $(OS.exec))$(OS.exec:sh)
OS = $(OS.guess)
SOFLAGS.darwin.true = -bundle -undefined dynamic_lookup
SOFLAGS.darwin.false = -shared
SOFLAGS.guess = $(SOFLAGS.darwin.$(OS.is_darwin))
SOFLAGS = $(SOFLAGS.guess)
.DEFAULT:
@printf "OS=%s\n" "$(OS)"
@printf "SOFLAGS=%s\n" "$(SOFLAGS)"