]> git.ozlabs.org Git - ccan/blob - Makefile
ccanlint: Correct default coverage tool for clang
[ccan] / Makefile
1 # Makefile for CCAN
2
3 # 'make quiet=1' builds silently
4 QUIETEN.1 := @
5 PRE := $(QUIETEN.$(quiet))
6
7 all::
8
9 # Our flags for building
10 WARN_CFLAGS := -Wall -Wstrict-prototypes -Wold-style-definition -Wundef \
11  -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings
12 DEP_CFLAGS = -MMD -MP -MF$(@:%=%.d) -MT$@
13 CCAN_CFLAGS := -g3 -ggdb $(WARN_CFLAGS) -DCCAN_STR_DEBUG=1 -I. $(CFLAGS)
14 CFLAGS_FORCE_C_SOURCE := -x c
15
16 # Anything with an _info file is a module ...
17 INFO_SRCS := $(wildcard ccan/*/_info ccan/*/*/_info)
18 ALL_INFOS := $(INFO_SRCS:%_info=%info)
19 ALL_MODULES := $(ALL_INFOS:%/info=%)
20
21 # ... Except stuff that needs external dependencies, which we exclude
22 EXCLUDE := altstack jmap jset nfs ogg_to_pcm tal/talloc wwviaudio
23 MODULES:= $(filter-out $(EXCLUDE:%=ccan/%), $(ALL_MODULES))
24
25 # Sources are C files in each module, objects the resulting .o files
26 SRCS := $(wildcard $(MODULES:%=%/*.c))
27 OBJS := $(SRCS:%.c=%.o)
28 DEPS := $(OBJS:%=%.d)
29
30 # We build all object files using our CCAN_CFLAGS, after config.h
31 %.o : %.c config.h
32         $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) -c $< -o $@
33
34 # _info files are compiled into executables and don't need dependencies
35 %info : %_info config.h
36         $(PRE)$(CC) $(CCAN_CFLAGS) -I. -o $@ $(CFLAGS_FORCE_C_SOURCE) $<
37
38 # config.h is built by configurator which has no ccan dependencies
39 CONFIGURATOR := tools/configurator/configurator
40 $(CONFIGURATOR): $(CONFIGURATOR).c
41         $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $< -o $@
42 config.h: $(CONFIGURATOR) Makefile
43         $(PRE)$(CONFIGURATOR) $(CC) $(CCAN_CFLAGS) >$@.tmp && mv $@.tmp $@
44
45 # Tools
46 TOOLS := tools/ccan_depends tools/doc_extract tools/namespacize tools/modfiles
47 TOOLS_SRCS := $(filter-out $(TOOLS:%=%.c), $(wildcard tools/*.c))
48 TOOLS_DEPS := $(TOOLS_SRCS:%.c=%.d) $(TOOLS:%=%.d)
49 TOOLS_CCAN_MODULES := err foreach hash htable list noerr opt rbuf \
50     read_write_all str take tal tal/grab_file tal/link tal/path tal/str time
51 TOOLS_CCAN_SRCS := $(wildcard $(TOOLS_CCAN_MODULES:%=ccan/%/*.c))
52 TOOLS_OBJS := $(TOOLS_SRCS:%.c=%.o) $(TOOLS_CCAN_SRCS:%.c=%.o)
53 tools/% : tools/%.c $(TOOLS_OBJS)
54         $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $< $(TOOLS_OBJS) -lm -o $@
55
56 # ccanlint
57 LINT := tools/ccanlint/ccanlint
58 LINT_OPTS.ok := -s
59 LINT_OPTS.fast.ok := -s -x tests_pass_valgrind -x tests_compile_coverage
60 LINT_SRCS := $(filter-out $(LINT).c, $(wildcard tools/ccanlint/*.c tools/ccanlint/tests/*.c))
61 LINT_DEPS := $(LINT_SRCS:%.c=%.d) $(LINT).d
62 LINT_CCAN_MODULES := asort autodata dgraph ilog lbalance ptr_valid strmap
63 LINT_CCAN_SRCS := $(wildcard $(LINT_CCAN_MODULES:%=ccan/%/*.c))
64 LINT_OBJS := $(LINT_SRCS:%.c=%.o) $(LINT_CCAN_SRCS:%.c=%.o) $(TOOLS_OBJS)
65 ifneq ($(GCOV),)
66 LINT_GCOV = --gcov="$(GCOV)"
67 endif
68 $(LINT): $(LINT).c $(LINT_OBJS)
69         $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $(LINT).c $(LINT_OBJS) -lm -o $@
70
71 # We generate dependencies for tests into a .d file
72 %/.d: %/info tools/gen_deps.sh tools/ccan_depends
73         $(PRE)tools/gen_deps.sh $* > $@ || rm -f $@
74 TEST_DEPS := $(MODULES:%=%/.d)
75
76 # We produce .ok files when the tests succeed
77 %.ok: $(LINT) %info
78         $(PRE)$(LINT) $(LINT_OPTS$(notdir $@)) --deps-fail-ignore $(LINT_GCOV) $(LINTFLAGS) $(dir $*) && touch $@
79
80 check: $(MODULES:%=%/.ok)
81 fastcheck: $(MODULES:%=%/.fast.ok)
82
83 ifeq ($(strip $(filter clean config.h, $(MAKECMDGOALS))),)
84 -include $(DEPS) $(LINT_DEPS) $(TOOLS_DEPS) $(TEST_DEPS)
85 endif
86
87 # Default target: object files, info files and tools
88 all:: $(OBJS) $(ALL_INFOS) $(CONFIGURATOR) $(LINT) $(TOOLS)
89
90 .PHONY: clean TAGS
91 clean:
92         $(PRE)find . -name "*.d" -o -name "*.o" -o -name "*.ok" | xargs -n 256 rm -f
93         $(PRE)rm -f $(CONFIGURATOR) $(LINT) $(TOOLS) TAGS config.h config.h.d $(ALL_INFOS)
94
95 # 'make TAGS' builds etags
96 TAGS:
97         $(PRE)find * -name '*.[ch]' | xargs etags