Explorar el Código

Merge branch 'master' of ktx_git:scossu/lsup_rdf

scossu hace 1 semana
padre
commit
e45ec2802d

+ 36 - 25
Makefile

@@ -13,22 +13,23 @@ AR = ar
 PREFIX ?= /usr/local
 bindir := $(PREFIX)/bin
 libdir := $(PREFIX)/lib
-includedir = $(PREFIX)/include/lsup
-outdir = ./bin
+INCLUDEDIR = $(PREFIX)/include
+BUILDDIR = ./build
+OUTDIR = ./bin
 VALGRIND_DUMP = /tmp/lsup_valgrind.log
 CALLGRIND_DUMP = /tmp/lsup_callgrind.out
 MASSIF_DUMP = /tmp/lsup_massif.out
 
 INCLUDE_BASE := . -Iinclude -Iext/tpl/src -Iext/hashmap -Iext/log/src
 INCLUDE := -I$(INCLUDE_BASE)
-_CFLAGS := -std=gnu11 -Wall -fPIC -MMD $(INCLUDE)
+_CFLAGS := -std=gnu11 -Wall -fPIC $(INCLUDE)
 CFLAGS = $(_CFLAGS) -O3
-DBG_CFLAGS = $(_CFLAGS) -Itest -O0 -g3 -DDEBUG
+DBG_CFLAGS = $(_CFLAGS) -Itest -O0 -ggdb -DDEBUG
 #$(info CFLAGS: $(CFLAGS))
 #$(info DBG_CFLAGS: $(DBG_CFLAGS))
 # NOTE: -luuid is a Linux system library. Other OS's might need a different
 # link or a non-system library built.
-LDFLAGS := -L$(libdir) -L$(outdir) -L. -llmdb -lxxhash -luuid
+LDFLAGS := -L$(libdir) -L$(OUTDIR) -L. -llmdb -lxxhash -luuid
 
 PARSER = bin/lemon
 LEMON_SRC = ext/sqlite/tool/lemon.c
@@ -55,15 +56,17 @@ CODEC_REL_SRC := $(CODEC_SRC:$(CODEC_DIR)/%=%)
 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)/%)
-CODEC_OBJ = $(CODEC_SRC:.c=.o)
-CODEC_DBG_OBJ = $(CODEC_SRC:.c=_dbg.o)
-OBJ = $(EXT_OBJ) $(LSUP_SRC:.c=.o)
-DBG_OBJ = $(EXT_OBJ) $(LSUP_SRC:.c=_dbg.o)
-
-STATIC_LIB = $(outdir)/liblsuprdf.a
-DYN_LIB = $(outdir)/liblsuprdf.so
-STATIC_DBG_LIB = $(outdir)/liblsuprdf_dbg.a
-DYN_DBG_LIB = $(outdir)/liblsuprdf_dbg.so
+
+CODEC_OBJ = $(patsubst $(CODEC_DIR)/%.c, $(BUILDDIR)/%.o, $(CODEC_SRC))
+CODEC_DBG_OBJ = $(CODEC_OBJ:.o=_dbg.o)
+LOCAL_OBJ = $(LSUP_SRC:src/%.c=$(BUILDDIR)/%.o)
+OBJ = $(EXT_OBJ) $(LOCAL_OBJ)
+DBG_OBJ = $(EXT_OBJ) $(LOCAL_OBJ)
+STATIC_LIB = $(OUTDIR)/liblsuprdf.a
+DYN_LIB = $(STATIC_LIB:.a=.so)
+STATIC_DBG_LIB = $(STATIC_LIB:.a=_dbg.a)
+DYN_DBG_LIB = $(DYN_LIB:.so=_dbg.so)
+
 LIBS = $(STATIC_LIB) $(DYN_LIB)
 DBG_LIBS = $(STATIC_DBG_LIB) $(DYN_DBG_LIB)
 
@@ -82,7 +85,7 @@ DOCS = docs
 ## Environment.
 
 # Tests need the freshly compiled libs.
-export LD_LIBRARY_PATH = $(outdir):$(libdir)
+export LD_LIBRARY_PATH = $(OUTDIR):$(libdir)
 
 
 ## Rules.
@@ -127,8 +130,13 @@ $(DYN_DBG_LIB): $(DBG_OBJ)
 	$(CC) -shared $(LDFLAGS) -o $@ $^ $(CODEC_DBG_OBJ)
 
 
+# Standard objects.
+$(BUILDDIR)/%.o: src/%.c
+	$(CC) $(DBG_CFLAGS) -c $^ -o $@
+
+
 # Debug objects.
-%_dbg.o: %.c
+$(BUILDDIR)/%_dbg.o: src/%.c
 	$(CC) $(DBG_CFLAGS) -c $^ -o $@
 
 
@@ -136,10 +144,12 @@ $(DYN_DBG_LIB): $(DBG_OBJ)
 
 .PHONY: codec
 codec: $(PARSER)
+	mkdir -p $(BUILDDIR) && \
 	$(MAKE) -C $(CODEC_DIR) codec
 
 .PHONY: codec_dbg
 codec_dbg: $(PARSER)
+	mkdir -p $(BUILDDIR) && \
 	$(MAKE) -C $(CODEC_DIR) debug
 
 # Build the parser executable.
@@ -149,21 +159,22 @@ $(PARSER): $(LEMON_SRC)
 
 install: lib ## Install library and dependencies to $PREFIX. May require sudo.
 	@echo "Installing library files in $(PREFIX)."
-	mkdir -p $(DESTDIR)$(libdir)
-	mkdir -p $(DESTDIR)$(includedir)
-	cp $(LIBS) $(DESTDIR)$(libdir) && \
-		cp -r include/*.h include/codec $(EXT_H) $(DESTDIR)$(includedir)
+	mkdir -p $(libdir)
+	mkdir -p $(INCLUDEDIR)/lsup
+	cp $(LIBS) $(libdir) && \
+		cp -r include/lsup/* $(EXT_H) $(INCLUDEDIR)/lsup && \
+		cp include/*.h $(INCLUDEDIR)
 
 
 debug_install: install debug ## Install standard and debug libraries.
 	@echo "Installing debug library files in $(PREFIX)."
-	cp $(DBG_LIBS) $(DESTDIR)$(libdir)
+	cp $(DBG_LIBS) $(libdir)
 
 
 .PHONY: clean
 clean: ## Clean up artifacts, including language parsers.
-	rm -f ./*.[aod] bin/* src/*.[aod] src/codec/*.[aod] src/codec/*.out
-	rm -rf build/ dist/ lsup_rdf.egg-info/
+	rm -f ./*.[aod] bin/* src/codec/*.out
+	rm -rf $(BUILDDIR)
 	rm -f $(LIBS) $(DBG_LIBS)
 	rm -f include/codec/grammar_*.h
 	rm -f src/codec/grammar_*.c src/codec/parser_*.c
@@ -172,8 +183,8 @@ clean: ## Clean up artifacts, including language parsers.
 
 .PHONY: uninstall ## Uninstall library (not the dependencies).
 uninstall:
-	rm -f $(DESTDIR)$(libdir)/liblsuprdf*
-	rm -rf $(DESTDIR)$(includedir)
+	rm -f $(libdir)/liblsuprdf*
+	rm -rf $(INCLUDEDIR)/lsup*
 	rm -f bin/test*
 
 

+ 1 - 1
include/buffer.h → include/lsup/buffer.h

@@ -1,7 +1,7 @@
 #ifndef _LSUP_BUFFER_H
 #define _LSUP_BUFFER_H
 
-#include "core.h"
+#include "lsup/core.h"
 
 /** @defgroup buffer Buffer module
  * @ingroup public

+ 1 - 1
include/codec.h → include/lsup/codec.h

@@ -1,7 +1,7 @@
 #ifndef _LSUP_CODEC_BASE_H
 #define _LSUP_CODEC_BASE_H
 
-#include "graph.h"
+#include "lsup/graph.h"
 
 /** @defgroup codec RDF codec module
  * @ingroup private

+ 0 - 0
include/codec/codec_nt.h → include/lsup/codec/codec_nt.h


+ 0 - 0
include/codec/codec_ttl.h → include/lsup/codec/codec_ttl.h


+ 0 - 0
include/codec/parser_nt.h → include/lsup/codec/parser_nt.h


+ 0 - 0
include/codec/parser_ttl.h → include/lsup/codec/parser_ttl.h


+ 7 - 0
include/lsup/codec/tokens_nt.h

@@ -0,0 +1,7 @@
+#define T_EOF                              1
+#define T_DOT                              2
+#define T_IRIREF                           3
+#define T_BNODE                            4
+#define T_LITERAL                          5
+#define T_EOL                              6
+#define T_WS                               7

+ 23 - 0
include/lsup/codec/tokens_ttl.h

@@ -0,0 +1,23 @@
+#define T_PERIOD                           1
+#define T_SEMICOLON                        2
+#define T_COMMA                            3
+#define T_STRING                           4
+#define T_INTEGER                          5
+#define T_DOUBLE                           6
+#define T_DECIMAL                          7
+#define T_BOOLEAN                          8
+#define T_QNAME                            9
+#define T_BNODE_ID                        10
+#define T_IRIREF                          11
+#define T_LANGTAG                         12
+#define T_PREFIX                          13
+#define T_COLON                           14
+#define T_EOF                             15
+#define T_WS                              16
+#define T_BASE                            17
+#define T_RDF_TYPE                        18
+#define T_DTYPE_MARKER                    19
+#define T_LBRACKET                        20
+#define T_RBRACKET                        21
+#define T_LPAREN                          22
+#define T_RPAREN                          23

+ 0 - 0
include/core.h → include/lsup/core.h


+ 0 - 0
include/data/bootstrap.h → include/lsup/data/bootstrap.h


+ 1 - 1
include/environment.h → include/lsup/environment.h

@@ -12,7 +12,7 @@
 #define _LSUP_ENVIRONMENT_H
 
 
-#include "term.h"
+#include "lsup/term.h"
 
 
 /**@defgroup environment Environment module

+ 3 - 3
include/graph.h → include/lsup/graph.h

@@ -1,9 +1,9 @@
 #ifndef _LSUP_GRAPH_H
 #define _LSUP_GRAPH_H
 
-#include "store.h"
-#include "environment.h"
-#include "term.h"
+#include "lsup/store.h"
+#include "lsup/environment.h"
+#include "lsup/term.h"
 
 
 /** @defgroup graph RDF graph module

+ 0 - 0
include/namespace.h → include/lsup/namespace.h


+ 2 - 2
include/store.h → include/lsup/store.h

@@ -16,8 +16,8 @@
 /*
  * Add new back end headers here.
  */
-#include "store_htable.h"
-#include "store_mdb.h"
+#include "lsup/store_htable.h"
+#include "lsup/store_mdb.h"
 
 /** @defgroup store Backend store module
  * @ingroup public

+ 2 - 2
include/store_htable.h → include/lsup/store_htable.h

@@ -20,8 +20,8 @@
 #ifndef _LSUP_STORE_HTABLE_H
 #define _LSUP_STORE_HTABLE_H
 
-#include "buffer.h"
-#include "store_interface.h"
+#include "lsup/buffer.h"
+#include "lsup/store_interface.h"
 
 
 extern const LSUP_StoreInt htstore_int;

+ 1 - 1
include/store_interface.h → include/lsup/store_interface.h

@@ -35,7 +35,7 @@
 #ifndef _LSUP_STORE_INTERFACE_H
 #define _LSUP_STORE_INTERFACE_H
 
-#include "environment.h"
+#include "lsup/environment.h"
 
 
 /** @defgroup store_interface Store interface module

+ 2 - 2
include/store_mdb.h → include/lsup/store_mdb.h

@@ -28,8 +28,8 @@
 
 #include "lmdb.h"
 
-#include "buffer.h"
-#include "store_interface.h"
+#include "lsup/buffer.h"
+#include "lsup/store_interface.h"
 
 
 // FIXME find a better cross-platform path.

+ 3 - 3
include/term.h → include/lsup/term.h

@@ -1,10 +1,10 @@
 #ifndef _LSUP_TERM_H
 #define _LSUP_TERM_H
 
-#include <assert.h>
+//#include <assert.h>
 
-#include "buffer.h"
-#include "namespace.h"
+#include "lsup/buffer.h"
+#include "lsup/namespace.h"
 
 /** @defgroup term RDF term and triple module
  * @ingroup public

+ 2 - 2
include/lsup_rdf.h

@@ -1,7 +1,7 @@
 #ifndef _LSUP_RDF_H
 #define _LSUP_RDF_H
 
-#include "codec/codec_nt.h"
-#include "codec/codec_ttl.h"
+#include "lsup/codec/codec_nt.h"
+#include "lsup/codec/codec_ttl.h"
 
 #endif  // _LSUP_RDF_H

+ 1 - 1
src/buffer.c

@@ -1,4 +1,4 @@
-#include "buffer.h"
+#include "lsup/buffer.h"
 
 /* * * Inline extern prototypes * * */
 

+ 1 - 1
src/codec.c

@@ -1,4 +1,4 @@
-#include "codec.h"
+#include "lsup/codec.h"
 
 
 /** @brief List of characters to be escaped in serialized literals.

+ 21 - 12
src/codec/Makefile

@@ -5,20 +5,25 @@ PARSER = $(BASEDIR)/bin/lemon
 LEMON_SRC_DIR = $(BASEDIR)/ext/sqlite/tool
 
 INCLUDE_DIR = $(BASEDIR)/include
-CODEC_INCLUDE_DIR = $(INCLUDE_DIR)/codec
-
-CODEC_SRC := $(wildcard codec_*.c)
-PARSER_SRC := $(CODEC_SRC:codec_%=parser_%)
-CODEC_OBJ := $(CODEC_SRC:.c=.o)
-PARSER_OBJ := $(CODEC_OBJ:codec_%=parser_%)
-GRAMMAR_OBJ := $(CODEC_OBJ:codec_%=grammar_%)
+CODEC_INCLUDE_DIR = $(INCLUDE_DIR)/lsup/codec
+BUILDDIR = ../../build
+
+CODEC_SRC = $(wildcard codec_*.c)
+PARSER_SRC = $(CODEC_SRC:codec_%=parser_%)
+CODEC_OBJ := $(CODEC_SRC:%.c=$(BUILDDIR)/%.o)
+PARSER_OBJ := $(subst codec,parser,$(CODEC_OBJ))
+GRAMMAR_OBJ := $(subst codec,grammar,$(CODEC_OBJ))
 OBJ = $(GRAMMAR_OBJ) $(PARSER_OBJ) $(CODEC_OBJ)
 DBG_OBJ = $(OBJ:%.o=%_dbg.o)
-$(info DBG_OBJ: $(DBG_OBJ))
+
+#$(info CODEC_OBJ: $(CODEC_OBJ))
+#$(info GRAMMAR_OBJ: $(GRAMMAR_OBJ))
+#$(info PARSER_OBJ: $(PARSER_OBJ))
+#$(info DBG_OBJ: $(DBG_OBJ))
 
 INCLUDE := -I$(INCLUDE_DIR) -I../../ext/tpl/src -I../../ext/hashmap \
 	-I../../ext/log/src
-CFLAGS = -std=gnu11 -Wall -fPIC -MMD $(INCLUDE)
+CFLAGS = -std=gnu11 -Wall -fPIC $(INCLUDE)
 DBG_CFLAGS = -I../../test -O0 -g3 -DDEBUG
 
 .DEFAULT_GOAL := codec
@@ -32,7 +37,10 @@ debug: $(DBG_OBJ)
 .PHONY: parsers
 parsers: $(PARSER_SRC)
 
-%_dbg.o: %.c
+$(BUILDDIR)/%.o: %.c
+	$(CC) $(CFLAGS) $(DBG_CFLAGS) -c $^ -o $@
+
+$(BUILDDIR)/%_dbg.o: %.c
 	$(CC) $(CFLAGS) $(DBG_CFLAGS) -c $^ -o $@
 
 # Parser C sources.
@@ -43,5 +51,6 @@ 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
-	$(PARSER) $< -p -T$(LEMON_SRC_DIR)/lempar.c -d.
-	mv grammar_$*.h $(CODEC_INCLUDE_DIR)/tokens_$*.h
+	$(PARSER) $< -p -T$(LEMON_SRC_DIR)/lempar.c -d$(BUILDDIR)
+	mv $(BUILDDIR)/grammar_$*.h $(CODEC_INCLUDE_DIR)/tokens_$*.h
+	mv $(BUILDDIR)/grammar_$*.c ./

+ 1 - 1
src/codec/codec_nt.c

@@ -1,4 +1,4 @@
-#include "codec/codec_nt.h"
+#include "lsup/codec/codec_nt.h"
 
 
 /// NT codec iterator type.

+ 1 - 1
src/codec/codec_ttl.c

@@ -1,4 +1,4 @@
-#include "codec/codec_ttl.h"
+#include "lsup/codec/codec_ttl.h"
 
 
 /** @brief NT codec iterator.

+ 1 - 1
src/codec/grammar_nt.y

@@ -8,7 +8,7 @@
  * To generate the parser, run: `lemon ${FILE}'
  */
 
-#include "codec.h"
+#include "lsup/codec.h"
 }
 
 %name NTParse

+ 1 - 1
src/codec/grammar_ttl.y

@@ -8,7 +8,7 @@
  * TTL EBNF: https://www.w3.org/TeamSubmission/turtle/#sec-grammar-grammar
  */
 
-#include "codec.h"
+#include "lsup/codec.h"
 
 }
 

+ 2 - 2
src/codec/lexer_nt.re

@@ -1,5 +1,5 @@
-#include "codec/parser_nt.h"
-#include "codec/tokens_nt.h"
+#include "lsup/codec/parser_nt.h"
+#include "lsup/codec/tokens_nt.h"
 
 
 #define YYCTYPE     uint8_t

+ 2 - 2
src/codec/lexer_ttl.re

@@ -1,5 +1,5 @@
-#include "codec/parser_ttl.h"
-#include "codec/tokens_ttl.h"
+#include "lsup/codec/parser_ttl.h"
+#include "lsup/codec/tokens_ttl.h"
 
 
 /** @brief TTL is UTF-8 encoded.

+ 2 - 1
src/core.c

@@ -2,7 +2,8 @@
 #include <errno.h>
 #include <ftw.h>
 #include <string.h>
-#include "core.h"
+
+#include "lsup/core.h"
 #include "lmdb.h"
 
 

+ 2 - 2
src/environment.c

@@ -1,5 +1,5 @@
-#include "environment.h"
-#include "data/bootstrap.h"
+#include "lsup/environment.h"
+#include "lsup/data/bootstrap.h"
 
 
 /** @brief Default context.

+ 1 - 1
src/graph.c

@@ -1,4 +1,4 @@
-#include "graph.h"
+#include "lsup/graph.h"
 
 /*
  * Data types.

+ 2 - 2
src/namespace.c

@@ -1,5 +1,5 @@
-#include "core.h"
-#include "namespace.h"
+#include "lsup/core.h"
+#include "lsup/namespace.h"
 
 
 /** @brief Prefix / Namespace pair.

+ 1 - 1
src/store.c

@@ -1,4 +1,4 @@
-#include "store.h"
+#include "lsup/store.h"
 
 
 #define ENTRY(a, b) case LSUP_STORE_##a: return &b;

+ 1 - 1
src/store_htable.c

@@ -1,6 +1,6 @@
 #include "hashmap.h"
 
-#include "store_htable.h"
+#include "lsup/store_htable.h"
 
 
 /**

+ 1 - 1
src/store_mdb.c

@@ -1,4 +1,4 @@
-#include "store_mdb.h"
+#include "lsup/store_mdb.h"
 
 /**
  * Number of DBs defined. See MAIN_TABLE and LOOKUP_TABLE defines below.

+ 1 - 1
src/term.c

@@ -1,6 +1,6 @@
 #include "tpl.h"
 
-#include "term.h"
+#include "lsup/term.h"
 
 /** @brief tpl packing format for a term.
  *

+ 1 - 1
test/test_codec_nt.c

@@ -1,5 +1,5 @@
+#include "lsup/codec/codec_nt.h"
 #include "test.h"
-#include "codec/codec_nt.h"
 
 #define TERM_CT 11
 #define TRP_CT 8

+ 1 - 1
test/test_codec_ttl.c

@@ -1,5 +1,5 @@
+#include "lsup/codec/codec_ttl.h"
 #include "test.h"
-#include "codec/codec_ttl.h"
 
 #define W3C_POS_TEST_CT 30
 #define W3C_NEG_TEST_CT 14

+ 1 - 1
test/test_graph.c

@@ -1,5 +1,5 @@
+#include "lsup/graph.h"
 #include "test.h"
-#include "graph.h"
 #include "assets/triples.h"
 
 #define N_LUT 13

+ 1 - 1
test/test_namespace.c

@@ -1,5 +1,5 @@
+#include "lsup/namespace.h"
 #include "test.h"
-#include "namespace.h"
 
 static int
 test_namespace()

+ 2 - 2
test/test_store.c

@@ -1,6 +1,6 @@
-#include "test.h"
-#include "store.h"
+#include "lsup/store.h"
 #include "assets/triples.h"
+#include "test.h"
 
 
 #define STORE_ID_MDB "file:///tmp/testdb";

+ 1 - 1
test/test_store_ht.c

@@ -1,5 +1,5 @@
+#include "lsup/store_htable.h"
 #include "test.h"
-#include "store_htable.h"
 #include "assets/triples.h"
 
 /** @brief Test hash table store.

+ 1 - 1
test/test_store_mdb.c

@@ -1,7 +1,7 @@
 #include <unistd.h>
 
+#include "lsup/store_mdb.h"
 #include "test.h"
-#include "store_mdb.h"
 
 
 #define MDBSTORE_ID "file:///tmp/testdb"