]> git.ozlabs.org Git - ccan/blob - Makefile
opt: minor API tweaks.
[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 # Here's my rough logarithmic timeout graph for my laptop:
24 #
25 # 302                                                  -     
26 #    |                                                  / --*  
27 #    |                                                 /       
28 #    |                                                 /       
29 #    |                                                /        
30 #    |Execution Time, seconds                        /        
31 #    |                                               /         
32 #    |                                          ---//          
33 #    |                                         /               
34 #    |                                       //                
35 #    |                    ---\            ---                  
36 #    |                 ---    \\    ------                     
37 #    |-----------------         \---                           
38 # 19 +------------------------------------------------------+--
39 #    0           Timeout (ms, logarithmic)               262144
40 #
41 # 140
42 #    |                                                         
43 #    |------------                                             
44 #    |            ---                                          
45 #    |               ---------                                 
46 #    |                        -------                          
47 #    |                               --\                       
48 #    |                                  \\-                    
49 #    | Tests skipped                       --\                 
50 #    |                                        \                
51 #    |                                         \\              
52 #    |                                           \\\           
53 #    |                                              \          
54 #    |                                               \----     
55 #  --+0---------------------------------------------------==+--
56 #    0           Timeout (ms, logarithmic)               262144
57 #
58 # On my laptop, this runs 574 tests in 40 seconds, vs. a full check which
59 # runs 676 tests in 260 seconds.
60 FASTTIMEOUT=750
61
62 default: libccan.a
63
64 include Makefile-ccan
65
66 fastcheck: $(ALL_TESTS:%=summary-fastcheck-%)
67
68 check: $(ALL_TESTS:%=summary-check-%)
69
70 distclean: clean
71         rm -f $(ALL_DEPENDS)
72
73 $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
74         tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
75
76 # Actual dependencies are created in inter-depends
77 check-%: tools/ccanlint/ccanlint
78         tools/ccanlint/ccanlint -d ccan/$*
79
80 fastcheck-%: tools/ccanlint/ccanlint
81         tools/ccanlint/ccanlint -t $(FASTTIMEOUT) -d ccan/$*
82
83 # Doesn't test dependencies, doesn't print verbose fail results.
84 summary-check-%: tools/ccanlint/ccanlint $(OBJFILES)
85         tools/ccanlint/ccanlint -s -d ccan/$*
86
87 summary-fastcheck-%: tools/ccanlint/ccanlint $(OBJFILES)
88         tools/ccanlint/ccanlint -t $(FASTTIMEOUT) -s -d ccan/$*
89
90 ccan/%/info: ccan/%/_info
91         $(CC) $(CFLAGS) -o $@ -x c $<
92
93 libccan.a(%.o): ccan/%.o
94         $(AR) r $@ $<
95
96 clean: tools-clean
97         $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'`  `find . -name info` `find . -name '*.d'`
98         $(RM) inter-depends lib-depends test-depends ccan/*-Makefile
99
100 # Creates a dependency from the tests to the object files which it needs.
101 inter-depends: $(ALL_DEPENDS) Makefile
102         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 > $@
103
104 # Creates dependencies between tests, so if foo depends on bar, bar is tested
105 # first 
106 test-depends: $(ALL_DEPENDS) Makefile
107         for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
108
109 include tools/Makefile
110 -include inter-depends
111 -include test-depends
112 -include Makefile-web