]> git.ozlabs.org Git - ccan/blob - Makefile
tdb: locking cleanup
[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 # Anything with an _info file is a module.
14 ALL=$(patsubst ccan/%/_info, %, $(wildcard ccan/*/_info))
15 ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
16 # Not all modules have tests.
17 ALL_TESTS=$(patsubst ccan/%/test/, %, $(wildcard ccan/*/test/))
18
19 default: libccan.a
20
21 include Makefile-ccan
22
23 check: $(ALL_TESTS:%=check-%)
24
25 distclean: clean
26         rm -f $(ALL_DEPENDS)
27
28 $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
29         @tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
30
31 # Actual dependencies are created in inter-depends
32 check-%: tools/run_tests ccan/%/info
33         @echo Testing $*...
34         @if tools/run_tests $(V) $$(for f in `ccan/$*/info libs`; do echo --lib=$$f; done) `[ ! -f ccan/$*.o ] || echo --apiobj=ccan/$*.o` ccan/$* $(filter-out ccan/$*.o, $(filter %.o, $^)) | grep ^'not ok'; then exit 1; else exit 0; fi
35
36 ccan/%/info: ccan/%/_info
37         $(CC) $(CFLAGS) -o $@ -x c $<
38
39 libccan.a(%.o): ccan/%.o
40         $(AR) r $@ $<
41
42 clean: tools-clean
43         $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'`  `find . -name info` `find . -name '*.d'`
44         $(RM) inter-depends lib-depends test-depends
45
46 # Creates a dependency from the tests to the object files which it needs.
47 inter-depends: $(ALL_DEPENDS) Makefile
48         @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 > $@
49
50 # Creates dependencies between tests, so if foo depends on bar, bar is tested
51 # first 
52 test-depends: $(ALL_DEPENDS) Makefile
53         @for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
54
55 include tools/Makefile
56 -include inter-depends
57 -include test-depends
58 -include Makefile-web