Skip to content

Commit

Permalink
mk/re: add C11 and Atomic detection (#61)
Browse files Browse the repository at this point in the history
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=.
  • Loading branch information
sreimers authored Dec 22, 2020
1 parent c200e91 commit 81400d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 23 additions & 4 deletions mk/re.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)"
Expand Down

0 comments on commit 81400d3

Please sign in to comment.