1 # Hacky makefile to compile everything and run the tests in some kind
6 # check: run tests on all ccan modules (use 'make check V=--verbose' for more)
7 # Includes building libccan.a.
8 # libccan.a: A library with all the ccan modules in it.
9 # tools: build useful tools in tools/ dir.
10 # Especially tools/ccanlint/ccanlint and tools/namespacize.
11 # distclean: destroy everything back to pristine state
13 ALL=$(patsubst ccan/%/test, %, $(wildcard ccan/*/test))
14 ALL_DIRS=$(patsubst %, ccan/%, $(ALL))
15 ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
21 check: $(ALL_DIRS:ccan/%=check-%)
26 $(ALL_DEPENDS): %/.depends: %/_info.c tools/ccan_depends
27 @tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
29 # Actual dependencies are created in inter-depends
30 check-%: tools/run_tests ccan/%/_info
32 @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
34 ccan/%/_info: ccan/%/_info.c
35 $(CC) $(CFLAGS) -o $@ $<
37 libccan.a(%.o): ccan/%.o
41 $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'` `find . -name _info` `find . -name '*.d'`
42 $(RM) inter-depends lib-depends test-depends
44 # Creates a dependency from the tests to the object files which it needs.
45 inter-depends: $(ALL_DEPENDS) Makefile
46 @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 > $@
48 # Creates dependencies between tests, so if foo depends on bar, bar is tested
50 test-depends: $(ALL_DEPENDS) Makefile
51 @for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
53 include tools/Makefile
54 -include inter-depends