]> git.ozlabs.org Git - ccan/blob - Makefile
Correctly include dependencies for nested modules
[ccan] / Makefile
1 # Hacky makefile to compile everything and run the tests in some kind
2 # of sane order.
3
4 # Main targets:
5
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
12
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
17
18 default: libccan.a
19
20 ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(MODS))
21
22 # By default, we skip modules with external deps (or plaform specific)
23 MODS_EXCLUDE:=altstack generator jmap jset nfs ogg_to_pcm tal/talloc wwviaudio
24
25 include Makefile-ccan
26
27 fastcheck: $(MODS:%=summary-fastcheck/%)
28
29 check: $(MODS:%=summary-check/%)
30
31 distclean: clean
32         rm -f $(ALL_DEPENDS)
33
34 scores: $(SCOREDIR)/SUMMARY
35
36 $(SCOREDIR)/SUMMARY: $(MODS:%=$(SCOREDIR)/%.score)
37         git describe --always > $@
38         uname -a >> $@
39         $(CC) -v >> $@
40         cat $^ | grep 'Total score:' >> $@
41
42 $(SCOREDIR)/%.score: ccan/%/_info tools/ccanlint/ccanlint $(OBJFILES)
43         mkdir -p `dirname $@`
44         $(CCANLINT) -v -s ccan/$* > $@ || true
45
46 $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
47         tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
48
49 # Actual dependencies are created in inter-depends
50 check/%: tools/ccanlint/ccanlint
51         $(CCANLINT) ccan/$*
52
53 fastcheck/%: tools/ccanlint/ccanlint
54         $(CCANLINT_FAST) ccan/$*
55
56 # Doesn't test dependencies, doesn't print verbose fail results.
57 summary-check/%: tools/ccanlint/ccanlint $(OBJFILES)
58         $(CCANLINT) -s ccan/$*
59
60 summary-fastcheck/%: tools/ccanlint/ccanlint $(OBJFILES)
61         $(CCANLINT_FAST) -s ccan/$*
62
63 ccan/%/info: ccan/%/_info
64         $(CC) $(CCAN_CFLAGS) -o $@ -x c $<
65
66 clean: tools-clean
67         rm -f `find * -name '*.o'` `find * -name '.depends'` `find * -name '*.a'`  `find * -name info` `find * -name '*.d'` `find ccan -name '*-Makefile'`
68         rm -f config.h
69         rm -f inter-depends lib-depends test-depends
70
71 # Creates a dependency from the tests to the object files which it needs.
72 inter-depends: $(ALL_DEPENDS) Makefile
73         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 > $@
74
75 # Creates dependencies between tests, so if foo depends on bar, bar is tested
76 # first 
77 test-depends: $(ALL_DEPENDS) Makefile
78         for f in $(ALL_DEPENDS); do echo check/`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check/\1,p' < $$f`; done > $@
79
80 TAGS: FORCE
81         find * -name '*.[ch]' | xargs etags
82
83 FORCE:
84
85 # Ensure we don't end up with empty file if configurator fails!
86 config.h: tools/configurator/configurator Makefile Makefile-ccan
87         tools/configurator/configurator $(CC) $(CCAN_CFLAGS) > $@.tmp && mv $@.tmp $@
88
89 include tools/Makefile
90 -include inter-depends
91 -include test-depends
92 -include Makefile-web