3 # 'make quiet=1' builds silently
5 PRE := $(QUIETEN.$(quiet))
9 # Our flags for building
10 WARN_CFLAGS := -Wall -Wstrict-prototypes -Wold-style-definition -Wundef \
11 -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wshadow=local
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
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=%)
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))
25 # Sources are C files in each module, objects the resulting .o files
26 SRCS := $(wildcard $(MODULES:%=%/*.c))
27 OBJS := $(SRCS:%.c=%.o)
30 # We build all object files using our CCAN_CFLAGS, after config.h
32 $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) -c $< -o $@
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) $<
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 $@
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 := asort err foreach hash htable list membuf 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 $@
57 LINT := tools/ccanlint/ccanlint
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 := 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)
66 LINT_GCOV = --gcov="$(GCOV)"
68 $(LINT): $(LINT).c $(LINT_OBJS)
69 $(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $(LINT).c $(LINT_OBJS) -lm -o $@
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)
76 # We produce .ok files when the tests succeed
78 $(PRE)$(LINT) $(LINT_OPTS.ok) --deps-fail-ignore $(LINT_GCOV) $(LINTFLAGS) $(dir $*) && touch $@
80 %.fast-ok: $(LINT) %info
81 $(PRE)$(LINT) $(LINT_OPTS.fast-ok) --deps-fail-ignore $(LINT_GCOV) $(LINTFLAGS) $(dir $*) && touch $@
83 check: $(MODULES:%=%/.ok)
84 fastcheck: $(MODULES:%=%/.fast-ok)
86 ifeq ($(strip $(filter clean config.h, $(MAKECMDGOALS))),)
87 -include $(DEPS) $(LINT_DEPS) $(TOOLS_DEPS) $(TEST_DEPS)
90 # Default target: object files, info files and tools
91 all:: $(OBJS) $(ALL_INFOS) $(CONFIGURATOR) $(LINT) $(TOOLS)
95 $(PRE)find . -name "*.d" -o -name "*.o" -o -name "*.ok" | xargs -n 256 rm -f
96 $(PRE)rm -f $(CONFIGURATOR) $(LINT) $(TOOLS) TAGS config.h config.h.d $(ALL_INFOS)
98 # 'make TAGS' builds etags
100 $(PRE)find * -name '*.[ch]' | xargs etags