Makefile 3.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# Makefile for CCAN

# 'make quiet=1' builds silently
QUIETEN.1 := @
PRE := $(QUIETEN.$(quiet))

all::

# Our flags for building
WARN_CFLAGS := -Wall -Wstrict-prototypes -Wold-style-definition -Wundef \
 -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings
DEP_CFLAGS = -MMD -MP -MF$(@:%=%.d) -MT$@
CCAN_CFLAGS := -g3 -ggdb $(WARN_CFLAGS) -DCCAN_STR_DEBUG=1 -I. $(CFLAGS)
14
CFLAGS_FORCE_C_SOURCE := -x c
15 16 17 18 19 20 21

# Anything with an _info file is a module ...
INFO_SRCS := $(wildcard ccan/*/_info ccan/*/*/_info)
ALL_INFOS := $(INFO_SRCS:%_info=%info)
ALL_MODULES := $(ALL_INFOS:%/info=%)

# ... Except stuff that needs external dependencies, which we exclude
22
EXCLUDE := altstack jmap jset nfs ogg_to_pcm tal/talloc wwviaudio
23 24 25 26 27 28 29 30 31 32 33 34 35
MODULES:= $(filter-out $(EXCLUDE:%=ccan/%), $(ALL_MODULES))

# Sources are C files in each module, objects the resulting .o files
SRCS := $(wildcard $(MODULES:%=%/*.c))
OBJS := $(SRCS:%.c=%.o)
DEPS := $(OBJS:%=%.d)

# We build all object files using our CCAN_CFLAGS, after config.h
%.o : %.c config.h
	$(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) -c $< -o $@

# _info files are compiled into executables and don't need dependencies
%info : %_info config.h
36
	$(PRE)$(CC) $(CCAN_CFLAGS) -I. -o $@ $(CFLAGS_FORCE_C_SOURCE) $<
37 38 39 40 41 42 43 44 45 46 47 48

# config.h is built by configurator which has no ccan dependencies
CONFIGURATOR := tools/configurator/configurator
$(CONFIGURATOR): $(CONFIGURATOR).c
	$(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $< -o $@
config.h: $(CONFIGURATOR) Makefile
	$(PRE)$(CONFIGURATOR) $(CC) $(CCAN_CFLAGS) >$@.tmp && mv $@.tmp $@

# Tools
TOOLS := tools/ccan_depends tools/doc_extract tools/namespacize tools/modfiles
TOOLS_SRCS := $(filter-out $(TOOLS:%=%.c), $(wildcard tools/*.c))
TOOLS_DEPS := $(TOOLS_SRCS:%.c=%.d) $(TOOLS:%=%.d)
49
TOOLS_CCAN_MODULES := asort err foreach hash htable list membuf noerr opt rbuf \
50 51 52 53 54 55 56 57 58
    read_write_all str take tal tal/grab_file tal/link tal/path tal/str time
TOOLS_CCAN_SRCS := $(wildcard $(TOOLS_CCAN_MODULES:%=ccan/%/*.c))
TOOLS_OBJS := $(TOOLS_SRCS:%.c=%.o) $(TOOLS_CCAN_SRCS:%.c=%.o)
tools/% : tools/%.c $(TOOLS_OBJS)
	$(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $< $(TOOLS_OBJS) -lm -o $@

# ccanlint
LINT := tools/ccanlint/ccanlint
LINT_OPTS.ok := -s
Rusty Russell's avatar
Rusty Russell committed
59
LINT_OPTS.fast-ok := -s -x tests_pass_valgrind -x tests_compile_coverage
60 61
LINT_SRCS := $(filter-out $(LINT).c, $(wildcard tools/ccanlint/*.c tools/ccanlint/tests/*.c))
LINT_DEPS := $(LINT_SRCS:%.c=%.d) $(LINT).d
62
LINT_CCAN_MODULES := autodata dgraph ilog lbalance ptr_valid strmap
63 64
LINT_CCAN_SRCS := $(wildcard $(LINT_CCAN_MODULES:%=ccan/%/*.c))
LINT_OBJS := $(LINT_SRCS:%.c=%.o) $(LINT_CCAN_SRCS:%.c=%.o) $(TOOLS_OBJS)
65 66 67
ifneq ($(GCOV),)
LINT_GCOV = --gcov="$(GCOV)"
endif
68 69 70 71 72 73 74 75 76
$(LINT): $(LINT).c $(LINT_OBJS)
	$(PRE)$(CC) $(CCAN_CFLAGS) $(DEP_CFLAGS) $(LINT).c $(LINT_OBJS) -lm -o $@

# We generate dependencies for tests into a .d file
%/.d: %/info tools/gen_deps.sh tools/ccan_depends
	$(PRE)tools/gen_deps.sh $* > $@ || rm -f $@
TEST_DEPS := $(MODULES:%=%/.d)

# We produce .ok files when the tests succeed
77
%.ok: $(LINT) %info
Rusty Russell's avatar
Rusty Russell committed
78 79 80 81
	$(PRE)$(LINT) $(LINT_OPTS.ok) --deps-fail-ignore $(LINT_GCOV) $(LINTFLAGS) $(dir $*) && touch $@

%.fast-ok: $(LINT) %info
	$(PRE)$(LINT) $(LINT_OPTS.fast-ok) --deps-fail-ignore $(LINT_GCOV) $(LINTFLAGS) $(dir $*) && touch $@
82 83

check: $(MODULES:%=%/.ok)
Rusty Russell's avatar
Rusty Russell committed
84
fastcheck: $(MODULES:%=%/.fast-ok)
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

ifeq ($(strip $(filter clean config.h, $(MAKECMDGOALS))),)
-include $(DEPS) $(LINT_DEPS) $(TOOLS_DEPS) $(TEST_DEPS)
endif

# Default target: object files, info files and tools
all:: $(OBJS) $(ALL_INFOS) $(CONFIGURATOR) $(LINT) $(TOOLS)

.PHONY: clean TAGS
clean:
	$(PRE)find . -name "*.d" -o -name "*.o" -o -name "*.ok" | xargs -n 256 rm -f
	$(PRE)rm -f $(CONFIGURATOR) $(LINT) $(TOOLS) TAGS config.h config.h.d $(ALL_INFOS)

# 'make TAGS' builds etags
TAGS:
	$(PRE)find * -name '*.[ch]' | xargs etags