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 # Trying to build the whole repo is usually a lose; there will be some
14 # dependencies you don't have.
15 EXCLUDE=ccan/wwviaudio ccan/ogg_to_pcm
17 # Anything with an _info file is a module.
18 ALL=$(filter-out $(EXCLUDE), $(patsubst ccan/%/_info, %, $(wildcard ccan/*/_info)))
19 ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
20 # Not all modules have tests.
21 ALL_TESTS=$(patsubst ccan/%/test/, %, $(foreach dir, $(ALL), $(wildcard ccan/$(dir)/test/)))
27 check: $(ALL_TESTS:%=summary-check-%)
32 $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
33 @tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
35 # Actual dependencies are created in inter-depends
36 check-%: tools/ccanlint/ccanlint
37 @tools/ccanlint/ccanlint -d ccan/$*
39 # Doesn't test dependencies, doesn't print verbose fail results.
40 summary-check-%: tools/ccanlint/ccanlint $(OBJFILES)
41 @tools/ccanlint/ccanlint -s -d ccan/$*
43 ccan/%/info: ccan/%/_info
44 $(CC) $(CFLAGS) -o $@ -x c $<
46 libccan.a(%.o): ccan/%.o
50 $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'` `find . -name info` `find . -name '*.d'`
51 $(RM) inter-depends lib-depends test-depends
53 # Creates a dependency from the tests to the object files which it needs.
54 inter-depends: $(ALL_DEPENDS) Makefile
55 @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 > $@
57 # Creates dependencies between tests, so if foo depends on bar, bar is tested
59 test-depends: $(ALL_DEPENDS) Makefile
60 @for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
62 include tools/Makefile
63 -include inter-depends