mdbx-make: use deferred simple variable expansion trick for CXXSTD.

Change-Id: I3852ff0af27c828a1ac73344330b4f5fb91e3f1f
This commit is contained in:
Leonid Yuriev 2020-09-20 18:07:33 +03:00
parent 35e9c6decf
commit f2ba1f6fdb
2 changed files with 19 additions and 8 deletions

View File

@ -1,11 +1,19 @@
# This makefile is for GNU Make, and nowadays provided # This makefile is for GNU Make 3.80 or above, and nowadays provided
# just for compatibility and preservation of traditions. # just for compatibility and preservation of traditions.
# Please use CMake in case of any difficulties or problems.
# #
# Preprocessor macros (for MDBX_OPTIONS) of interest... # Please use CMake in case of any difficulties or
# problems with this old-school's magic.
#
################################################################################
#
# Preprocessor macros (for MDBX_OPTIONS) of interest.
#
# Note that the defaults should already be correct for most platforms; # Note that the defaults should already be correct for most platforms;
# you should not need to change any of these. Read their descriptions # you should not need to change any of these. Read their descriptions
# in README and source code if you do. There may be other macros of interest. # in README and source code (see src/options.h) if you do.
# There may be other macros of interest.
#
SHELL := env bash SHELL := env bash
# install sandbox # install sandbox
@ -25,8 +33,9 @@ MDBX_OPTIONS ?= -DNDEBUG=1
CFLAGS ?= -O2 -g -Wall -Werror -Wextra -Wpedantic -ffunction-sections -fPIC -fvisibility=hidden -std=gnu11 -pthread -Wno-error=attributes $(CFLAGS_EXTRA) CFLAGS ?= -O2 -g -Wall -Werror -Wextra -Wpedantic -ffunction-sections -fPIC -fvisibility=hidden -std=gnu11 -pthread -Wno-error=attributes $(CFLAGS_EXTRA)
# -Wno-tautological-compare # -Wno-tautological-compare
CXX ?= g++ CXX ?= g++
CXXSTD ?= $(shell PROBE=$$([ -f mdbx.c++ ] && echo mdbx.c++ || echo src/mdbx.c++); for std in gnu++20 c++20 gnu++2a c++2a gnu++17 c++17 gnu++14 c++14 gnu+11 c++11; do $(CXX) -std=$${std} -c $${PROBE} -o /dev/null 2>/dev/null >/dev/null && echo "-std=$${std}" && exit; done) # choicing C++ standard with deferred simple variable expansion trick
CXXFLAGS:= $(CXXSTD) $(filter-out -std=gnu11,$(CFLAGS)) CXXSTD ?= $(eval CXXSTD := $$(shell PROBE=$$$$([ -f mdbx.c++ ] && echo mdbx.c++ || echo src/mdbx.c++); for std in gnu++20 c++20 gnu++2a c++2a gnu++17 c++17 gnu++14 c++14 gnu+11 c++11; do $(CXX) -std=$$$${std} -c $$$${PROBE} -o /dev/null 2>/dev/null >/dev/null && echo "-std=$$$${std}" && exit; done))$(CXXSTD)
CXXFLAGS = $(CXXSTD) $(filter-out -std=gnu11,$(CFLAGS))
# HINT: Try append '--no-as-needed,-lrt' for ability to built with modern glibc, but then run with the old. # HINT: Try append '--no-as-needed,-lrt' for ability to built with modern glibc, but then run with the old.
LIBS ?= $(shell uname | grep -qi SunOS && echo "-lkstat") $(shell uname | grep -qi -e Darwin -e OpenBSD || echo "-lrt") $(shell uname | grep -qi Windows && echo "-lntdll") LIBS ?= $(shell uname | grep -qi SunOS && echo "-lkstat") $(shell uname | grep -qi -e Darwin -e OpenBSD || echo "-lrt") $(shell uname | grep -qi Windows && echo "-lntdll")
@ -209,7 +218,7 @@ build-test: all mdbx_example mdbx_test
define test-rule define test-rule
$(patsubst %.cc,%.o,$(1)): $(1) $(TEST_INC) mdbx.h $(lastword $(MAKEFILE_LIST)) $(patsubst %.cc,%.o,$(1)): $(1) $(TEST_INC) mdbx.h $(lastword $(MAKEFILE_LIST))
$(CXX) $(CXXFLAGS) $(MDBX_OPTIONS) -c $(1) -o $$@ $$(CXX) $$(CXXFLAGS) $$(MDBX_OPTIONS) -c $(1) -o $$@
endef endef
$(foreach file,$(TEST_SRC),$(eval $(call test-rule,$(file)))) $(foreach file,$(TEST_SRC),$(eval $(call test-rule,$(file))))

View File

@ -1,5 +1,7 @@
# This is thunk-Makefile for calling GNU Make 3.80 or above
all bench bench-quartet build-test check clean clean-bench cross-gcc cross-qemu dist doxygen gcc-analyzer install mdbx memcheck reformat release-assets strip test test-asan test-fault test-leak test-singleprocess test-ubsan test-valgrind tools: all bench bench-quartet build-test check clean clean-bench cross-gcc cross-qemu dist doxygen gcc-analyzer install mdbx memcheck reformat release-assets strip test test-asan test-fault test-leak test-singleprocess test-ubsan test-valgrind tools:
@CC=$(CC) \ @CC=$(CC) \
CXX=`if test -n "$(CXX)" && which "$(CXX)" > /dev/null; then echo "$(CXX)"; elif test -n "$(CCC)" && which "$(CCC)" > /dev/null; then echo "$(CCC)"; else echo "c++"; fi` \ CXX=`if test -n "$(CXX)" && which "$(CXX)" > /dev/null; then echo "$(CXX)"; elif test -n "$(CCC)" && which "$(CCC)" > /dev/null; then echo "$(CCC)"; else echo "c++"; fi` \
`which gmake || which gnumake || echo 'echo "GNU Make is required"; exit 2;'` \ `which gmake || which gnumake || echo 'echo "GNU Make 3.80 or above is required"; exit 2;'` \
$(MAKEFLAGS) -f GNUmakefile $@ $(MAKEFLAGS) -f GNUmakefile $@