Explorar o código

Package for distribution.

Stefano Cossu %!s(int64=3) %!d(string=hai) anos
pai
achega
52655f6e34
Modificáronse 7 ficheiros con 113 adicións e 64 borrados
  1. 10 0
      .gitmodules
  2. 101 43
      Makefile
  3. 0 4
      ext/lemon/README
  4. 1 0
      ext/re2c
  5. 0 16
      src/codec/Makefile
  6. 0 0
      src/codec/lempar.c
  7. 1 1
      src/codec/nt_lexer.re

+ 10 - 0
.gitmodules

@@ -2,19 +2,29 @@
 	path = ext/xxHash
 	url = https://github.com/Cyan4973/xxHash.git
 	branch = release
+    shallow = true
 [submodule "ext/uuid4"]
 	path = ext/uuid4
 	url = https://github.com/rxi/uuid4.git
+    shallow = true
 [submodule "ext/openldap"]
 	path = ext/openldap
 	url = https://git.openldap.org/openldap/openldap.git
 	branch = mdb.RE/0.9
+    shallow = true
 [submodule "ext/uthash"]
 	path = ext/uthash
 	url = https://github.com/troydhanson/uthash.git
+    shallow = true
 [submodule "ext/log"]
 	path = ext/log
 	url = https://github.com/rxi/log.c.git
+    shallow = true
 [submodule "ext/tpl"]
 	path = ext/tpl
 	url = https://github.com/troydhanson/tpl.git
+    shallow = true
+[submodule "ext/re2c"]
+	path = ext/re2c
+	url = https://github.com/skvadrik/re2c.git
+    shallow = true

+ 101 - 43
Makefile

@@ -1,29 +1,111 @@
-CODEC_DIR = src/codec
+# NOTE: only tested in GNU/Linux.
+
+## Binary dependencies.
+
 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 \
 	-Iext/tpl/src -Iext/uthash/src -Iext/log/src
 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')
 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) \
-		$(CFLAGS) -Werror
-		$(INCLUDE) \
-		$(LIB) \
-		$(SRC) \
-		-o bin/lsup_rdf.so
+		$(CFLAGS) -g3 -DDEBUG \
+		$(INCLUDE) -Itest \
+		test.c -L. $(LDFLAGS) -llsuprdf \
+		-o bin/test
 
 lint:
 	splint \
@@ -33,44 +115,23 @@ lint:
 		-posix-lib \
 		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 \
 	--leak-check=full --show-leak-kinds=all --track-origins=yes \
 	--log-file=/tmp/lsup_valgrind.log \
-	./bin/test && \
+	./bin/test
 	echo "Memcheck complete. Valgrind log is at /tmp/lsup_valgrind.log"
 
 
-memcheck: test valgrind
+memtest: test memcheck
 
 
 profile: build_parsers
 	$(CC) \
 		$(CFLAGS) -g -DTESTING \
 		$(INCLUDE) \
-		$(LIB) \
 		$(SRC) profile.c \
 		-o bin/profile
 
@@ -86,6 +147,3 @@ depgraph: src/* include/*
 	cinclude2dot --merge=module --include=$(DEPS) \
 		--exclude='test|ext' >| $(DOCS)/dev/deps.dot
 	dot $(DOCS)/dev/deps.dot -Tpdf >| $(DOCS)/dev/deps.pdf
-
-
-build_parsers:; $(MAKE) -C $(CODEC_DIR)

+ 0 - 4
ext/lemon/README

@@ -1,4 +0,0 @@
-NOTE: The lempar.c file is not under version control. It is copied from the
-git repository at https://github.com/sqlite/sqlite/blob/master/tool/lempar.c
-Pinned at commit 5e5683ae466667c61aa4cd5127850f080508eab9 (Jan 31, 2021)
-https://github.com/sqlite/sqlite/blob/5e5683ae466667c61aa4cd5127850f080508eab9/tool/lempar.c

+ 1 - 0
ext/re2c

@@ -0,0 +1 @@
+Subproject commit 342e53a71e87dec549a029a815f443fb9cbf66b3

+ 0 - 16
src/codec/Makefile

@@ -1,16 +0,0 @@
-LEXER = /usr/bin/re2c
-PARSER = /usr/bin/lemon
-
-# List of codec to be generated. Each must be prefixed with "_codec".
-codecs = nt_codec# ttl_codec […]
-
-parsers := $(codecs:_codec=_parser.c)
-
-all: $(parsers)
-
-$(parsers): %_parser.c: %_lexer.re %_grammar.c
-	$(LEXER) $< -o $@ -T --case-ranges
-
-%_grammar.c: %_grammar.y
-	$(PARSER) $< -c -q -T../../ext/lemon/lempar.c
-

+ 0 - 0
ext/lemon/lempar.c → src/codec/lempar.c


+ 1 - 1
src/codec/nt_lexer.re

@@ -1,4 +1,4 @@
-#include "src/codec/nt_grammar.h"
+#include "nt_grammar.h"
 #include "nt_parser.h"