Makefile 2.1 KB

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