|
@@ -25,11 +25,10 @@ else
|
|
|
PREFIX ?= /usr/local
|
|
|
endif
|
|
|
|
|
|
-bindir := $(PREFIX)/bin
|
|
|
-libdir := $(PREFIX)/lib
|
|
|
+BINDIR := $(PREFIX)/bin
|
|
|
+LIBDIR := $(PREFIX)/lib
|
|
|
INCLUDEDIR := $(PREFIX)/include
|
|
|
BUILDDIR := ./build
|
|
|
-OUTDIR := ./bin
|
|
|
TMPDIR ?= /tmp
|
|
|
VALGRIND_DUMP := $(TMPDIR)/volksdata_valgrind.log
|
|
|
CALLGRIND_DUMP := $(TMPDIR)/volksdata_callgrind.out
|
|
@@ -37,16 +36,16 @@ MASSIF_DUMP := $(TMPDIR)/volksdata_massif.out
|
|
|
|
|
|
INCLUDE_BASE := . -Iinclude -Iext/hashmap -Iext/log/src
|
|
|
INCLUDE := -I$(INCLUDE_BASE)
|
|
|
-_CFLAGS = -std=gnu11 -Wall -fPIC $(INCLUDE)
|
|
|
-ifneq ($(DEBUG), 0)
|
|
|
+_CFLAGS = -std=gnu11 -Wall -Wextra -fPIC $(INCLUDE)
|
|
|
+ifneq ($(DEBUG), 0) # DEBUG on
|
|
|
CFLAGS = $(_CFLAGS) -Itest -O0 -ggdb -DDEBUG
|
|
|
-else
|
|
|
-CFLAGS = $(_CFLAGS) -O3
|
|
|
+else # DEBUG off
|
|
|
+CFLAGS = $(_CFLAGS) -O3 -g0
|
|
|
endif
|
|
|
-$(info CFLAGS: $(CFLAGS))
|
|
|
+#$(info CFLAGS: $(CFLAGS))
|
|
|
# NOTE: -luuid is a Linux system library. Other OS's might need a different
|
|
|
# link or a non-system library built.
|
|
|
-LDFLAGS := -L$(OUTDIR) -L$(libdir) -L. -llmdb -lxxhash -luuid
|
|
|
+LDFLAGS := -L$(BUILDDIR) -L$(LIBDIR) -llmdb -lxxhash -luuid
|
|
|
|
|
|
PARSER = bin/lemon
|
|
|
LEMON_SRC = ext/sqlite/tool/lemon.c
|
|
@@ -78,11 +77,11 @@ else
|
|
|
CODEC_OBJ = $(patsubst $(CODEC_DIR)/%.c, $(BUILDDIR)/%.o, $(CODEC_SRC))
|
|
|
endif
|
|
|
|
|
|
-ifneq ($(DEBUG), 0)
|
|
|
-STATIC_LIB = $(OUTDIR)/libvolksdata_dbg.a
|
|
|
+ifneq ($(DEBUG), 0) # DEBUG on
|
|
|
+STATIC_LIB = $(BUILDDIR)/libvolksdata_dbg.a
|
|
|
LOCAL_OBJ = $(VOLK_SRC:src/%.c=$(BUILDDIR)/%_dbg.o)
|
|
|
-else
|
|
|
-STATIC_LIB = $(OUTDIR)/libvolksdata.a
|
|
|
+else # DEBUG off
|
|
|
+STATIC_LIB = $(BUILDDIR)/libvolksdata.a
|
|
|
LOCAL_OBJ = $(VOLK_SRC:src/%.c=$(BUILDDIR)/%.o)
|
|
|
endif
|
|
|
OBJ = $(EXT_OBJ) $(LOCAL_OBJ)
|
|
@@ -90,10 +89,10 @@ DYN_LIB = $(STATIC_LIB:.a=.so)
|
|
|
|
|
|
LIBS = $(STATIC_LIB) $(DYN_LIB)
|
|
|
|
|
|
-$(info EXT_SRC: $(EXT_SRC))
|
|
|
-$(info EXT_OBJ: $(EXT_OBJ))
|
|
|
-$(info OBJ: $(OBJ))
|
|
|
-$(info LIBS: $(LIBS))
|
|
|
+#$(info EXT_SRC: $(EXT_SRC))
|
|
|
+#$(info EXT_OBJ: $(EXT_OBJ))
|
|
|
+#$(info OBJ: $(OBJ))
|
|
|
+#$(info LIBS: $(LIBS))
|
|
|
|
|
|
# LDD for Linux, otool -L for OSX.
|
|
|
ifeq (, $(shell which ldd))
|
|
@@ -109,7 +108,7 @@ DOCS = docs
|
|
|
## Environment.
|
|
|
|
|
|
# Tests need the freshly compiled libs.
|
|
|
-export LD_LIBRARY_PATH = $(OUTDIR):$(libdir)
|
|
|
+export LD_LIBRARY_PATH = $(LIBDIR)
|
|
|
|
|
|
|
|
|
## Rules.
|
|
@@ -119,11 +118,10 @@ export LD_LIBRARY_PATH = $(OUTDIR):$(libdir)
|
|
|
# Extract all rule comments into a help message.
|
|
|
.PHONY: help
|
|
|
help:
|
|
|
- @echo "Command overview:"; echo; \
|
|
|
- grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
|
|
|
- | sed -n 's/^\(.*\): \(.*\)##\(.*\)/\1|\3/p' \
|
|
|
- | column -t -s '|'
|
|
|
-
|
|
|
+ @echo "Command overview:"; echo
|
|
|
+ grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
|
|
|
+ | sed -n 's/^\(.*\): \(.*\)##\(.*\)/\1|\3/p' \
|
|
|
+ | column -t -s '|'
|
|
|
|
|
|
|
|
|
.PHONY: lib
|
|
@@ -132,6 +130,8 @@ lib: codec $(LIBS) ## Compile main library (static and dynamic linking).
|
|
|
|
|
|
# Static library.
|
|
|
$(STATIC_LIB): $(OBJ)
|
|
|
+ @echo "DEBUG: $(DEBUG)"
|
|
|
+ @echo "OBJ: $(OBJ)"
|
|
|
$(AR) rs $@ $^ $(CODEC_OBJ)
|
|
|
|
|
|
|
|
@@ -160,57 +160,67 @@ $(BUILDDIR)/%_dbg.o: src/%.c
|
|
|
|
|
|
.PHONY: codec
|
|
|
codec: $(PARSER)
|
|
|
- mkdir -p $(BUILDDIR) && \
|
|
|
+ mkdir -p $(BUILDDIR)
|
|
|
$(MAKE) -C $(CODEC_DIR) codec DEBUG=$(DEBUG)
|
|
|
|
|
|
|
|
|
# Build the parser executable.
|
|
|
$(PARSER): $(LEMON_SRC)
|
|
|
+ mkdir -p $(dir $@)
|
|
|
$(CC) $^ -o $@
|
|
|
|
|
|
|
|
|
-install: lib ## Install library and dependencies to $PREFIX. May require sudo.
|
|
|
+install: lib ## Install library and dependencies to $PREFIX (or, if LOCAL = 1, to $LOCAL_PREFIX). May require sudo.
|
|
|
@echo "Installing library files in $(PREFIX)."
|
|
|
- mkdir -p $(libdir)
|
|
|
+ mkdir -p $(LIBDIR)
|
|
|
mkdir -p $(INCLUDEDIR)/volksdata
|
|
|
- cp $(LIBS) $(libdir) && \
|
|
|
- cp -r include/volksdata/* $(EXT_H) $(INCLUDEDIR)/volksdata && \
|
|
|
- cp include/*.h $(INCLUDEDIR)
|
|
|
+ cp $(LIBS) $(LIBDIR)
|
|
|
+ cp -r include/volksdata/* $(EXT_H) $(INCLUDEDIR)/volksdata
|
|
|
+ cp include/*.h $(INCLUDEDIR)
|
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
-clean: DEBUG = 0
|
|
|
-clean: ## Clean up artifacts, including language parsers.
|
|
|
+clean: ## Clean up artifacts.
|
|
|
rm -rf $(BUILDDIR)
|
|
|
- rm -f bin/*
|
|
|
+
|
|
|
+
|
|
|
+.PHONY: deepclean
|
|
|
+deepclean: clean ## Clean up artifacts, including language parsers that normally are kept.
|
|
|
rm -f include/codec/grammar_*.h
|
|
|
rm -f src/codec/grammar_*.c src/codec/parser_*.c
|
|
|
|
|
|
|
|
|
-.PHONY: uninstall ## Uninstall library (not the dependencies).
|
|
|
+.PHONY: uninstall ## Uninstall library.
|
|
|
uninstall:
|
|
|
- rm -f $(libdir)/libvolksdata*
|
|
|
+ rm -f $(LIBDIR)/libvolksdata*
|
|
|
rm -rf $(INCLUDEDIR)/volksdata*
|
|
|
rm -f bin/test*
|
|
|
|
|
|
|
|
|
-# For testing, use debug symbols.
|
|
|
-bin/test: override DEBUG = 1
|
|
|
bin/test: lib $(TEST_SRC)
|
|
|
- $(CC) $(CFLAGS) $(LDFLAGS) -lvolksdata_dbg \
|
|
|
- test.c -o bin/test
|
|
|
+ $(CC) $(CFLAGS) $(LDFLAGS) -lvolksdata_dbg test.c -o bin/test
|
|
|
|
|
|
|
|
|
.PHONY: test
|
|
|
-test: bin/test ## Run a test suite.
|
|
|
- @echo "Using libraries: "; $(LDD) bin/test
|
|
|
- exec bin/test
|
|
|
+test:
|
|
|
+ $(MAKE) bin/test DEBUG=1
|
|
|
+ LD_LIBRARY_PATH=$(BUILDDIR) exec bin/test
|
|
|
|
|
|
|
|
|
.PHONY: gdb_test
|
|
|
-gdb_test: bin/test ## Run a test suite within gdb.
|
|
|
- @echo "Using libraries: "; $(LDD) bin/test
|
|
|
- exec gdb bin/test
|
|
|
+gdb_test: ## Run a test suite within gdb.
|
|
|
+ $(MAKE) bin/test DEBUG=1
|
|
|
+ LD_LIBRARY_PATH=$(BUILDDIR) exec gdb bin/test
|
|
|
+
|
|
|
+
|
|
|
+.PHONY: memtest
|
|
|
+memtest: ## Run test suite within Valgrind and report memory errors.
|
|
|
+ $(MAKE) bin/test DEBUG=1
|
|
|
+ LD_LIBRARY_PATH=$(BUILDDIR) valgrind \
|
|
|
+ --leak-check=full --show-leak-kinds=all --track-origins=yes \
|
|
|
+ --log-file=$(VALGRIND_DUMP) \
|
|
|
+ ./bin/test || true
|
|
|
+ @echo "Memcheck complete. Valgrind log is at $(VALGRIND_DUMP)"
|
|
|
|
|
|
|
|
|
lint:
|
|
@@ -222,27 +232,13 @@ lint:
|
|
|
test.c
|
|
|
|
|
|
|
|
|
-.PHONY: memcheck
|
|
|
-memcheck:
|
|
|
- valgrind \
|
|
|
- --leak-check=full --show-leak-kinds=all --track-origins=yes \
|
|
|
- --log-file=$(VALGRIND_DUMP) \
|
|
|
- ./bin/test || true
|
|
|
- @echo "Memcheck complete. Valgrind log is at $(VALGRIND_DUMP)"
|
|
|
-
|
|
|
-
|
|
|
-memtest: bin/test memcheck ## Run a test suite using Valgrind. Output to separate file.
|
|
|
-
|
|
|
-
|
|
|
# Profiling application.
|
|
|
-bin/profile: DEBUG = 1
|
|
|
bin/profile: lib profile.c
|
|
|
$(CC) $(CFLAGS) -g -DTESTING $(LDFLAGS) -lvolksdata_dbg \
|
|
|
profile.c -o bin/profile
|
|
|
|
|
|
|
|
|
# Performance test application. Essentially the profiling code without debug.
|
|
|
-bin/perftest: DEBUG = 0
|
|
|
bin/perftest: lib profile.c
|
|
|
$(CC) $(CFLAGS) -g $(LDFLAGS) -lvolksdata profile.c -o bin/perftest
|
|
|
|
|
@@ -253,8 +249,9 @@ perftest: bin/perftest ## Run a performance test by creating, inserting and look
|
|
|
|
|
|
|
|
|
.PHONY: profile
|
|
|
-profile: bin/profile ## Run a profiling session on a limited set of high-volume commands.
|
|
|
- VOLK_MDB_MAPSIZE=800000 valgrind --tool=callgrind \
|
|
|
+profile: ## Run a profiling session on a limited set of high-volume commands.
|
|
|
+ $(MAKE) bin/profile DEBUG=1
|
|
|
+ LD_LIBRARY_PATH=$(BUILDDIR) VOLK_MDB_MAPSIZE=800000 exec valgrind --tool=callgrind \
|
|
|
--callgrind-out-file="$(CALLGRIND_DUMP)" bin/profile 1000
|
|
|
@echo "Profile dump written at $(CALLGRIND_DUMP) . Open it with "\
|
|
|
"qcachegrind, kcachegrind, etc."
|
|
@@ -262,7 +259,8 @@ profile: bin/profile ## Run a profiling session on a limited set of high-volume
|
|
|
|
|
|
.PHONY: test_profile
|
|
|
test_profile: bin/test ## Run profiling on the standard test suite.
|
|
|
- VOLK_MDB_MAPSIZE=800000 valgrind --tool=callgrind \
|
|
|
+ $(MAKE) bin/profile DEBUG=1
|
|
|
+ LD_LIBRARY_PATH=$(BUILDDIR) VOLK_MDB_MAPSIZE=800000 exec valgrind --tool=callgrind \
|
|
|
--callgrind-out-file="$(CALLGRIND_DUMP)" bin/test
|
|
|
@echo "Profile dump written at $(CALLGRIND_DUMP) . Open it with "\
|
|
|
"qcachegrind, kcachegrind, etc."
|
|
@@ -270,7 +268,7 @@ test_profile: bin/test ## Run profiling on the standard test suite.
|
|
|
|
|
|
.PHONY: footprint
|
|
|
footprint: bin/perftest ## Measure memory footprint by generating and storing 100K triples.
|
|
|
- VOLK_MDB_MAPSIZE=80000000 valgrind --tool=massif \
|
|
|
+ LD_LIBRARY_PATH=$(BUILDDIR) VOLK_MDB_MAPSIZE=80000000 exec valgrind --tool=massif \
|
|
|
--massif-out-file=$(MASSIF_DUMP) bin/perftest 100000
|
|
|
@echo "Memory stats file written at $(MASSIF_DUMP). Open it with "\
|
|
|
"massif-visualizer or similar."
|