Makefile 2.1 KB

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