Makefile 3.5 KB

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