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