|
@@ -10,7 +10,7 @@ AR = ar
|
|
|
# Global switches.
|
|
|
# Compile with debug symbols. Libraries are suffixed with _dbg and can coexist
|
|
|
# with non-debug libraries.
|
|
|
-DEBUG ?= 0
|
|
|
+DEBUG := $(filter 1,$(DEBUG))
|
|
|
|
|
|
# Install in a user-owned directory provided as LOCAL_PREFIX or a default
|
|
|
# (~/.local), instead of a system directory.
|
|
@@ -37,11 +37,10 @@ MASSIF_DUMP := $(TMPDIR)/volksdata_massif.out
|
|
|
INCLUDE_BASE := . -Iinclude -Iext/hashmap -Iext/log/src
|
|
|
INCLUDE := -I$(INCLUDE_BASE)
|
|
|
_CFLAGS = -std=gnu11 -Wall -Wextra -fPIC $(INCLUDE)
|
|
|
-ifneq ($(DEBUG), 0) # DEBUG on
|
|
|
-CFLAGS = $(_CFLAGS) -Itest -O0 -ggdb -DDEBUG
|
|
|
-else # DEBUG off
|
|
|
-CFLAGS = $(_CFLAGS) -O3 -g0
|
|
|
-endif
|
|
|
+CFLAGS = $(if $(DEBUG),\
|
|
|
+ $(_CFLAGS) -Itest -O0 -ggdb -DDEBUG,\
|
|
|
+ $(_CFLAGS) -O3 -g0)
|
|
|
+
|
|
|
#$(info CFLAGS: $(CFLAGS))
|
|
|
# NOTE: -luuid is a Linux system library. Other OS's might need a different
|
|
|
# link or a non-system library built.
|
|
@@ -71,19 +70,18 @@ ALL_CODEC_REL_SRC := $(CODEC_REL_SRC) $(CODEC_REL_SRC:codec_%=parser_%) \
|
|
|
$(CODEC_REL_SRC:codec_%=grammar_%)
|
|
|
CODEC_SRC = $(ALL_CODEC_REL_SRC:%=$(CODEC_DIR)/%)
|
|
|
|
|
|
-ifneq ($(DEBUG), 0)
|
|
|
-CODEC_OBJ = $(patsubst $(CODEC_DIR)/%.c, $(BUILDDIR)/%_dbg.o, $(CODEC_SRC))
|
|
|
-else
|
|
|
-CODEC_OBJ = $(patsubst $(CODEC_DIR)/%.c, $(BUILDDIR)/%.o, $(CODEC_SRC))
|
|
|
-endif
|
|
|
+CODEC_OBJ = $(if $(DEBUG),\
|
|
|
+ $(patsubst $(CODEC_DIR)/%.c, $(BUILDDIR)/%_dbg.o, $(CODEC_SRC)),\
|
|
|
+ $(patsubst $(CODEC_DIR)/%.c, $(BUILDDIR)/%.o, $(CODEC_SRC)))
|
|
|
+
|
|
|
+STATIC_LIB = $(if $(DEBUG),\
|
|
|
+ $(BUILDDIR)/libvolksdata_dbg.a,\
|
|
|
+ $(BUILDDIR)/libvolksdata.a)
|
|
|
+
|
|
|
+LOCAL_OBJ = $(if $(DEBUG),\
|
|
|
+ $(VOLK_SRC:src/%.c=$(BUILDDIR)/%_dbg.o),\
|
|
|
+ $(VOLK_SRC:src/%.c=$(BUILDDIR)/%.o))
|
|
|
|
|
|
-ifneq ($(DEBUG), 0) # DEBUG on
|
|
|
-STATIC_LIB = $(BUILDDIR)/libvolksdata_dbg.a
|
|
|
-LOCAL_OBJ = $(VOLK_SRC:src/%.c=$(BUILDDIR)/%_dbg.o)
|
|
|
-else # DEBUG off
|
|
|
-STATIC_LIB = $(BUILDDIR)/libvolksdata.a
|
|
|
-LOCAL_OBJ = $(VOLK_SRC:src/%.c=$(BUILDDIR)/%.o)
|
|
|
-endif
|
|
|
OBJ = $(EXT_OBJ) $(LOCAL_OBJ)
|
|
|
DYN_LIB = $(STATIC_LIB:.a=.so)
|
|
|
|
|
@@ -130,14 +128,14 @@ 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)
|
|
|
+ $(info Static Lib: $(STATIC_LIB))
|
|
|
+ $(info OBJ: $(OBJ))
|
|
|
+ $(AR) rs $(STATIC_LIB) $^ $(CODEC_OBJ)
|
|
|
|
|
|
|
|
|
# Dynamic library.
|
|
|
$(DYN_LIB): $(OBJ)
|
|
|
- $(CC) -shared $(LDFLAGS) -o $@ $^ $(CODEC_OBJ)
|
|
|
+ $(CC) -shared $(LDFLAGS) -o $(DYN_LIB) $^ $(CODEC_OBJ)
|
|
|
|
|
|
|
|
|
# External libraries.
|
|
@@ -198,24 +196,28 @@ uninstall:
|
|
|
|
|
|
|
|
|
bin/test: lib $(TEST_SRC)
|
|
|
+ $(info DEBUG in bin/test: $(DEBUG))
|
|
|
+ $(info OBJ in bin/test: $(OBJ))
|
|
|
+ $(info CFLAGS in bin/test: $(CFLAGS))
|
|
|
$(CC) $(CFLAGS) $(LDFLAGS) -lvolksdata_dbg test.c -o bin/test
|
|
|
|
|
|
|
|
|
.PHONY: test
|
|
|
-test:
|
|
|
- $(MAKE) bin/test DEBUG=1
|
|
|
+test: DEBUG = 1
|
|
|
+test: bin/test
|
|
|
+ $(info DEBUG in test: $(DEBUG))
|
|
|
LD_LIBRARY_PATH=$(BUILDDIR) exec bin/test
|
|
|
|
|
|
|
|
|
.PHONY: gdb_test
|
|
|
-gdb_test: ## Run a test suite within gdb.
|
|
|
- $(MAKE) bin/test DEBUG=1
|
|
|
+gdb_test: DEBUG = 1
|
|
|
+gdb_test: bin/test ## Run a test suite within gdb.
|
|
|
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
|
|
|
+memtest: DEBUG = 1
|
|
|
+memtest: bin/test ## Run test suite within Valgrind and report memory errors.
|
|
|
LD_LIBRARY_PATH=$(BUILDDIR) valgrind \
|
|
|
--leak-check=full --show-leak-kinds=all --track-origins=yes \
|
|
|
--log-file=$(VALGRIND_DUMP) \
|
|
@@ -249,8 +251,8 @@ perftest: bin/perftest ## Run a performance test by creating, inserting and look
|
|
|
|
|
|
|
|
|
.PHONY: profile
|
|
|
-profile: ## Run a profiling session on a limited set of high-volume commands.
|
|
|
- $(MAKE) bin/profile DEBUG=1
|
|
|
+profile: DEBUG = 1
|
|
|
+profile: bin/profile ## Run a profiling session on a limited set of high-volume commands.
|
|
|
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 "\
|
|
@@ -258,8 +260,8 @@ profile: ## Run a profiling session on a limited set of high-volume commands.
|
|
|
|
|
|
|
|
|
.PHONY: test_profile
|
|
|
-test_profile: bin/test ## Run profiling on the standard test suite.
|
|
|
- $(MAKE) bin/profile DEBUG=1
|
|
|
+test_profile: DEBUG = 1
|
|
|
+test_profile: bin/profile ## Run profiling on the standard test suite.
|
|
|
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 "\
|