Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # NOTE: only tested in GNU/Linux.
  2. ## Binary dependencies.
  3. CC = gcc
  4. AR = ar
  5. LEXER = re2c
  6. PARSER = lemon
  7. ## Paths.
  8. PREFIX = /usr/local
  9. bindir = $(PREFIX)/bin
  10. libdir = $(PREFIX)/lib
  11. includedir = $(PREFIX)/include/lsup_rdf
  12. INCLUDE_BASE = . -Iinclude -Iext/xxHash -Iext/openldap/libraries/liblmdb \
  13. -Iext/tpl/src -Iext/uthash/src -Iext/log/src
  14. INCLUDE = -I$(INCLUDE_BASE)
  15. CFLAGS += -Wall -fPIC -MMD -DLOG_USE_COLOR $(INCLUDE)
  16. TEST_CFLAGS = -Itest -O0 -g3 -DDEBUG
  17. # NOTE: -luuid is a Linux system library. Other OS's might need a different
  18. # link or a non-system library built.
  19. LDFLAGS = -Lext/openldap/libraries/liblmdb -Lext/xxHash \
  20. -llmdb -lxxhash -luuid
  21. CODEC_DIR = src/codec
  22. #CODEC_SRC = $(wildcard src/codec/*_parser.c)
  23. CODEC_SRC = $(wildcard src/codec/*_grammar.c) \
  24. $(wildcard src/codec/*_parser.c)
  25. CODEC_OBJ = $(CODEC_SRC:.c=.o)
  26. # External sources compiled in core object.
  27. EXT_SRC = $(wildcard ext/log/src/*.c) \
  28. $(wildcard ext/tpl/src/*.c)
  29. # External headers of libraries compiled in core.
  30. EXT_H = $(wildcard ext/log/src/*.h) \
  31. $(wildcard ext/tpl/src/*.h) \
  32. $(wildcard ext/uthash/src/*.h)
  33. SRC = $(EXT_SRC) $(wildcard src/*.c)
  34. #CODEC_OBJ = $(wildcard src/codec/*.o)
  35. OBJ = $(SRC:.c=.o) $(CODEC_OBJ)
  36. TEST_SRC = $(wildcard test/*.c) test.c
  37. #TEST_OBJ = $(TEST_SRC:.c=.o)
  38. DEPLIBS = libxxhash liblmdb
  39. LIBS = liblsuprdf.a liblsuprdf.so
  40. # For visual dep graph.
  41. DEPS := $(shell echo "${INCLUDE_BASE}" | sed -e 's/ -I/,/g')
  42. DOCS = docs
  43. ## Rules.
  44. all: $(DEPLIBS) $(LIBS)
  45. liblsuprdf.a: $(OBJ)
  46. $(AR) rs $@ $^
  47. liblsuprdf.so: $(OBJ)
  48. $(CC) -shared $(LDFLAGS) -o $@ $^
  49. $(CODEC_OBJ): $(CODEC_SRC)
  50. %_parser.c: %_lexer.re %_grammar.c
  51. $(LEXER) $< -o $@ -T --case-ranges
  52. %_grammar.c: %_grammar.y
  53. $(PARSER) $< -q -m -T$(CODEC_DIR)/lempar.c -d$(CODEC_DIR)
  54. # Build all external dependencies in core object.
  55. core.o: core.c $(EXT_SRC) $(EXT_H)
  56. $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
  57. # Ext libraries compiled as shared objects.
  58. .PHONY: libxxhash
  59. libxxhash:
  60. $(MAKE) -C ext/xxHash
  61. .PHONY: liblmdb
  62. liblmdb:
  63. $(MAKE) -C ext/openldap/libraries/liblmdb
  64. install: all
  65. mkdir -p $(DESTDIR)$(libdir)
  66. mkdir -p $(DESTDIR)$(includedir)
  67. cp liblsuprdf.* $(DESTDIR)$(libdir) && \
  68. cp include/*.h $(EXT_H) $(DESTDIR)$(includedir)
  69. .PHONY: clean
  70. clean:
  71. rm -rf src/*.[aod] ./*[aod] src/codec/*[aod]
  72. .PHONY: uninstall
  73. uninstall:
  74. rm -f $(DESTDIR)$(libdir)/liblsuprdf.*
  75. rm -rf $(DESTDIR)$(includedir)
  76. bin/test: $(OBJ) $(TEST_SRC) $(DEPLIBS)
  77. $(CC) \
  78. $(CFLAGS) $(TEST_CFLAGS) $(SRC) $(CODEC_SRC) test.c -L. $(LDFLAGS) \
  79. -o bin/test
  80. .PHONY: debug
  81. debug: bin/test
  82. exec gdb bin/test
  83. .PHONY: test
  84. test: bin/test
  85. exec bin/test
  86. lint:
  87. splint \
  88. $(INCLUDE) -Itest \
  89. -DUINT_MAX=0xFFFFFFFFUL \
  90. -nullpass \
  91. -posix-lib \
  92. test.c
  93. .PHONY: memcheck
  94. memcheck:
  95. valgrind \
  96. --leak-check=full --show-leak-kinds=all --track-origins=yes \
  97. --log-file=/tmp/lsup_valgrind.log \
  98. ./bin/test
  99. echo "Memcheck complete. Valgrind log is at /tmp/lsup_valgrind.log"
  100. memtest: test memcheck
  101. profile: build_parsers
  102. $(CC) \
  103. $(CFLAGS) -g -DTESTING \
  104. $(INCLUDE) \
  105. $(SRC) profile.c \
  106. -o bin/profile
  107. py_test:
  108. pip3 install --user . && \
  109. python3 test/cpython_test.py
  110. # Build a visual dependency graph.
  111. # Requires cinclude2dot (https://www.flourish.org/cinclude2dot) and Graphviz.
  112. depgraph: src/* include/*
  113. cinclude2dot --merge=module --include=$(DEPS) \
  114. --exclude='test|ext' >| $(DOCS)/dev/deps.dot
  115. dot $(DOCS)/dev/deps.dot -Tpdf >| $(DOCS)/dev/deps.pdf