diff --git a/Makefile b/Makefile index 4b6c3614..fb3db7ba 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,9 @@ suffix ?= CC ?= gcc XCFLAGS ?= -DNDEBUG=1 -DMDB_DEBUG=0 -CFLAGS ?= -O2 -g3 -Wall -Werror -Wextra -ffunction-sections +CFLAGS ?= -O2 -g3 -Wall -Werror -Wextra -ffunction-sections -fPIC CFLAGS += -std=gnu99 -pthread $(XCFLAGS) +COVER ?= -coverage -fprofile-arcs -ftest-coverage -O0 # LY: for ability to built with modern glibc, # but then run with the old @@ -40,10 +41,10 @@ HEADERS := mdbx.h LIBRARIES := libmdbx.a libmdbx.so TOOLS := mdbx_stat mdbx_copy mdbx_dump mdbx_load mdbx_chk MANPAGES := mdbx_stat.1 mdbx_copy.1 mdbx_dump.1 mdbx_load.1 -TESTS := mtest0 mtest1 mtest2 mtest3 mtest4 mtest5 mtest6 wbench \ - yota_test1 yota_test2 +TESTS := test0 test1 test2 test3 test4 test5 test6 test_bench \ + test_yota1 test_yota2 -SRC_MDBX := mdbx.c mdbx.h reopen.h barriers.h +SRC_MDBX := $(add_prefix src/, mdbx.c mdbx.h reopen.h barriers.h midl.h) .PHONY: mdbx all install clean check tests coverage @@ -64,94 +65,46 @@ install: $(LIBRARIES) $(TOOLS) $(HEADERS) && cp -t $(SANDBOX)$(mandir)/man1 $(MANPAGES) clean: - rm -rf $(TOOLS) $(TESTS) @* *.[ao] *.[ls]o *~ testdb/* *.gcov + rm -rf $(TOOLS) $(TESTS) @* *.[ao] *.[ls]o *~ tmp.db/* *.gcov *.log *.err tests: $(TESTS) check: tests - [ -d testdb ] || mkdir testdb && rm -f testdb/* \ - && echo "*** LMDB-TEST-0" && ./mtest0 && ./mdbx_chk -v testdb \ - && echo "*** LMDB-TEST-1" && ./mtest1 && ./mdbx_chk -v testdb \ - && echo "*** LMDB-TEST-2" && ./mtest2 && ./mdbx_chk -v testdb \ - && echo "*** LMDB-TEST-3" && ./mtest3 && ./mdbx_chk -v testdb \ - && echo "*** LMDB-TEST-4" && ./mtest4 && ./mdbx_chk -v testdb \ - && echo "*** LMDB-TEST-5" && ./mtest5 && ./mdbx_chk -v testdb \ - && echo "*** LMDB-TEST-6" && ./mtest6 && ./mdbx_chk -v testdb \ + [ -d tmp.db ] || mkdir tmp.db && rm -f tmp.db/* \ + && echo "*** LMDB-TEST-0" && ./test0 && ./mdbx_chk -v tmp.db \ + && echo "*** LMDB-TEST-1" && ./test1 && ./mdbx_chk -v tmp.db \ + && echo "*** LMDB-TEST-2" && ./test2 && ./mdbx_chk -v tmp.db \ + && echo "*** LMDB-TEST-3" && ./test3 && ./mdbx_chk -v tmp.db \ + && echo "*** LMDB-TEST-4" && ./test4 && ./mdbx_chk -v tmp.db \ + && echo "*** LMDB-TEST-5" && ./test5 && ./mdbx_chk -v tmp.db \ + && echo "*** LMDB-TEST-6" && ./test6 && ./mdbx_chk -v tmp.db \ && echo "*** LMDB-TESTs - all done" +mdbx.o: $(SRC_MDBX) Makefile + $(CC) $(CFLAGS) -c src/mdbx.c -o $@ + libmdbx.a: mdbx.o $(AR) rs $@ $^ -libmdbx.so: mdbx.lo +libmdbx.so: mdbx.o $(CC) $(CFLAGS) $(LDFLAGS) -save-temps -pthread -shared $(LDOPS) -o $@ $^ -mdbx_stat: mdbx_stat.o mdbx.o +mdbx_%: src/mdbx_%.c mdbx.o $(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^ -mdbx_copy: mdbx_copy.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^ +test%: test/test%.c mdbx.o + $(CC) $(CFLAGS) $(LDFLAGS) -Isrc -o $@ $^ -mdbx_dump: mdbx_dump.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^ +gcov-mdbx.o: $(SRC_MDBX) Makefile + $(CC) $(CFLAGS) $(COVER) -c src/mdbx.c -o $@ -mdbx_load: mdbx_load.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^ - -mdbx_chk: mdbx_chk.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) $(LDOPS) -o $@ $^ - -mtest0: mtest0.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -mtest1: mtest1.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -mtest2: mtest2.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -mtest3: mtest3.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -mtest4: mtest4.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -mtest5: mtest5.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -mtest6: mtest6.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -yota_test1: yota_test1.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -yota_test2: yota_test2.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -wbench: wbench.o mdbx.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ - -mdbx.o: $(SRC_MDBX) - $(CC) $(CFLAGS) -c mdbx.c -o $@ - -mdbx.lo: $(SRC_MDBX) - $(CC) $(CFLAGS) -fPIC -c mdbx.c -o $@ - -%: %.o - $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ - -%.o: %.c mdbx.h - $(CC) $(CFLAGS) -c $< - -COFLAGS = -fprofile-arcs -ftest-coverage - -@gcov-mdb.o: $(SRC_MDBX) - $(CC) $(CFLAGS) $(COFLAGS) -O0 -c mdbx.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 $(COFLAGS); \ - rm -rf testdb; mkdir testdb; ./@gcov-$$x; done - gcov @gcov-mdb +# Seem this useless :( +coverage: gcov-mdbx.o + for t in test/test[0-9]*.c; do x=`basename \$$t .c`; \ + $(CC) $(CFLAGS) $(COVER) -Isrc $$t -o gcov-$$x $^; \ + rm -rf tmp.db; mkdir tmp.db; ./gcov-$$x; \ + done + gcov *.gcno ifneq ($(wildcard $(IOARENA)),) diff --git a/barriers.h b/src/barriers.h similarity index 100% rename from barriers.h rename to src/barriers.h diff --git a/mdbx.c b/src/mdbx.c similarity index 100% rename from mdbx.c rename to src/mdbx.c diff --git a/mdbx.h b/src/mdbx.h similarity index 100% rename from mdbx.h rename to src/mdbx.h diff --git a/mdbx_chk.c b/src/mdbx_chk.c similarity index 100% rename from mdbx_chk.c rename to src/mdbx_chk.c diff --git a/mdbx_copy.1 b/src/mdbx_copy.1 similarity index 100% rename from mdbx_copy.1 rename to src/mdbx_copy.1 diff --git a/mdbx_copy.c b/src/mdbx_copy.c similarity index 100% rename from mdbx_copy.c rename to src/mdbx_copy.c diff --git a/mdbx_dump.1 b/src/mdbx_dump.1 similarity index 100% rename from mdbx_dump.1 rename to src/mdbx_dump.1 diff --git a/mdbx_dump.c b/src/mdbx_dump.c similarity index 100% rename from mdbx_dump.c rename to src/mdbx_dump.c diff --git a/mdbx_load.1 b/src/mdbx_load.1 similarity index 100% rename from mdbx_load.1 rename to src/mdbx_load.1 diff --git a/mdbx_load.c b/src/mdbx_load.c similarity index 100% rename from mdbx_load.c rename to src/mdbx_load.c diff --git a/mdbx_stat.1 b/src/mdbx_stat.1 similarity index 100% rename from mdbx_stat.1 rename to src/mdbx_stat.1 diff --git a/mdbx_stat.c b/src/mdbx_stat.c similarity index 100% rename from mdbx_stat.c rename to src/mdbx_stat.c diff --git a/midl.h b/src/midl.h similarity index 100% rename from midl.h rename to src/midl.h diff --git a/reopen.h b/src/reopen.h similarity index 100% rename from reopen.h rename to src/reopen.h diff --git a/mtest0.c b/test/test0.c similarity index 99% rename from mtest0.c rename to test/test0.c index 162cfec9..29037618 100644 --- a/mtest0.c +++ b/test/test0.c @@ -33,7 +33,7 @@ abort())) #ifndef DBPATH -#define DBPATH "./testdb" +#define DBPATH "./tmp.db" #endif void *thread_entry(void *ctx) { diff --git a/mtest1.c b/test/test1.c similarity index 99% rename from mtest1.c rename to test/test1.c index 826462dc..58be6928 100644 --- a/mtest1.c +++ b/test/test1.c @@ -30,7 +30,7 @@ abort())) #ifndef DBPATH -#define DBPATH "./testdb" +#define DBPATH "./tmp.db" #endif int main(int argc, char *argv[]) { diff --git a/mtest2.c b/test/test2.c similarity index 99% rename from mtest2.c rename to test/test2.c index 93caa6e9..2244c7b3 100644 --- a/mtest2.c +++ b/test/test2.c @@ -33,7 +33,7 @@ abort())) #ifndef DBPATH -#define DBPATH "./testdb" +#define DBPATH "./tmp.db" #endif int main(int argc, char *argv[]) { diff --git a/mtest3.c b/test/test3.c similarity index 99% rename from mtest3.c rename to test/test3.c index be46fe06..1f1cacac 100644 --- a/mtest3.c +++ b/test/test3.c @@ -33,7 +33,7 @@ abort())) #ifndef DBPATH -#define DBPATH "./testdb" +#define DBPATH "./tmp.db" #endif int main(int argc, char *argv[]) { diff --git a/mtest4.c b/test/test4.c similarity index 99% rename from mtest4.c rename to test/test4.c index 16aca90c..423535c7 100644 --- a/mtest4.c +++ b/test/test4.c @@ -33,7 +33,7 @@ abort())) #ifndef DBPATH -#define DBPATH "./testdb" +#define DBPATH "./tmp.db" #endif int main(int argc, char *argv[]) { diff --git a/mtest5.c b/test/test5.c similarity index 99% rename from mtest5.c rename to test/test5.c index abca4e72..a482274a 100644 --- a/mtest5.c +++ b/test/test5.c @@ -33,7 +33,7 @@ abort())) #ifndef DBPATH -#define DBPATH "./testdb" +#define DBPATH "./tmp.db" #endif int main(int argc, char *argv[]) { diff --git a/mtest6.c b/test/test6.c similarity index 99% rename from mtest6.c rename to test/test6.c index e7de6ab5..ccd6c93a 100644 --- a/mtest6.c +++ b/test/test6.c @@ -33,7 +33,7 @@ abort())) #ifndef DBPATH -#define DBPATH "./testdb" +#define DBPATH "./tmp.db" #endif char dkbuf[1024]; diff --git a/wbench.c b/test/test_bench.c similarity index 99% rename from wbench.c rename to test/test_bench.c index debb8be9..95dc60d6 100644 --- a/wbench.c +++ b/test/test_bench.c @@ -32,7 +32,7 @@ abort())) #ifndef DBPATH -#define DBPATH "./testdb" +#define DBPATH "./tmp.db" #endif struct t0 { diff --git a/yota_test1.c b/test/test_yota1.c similarity index 100% rename from yota_test1.c rename to test/test_yota1.c diff --git a/yota_test2.c b/test/test_yota2.c similarity index 100% rename from yota_test2.c rename to test/test_yota2.c diff --git a/tutorial/README.md b/tutorial/README.md new file mode 100644 index 00000000..b5218da3 --- /dev/null +++ b/tutorial/README.md @@ -0,0 +1 @@ +This directory is just a placeholder for now. Tutorial and examples will be added later. diff --git a/sample-bdb.txt b/tutorial/sample-bdb.txt similarity index 100% rename from sample-bdb.txt rename to tutorial/sample-bdb.txt diff --git a/sample-mdb.txt b/tutorial/sample-mdb.txt similarity index 100% rename from sample-mdb.txt rename to tutorial/sample-mdb.txt