#! /bin/sh # # cpp11-gcc # # Detect compatible GCC version and add c++11/14 flags # # From the online doc # __CXXC__ # __CXXC_MINOR__ # __CXXC_PATCHLEVEL__ # These macros are defined by all CXX compilers that use the C preprocessor: C, C++, Objective-C and Fortran. # Their values are the major version, minor version, and patch level of the compiler, as integer constants. # For example, GCC 3.2.1 will define __CXXC__ to 3, __CXXC_MINOR__ to 2, and __CXXC_PATCHLEVEL__ to 1. i # These macros are also defined if you invoke the preprocessor directly. # # __VERSION__ # This macro expands to a string constant which describes the version of the compiler in use. # You should not rely on its contents having any particular form, but it can be counted on to contain # at least the release number. # CXXMAJOR := $(shell $(CXX) -E -dM - < /dev/null | grep __GNUC__ | sed -e 's/^.* //g') CXXMINOR := $(shell $(CXX) -E -dM - < /dev/null | grep __GNUC_MINOR__ | sed -e 's/^.* //g') CXXPATCH := $(shell $(CXX) -E -dM - < /dev/null | grep __GNUC_PATCHLEVEL__ | sed -e 's/^.* //g') CXXVERSION := $(CXXMAJOR)$(CXXMINOR)$(CXXPATCH) # # GCC 4.8 (or 4.6?) doesn't accept -std=c++11, only -std=c++0x. # # C++14 needs GCC 4.9.2 ifeq ($(shell test $(CXXVERSION) -ge 492 && echo 1), 1) CXXFLAGS += -std=c++14 # C++11 needs GCC 4.8.1 else ifeq ($(shell test $(CXXVERSION) -ge 481 && echo 1), 1) CXXFLAGS += -std=c++11 else CXXFLAGS += -std=c++03 endif