Просмотр исходного кода

Fix DEBUG envvar issue in Makefile.

scossu 7 часов назад
Родитель
Сommit
27fe7be6ce
4 измененных файлов с 69 добавлено и 70 удалено
  1. 60 62
      Makefile
  2. 3 3
      README.md
  3. 0 0
      bin/.keep
  4. 6 5
      src/codec/Makefile

+ 60 - 62
Makefile

@@ -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."

+ 3 - 3
README.md

@@ -95,11 +95,13 @@ workable set of features as a standalone library:
 - A C compiler. This has been only tested with `gcc` so far.
 - [LMDB](https://symas.com/lmdb/) libraries and headers.
 - [XXHash](https://github.com/Cyan4973/xxHash) >=0.8 libraries and headers.
+
+### Optional dependencies
 - [re2c](https://re2c.org/) to build the RDF language lexers. Only required if
   the codecs are changed. Otherwise, compiled lexers are included in this git
   repo.
 - [cinclude2dot](https://www.flourish.org/cinclude2dot) and
-  [Graphviz](https://graphviz.org/) for generating dependency graph (optional).
+  [Graphviz](https://graphviz.org/) for generating visual dependency graph.
 
 
 ### `make` commands
@@ -125,8 +127,6 @@ make install DEBUG=1 LOCAL=1
 
 Installs the library with debug symbols in `~/.local`.
 
-**FIXME:** At the moment, `make test` needs `DEBUG=1 to run.
-
 
 ### Compile-Time defines (`-D[...]`)
 


+ 6 - 5
src/codec/Makefile

@@ -6,7 +6,7 @@ LEMON_SRC_DIR = $(BASEDIR)/ext/sqlite/tool
 
 INCLUDE_DIR = $(BASEDIR)/include
 CODEC_INCLUDE_DIR = $(INCLUDE_DIR)/volksdata/codec
-BUILDDIR = ../../build
+BUILDDIR = $(BASEDIR)/build
 
 CODEC_SRC = $(wildcard codec_*.c)
 PARSER_SRC = $(CODEC_SRC:codec_%=parser_%)
@@ -19,14 +19,14 @@ PARSER_OBJ := $(subst codec,parser,$(CODEC_OBJ))
 GRAMMAR_OBJ := $(subst codec,grammar,$(CODEC_OBJ))
 OBJ = $(GRAMMAR_OBJ) $(PARSER_OBJ) $(CODEC_OBJ)
 
-INCLUDE := -I$(INCLUDE_DIR) -I../../ext/tpl/src -I../../ext/hashmap \
-	-I../../ext/log/src
+INCLUDE := -I$(INCLUDE_DIR) -I$(BASEDIR)/ext/tpl/src -I$(BASEDIR)/ext/hashmap \
+	-I$(BASEDIR)/ext/log/src
 _CFLAGS := -std=gnu11 -Wall -fPIC $(INCLUDE)
 
 ifneq ($(DEBUG), 0)
-CFLAGS = $(_CFLAGS) -I../../test -O0 -g3 -DDEBUG
+CFLAGS = $(_CFLAGS) -I$(BASEDIR)/test -O0 -g3 -DDEBUG
 else
-CFLAGS = $(_CFLAGS) -O3
+CFLAGS = $(_CFLAGS) -O3 -g0
 endif
 
 $(info CODEC_OBJ: $(CODEC_OBJ))
@@ -57,6 +57,7 @@ parser_%.c: lexer_%.re grammar_%.c ../codec.c
 .PRECIOUS: grammar_%.c $(CODEC_INCLUDE_DIR)/tokens_%.h
 # Parser generators.
 grammar_%.c $(CODEC_INCLUDE_DIR)/tokens_%.h: grammar_%.y
+	mkdir -p $(BUILDDIR)
 	$(PARSER) $< -p -T$(LEMON_SRC_DIR)/lempar.c -d$(BUILDDIR)
 	mv $(BUILDDIR)/grammar_$*.h $(CODEC_INCLUDE_DIR)/tokens_$*.h
 	mv $(BUILDDIR)/grammar_$*.c ./