]> git.ozlabs.org Git - ccan/blob - Makefile
Fix EXCLUDE logic for makefiles, add fastcheck
[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 # 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
16
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/)))
22
23 default: libccan.a
24
25 include Makefile-ccan
26
27 fastcheck: $(ALL_TESTS:%=summary-fastcheck-%)
28
29 check: $(ALL_TESTS:%=summary-check-%)
30
31 distclean: clean
32         rm -f $(ALL_DEPENDS)
33
34 $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
35         @tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
36
37 # Actual dependencies are created in inter-depends
38 check-%: tools/ccanlint/ccanlint
39         @tools/ccanlint/ccanlint -d ccan/$*
40
41 fastcheck-%: tools/ccanlint/ccanlint
42         @tools/ccanlint/ccanlint -t -d ccan/$*
43
44 # Doesn't test dependencies, doesn't print verbose fail results.
45 summary-check-%: tools/ccanlint/ccanlint $(OBJFILES)
46         @tools/ccanlint/ccanlint -s -d ccan/$*
47
48 summary-fastcheck-%: tools/ccanlint/ccanlint $(OBJFILES)
49         @tools/ccanlint/ccanlint -t -s -d ccan/$*
50
51 ccan/%/info: ccan/%/_info
52         $(CC) $(CFLAGS) -o $@ -x c $<
53
54 libccan.a(%.o): ccan/%.o
55         $(AR) r $@ $<
56
57 clean: tools-clean
58         $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'`  `find . -name info` `find . -name '*.d'`
59         $(RM) inter-depends lib-depends test-depends ccan/*-Makefile
60
61 # Creates a dependency from the tests to the object files which it needs.
62 inter-depends: $(ALL_DEPENDS) Makefile
63         @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 > $@
64
65 # Creates dependencies between tests, so if foo depends on bar, bar is tested
66 # first 
67 test-depends: $(ALL_DEPENDS) Makefile
68         @for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
69
70 include tools/Makefile
71 -include inter-depends
72 -include test-depends
73 -include Makefile-web