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