From 81400d3edcdab9e468ed0cb3557fdcdacf6475a6 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Tue, 22 Dec 2020 11:44:12 +0100 Subject: [PATCH] mk/re: add C11 and Atomic detection (#61) Adding C11 detection (gcc/clang 5.x and newer). It can be disabled with make CC_C11=. When C11 is detected, it defines HAVE_ATOMIC. This can also be disabled with make HAVE_ATOMIC=. --- README.md | 2 +- mk/re.mk | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9438e65ba..317ef3e2a 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Please send private feedback to libre [at] creytiv.com ## Design goals -* Portable POSIX source code (ANSI C89 and ISO C99 standard) +* Portable POSIX source code (ISO C99 and C11 standard) * Robust, fast, low memory footprint * RFC compliance * IPv4 and IPv6 support diff --git a/mk/re.mk b/mk/re.mk index 61382a1b2..9f8a4e9f8 100644 --- a/mk/re.mk +++ b/mk/re.mk @@ -79,22 +79,31 @@ ifeq ($(CC),cc) CC := gcc endif LD := $(CC) -CC_LONGVER := $(shell $(CC) - --version|head -n 1) + +CC_LONGVER := $(shell $(CC) - --version|head -n 1) CC_SHORTVER := $(shell $(CC) -dumpversion) +CC_MAJORVER := $(shell echo $(CC_SHORTVER) |\ + sed -e 's/\([0-9]*\)\.[0-9]\+\.[0-9]\+/\1/g') # find-out the compiler's name ifneq (,$(findstring gcc, $(CC_LONGVER))) CC_NAME := gcc - CC_VER := $(CC) $(CC_SHORTVER) + CC_VER := $(CC) $(CC_SHORTVER) ($(CC_MAJORVER).x) MKDEP := $(CC) -MM +ifneq ($(CC_MAJORVER), 4) + CC_C11 := 1 +endif endif ifeq ($(CC_NAME),) ifneq (,$(findstring clang, $(CC_LONGVER))) CC_NAME := clang - CC_VER := $(CC) $(CC_SHORTVER) + CC_VER := $(CC) $(CC_SHORTVER) ($(CC_MAJORVER).x) MKDEP := $(CC) -MM +ifneq ($(CC_MAJORVER), 4) + CC_C11 := 1 +endif endif endif @@ -295,9 +304,19 @@ endif CFLAGS += -DOS=\"$(OS)\" +ifeq ($(CC_C11),) CFLAGS += -std=c99 +else +CFLAGS += -std=c11 +HAVE_ATOMIC := 1 +endif + CFLAGS += -pedantic +ifneq ($(HAVE_ATOMIC),) +CFLAGS += -DHAVE_ATOMIC +endif + ifeq ($(OS),) $(warning Could not detect OS) @@ -613,7 +632,7 @@ info: @echo " OS: $(OS)" @echo " BUILD: $(BUILD)" @echo " CCACHE: $(CCACHE)" - @echo " CC: $(CC_NAME) $(CC_SHORTVER)" + @echo " CC: $(CC_VER)" @echo " CFLAGS: $(CFLAGS)" @echo " DFLAGS: $(DFLAGS)" @echo " LFLAGS: $(LFLAGS)"