From a5e99069674883e9b0dc41240d047ddd2cece06c Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 26 Dec 2021 22:10:23 +0100 Subject: [PATCH] Fix the compilation under clang --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bb339e3..b1a7a7f 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ CONFIG_STATS := false define safe_flag $(shell $(CC) $(if $(filter clang,$(CC)),-Werror=unknown-warning-option) -E $1 - /dev/null 2>&1 && echo $1 || echo $2) endef +define safe_flag_cpp +$(shell $(CXX) $(if $(filter clang++,$(CXX)),-Werror=unknown-warning-option) -xc++ -E $1 - /dev/null 2>&1 && echo $1 || echo $2) +endef CPPFLAGS := $(CPPFLAGS) -D_GNU_SOURCE -I include SHARED_FLAGS := -O3 -flto -fPIC -fvisibility=hidden $(call safe_flag,-fno-plt) \ @@ -43,15 +46,17 @@ ifeq ($(CONFIG_NATIVE),true) endif CFLAGS := $(CFLAGS) -std=c11 $(SHARED_FLAGS) -Wmissing-prototypes -CXXFLAGS := $(CXXFLAGS) $(call safe_flag,-std=c++17,-std=c++14) $(SHARED_FLAGS) +CXXFLAGS := $(CXXFLAGS) $(call safe_flag_cpp,-std=c++17,-std=c++14) $(SHARED_FLAGS) LDFLAGS := $(LDFLAGS) -Wl,--as-needed,-z,defs,-z,relro,-z,now,-z,nodlopen,-z,text SOURCES := chacha.c h_malloc.c memory.c pages.c random.c util.c OBJECTS := $(SOURCES:.c=.o) ifeq ($(CONFIG_CXX_ALLOCATOR),true) +ifneq ($(CXX),clang++) # make sure LTO is compatible in case CC and CXX don't match (such as clang and g++) CXX := $(CC) +endif LDLIBS += -lstdc++ -lgcc_s SOURCES += new.cc