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 # Where make scores puts the results
14 SCOREDIR=scores/$(shell whoami)/$(shell uname -s)-$(shell uname -m)-$(CC)-$(shell git describe --always --dirty)
15 CCANLINT=tools/ccanlint/ccanlint --deps-fail-ignore
16 CCANLINT_FAST=$(CCANLINT) -x tests_pass_valgrind -x tests_compile_coverage
20 ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(MODS))
22 # By default, we skip modules with external deps.
23 MODS_EXCLUDE:=jmap jset nfs ogg_to_pcm tal/talloc wwviaudio
27 fastcheck: $(MODS:%=summary-fastcheck-%)
29 check: $(MODS:%=summary-check-%)
34 scores: $(SCOREDIR)/SUMMARY
36 $(SCOREDIR)/SUMMARY: $(MODS:%=$(SCOREDIR)/%.score)
37 git describe --always > $@
40 cat $^ | grep 'Total score:' >> $@
42 $(SCOREDIR)/%.score: ccan/%/_info tools/ccanlint/ccanlint $(OBJFILES)
44 $(CCANLINT) -v -s ccan/$* > $@ || true
46 $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
47 tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
49 # Actual dependencies are created in inter-depends
50 check-%: tools/ccanlint/ccanlint
53 fastcheck-%: tools/ccanlint/ccanlint
54 $(CCANLINT_FAST) ccan/$*
56 # Doesn't test dependencies, doesn't print verbose fail results.
57 summary-check-%: tools/ccanlint/ccanlint $(OBJFILES)
58 $(CCANLINT) -s ccan/$*
60 summary-fastcheck-%: tools/ccanlint/ccanlint $(OBJFILES)
61 $(CCANLINT_FAST) -s ccan/$*
63 # FIXME: Horrible hacks because % doesn't match /
64 summary-check-antithread/%: tools/ccanlint/ccanlint $(OBJFILES)
65 $(CCANLINT) -s ccan/antithread/$*
67 summary-fastcheck-antithread/%: tools/ccanlint/ccanlint $(OBJFILES)
68 $(CCANLINT_FAST) -s ccan/antithread/$*
70 summary-check-tal/%: tools/ccanlint/ccanlint $(OBJFILES)
71 $(CCANLINT) -s ccan/tal/$*
73 summary-fastcheck-tal/%: tools/ccanlint/ccanlint $(OBJFILES)
74 $(CCANLINT_FAST) -s ccan/tal/$*
76 summary-check-str/%: tools/ccanlint/ccanlint $(OBJFILES)
77 $(CCANLINT) -s ccan/str/$*
79 summary-fastcheck-str/%: tools/ccanlint/ccanlint $(OBJFILES)
80 $(CCANLINT_FAST) -s ccan/str/$*
82 summary-check-crypto/%: tools/ccanlint/ccanlint $(OBJFILES)
83 $(CCANLINT) -s ccan/crypto/$*
85 summary-fastcheck-crypto/%: tools/ccanlint/ccanlint $(OBJFILES)
86 $(CCANLINT_FAST) -s ccan/crypto/$*
88 ccan/%/info: ccan/%/_info
89 $(CC) $(CCAN_CFLAGS) -o $@ -x c $<
92 $(RM) `find * -name '*.o'` `find * -name '.depends'` `find * -name '*.a'` `find * -name info` `find * -name '*.d'`
93 $(RM) inter-depends lib-depends test-depends ccan/*-Makefile
95 # Creates a dependency from the tests to the object files which it needs.
96 inter-depends: $(ALL_DEPENDS) Makefile
97 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 > $@
99 # Creates dependencies between tests, so if foo depends on bar, bar is tested
101 test-depends: $(ALL_DEPENDS) Makefile
102 for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
105 find * -name '*.[ch]' | xargs etags
109 # Ensure we don't end up with empty file if configurator fails!
110 config.h: tools/configurator/configurator Makefile Makefile-ccan
111 tools/configurator/configurator $(CC) $(CCAN_CFLAGS) > $@.tmp && mv $@.tmp $@
113 include tools/Makefile
114 -include inter-depends
115 -include test-depends
116 -include Makefile-web