Makefile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Hacky makefile to compile everything and run the tests in some kind
  2. # of sane order.
  3. # Main targets:
  4. #
  5. # check: run tests on all ccan modules (use 'make check V=--verbose' for more)
  6. # Includes building libccan.a.
  7. # libccan.a: A library with all the ccan modules in it.
  8. # tools: build useful tools in tools/ dir.
  9. # Especially tools/ccanlint/ccanlint and tools/namespacize.
  10. # distclean: destroy everything back to pristine state
  11. # Trying to build the whole repo is usually a lose; there will be some
  12. # dependencies you don't have.
  13. EXCLUDE=wwviaudio ogg_to_pcm
  14. # Anything with an _info file is a module.
  15. ALL=$(filter-out $(EXCLUDE), $(patsubst ccan/%/_info, %, $(wildcard ccan/*/_info)))
  16. ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
  17. # Not all modules have tests.
  18. ALL_TESTS=$(patsubst ccan/%/test/, %, $(foreach dir, $(ALL), $(wildcard ccan/$(dir)/test/)))
  19. # Here's my rough logarithmic timeout graph for my laptop:
  20. #
  21. # 302 -
  22. # | / --*
  23. # | /
  24. # | /
  25. # | /
  26. # |Execution Time, seconds /
  27. # | /
  28. # | ---//
  29. # | /
  30. # | //
  31. # | ---\ ---
  32. # | --- \\ ------
  33. # |----------------- \---
  34. # 19 +------------------------------------------------------+--
  35. # 0 Timeout (ms, logarithmic) 262144
  36. #
  37. # 140
  38. # |
  39. # |------------
  40. # | ---
  41. # | ---------
  42. # | -------
  43. # | --\
  44. # | \\-
  45. # | Tests skipped --\
  46. # | \
  47. # | \\
  48. # | \\\
  49. # | \
  50. # | \----
  51. # --+0---------------------------------------------------==+--
  52. # 0 Timeout (ms, logarithmic) 262144
  53. #
  54. # On my laptop, this runs 574 tests in 40 seconds, vs. a full check which
  55. # runs 676 tests in 260 seconds.
  56. FASTTIMEOUT=750
  57. default: libccan.a
  58. include Makefile-ccan
  59. fastcheck: $(ALL_TESTS:%=summary-fastcheck-%)
  60. check: $(ALL_TESTS:%=summary-check-%)
  61. distclean: clean
  62. rm -f $(ALL_DEPENDS)
  63. $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
  64. tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
  65. # Actual dependencies are created in inter-depends
  66. check-%: tools/ccanlint/ccanlint
  67. tools/ccanlint/ccanlint -d ccan/$*
  68. fastcheck-%: tools/ccanlint/ccanlint
  69. tools/ccanlint/ccanlint -t $(FASTTIMEOUT) -d ccan/$*
  70. # Doesn't test dependencies, doesn't print verbose fail results.
  71. summary-check-%: tools/ccanlint/ccanlint $(OBJFILES)
  72. tools/ccanlint/ccanlint -s -d ccan/$*
  73. summary-fastcheck-%: tools/ccanlint/ccanlint $(OBJFILES)
  74. tools/ccanlint/ccanlint -t $(FASTTIMEOUT) -s -d ccan/$*
  75. ccan/%/info: ccan/%/_info
  76. $(CC) $(CFLAGS) -o $@ -x c $<
  77. libccan.a(%.o): ccan/%.o
  78. $(AR) r $@ $<
  79. clean: tools-clean
  80. $(RM) `find * -name '*.o'` `find * -name '.depends'` `find * -name '*.a'` `find * -name info` `find * -name '*.d'`
  81. $(RM) inter-depends lib-depends test-depends ccan/*-Makefile
  82. # Creates a dependency from the tests to the object files which it needs.
  83. inter-depends: $(ALL_DEPENDS) Makefile
  84. for f in $(ALL_DEPENDS); do echo check-$$(basename $$(dirname $$f) ): $$(for dir in $$(cat $$f) $$(dirname $$f); do [ "$$(echo $$dir/*.c)" = "$$dir/*.c" ] || echo ccan/"$$(basename $$dir)".o; done); done > $@
  85. # Creates dependencies between tests, so if foo depends on bar, bar is tested
  86. # first
  87. test-depends: $(ALL_DEPENDS) Makefile
  88. for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
  89. include tools/Makefile
  90. -include inter-depends
  91. -include test-depends
  92. -include Makefile-web