I’m trying to make a custom function in a Makefile to detect the current platform and return the proper file accordingly. Here is my attempt.
UNAME := $(shell uname -s)
define platform
ifeq ($(UNAME),Linux)
$1
else ifneq ($(findstring MINGW32_NT, $(UNAME)),)
$2
else ifeq ($(UNAME),Darwin)
$3
endif
endef
all:
@echo $(call platform,linux,windows,mac)
It fails with the following error.
/bin/sh: Syntax error: "(" unexpected
[Finished]make: *** [all] Error 2
What am I doing wrong?
Another option would be to concatenate outputs of
unameto form a platform string in a certain format and have platform specific makefiles named accordingly: