Makefile 3.6 KB

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