Makefile 3.2 KB

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