Skip to content

Commit 5ab8dcf

Browse files
authored
Merge pull request #382 from ararslan/aa/freebsd
Make the build logic more robust for BSD systems
2 parents a94b02b + f5c665b commit 5ab8dcf

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

makefile_include.mk

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@ ifndef CROSS_COMPILE
1313
CROSS_COMPILE:=
1414
endif
1515

16-
ifeq ($(CC),cc)
17-
CC := $(CROSS_COMPILE)gcc
16+
# We only need to go through this dance of determining the right compiler if we're using
17+
# cross compilation, otherwise $(CC) is fine as-is.
18+
ifneq (,$(CROSS_COMPILE))
19+
ifeq ($(origin CC),default)
20+
CSTR := "\#ifdef __clang__\nCLANG\n\#endif\n"
21+
ifeq ($(PLATFORM),FreeBSD)
22+
# XXX: FreeBSD needs extra escaping for some reason
23+
CSTR := $$$(CSTR)
1824
endif
25+
ifneq (,$(shell echo $(CSTR) | $(CC) -E - | grep CLANG))
26+
CC := $(CROSS_COMPILE)clang
27+
else
28+
CC := $(CROSS_COMPILE)gcc
29+
endif # Clang
30+
endif # cc is Make's default
31+
endif # CROSS_COMPILE non-empty
32+
1933
LD:=$(CROSS_COMPILE)ld
2034
AR:=$(CROSS_COMPILE)ar
2135

@@ -24,7 +38,12 @@ AR:=$(CROSS_COMPILE)ar
2438
ARFLAGS:=r
2539

2640
ifndef MAKE
27-
MAKE:=make
41+
# BSDs refer to GNU Make as gmake
42+
ifneq (,$(findstring $(PLATFORM),FreeBSD OpenBSD DragonFly NetBSD))
43+
MAKE=gmake
44+
else
45+
MAKE=make
46+
endif
2847
endif
2948

3049
ifndef INSTALL_CMD

0 commit comments

Comments
 (0)