Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Makefile for CCAN
  2. # 'make quiet=1' builds silently
  3. QUIETEN.1 := @
  4. PRE := $(QUIETEN.$(quiet))
  5. all::
  6. # Our flags for building
  7. WARN_CFLAGS := -Wall -Wstrict-prototypes -Wold-style-definition -Wundef \
  8. -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings
  9. DEP_CFLAGS = -MMD -MP -MF$(@:%=%.d) -MT$@
  10. CCAN_CFLAGS := -g3 -ggdb $(WARN_CFLAGS) -DCCAN_STR_DEBUG=1 -I. $(CFLAGS)
  11. CFLAGS_FORCE_C_SOURCE := -x c
  12. # Anything with an _info file is a module ...
  13. INFO_SRCS := $(wildcard ccan/*/_info ccan/*/*/_info)
  14. ALL_INFOS := $(INFO_SRCS:%_info=%info)
  15. ALL_MODULES := $(ALL_INFOS:%/info=%)
  16. # ... Except stuff that needs external dependencies, which we exclude
  17. EXCLUDE := altstack jmap jset nfs ogg_to_pcm tal/talloc wwviaudio
  18. MODULES:= $(filter-out $(EXCLUDE:%=ccan/%), $(ALL_MODULES))
  19. # Sources are C files in each module, objects the resulting .o files
  20. SRCS := $(wildcard $(MODULES:%=%/*.c))
  21. OBJS := $(SRCS:%.c=%.o)
  22. DEPS := $(OBJS:%=%.d)
  23. # We build all object files using our CCAN_CFLAGS, after config.h
  24. %.o : %.c config.h
  25. $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) -c $< -o $@
  26. # _info files are compiled into executables and don't need dependencies
  27. %info : %_info config.h
  28. $(PRE)$(CC) $(CCAN_CFLAGS) -I. -o $@ $(CFLAGS_FORCE_C_SOURCE) $<
  29. # config.h is built by configurator which has no ccan dependencies
  30. CONFIGURATOR := tools/configurator/configurator
  31. $(CONFIGURATOR): $(CONFIGURATOR).c
  32. $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $< -o $@
  33. config.h: $(CONFIGURATOR) Makefile
  34. $(PRE)$(CONFIGURATOR) $(CC) $(CCAN_CFLAGS) >$@.tmp && mv $@.tmp $@
  35. # Tools
  36. TOOLS := tools/ccan_depends tools/doc_extract tools/namespacize tools/modfiles
  37. TOOLS_SRCS := $(filter-out $(TOOLS:%=%.c), $(wildcard tools/*.c))
  38. TOOLS_DEPS := $(TOOLS_SRCS:%.c=%.d) $(TOOLS:%=%.d)
  39. TOOLS_CCAN_MODULES := err foreach hash htable list noerr opt rbuf \
  40. read_write_all str take tal tal/grab_file tal/link tal/path tal/str time
  41. TOOLS_CCAN_SRCS := $(wildcard $(TOOLS_CCAN_MODULES:%=ccan/%/*.c))
  42. TOOLS_OBJS := $(TOOLS_SRCS:%.c=%.o) $(TOOLS_CCAN_SRCS:%.c=%.o)
  43. tools/% : tools/%.c $(TOOLS_OBJS)
  44. $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $< $(TOOLS_OBJS) -lm -o $@
  45. # ccanlint
  46. LINT := tools/ccanlint/ccanlint
  47. LINT_OPTS.ok := -s
  48. LINT_OPTS.fast-ok := -s -x tests_pass_valgrind -x tests_compile_coverage
  49. LINT_SRCS := $(filter-out $(LINT).c, $(wildcard tools/ccanlint/*.c tools/ccanlint/tests/*.c))
  50. LINT_DEPS := $(LINT_SRCS:%.c=%.d) $(LINT).d
  51. LINT_CCAN_MODULES := asort autodata dgraph ilog lbalance ptr_valid strmap
  52. LINT_CCAN_SRCS := $(wildcard $(LINT_CCAN_MODULES:%=ccan/%/*.c))
  53. LINT_OBJS := $(LINT_SRCS:%.c=%.o) $(LINT_CCAN_SRCS:%.c=%.o) $(TOOLS_OBJS)
  54. ifneq ($(GCOV),)
  55. LINT_GCOV = --gcov="$(GCOV)"
  56. endif
  57. $(LINT): $(LINT).c $(LINT_OBJS)
  58. $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $(LINT).c $(LINT_OBJS) -lm -o $@
  59. # We generate dependencies for tests into a .d file
  60. %/.d: %/info tools/gen_deps.sh tools/ccan_depends
  61. $(PRE)tools/gen_deps.sh $* > $@ || rm -f $@
  62. TEST_DEPS := $(MODULES:%=%/.d)
  63. # We produce .ok files when the tests succeed
  64. %.ok: $(LINT) %info
  65. $(PRE)$(LINT) $(LINT_OPTS.ok) --deps-fail-ignore $(LINT_GCOV) $(LINTFLAGS) $(dir $*) && touch $@
  66. %.fast-ok: $(LINT) %info
  67. $(PRE)$(LINT) $(LINT_OPTS.fast-ok) --deps-fail-ignore $(LINT_GCOV) $(LINTFLAGS) $(dir $*) && touch $@
  68. check: $(MODULES:%=%/.ok)
  69. fastcheck: $(MODULES:%=%/.fast-ok)
  70. ifeq ($(strip $(filter clean config.h, $(MAKECMDGOALS))),)
  71. -include $(DEPS) $(LINT_DEPS) $(TOOLS_DEPS) $(TEST_DEPS)
  72. endif
  73. # Default target: object files, info files and tools
  74. all:: $(OBJS) $(ALL_INFOS) $(CONFIGURATOR) $(LINT) $(TOOLS)
  75. .PHONY: clean TAGS
  76. clean:
  77. $(PRE)find . -name "*.d" -o -name "*.o" -o -name "*.ok" | xargs -n 256 rm -f
  78. $(PRE)rm -f $(CONFIGURATOR) $(LINT) $(TOOLS) TAGS config.h config.h.d $(ALL_INFOS)
  79. # 'make TAGS' builds etags
  80. TAGS:
  81. $(PRE)find * -name '*.[ch]' | xargs etags