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=wwviaudio 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/)))
23 # Here's my rough logarithmic timeout graph for my laptop:
30 # |Execution Time, seconds /
37 # |----------------- \---
38 # 19 +------------------------------------------------------+--
39 # 0 Timeout (ms, logarithmic) 262144
55 # --+0---------------------------------------------------==+--
56 # 0 Timeout (ms, logarithmic) 262144
58 # On my laptop, this runs 574 tests in 40 seconds, vs. a full check which
59 # runs 676 tests in 260 seconds.
66 fastcheck: $(ALL_TESTS:%=summary-fastcheck-%)
68 check: $(ALL_TESTS:%=summary-check-%)
73 $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
74 tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
76 # Actual dependencies are created in inter-depends
77 check-%: tools/ccanlint/ccanlint
78 tools/ccanlint/ccanlint -d ccan/$*
80 fastcheck-%: tools/ccanlint/ccanlint
81 tools/ccanlint/ccanlint -t $(FASTTIMEOUT) -d ccan/$*
83 # Doesn't test dependencies, doesn't print verbose fail results.
84 summary-check-%: tools/ccanlint/ccanlint $(OBJFILES)
85 tools/ccanlint/ccanlint -s -d ccan/$*
87 summary-fastcheck-%: tools/ccanlint/ccanlint $(OBJFILES)
88 tools/ccanlint/ccanlint -t $(FASTTIMEOUT) -s -d ccan/$*
90 ccan/%/info: ccan/%/_info
91 $(CC) $(CFLAGS) -o $@ -x c $<
93 libccan.a(%.o): ccan/%.o
97 $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'` `find . -name info` `find . -name '*.d'`
98 $(RM) inter-depends lib-depends test-depends ccan/*-Makefile
100 # Creates a dependency from the tests to the object files which it needs.
101 inter-depends: $(ALL_DEPENDS) Makefile
102 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 > $@
104 # Creates dependencies between tests, so if foo depends on bar, bar is tested
106 test-depends: $(ALL_DEPENDS) Makefile
107 for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
109 include tools/Makefile
110 -include inter-depends
111 -include test-depends
112 -include Makefile-web