]> git.ozlabs.org Git - ccan/blob - Makefile
Various fixes and debugging help: particularly don't use random().
[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 # tools: build useful tools in tools/ dir.
9 #        Especially tools/ccanlint/ccanlint and tools/namespacize.
10 # distclean: destroy everything back to pristine state
11
12 ALL=$(patsubst ccan/%/test, %, $(wildcard ccan/*/test))
13 ALL_DIRS=$(patsubst %, ccan/%, $(ALL))
14 ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
15
16 include Makefile-ccan
17
18 check: $(ALL_DIRS:%=test-%)
19         echo $(ALL_DIRS)
20
21 distclean: clean
22         rm -f $(ALL_DEPENDS)
23
24 # Override implicit attempt to link directory.
25 $(ALL_DIRS):
26         @touch $@
27
28 $(ALL_DEPENDS): %/.depends: tools/ccan_depends
29         tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
30
31 test-ccan/%: tools/run_tests libccan.a(%.o)
32         @echo Testing $*...
33         @if tools/run_tests $(V) ccan/$* | grep ^'not ok'; then exit 1; else exit 0; fi
34
35 # Some don't have object files.
36 test-ccan/%:: tools/run_tests
37         @echo Testing $*...
38         @if tools/run_tests $(V) ccan/$* | grep ^'not ok'; then exit 1; else exit 0; fi
39
40 clean: tools-clean
41         $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'`  `find . -name _info`
42         $(RM) inter-depends lib-depends test-depends
43
44 # Only list a dependency if there are object files to build.
45 inter-depends: $(ALL_DEPENDS)
46         for f in $(ALL_DEPENDS); do echo test-ccan/$$(basename $$(dirname $$f) ): $$(for dir in $$(cat $$f); do [ "$$(echo $$dir/[a-z]*.c)" = "$$dir/[a-z]*.c" ] || echo libccan.a\("$$(basename $$dir)".o\); done); done > $@
47
48 test-depends: $(ALL_DEPENDS)
49         for f in $(ALL_DEPENDS); do echo test-ccan/`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),test-ccan/\1,p' < $$f`; done > $@
50
51 include tools/Makefile
52 -include inter-depends
53 -include test-depends
54 -include Makefile-web