Makefile 3.7 KB

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