|
@@ -1,29 +1,111 @@
|
|
-CODEC_DIR = src/codec
|
|
|
|
|
|
+# NOTE: only tested in GNU/Linux.
|
|
|
|
+
|
|
|
|
+## Binary dependencies.
|
|
|
|
+
|
|
CC = gcc
|
|
CC = gcc
|
|
-CFLAGS += -Wall -DLOG_USE_COLOR
|
|
|
|
|
|
+AR = ar
|
|
|
|
+LEXER = re2c
|
|
|
|
+PARSER = lemon
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+## Paths.
|
|
|
|
+
|
|
|
|
+PREFIX = /usr/local
|
|
|
|
+bindir = $(PREFIX)/bin
|
|
|
|
+libdir = $(PREFIX)/lib
|
|
|
|
+includedir = $(PREFIX)/include/lsup_rdf
|
|
|
|
+
|
|
INCLUDE_BASE = . -Iinclude -Iext/xxHash -Iext/openldap/libraries/liblmdb \
|
|
INCLUDE_BASE = . -Iinclude -Iext/xxHash -Iext/openldap/libraries/liblmdb \
|
|
-Iext/tpl/src -Iext/uthash/src -Iext/log/src
|
|
-Iext/tpl/src -Iext/uthash/src -Iext/log/src
|
|
INCLUDE = -I$(INCLUDE_BASE)
|
|
INCLUDE = -I$(INCLUDE_BASE)
|
|
-LIB = -luuid -lpthread
|
|
|
|
-SRC = ext/xxHash/xxhash.c ext/tpl/src/tpl.c \
|
|
|
|
- ext/openldap/libraries/liblmdb/mdb.c \
|
|
|
|
- ext/openldap/libraries/liblmdb/midl.c ext/log/src/log.c \
|
|
|
|
- src/*.c src/codec/*_grammar.c src/codec/*_parser.c
|
|
|
|
|
|
+CFLAGS += -Wall -fPIC -MMD -DLOG_USE_COLOR $(INCLUDE)
|
|
|
|
+# NOTE: -luuid is a Linux system library. Other OS's might need a different
|
|
|
|
+# link or a non-system library built.
|
|
|
|
+LDFLAGS = -Lext/openldap/libraries/liblmdb -Lext/xxHash \
|
|
|
|
+ -llmdb -lxxhash -luuid -pthread
|
|
|
|
+
|
|
|
|
+CODEC_DIR = src/codec
|
|
|
|
+#CODEC_SRC = $(wildcard src/codec/*_parser.c)
|
|
|
|
+CODEC_SRC = $(wildcard src/codec/*_grammar.c) \
|
|
|
|
+ $(wildcard src/codec/*_parser.c)
|
|
|
|
+CODEC_OBJ = $(CODEC_SRC:.c=.o)
|
|
|
|
+
|
|
|
|
+# External sources compiled in core object.
|
|
|
|
+EXT_SRC = $(wildcard ext/log/src/*.c) \
|
|
|
|
+ $(wildcard ext/tpl/src/*.c)
|
|
|
|
+
|
|
|
|
+SRC = $(EXT_SRC) $(wildcard src/*.c)
|
|
|
|
+#CODEC_OBJ = $(wildcard src/codec/*.o)
|
|
|
|
+OBJ = $(SRC:.c=.o) $(CODEC_OBJ)
|
|
|
|
|
|
|
|
+TEST_SRC = $(wildcard test/*.c) test.c
|
|
|
|
+#TEST_OBJ = $(TEST_SRC:.c=.o)
|
|
|
|
+
|
|
|
|
+DEPLIBS = libxxhash liblmdb
|
|
|
|
+LIBS = liblsuprdf.a liblsuprdf.so
|
|
|
|
+
|
|
|
|
+# For visual dep graph.
|
|
DEPS := $(shell echo "${INCLUDE_BASE}" | sed -e 's/ -I/,/g')
|
|
DEPS := $(shell echo "${INCLUDE_BASE}" | sed -e 's/ -I/,/g')
|
|
DOCS = docs
|
|
DOCS = docs
|
|
|
|
|
|
-.PHONY: build_parsers lint profile
|
|
|
|
|
|
|
|
-default: test
|
|
|
|
|
|
+## Rules.
|
|
|
|
+
|
|
|
|
+all: $(DEPLIBS) $(LIBS)
|
|
|
|
+
|
|
|
|
+liblsuprdf.a: $(OBJ)
|
|
|
|
+ $(AR) rs $@ $^
|
|
|
|
+
|
|
|
|
+liblsuprdf.so: $(OBJ)
|
|
|
|
+ $(CC) -shared $(LDFLAGS) -o $@ $^
|
|
|
|
+
|
|
|
|
+$(CODEC_OBJ): $(CODEC_SRC)
|
|
|
|
+
|
|
|
|
+%_parser.c: %_lexer.re %_grammar.c
|
|
|
|
+ $(LEXER) $< -o $@ -T --case-ranges
|
|
|
|
+
|
|
|
|
+%_grammar.c: %_grammar.y
|
|
|
|
+ $(PARSER) $< -q -m -T$(CODEC_DIR)/lempar.c -d$(CODEC_DIR)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# Build all external dependencies in core object.
|
|
|
|
+core.o: core.c $(EXT_SRC) \
|
|
|
|
+ $(wildcard ext/tpl/*.c) $(wildcard ext/tpl/*.h)
|
|
|
|
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
|
|
|
|
|
|
-build: build_parsers
|
|
|
|
|
|
+
|
|
|
|
+# Ext libraries compiled as shared objects.
|
|
|
|
+
|
|
|
|
+.PHONY: libxxhash
|
|
|
|
+libxxhash:
|
|
|
|
+ $(MAKE) -C ext/xxHash
|
|
|
|
+
|
|
|
|
+.PHONY: liblmdb
|
|
|
|
+liblmdb:
|
|
|
|
+ $(MAKE) -C ext/openldap/libraries/liblmdb
|
|
|
|
+
|
|
|
|
+install: all
|
|
|
|
+ mkdir -p $(DESTDIR)$(libdir)
|
|
|
|
+ mkdir -p $(DESTDIR)$(includedir)
|
|
|
|
+ cp liblsuprdf.* $(DESTDIR)$(libdir) && \
|
|
|
|
+ cp include/*.h $(DESTDIR)$(includedir)
|
|
|
|
+
|
|
|
|
+.PHONY: clean
|
|
|
|
+clean:
|
|
|
|
+ rm -rf src/*.[aod] ./*[aod] src/codec/*[aod]
|
|
|
|
+
|
|
|
|
+.PHONY: uninstall
|
|
|
|
+uninstall:
|
|
|
|
+ rm -f $(DESTDIR)$(libdir)/liblsuprdf.*
|
|
|
|
+ rm -rf $(DESTDIR)$(includedir)
|
|
|
|
+
|
|
|
|
+.PHONY: test
|
|
|
|
+test: all $(TEST_SRC)
|
|
$(CC) \
|
|
$(CC) \
|
|
- $(CFLAGS) -Werror
|
|
|
|
- $(INCLUDE) \
|
|
|
|
- $(LIB) \
|
|
|
|
- $(SRC) \
|
|
|
|
- -o bin/lsup_rdf.so
|
|
|
|
|
|
+ $(CFLAGS) -g3 -DDEBUG \
|
|
|
|
+ $(INCLUDE) -Itest \
|
|
|
|
+ test.c -L. $(LDFLAGS) -llsuprdf \
|
|
|
|
+ -o bin/test
|
|
|
|
|
|
lint:
|
|
lint:
|
|
splint \
|
|
splint \
|
|
@@ -33,44 +115,23 @@ lint:
|
|
-posix-lib \
|
|
-posix-lib \
|
|
test.c
|
|
test.c
|
|
|
|
|
|
-test: build_parsers
|
|
|
|
- $(CC) \
|
|
|
|
- $(CFLAGS) -g3 -DDEBUG \
|
|
|
|
- $(INCLUDE) -Itest \
|
|
|
|
- $(LIB) \
|
|
|
|
- $(SRC) test.c \
|
|
|
|
- -o bin/test
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-test_lexer:
|
|
|
|
- cd src/codec && \
|
|
|
|
- lemon -T/usr/share/lemon/lempar.c nt_grammar.y && \
|
|
|
|
- re2c nt_lexer.re -o nt_codec.c -T --case-ranges && \
|
|
|
|
- cd ../../
|
|
|
|
- $(CC) \
|
|
|
|
- $(CFLAGS) -g3 -DDEBUG \
|
|
|
|
- $(INCLUDE) -I. \
|
|
|
|
- $(LIB) \
|
|
|
|
- $(SRC) src/codec/nt_codec.c src/codec/nt_grammar.c \
|
|
|
|
- -o bin/test_lexer
|
|
|
|
-
|
|
|
|
|
|
|
|
-valgrind:
|
|
|
|
|
|
+.PHONY: memcheck
|
|
|
|
+memcheck:
|
|
valgrind \
|
|
valgrind \
|
|
--leak-check=full --show-leak-kinds=all --track-origins=yes \
|
|
--leak-check=full --show-leak-kinds=all --track-origins=yes \
|
|
--log-file=/tmp/lsup_valgrind.log \
|
|
--log-file=/tmp/lsup_valgrind.log \
|
|
- ./bin/test && \
|
|
|
|
|
|
+ ./bin/test
|
|
echo "Memcheck complete. Valgrind log is at /tmp/lsup_valgrind.log"
|
|
echo "Memcheck complete. Valgrind log is at /tmp/lsup_valgrind.log"
|
|
|
|
|
|
|
|
|
|
-memcheck: test valgrind
|
|
|
|
|
|
+memtest: test memcheck
|
|
|
|
|
|
|
|
|
|
profile: build_parsers
|
|
profile: build_parsers
|
|
$(CC) \
|
|
$(CC) \
|
|
$(CFLAGS) -g -DTESTING \
|
|
$(CFLAGS) -g -DTESTING \
|
|
$(INCLUDE) \
|
|
$(INCLUDE) \
|
|
- $(LIB) \
|
|
|
|
$(SRC) profile.c \
|
|
$(SRC) profile.c \
|
|
-o bin/profile
|
|
-o bin/profile
|
|
|
|
|
|
@@ -86,6 +147,3 @@ depgraph: src/* include/*
|
|
cinclude2dot --merge=module --include=$(DEPS) \
|
|
cinclude2dot --merge=module --include=$(DEPS) \
|
|
--exclude='test|ext' >| $(DOCS)/dev/deps.dot
|
|
--exclude='test|ext' >| $(DOCS)/dev/deps.dot
|
|
dot $(DOCS)/dev/deps.dot -Tpdf >| $(DOCS)/dev/deps.pdf
|
|
dot $(DOCS)/dev/deps.dot -Tpdf >| $(DOCS)/dev/deps.pdf
|
|
-
|
|
|
|
-
|
|
|
|
-build_parsers:; $(MAKE) -C $(CODEC_DIR)
|
|
|