Makefile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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=ccan/wwviaudio ccan/ogg_to_pcm
  14. # Anything with an _info file is a module.
  15. ALL=$(filter-out $(EXCLUDE), $(patsubst ccan/%/_info, %, $(wildcard ccan/*/_info)))
  16. ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
  17. # Not all modules have tests.
  18. ALL_TESTS=$(patsubst ccan/%/test/, %, $(foreach dir, $(ALL), $(wildcard ccan/$(dir)/test/)))
  19. default: libccan.a
  20. include Makefile-ccan
  21. check: $(ALL_TESTS:%=summary-check-%)
  22. distclean: clean
  23. rm -f $(ALL_DEPENDS)
  24. $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
  25. @tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
  26. # Actual dependencies are created in inter-depends
  27. check-%: tools/ccanlint/ccanlint
  28. @tools/ccanlint/ccanlint -d ccan/$*
  29. # Doesn't test dependencies, doesn't print verbose fail results.
  30. summary-check-%: tools/ccanlint/ccanlint $(OBJFILES)
  31. @tools/ccanlint/ccanlint -s -d ccan/$*
  32. ccan/%/info: ccan/%/_info
  33. $(CC) $(CFLAGS) -o $@ -x c $<
  34. libccan.a(%.o): ccan/%.o
  35. $(AR) r $@ $<
  36. clean: tools-clean
  37. $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'` `find . -name info` `find . -name '*.d'`
  38. $(RM) inter-depends lib-depends test-depends ccan/*-Makefile
  39. # Creates a dependency from the tests to the object files which it needs.
  40. inter-depends: $(ALL_DEPENDS) Makefile
  41. @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 > $@
  42. # Creates dependencies between tests, so if foo depends on bar, bar is tested
  43. # first
  44. test-depends: $(ALL_DEPENDS) Makefile
  45. @for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
  46. include tools/Makefile
  47. -include inter-depends
  48. -include test-depends
  49. -include Makefile-web