Makefile 5.0 KB

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