Makefile: list modules explicitly.
[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 # Where make scores puts the results
14 SCOREDIR=scores/$(shell whoami)/$(shell uname -s)-$(shell uname -m)-$(CC)-$(shell git describe --always --dirty)
15
16 # Here's my rough logarithmic timeout graph for my laptop:
17 #
18 # 302                                                  -     
19 #    |                                                  / --*  
20 #    |                                                 /       
21 #    |                                                 /       
22 #    |                                                /        
23 #    |Execution Time, seconds                        /        
24 #    |                                               /         
25 #    |                                          ---//          
26 #    |                                         /               
27 #    |                                       //                
28 #    |                    ---\            ---                  
29 #    |                 ---    \\    ------                     
30 #    |-----------------         \---                           
31 # 19 +------------------------------------------------------+--
32 #    0           Timeout (ms, logarithmic)               262144
33 #
34 # 140
35 #    |                                                         
36 #    |------------                                             
37 #    |            ---                                          
38 #    |               ---------                                 
39 #    |                        -------                          
40 #    |                               --\                       
41 #    |                                  \\-                    
42 #    | Tests skipped                       --\                 
43 #    |                                        \                
44 #    |                                         \\              
45 #    |                                           \\\           
46 #    |                                              \          
47 #    |                                               \----     
48 #  --+0---------------------------------------------------==+--
49 #    0           Timeout (ms, logarithmic)               262144
50 #
51 # On my laptop, this runs 574 tests in 40 seconds, vs. a full check which
52 # runs 676 tests in 260 seconds.
53 FASTTIMEOUT=750
54
55 default: libccan.a
56
57 ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(MODS_NORMAL) $(MODS_EXTERNAL))
58
59 include Makefile-ccan
60
61 fastcheck: $(MODS_NORMAL:%=summary-fastcheck-%)
62
63 check: $(MODS_NORMAL:%=summary-check-%)
64
65 distclean: clean
66         rm -f $(ALL_DEPENDS)
67
68 scores: $(SCOREDIR)/SUMMARY
69
70 $(SCOREDIR)/SUMMARY: $(MODS:%=$(SCOREDIR)/score-%)
71         git describe --always > $@
72         uname -a >> $@
73         $(CC) -v >> $@
74         cat $^ | grep 'Total score:' >> $@
75
76 $(SCOREDIR)/score-%: ccan/%/_info tools/ccanlint/ccanlint $(OBJFILES)
77         mkdir -p $(SCOREDIR)
78         tools/ccanlint/ccanlint -v -s ccan/$* > $@ || true
79
80 $(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends
81         tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
82
83 # Actual dependencies are created in inter-depends
84 check-%: tools/ccanlint/ccanlint
85         tools/ccanlint/ccanlint ccan/$*
86
87 fastcheck-%: tools/ccanlint/ccanlint
88         tools/ccanlint/ccanlint --timeout $(FASTTIMEOUT) ccan/$*
89
90 # Doesn't test dependencies, doesn't print verbose fail results.
91 summary-check-%: tools/ccanlint/ccanlint $(OBJFILES)
92         tools/ccanlint/ccanlint -s ccan/$*
93
94 summary-fastcheck-%: tools/ccanlint/ccanlint $(OBJFILES)
95         tools/ccanlint/ccanlint -x tests_pass_valgrind -x tests_compile_coverage -s ccan/$*
96
97 ccan/%/info: ccan/%/_info
98         $(CC) $(CCAN_CFLAGS) -o $@ -x c $<
99
100 libccan.a(%.o): ccan/%.o
101         $(AR) r $@ $<
102
103 clean: tools-clean
104         $(RM) `find * -name '*.o'` `find * -name '.depends'` `find * -name '*.a'`  `find * -name info` `find * -name '*.d'`
105         $(RM) inter-depends lib-depends test-depends ccan/*-Makefile
106
107 # Creates a dependency from the tests to the object files which it needs.
108 inter-depends: $(ALL_DEPENDS) Makefile
109         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 > $@
110
111 # Creates dependencies between tests, so if foo depends on bar, bar is tested
112 # first 
113 test-depends: $(ALL_DEPENDS) Makefile
114         for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@
115
116 TAGS: FORCE
117         find * -name '*.[ch]' | xargs etags
118
119 FORCE:
120
121 # Ensure we don't end up with empty file if configurator fails!
122 config.h: tools/configurator/configurator Makefile Makefile-ccan
123         tools/configurator/configurator $(CC) $(CCAN_CFLAGS) > $@.tmp && mv $@.tmp $@
124
125 include tools/Makefile
126 -include inter-depends
127 -include test-depends
128 -include Makefile-web