mdbx: refine & clarify Makefile.

Change-Id: I4e5b388c65872d4cd413d0ff30f232ed0ad2112d
This commit is contained in:
Leo Yuriev 2016-06-01 01:58:23 +03:00
parent daba18111b
commit ba943fcff2

View File

@ -1,4 +1,4 @@
# GNU Makefile for libmdbx (lightning memory-mapped database library for Linux).
# GNU Makefile for libmdbx (reliable lightning memory-mapped DB library for Linux).
########################################################################
# Configuration. The compiler options must enable threaded compilation.
@ -6,58 +6,69 @@
# Preprocessor macros (for XCFLAGS) of interest...
# Note that the defaults should already be correct for most
# platforms; you should not need to change any of these.
# Read their descriptions in mdb.c if you do:
# Read their descriptions in mdb.c if you do. There may be
# other macros of interest. You should read mdb.c
# before changing any of them.
#
# - MDB_USE_ROBUST
#
# There may be other macros in mdb.c of interest. You should
# read mdb.c before changing any of them.
#
DESTDIR ?=
# install sandbox
SANDBOX ?=
# install prefixes (inside sandbox)
prefix ?= /usr/local
mandir ?= $(prefix)/man
# lib/bin suffix for multiarch/biarch, e.g. '.x86_64'
suffix ?=
CC ?= gcc
XCFLAGS ?= -DNDEBUG=1 -DMDB_DEBUG=0
CFLAGS ?= -O2 -g3 -Wall -Werror -Wextra
CFLAGS += -pthread $(XCFLAGS)
# LY: for ability to built with modern glibc,
# but then run with the old
LDOPS ?= -Wl,--no-as-needed,-lrt
# LY: just for benchmarking
IOARENA ?= ../ioarena.git/@BUILD/src/ioarena
########################################################################
IHDRS := lmdb.h mdbx.h
ILIBS := libmdbx.a libmdbx.so
IPROGS := mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_chk
IDOCS := mdb_stat.1 mdb_copy.1 mdb_dump.1 mdb_load.1
PROGS := $(IPROGS) mtest0 mtest1 mtest2 mtest3 mtest4 mtest5 mtest6 wbench
PROGS += yota_test1 yota_test2
HEADERS := lmdb.h mdbx.h
LIBRARIES := libmdbx.a libmdbx.so
TOOLS := mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_chk
MANPAGES := mdb_stat.1 mdb_copy.1 mdb_dump.1 mdb_load.1
TESTS := mtest0 mtest1 mtest2 mtest3 mtest4 mtest5 mtest6 wbench \
yota_test1 yota_test2
SRC_LMDB := mdb.c midl.c lmdb.h midl.h reopen.h barriers.h
SRC_MDBX := $(SRC_LMDB) mdbx.h
.PHONY: mdbx lmdb all install clean check tests coverage
all: $(ILIBS) $(IPROGS)
all: $(LIBRARIES) $(TOOLS)
mdbx: libmdbx.a libmdbx.so
lmdb: liblmdb.a liblmdb.so
install: $(ILIBS) $(IPROGS) $(IHDRS)
mkdir -p $(DESTDIR)$(prefix)/bin \
&& cp -t $(DESTDIR)$(prefix)/bin $(IPROGS) && \
mkdir -p $(DESTDIR)$(prefix)/lib \
&& cp -t $(DESTDIR)$(prefix)/lib $(ILIBS) && \
mkdir -p $(DESTDIR)$(prefix)/include \
&& cp -t $(DESTDIR)$(prefix)/include $(IHDRS) && \
mkdir -p $(DESTDIR)$(mandir)/man1 \
&& cp -t $(DESTDIR)$(mandir)/man1 $(IDOCS)
tools: $(TOOLS)
install: $(LIBRARIES) $(TOOLS) $(HEADERS)
mkdir -p $(SANDBOX)$(prefix)/bin$(suffix) \
&& cp -t $(SANDBOX)$(prefix)/bin$(suffix) $(TOOLS) && \
mkdir -p $(SANDBOX)$(prefix)/lib$(suffix) \
&& cp -t $(SANDBOX)$(prefix)/lib$(suffix) $(LIBRARIES) && \
mkdir -p $(SANDBOX)$(prefix)/include \
&& cp -t $(SANDBOX)$(prefix)/include $(HEADERS) && \
mkdir -p $(SANDBOX)$(mandir)/man1 \
&& cp -t $(SANDBOX)$(mandir)/man1 $(MANPAGES)
clean:
rm -rf $(PROGS) @* *.[ao] *.[ls]o *~ testdb/* *.gcov
rm -rf $(TOOLS )$(TESTS) @* *.[ao] *.[ls]o *~ testdb/* *.gcov
tests: mdbx $(PROGS)
tests: $(TESTS)
check: tests
[ -d testdb ] || mkdir testdb && rm -f testdb/* \
@ -74,28 +85,28 @@ libmdbx.a: mdbx.o
$(AR) rs $@ $^
libmdbx.so: mdbx.lo
$(CC) $(CFLAGS) $(LDFLAGS) -save-temps -pthread -shared -o $@ $^
$(CC) $(CFLAGS) $(LDFLAGS) -save-temps -pthread -shared $(LDOPS) -o $@ $^
liblmdb.a: lmdb.o
$(AR) rs $@ $^
liblmdb.so: lmdb.lo
$(CC) $(CFLAGS) $(LDFLAGS) -pthread -shared -o $@ $^
$(CC) $(CFLAGS) $(LDFLAGS) -pthread -shared $(LDOPS) -o $@ $^
mdbx_stat: mdb_stat.o mdbx.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
$(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^
mdbx_copy: mdb_copy.o mdbx.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
$(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^
mdbx_dump: mdb_dump.o mdbx.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
$(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^
mdbx_load: mdb_load.o mdbx.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
$(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^
mdbx_chk: mdb_chk.o mdbx.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -Wl,--no-as-needed,-lrt
$(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^
mtest0: mtest0.o mdbx.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
@ -125,7 +136,7 @@ yota_test2: yota_test2.o mdbx.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
wbench: wbench.o mdbx.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -Wl,--no-as-needed,-lrt
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
mdbx.o: $(SRC_MDBX)
$(CC) $(CFLAGS) -include mdbx.h -c mdb.c -o $@
@ -145,14 +156,14 @@ lmdb.lo: $(SRC_LMDB)
%.o: %.c lmdb.h mdbx.h
$(CC) $(CFLAGS) -c $<
COV_FLAGS=-fprofile-arcs -ftest-coverage
COFLAGS = -fprofile-arcs -ftest-coverage
@gcov-mdb.o: $(SRC_MDBX)
$(CC) $(CFLAGS) $(COV_FLAGS) -O0 -include mdbx.h -c mdb.c -o $@
$(CC) $(CFLAGS) $(COFLAGS) -O0 -include mdbx.h -c mdb.c -o $@
coverage: @gcov-mdb.o
for t in mtest*.c; do x=`basename \$$t .c`; $(MAKE) $$x.o; \
gcc -o @gcov-$$x $$x.o $^ -pthread $(COV_FLAGS); \
gcc -o @gcov-$$x $$x.o $^ -pthread $(COFLAGS); \
rm -rf testdb; mkdir testdb; ./@gcov-$$x; done
gcov @gcov-mdb