Makefile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 jmap jset nfs
  14. # Where make scores puts the results
  15. SCOREDIR=scores/$(shell whoami)/$(shell uname -s)-$(shell uname -m)-$(CC)-$(shell git describe --always --dirty)
  16. ALL=$(filter-out $(EXCLUDE), $(REALLY_ALL))
  17. ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(REALLY_ALL))
  18. # Not all modules have tests.
  19. ALL_TESTS=$(patsubst ccan/%/test/, %, $(foreach dir, $(ALL), $(wildcard ccan/$(dir)/test/)))
  20. # Here's my rough logarithmic timeout graph for my laptop:
  21. #
  22. # 302 -
  23. # | / --*
  24. # | /
  25. # | /
  26. # | /
  27. # |Execution Time, seconds /
  28. # | /
  29. # | ---//
  30. # | /
  31. # | //
  32. # | ---\ ---
  33. # | --- \\ ------
  34. # |----------------- \---
  35. # 19 +------------------------------------------------------+--
  36. # 0 Timeout (ms, logarithmic) 262144
  37. #
  38. # 140
  39. # |
  40. # |------------
  41. # | ---
  42. # | ---------
  43. # | -------
  44. # | --\
  45. # | \\-
  46. # | Tests skipped --\
  47. # | \
  48. # | \\
  49. # | \\\
  50. # | \
  51. # | \----
  52. # --+0---------------------------------------------------==+--
  53. # 0 Timeout (ms, logarithmic) 262144
  54. #
  55. # On my laptop, this runs 574 tests in 40 seconds, vs. a full check which
  56. # runs 676 tests in 260 seconds.
  57. FASTTIMEOUT=750
  58. default: libccan.a
  59. include Makefile-ccan
  60. fastcheck: $(ALL_TESTS:%=summary-fastcheck-%)
  61. check: $(ALL_TESTS:%=summary-check-%)
  62. distclean: clean
  63. rm -f $(ALL_DEPENDS)
  64. scores: $(SCOREDIR)/SUMMARY
  65. $(SCOREDIR)/SUMMARY: $(patsubst ccan/%/_info, $(SCOREDIR)/score-%, $(wildcard ccan/*/_info))
  66. git describe --always > $@
  67. uname -a >> $@
  68. $(CC) -v >> $@
  69. cat $^ | grep 'Total score:' >> $@
  70. $(SCOREDIR)/score-%: ccan/%/_info tools/ccanlint/ccanlint $(OBJFILES)
  71. mkdir -p $(SCOREDIR)
  72. tools/ccanlint/ccanlint -v -s ccan/$* > $@ || true
  73. $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
  74. tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
  75. # Actual dependencies are created in inter-depends
  76. check-%: tools/ccanlint/ccanlint
  77. tools/ccanlint/ccanlint ccan/$*
  78. fastcheck-%: tools/ccanlint/ccanlint
  79. tools/ccanlint/ccanlint --timeout $(FASTTIMEOUT) ccan/$*
  80. # Doesn't test dependencies, doesn't print verbose fail results.
  81. summary-check-%: tools/ccanlint/ccanlint $(OBJFILES)
  82. tools/ccanlint/ccanlint -s ccan/$*
  83. summary-fastcheck-%: tools/ccanlint/ccanlint $(OBJFILES)
  84. tools/ccanlint/ccanlint -x tests_pass_valgrind -x tests_compile_coverage -s ccan/$*
  85. ccan/%/info: ccan/%/_info
  86. $(CC) $(CCAN_CFLAGS) -o $@ -x c $<
  87. libccan.a(%.o): ccan/%.o
  88. $(AR) r $@ $<
  89. clean: tools-clean
  90. $(RM) `find * -name '*.o'` `find * -name '.depends'` `find * -name '*.a'` `find * -name info` `find * -name '*.d'`
  91. $(RM) inter-depends lib-depends test-depends ccan/*-Makefile
  92. # Creates a dependency from the tests to the object files which it needs.
  93. inter-depends: $(ALL_DEPENDS) Makefile
  94. 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 > $@
  95. # Creates dependencies between tests, so if foo depends on bar, bar is tested
  96. # first
  97. test-depends: $(ALL_DEPENDS) Makefile
  98. for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
  99. config.h: tools/configurator/configurator Makefile Makefile-ccan
  100. @tools/configurator/configurator $(CC) $(CCAN_CFLAGS) > config.h
  101. include tools/Makefile
  102. -include inter-depends
  103. -include test-depends
  104. -include Makefile-web