Skip to content

Commit

Permalink
better determine compiler support for c++11/17
Browse files Browse the repository at this point in the history
  • Loading branch information
mirostauder committed Oct 18, 2023
1 parent 7584f5a commit 1402c7c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 53 deletions.
24 changes: 16 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,23 @@ DEBUG=${ALL_DEBUG}
#export EXTRALINK
export MAKE
export CURVER?=2.6.0
export CPLUSPLUS=$(shell ${CC} -dM -E -x c++ /dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
$(warning __cplusplus=${CPLUSPLUS})


# determine compiler support for c++11/17
export CPLUSPLUS=$(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
ifeq ($(CPLUSPLUS),)
export CPLUSPLUS=$(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
ifeq ($(CPLUSPLUS),)
$(error Compiler must support at least c++11)
endif
endif

DISTRO := Unknown
ifneq (,$(wildcard /etc/os-release))
DISTRO := $(shell awk -F= '/^NAME/{print $$2}' /etc/os-release)
else
DISTRO := Unknown
endif


NPROCS := 1
OS := $(shell uname -s)
ifeq ($(OS),Linux)
Expand All @@ -59,14 +67,14 @@ endif
ifeq ($(OS),Darwin)
NPROCS := $(shell sysctl -n hw.ncpu)
endif

export MAKEOPT=-j ${NPROCS}


SYSTEMD := 0
ifeq ($(wildcard /usr/lib/systemd/system), /usr/lib/systemd/system)
SYSTEMD=1
else
SYSTEMD=0
SYSTEMD := 1
endif

USERCHECK := $(shell getent passwd proxysql)
GROUPCHECK := $(shell getent group proxysql)

Expand Down
25 changes: 9 additions & 16 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,14 @@ endif
endif


# determine good compiler version for stdc++17
#IS_CXX17 := 0
#ifeq ($(CXX),clang++)
# CLANG_VERSION := $(shell clang -dumpversion | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
# CLANG_MIN_VER := $(shell echo 14.0 | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
#ifeq ($(CLANG_MIN_VER),$(firstword $(sort $(CLANG_VERSION) $(CLANG_MIN_VER))))
# IS_CXX17 := 1
#endif
#else
# GCC_VERSION := $(shell gcc -dumpfullversion 2>/dev/null || gcc -dumpversion | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
# GCC_MIN_VER := $(shell echo 8.2.0 | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
#ifeq ($(GCC_MIN_VER),$(firstword $(sort $(GCC_VERSION) $(GCC_MIN_VER))))
# IS_CXX17 := 1
#endif
#endif
# determine compiler support for c++11/17
export CPLUSPLUS=$(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
ifeq ($(CPLUSPLUS),)
export CPLUSPLUS=$(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
ifeq ($(CPLUSPLUS),)
$(error Compiler must support at least c++11)
endif
endif


PROXYSQLCLICKHOUSE := $(shell echo $(PROXYSQLCLICKHOUSE))
Expand Down Expand Up @@ -191,7 +184,7 @@ lz4: lz4/lz4/lib/liblz4.a

clickhouse-cpp/clickhouse-cpp/clickhouse/libclickhouse-cpp-lib-static.a:
cd clickhouse-cpp && rm -rf clickhouse-cpp-*/ || true
#ifeq ($(IS_CXX17), 1)
#ifeq ($(CPLUSPLUS),201703L)
# echo ">>> Clickhouse CXX17"
cd clickhouse-cpp && ln -fs clickhouse-cpp-2.3.0 clickhouse-cpp
cd clickhouse-cpp && tar -zxf v2.3.0.tar.gz && sync
Expand Down
21 changes: 7 additions & 14 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,12 @@ WGCOV=
endif


# determine good compiler version for stdc++17
IS_CXX17 := 0
ifeq ($(CXX),clang++)
CLANG_VERSION := $(shell clang -dumpversion | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
CLANG_MIN_VER := $(shell echo 14.0 | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
ifeq ($(CLANG_MIN_VER),$(firstword $(sort $(CLANG_VERSION) $(CLANG_MIN_VER))))
IS_CXX17 := 1
endif
else
GCC_VERSION := $(shell gcc -dumpfullversion 2>/dev/null || gcc -dumpversion | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
GCC_MIN_VER := $(shell echo 8.2.0 | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
ifeq ($(GCC_MIN_VER),$(firstword $(sort $(GCC_VERSION) $(GCC_MIN_VER))))
IS_CXX17 := 1
# determine compiler support for c++11/17
export CPLUSPLUS=$(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
ifeq ($(CPLUSPLUS),)
export CPLUSPLUS=$(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
ifeq ($(CPLUSPLUS),)
$(error Compiler must support at least c++11)
endif
endif

Expand All @@ -137,7 +130,7 @@ endif
MYCFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall -DGITVERSION=\"$(GIT_VERSION)\" $(NOJEM) $(WGCOV) $(WASAN)

MYCXXFLAGS=-std=c++11 -DCXX11
ifeq ($(IS_CXX17),1)
ifeq ($(CPLUSPLUS),201703L)
MYCXXFLAGS=-std=c++17 -DCXX17
endif
MYCXXFLAGS+= $(MYCFLAGS) $(PSQLCH) $(ENABLE_EPOLL)
Expand Down
22 changes: 7 additions & 15 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,12 @@ ifeq ($(UNAME_S),Darwin)
endif


# determine good compiler version for stdc++17
IS_CXX17 := 0
ifeq ($(CXX),clang++)
CLANG_VERSION := $(shell clang -dumpversion | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
CLANG_MIN_VER := $(shell echo 14.0 | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
ifeq ($(CLANG_MIN_VER),$(firstword $(sort $(CLANG_VERSION) $(CLANG_MIN_VER))))
IS_CXX17 := 1
endif
else
GCC_VERSION := $(shell gcc -dumpfullversion 2>/dev/null || gcc -dumpversion | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
GCC_MIN_VER := $(shell echo 8.2.0 | tr '.' ' ' | awk '{ printf("%04d.%04d.%04d", $$1, $$2, $$3) }')
ifeq ($(GCC_MIN_VER),$(firstword $(sort $(GCC_VERSION) $(GCC_MIN_VER))))
IS_CXX17 := 1
# determine compiler support for c++11/17
export CPLUSPLUS=$(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
ifeq ($(CPLUSPLUS),)
export CPLUSPLUS=$(shell ${CC} -std=c++11 -dM -E -x c++ /dev/null 2>/dev/null| grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
ifeq ($(CPLUSPLUS),)
$(error Compiler must support at least c++11)
endif
endif

Expand All @@ -120,7 +113,6 @@ ifeq ($(PROXYSQLCLICKHOUSE),1)
PSQLCH=-DPROXYSQLCLICKHOUSE
endif


WITHGCOVVAR := $(shell echo $(WITHGCOV))
ifeq ($(WITHGCOVVAR),1)
WGCOV=-DWITHGCOV --coverage
Expand All @@ -143,7 +135,7 @@ WASAN+= -DTEST_WITHASAN
endif

MYCXXFLAGS=-std=c++11 -DCXX11
ifeq ($(IS_CXX17),1)
ifeq ($(CPLUSPLUS),201703L)
MYCXXFLAGS=-std=c++17 -DCXX17
endif
ifeq ($(CXX),clang++)
Expand Down

0 comments on commit 1402c7c

Please sign in to comment.