From f5c665b9f6b7ecbae9da1b54b50dde0dec7b181e Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 13 Apr 2018 16:06:44 -0700 Subject: [PATCH] Make the build logic more robust for BSD systems This properly sets MAKE (when undefined) on BSDs to gmake rather than make, which refers to the incompatible BSD Make. Further, it betters detection of Clang as the default compiler, which is the case on FreeBSD 11.0+ and OpenBSD 6.0+. --- makefile_include.mk | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/makefile_include.mk b/makefile_include.mk index 69f9c535c..e9f25cab2 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -13,9 +13,23 @@ ifndef CROSS_COMPILE CROSS_COMPILE:= endif -ifeq ($(CC),cc) - CC := $(CROSS_COMPILE)gcc +# We only need to go through this dance of determining the right compiler if we're using +# cross compilation, otherwise $(CC) is fine as-is. +ifneq (,$(CROSS_COMPILE)) +ifeq ($(origin CC),default) +CSTR := "\#ifdef __clang__\nCLANG\n\#endif\n" +ifeq ($(PLATFORM),FreeBSD) + # XXX: FreeBSD needs extra escaping for some reason + CSTR := $$$(CSTR) endif +ifneq (,$(shell echo $(CSTR) | $(CC) -E - | grep CLANG)) + CC := $(CROSS_COMPILE)clang +else + CC := $(CROSS_COMPILE)gcc +endif # Clang +endif # cc is Make's default +endif # CROSS_COMPILE non-empty + LD:=$(CROSS_COMPILE)ld AR:=$(CROSS_COMPILE)ar @@ -24,7 +38,12 @@ AR:=$(CROSS_COMPILE)ar ARFLAGS:=r ifndef MAKE - MAKE:=make +# BSDs refer to GNU Make as gmake +ifneq (,$(findstring $(PLATFORM),FreeBSD OpenBSD DragonFly NetBSD)) + MAKE=gmake +else + MAKE=make +endif endif ifndef INSTALL_CMD