Makefile 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 ccan/%/_info
  23. @echo Testing $*...
  24. @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
  25. ccan/%/_info: ccan/%/_info.c
  26. $(CC) $(CFLAGS) -o $@ $<
  27. libccan.a(%.o): ccan/%.o
  28. $(AR) r $@ $<
  29. clean: tools-clean
  30. $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'` `find . -name _info` `find . -name '*.d'`
  31. $(RM) inter-depends lib-depends test-depends
  32. # Creates a dependency from the tests to the object files which it needs.
  33. inter-depends: $(ALL_DEPENDS) Makefile
  34. @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 > $@
  35. # Creates dependencies between tests, so if foo depends on bar, bar is tested
  36. # first
  37. test-depends: $(ALL_DEPENDS) Makefile
  38. @for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
  39. include tools/Makefile
  40. -include inter-depends
  41. -include test-depends
  42. -include Makefile-web