mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-29 15:17:18 +00:00
276 lines
11 KiB
Makefile
276 lines
11 KiB
Makefile
# This makefile is for GNU Make 3.80 or above, and nowadays provided
|
|
# just for compatibility and preservation of traditions.
|
|
#
|
|
# Please use CMake in case of any difficulties or
|
|
# problems with this old-school's magic.
|
|
#
|
|
################################################################################
|
|
#
|
|
# Use `make options` to list the available libmdbx build options.
|
|
#
|
|
# Note that the defaults should already be correct for most platforms;
|
|
# you should not need to change any of these. Read their descriptions
|
|
# in README and source code (see src/options.h) if you do.
|
|
#
|
|
|
|
SHELL := env bash
|
|
|
|
# install sandbox
|
|
DESTDIR ?=
|
|
|
|
# install prefixes (inside sandbox)
|
|
prefix ?= /usr/local
|
|
mandir ?= $(prefix)/man
|
|
|
|
# lib/bin suffix for multiarch/biarch, e.g. '.x86_64'
|
|
suffix ?=
|
|
|
|
INSTALL ?= install
|
|
CC ?= gcc
|
|
CFLAGS_EXTRA ?=
|
|
LD ?= ld
|
|
MDBX_BUILD_OPTIONS ?=-DNDEBUG=1
|
|
MDBX_BUILD_TIMESTAMP ?=$(shell date +%Y-%m-%dT%H:%M:%S%z)
|
|
CFLAGS ?= -std=gnu11 -O2 -g -Wall -Werror -Wextra -Wpedantic -ffunction-sections -fPIC -fvisibility=hidden -pthread -Wno-error=attributes $(CFLAGS_EXTRA)
|
|
# -Wno-tautological-compare
|
|
CXX ?= g++
|
|
# Choosing C++ standard with deferred simple variable expansion trick
|
|
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))
|
|
|
|
# TIP: Try append '--no-as-needed,-lrt' for ability to built with modern glibc, but then use 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")
|
|
|
|
LDFLAGS ?= $(shell $(LD) --help 2>/dev/null | grep -q -- --gc-sections && echo '-Wl,--gc-sections,-z,relro,-O1')$(shell $(LD) --help 2>/dev/null | grep -q -- -dead_strip && echo '-Wl,-dead_strip')
|
|
EXE_LDFLAGS ?= -pthread
|
|
|
|
################################################################################
|
|
|
|
UNAME := $(shell uname -s 2>/dev/null || echo Unknown)
|
|
define uname2sosuffix
|
|
case "$(UNAME)" in
|
|
Darwin*|Mach*) echo dylib;;
|
|
CYGWIN*|MINGW*|MSYS*|Windows*) echo dll;;
|
|
*) echo so;;
|
|
esac
|
|
endef
|
|
SO_SUFFIX := $(shell $(uname2sosuffix))
|
|
HEADERS := mdbx.h mdbx.h++
|
|
LIBRARIES := libmdbx.a libmdbx.$(SO_SUFFIX)
|
|
TOOLS := mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_chk mdbx_drop
|
|
MANPAGES := mdbx_stat.1 mdbx_copy.1 mdbx_dump.1 mdbx_load.1 mdbx_chk.1 mdbx_drop.1
|
|
|
|
.PHONY: all help options lib tools clean install uninstall
|
|
.PHONY: install-strip install-no-strip strip libmdbx mdbx show-options
|
|
|
|
ifeq ("$(origin V)", "command line")
|
|
MDBX_BUILD_VERBOSE := $(V)
|
|
endif
|
|
ifndef MDBX_BUILD_VERBOSE
|
|
MDBX_BUILD_VERBOSE := 0
|
|
endif
|
|
|
|
ifeq ($(MDBX_BUILD_VERBOSE),1)
|
|
QUIET :=
|
|
HUSH :=
|
|
$(info ## TIP: Use `make V=0` for quiet.)
|
|
else
|
|
QUIET := @
|
|
HUSH := >/dev/null
|
|
$(info ## TIP: Use `make V=1` for verbose.)
|
|
endif
|
|
|
|
all: show-options $(LIBRARIES) $(TOOLS)
|
|
|
|
help:
|
|
@echo " make all - build libraries and tools"
|
|
@echo " make help - print this help"
|
|
@echo " make options - list build options"
|
|
@echo " make lib - build libraries"
|
|
@echo " make tools - built tools"
|
|
@echo " make clean "
|
|
@echo " make install "
|
|
@echo " make uninstall "
|
|
@echo ""
|
|
@echo " make strip - strip debug symbols from binaries"
|
|
@echo " make install-no-strip - install explicitly without strip"
|
|
@echo " make install-strip - install explicitly with strip"
|
|
@echo ""
|
|
@echo " make bench - run ioarena-benchmark"
|
|
@echo " make bench-couple - run ioarena-benchmark for mdbx and lmdb"
|
|
@echo " make bench-triplet - run ioarena-benchmark for mdbx, lmdb, sqlite3"
|
|
@echo " make bench-quartet - run ioarena-benchmark for mdbx, lmdb, rocksdb, wiredtiger"
|
|
@echo " make bench-clean - remove temp database(s) after benchmark"
|
|
|
|
show-options:
|
|
@echo " MDBX_BUILD_OPTIONS = $(MDBX_BUILD_OPTIONS)"
|
|
@echo " MDBX_BUILD_TIMESTAMP = $(MDBX_BUILD_TIMESTAMP)"
|
|
@echo '## TIP: Use `make options` to listing available build options.'
|
|
@echo " CFLAGS =$(CFLAGS)"
|
|
@echo " CXXFLAGS =$(CXXFLAGS)"
|
|
@echo " LDFLAGS =$(LDFLAGS) $(LIBS) $(EXE_LDFLAGS)"
|
|
@echo '## TIP: Use `make help` to listing available targets.'
|
|
|
|
options:
|
|
@echo " INSTALL =$(INSTALL)"
|
|
@echo " DESTDIR =$(DESTDIR)"
|
|
@echo " prefix =$(prefix)"
|
|
@echo " mandir =$(mandir)"
|
|
@echo " suffix =$(suffix)"
|
|
@echo ""
|
|
@echo " CC =$(CC)"
|
|
@echo " CFLAGS_EXTRA =$(CFLAGS_EXTRA)"
|
|
@echo " CFLAGS =$(CFLAGS)"
|
|
@echo " CXX =$(CXX)"
|
|
@echo " CXXSTD =$(CXXSTD)"
|
|
@echo " CXXFLAGS =$(CXXFLAGS)"
|
|
@echo ""
|
|
@echo " LD =$(LD)"
|
|
@echo " LDFLAGS =$(LDFLAGS)"
|
|
@echo " EXE_LDFLAGS =$(EXE_LDFLAGS)"
|
|
@echo " LIBS =$(LIBS)"
|
|
@echo ""
|
|
@echo " MDBX_BUILD_OPTIONS = $(MDBX_BUILD_OPTIONS)"
|
|
@echo " MDBX_BUILD_TIMESTAMP = $(MDBX_BUILD_TIMESTAMP)"
|
|
@echo ""
|
|
@echo "## Assortment items for MDBX_BUILD_OPTIONS:"
|
|
@echo "## Note that the defaults should already be correct for most platforms;"
|
|
@echo "## you should not need to change any of these. Read their descriptions"
|
|
@echo "## in README and source code (see mdbx.c) if you do."
|
|
@grep -h '#ifndef MDBX_' mdbx.c | grep -v BUILD | uniq | sed 's/#ifndef / /'
|
|
|
|
lib libmdbx mdbx: libmdbx.a libmdbx.$(SO_SUFFIX)
|
|
|
|
tools: $(TOOLS)
|
|
|
|
strip: all
|
|
@echo ' STRIP libmdbx.$(SO_SUFFIX) $(TOOLS)'
|
|
$(TRACE )strip libmdbx.$(SO_SUFFIX) $(TOOLS)
|
|
|
|
clean:
|
|
@echo ' REMOVE ...'
|
|
$(QUIET)rm -rf $(TOOLS) mdbx_test @* *.[ao] *.[ls]o *.$(SO_SUFFIX) *.dSYM *~ tmp.db/* \
|
|
*.gcov *.log *.err src/*.o test/*.o mdbx_example dist \
|
|
config.h src/config.h src/version.c *.tar*
|
|
|
|
libmdbx.a: mdbx-static.o mdbx++-static.o
|
|
@echo ' AR $@'
|
|
$(QUIET)$(AR) rcs $@ $? $(HUSH)
|
|
|
|
libmdbx.$(SO_SUFFIX): mdbx-dylib.o mdbx++-dylib.o
|
|
@echo ' LD $@'
|
|
$(QUIET)$(CXX) $(CXXFLAGS) $^ -pthread -shared $(LDFLAGS) $(LIBS) -v -o $@
|
|
|
|
|
|
################################################################################
|
|
# Amalgamated source code, i.e. distributed after `make dist`
|
|
MAN_SRCDIR := man1/
|
|
|
|
config.h: mdbx.c $(lastword $(MAKEFILE_LIST))
|
|
@echo ' MAKE $@'
|
|
$(QUIET)(echo '#define MDBX_BUILD_TIMESTAMP "$(MDBX_BUILD_TIMESTAMP)"' \
|
|
&& echo '#define MDBX_BUILD_FLAGS "$(CXXSTD) $(CFLAGS) $(LDFLAGS) $(LIBS)"' \
|
|
&& echo '#define MDBX_BUILD_COMPILER "$(shell (LC_ALL=C $(CC) --version || echo 'Please use GCC or CLANG compatible compiler') | head -1)"' \
|
|
&& echo '#define MDBX_BUILD_TARGET "$(shell set -o pipefail; (LC_ALL=C $(CC) -v 2>&1 | grep -i '^Target:' | cut -d ' ' -f 2- || (LC_ALL=C $(CC) --version | grep -qi e2k && echo E2K) || echo 'Please use GCC or CLANG compatible compiler') | head -1)"' \
|
|
) > $@
|
|
|
|
mdbx-dylib.o: config.h mdbx.c mdbx.h $(lastword $(MAKEFILE_LIST))
|
|
@echo ' CC $@'
|
|
$(QUIET)$(CC) $(CFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -DLIBMDBX_EXPORTS=1 -c mdbx.c -o $@
|
|
|
|
mdbx-static.o: config.h mdbx.c mdbx.h $(lastword $(MAKEFILE_LIST))
|
|
@echo ' CC $@'
|
|
$(QUIET)$(CC) $(CFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -ULIBMDBX_EXPORTS -c mdbx.c -o $@
|
|
|
|
mdbx++-dylib.o: config.h mdbx.c++ mdbx.h mdbx.h++ $(lastword $(MAKEFILE_LIST))
|
|
@echo ' CC $@'
|
|
$(QUIET)$(CXX) $(CXXFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -DLIBMDBX_EXPORTS=1 -c mdbx.c++ -o $@
|
|
|
|
mdbx++-static.o: config.h mdbx.c++ mdbx.h mdbx.h++ $(lastword $(MAKEFILE_LIST))
|
|
@echo ' CC $@'
|
|
$(QUIET)$(CXX) $(CXXFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' -ULIBMDBX_EXPORTS -c mdbx.c++ -o $@
|
|
|
|
mdbx_%: mdbx_%.c libmdbx.a
|
|
@echo ' CC+LD $@'
|
|
$(QUIET)$(CC) $(CFLAGS) $(MDBX_BUILD_OPTIONS) '-DMDBX_CONFIG_H="config.h"' $^ $(EXE_LDFLAGS) $(LIBS) -o $@
|
|
|
|
|
|
install: $(LIBRARIES) $(TOOLS) $(HEADERS)
|
|
@echo ' INSTALLING...'
|
|
$(INSTALL) -D -p $(EXE_INSTALL_FLAGS) -t $(DESTDIR)$(prefix)/bin$(suffix) $(TOOLS) && \
|
|
$(INSTALL) -D -p $(EXE_INSTALL_FLAGS) -t $(DESTDIR)$(prefix)/lib$(suffix) $(filter-out libmdbx.a,$(LIBRARIES)) && \
|
|
$(INSTALL) -D -p -t $(DESTDIR)$(prefix)/lib$(suffix) libmdbx.a && \
|
|
$(INSTALL) -D -p -m 444 -t $(DESTDIR)$(prefix)/include $(HEADERS) && \
|
|
$(INSTALL) -D -p -m 444 -t $(DESTDIR)$(mandir)/man1 $(addprefix $(MAN_SRCDIR), $(MANPAGES))
|
|
|
|
install-strip: EXE_INSTALL_FLAGS = -s
|
|
install-strip: install
|
|
|
|
install-no-strip: EXE_INSTALL_FLAGS =
|
|
install-no-strip: install
|
|
|
|
uninstall:
|
|
@echo ' UNINSTALLING/REMOVE...'
|
|
$(QUIET)rm -f $(addprefix $(DESTDIR)$(prefix)/bin$(suffix)/,$(TOOLS)) \
|
|
$(addprefix $(DESTDIR)$(prefix)/lib$(suffix)/,$(LIBRARIES)) \
|
|
$(addprefix $(DESTDIR)$(prefix)/include/,$(HEADERS)) \
|
|
$(addprefix $(DESTDIR)$(mandir)/man1/,$(MANPAGES))
|
|
|
|
################################################################################
|
|
# Benchmarking by ioarena
|
|
|
|
IOARENA ?= $(shell \
|
|
(test -x ../ioarena/@BUILD/src/ioarena && echo ../ioarena/@BUILD/src/ioarena) || \
|
|
(test -x ../../@BUILD/src/ioarena && echo ../../@BUILD/src/ioarena) || \
|
|
(test -x ../../src/ioarena && echo ../../src/ioarena) || which ioarena 2>&- || \
|
|
echo '\#\# TIP: Clone and build the https://github.com/pmwkaa/ioarena.git within a neighbouring directory for availability of benchmarking.' >&2)
|
|
NN ?= 25000000
|
|
BENCH_CRUD_MODE ?= nosync
|
|
|
|
ifneq ($(wildcard $(IOARENA)),)
|
|
|
|
.PHONY: bench bench-clean bench-couple re-bench bench-quartet bench-triplet
|
|
|
|
bench-clean:
|
|
@echo ' REMOVE bench-*.txt _ioarena/*'
|
|
$(QUIET)rm -rf bench-*.txt _ioarena/*
|
|
|
|
re-bench: bench-clean bench
|
|
|
|
define bench-rule
|
|
bench-$(1)_$(2).txt: $(3) $(IOARENA) $(lastword $(MAKEFILE_LIST))
|
|
@echo ' RUNNING ioarena for $1/$2...'
|
|
$(QUIET)LD_LIBRARY_PATH="./:$$$${LD_LIBRARY_PATH}" \
|
|
$(IOARENA) -D $(1) -B crud -m $(BENCH_CRUD_MODE) -n $(2) \
|
|
| tee $$@ | grep throughput && \
|
|
LD_LIBRARY_PATH="./:$$$${LD_LIBRARY_PATH}" \
|
|
$(IOARENA) -D $(1) -B get,iterate -m $(BENCH_CRUD_MODE) -r 4 -n $(2) \
|
|
| tee -a $$@ | grep throughput \
|
|
|| mv -f $$@ $$@.error
|
|
|
|
endef
|
|
|
|
$(eval $(call bench-rule,mdbx,$(NN),libmdbx.$(SO_SUFFIX)))
|
|
|
|
$(eval $(call bench-rule,sophia,$(NN)))
|
|
$(eval $(call bench-rule,leveldb,$(NN)))
|
|
$(eval $(call bench-rule,rocksdb,$(NN)))
|
|
$(eval $(call bench-rule,wiredtiger,$(NN)))
|
|
$(eval $(call bench-rule,forestdb,$(NN)))
|
|
$(eval $(call bench-rule,lmdb,$(NN)))
|
|
$(eval $(call bench-rule,nessdb,$(NN)))
|
|
$(eval $(call bench-rule,sqlite3,$(NN)))
|
|
$(eval $(call bench-rule,ejdb,$(NN)))
|
|
$(eval $(call bench-rule,vedisdb,$(NN)))
|
|
$(eval $(call bench-rule,dummy,$(NN)))
|
|
bench: bench-mdbx_$(NN).txt
|
|
bench-quartet: bench-mdbx_$(NN).txt bench-lmdb_$(NN).txt bench-rocksdb_$(NN).txt bench-wiredtiger_$(NN).txt
|
|
bench-triplet: bench-mdbx_$(NN).txt bench-lmdb_$(NN).txt bench-sqlite3_$(NN).txt
|
|
bench-couple: bench-mdbx_$(NN).txt bench-lmdb_$(NN).txt
|
|
|
|
# $(eval $(call bench-rule,debug,10))
|
|
# .PHONY: bench-debug
|
|
# bench-debug: bench-debug_10.txt
|
|
|
|
endif
|