Makefile 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. ALL=$(patsubst ccan/%/test, %, $(wildcard ccan/*/test))
  12. ALL_DIRS=$(patsubst %, ccan/%, $(ALL))
  13. ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
  14. default: libccan.a
  15. include Makefile-ccan
  16. check: $(ALL_DIRS:ccan/%=check-%)
  17. distclean: clean
  18. rm -f $(ALL_DEPENDS)
  19. $(ALL_DEPENDS): %/.depends: %/_info.c tools/ccan_depends
  20. @tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
  21. # Actual dependencies are created in inter-depends
  22. check-%: tools/run_tests
  23. @echo Testing $*...
  24. @if tools/run_tests $(V) `[ ! -f ccan/$*.o ] || echo --apiobj=ccan/$*.o` ccan/$* $(filter-out ccan/$*.o, $(filter %.o, $^)) | grep ^'not ok'; then exit 1; else exit 0; fi
  25. libccan.a(%.o): ccan/%.o
  26. $(AR) r $@ $<
  27. clean: tools-clean
  28. $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'` `find . -name _info` `find . -name '*.d'`
  29. $(RM) inter-depends lib-depends test-depends
  30. # Creates a dependency from the tests to the object files which it needs.
  31. inter-depends: $(ALL_DEPENDS) Makefile
  32. @for f in $(ALL_DEPENDS); do echo check-$$(basename $$(dirname $$f) ): $$(for dir in $$(cat $$f) $$(dirname $$f); do [ "$$(echo $$dir/[a-z]*.c)" = "$$dir/[a-z]*.c" ] || echo ccan/"$$(basename $$dir)".o; done); done > $@
  33. # Creates dependencies between tests, so if foo depends on bar, bar is tested
  34. # first
  35. test-depends: $(ALL_DEPENDS) Makefile
  36. @for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
  37. include tools/Makefile
  38. -include inter-depends
  39. -include test-depends
  40. -include Makefile-web