From da49ebb927cc15e5d77574b608b3a59b05cebc56 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 1 Oct 2023 00:48:57 +0200 Subject: Linux: Better detection of gcc version to correctly enable c++11 This allows to build correctly under CentOS 6 and CentOS 7 --- src/Makefile | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 356f0a7b..ed62a4f0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -195,14 +195,21 @@ ifeq "$(shell uname -s)" "Linux" # PCSC C_CXX_FLAGS += $(shell pkg-config --cflags libpcsclite) - - # GNU GCC version 11 and higher compile with -std=gnu++17 by default - # which breaks "byte" definitions in Crypto++ library. So set - # -std=gnu++14 instead. - GCC11PLUS := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 11) - ifeq "$(GCC11PLUS)" "1" - CXXFLAGS += -std=gnu++14 - endif + # Extract the major and minor version numbers of GCC in a combined format for easy comparison + GCC_VERSION := $(shell $(CC) -dumpversion | awk -F. '{printf "%d%02d", $$1, $$2}') + + # Set the C++ standard based on the version numbers + ifeq ($(shell expr $(GCC_VERSION) \< 408), 1) + # GCC version below 4.8 support minimal C++11 features through the switch -std=c++0x + CXXFLAGS += -std=c++0x + else ifeq ($(GCC_VERSION), 408) + # GCC version 4.8 supports C++11 features through the switch -std=gnu++11 + CXXFLAGS += -std=gnu++11 + else ifeq ($(shell expr $(GCC_VERSION) \>= 1100), 1) + # GNU GCC version 11 and higher compile with -std=gnu++17 by default + # which breaks "byte" definitions in Crypto++ library. So set -std=gnu++14 instead. + CXXFLAGS += -std=gnu++14 + endif ifeq "$(SIMD_SUPPORTED)" "1" -- cgit v1.2.3