X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=Makefile;h=d53e89f4d1ca9556e64187e4d3a1a63272b64c74;hp=c73569a5ae77cc4364015cf60a44119848d189de;hb=HEAD;hpb=758ab1f402b4af3cccac09548b709deca17ef930 diff --git a/Makefile b/Makefile index c73569a5..875e99f2 100644 --- a/Makefile +++ b/Makefile @@ -1,131 +1,100 @@ -# Hacky makefile to compile everything and run the tests in some kind -# of sane order. - -# Main targets: -# -# check: run tests on all ccan modules (use 'make check V=--verbose' for more) -# Includes building libccan.a. -# libccan.a: A library with all the ccan modules in it. -# tools: build useful tools in tools/ dir. -# Especially tools/ccanlint/ccanlint and tools/namespacize. -# distclean: destroy everything back to pristine state - -# Trying to build the whole repo is usually a lose; there will be some -# dependencies you don't have. -EXCLUDE=wwviaudio ogg_to_pcm jmap jset nfs - -# Where make scores puts the results -SCOREDIR=scores/$(shell whoami)/$(shell uname -s)-$(shell uname -m)-$(CC)-$(shell git describe --always --dirty) - -ALL=$(filter-out $(EXCLUDE), $(REALLY_ALL)) - -ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(REALLY_ALL)) - -# Not all modules have tests. -ALL_TESTS=$(patsubst ccan/%/test/, %, $(foreach dir, $(ALL), $(wildcard ccan/$(dir)/test/))) - -# Here's my rough logarithmic timeout graph for my laptop: -# -# 302 - -# | / --* -# | / -# | / -# | / -# |Execution Time, seconds / -# | / -# | ---// -# | / -# | // -# | ---\ --- -# | --- \\ ------ -# |----------------- \--- -# 19 +------------------------------------------------------+-- -# 0 Timeout (ms, logarithmic) 262144 -# -# 140 -# | -# |------------ -# | --- -# | --------- -# | ------- -# | --\ -# | \\- -# | Tests skipped --\ -# | \ -# | \\ -# | \\\ -# | \ -# | \---- -# --+0---------------------------------------------------==+-- -# 0 Timeout (ms, logarithmic) 262144 -# -# On my laptop, this runs 574 tests in 40 seconds, vs. a full check which -# runs 676 tests in 260 seconds. -FASTTIMEOUT=750 - -default: libccan.a - -include Makefile-ccan - -fastcheck: $(ALL_TESTS:%=summary-fastcheck-%) - -check: $(ALL_TESTS:%=summary-check-%) - -distclean: clean - rm -f $(ALL_DEPENDS) - -scores: $(SCOREDIR)/SUMMARY - -$(SCOREDIR)/SUMMARY: $(patsubst ccan/%/_info, $(SCOREDIR)/score-%, $(wildcard ccan/*/_info)) - git describe --always > $@ - uname -a >> $@ - $(CC) -v >> $@ - cat $^ | grep 'Total score:' >> $@ - -$(SCOREDIR)/score-%: ccan/%/_info tools/ccanlint/ccanlint $(OBJFILES) - mkdir -p $(SCOREDIR) - tools/ccanlint/ccanlint -v -s ccan/$* > $@ || true - -$(ALL_DEPENDS): %/.depends: %/_info tools/ccan_depends - tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 ) - -# Actual dependencies are created in inter-depends -check-%: tools/ccanlint/ccanlint - tools/ccanlint/ccanlint ccan/$* - -fastcheck-%: tools/ccanlint/ccanlint - tools/ccanlint/ccanlint -t $(FASTTIMEOUT) ccan/$* - -# Doesn't test dependencies, doesn't print verbose fail results. -summary-check-%: tools/ccanlint/ccanlint $(OBJFILES) - tools/ccanlint/ccanlint -s ccan/$* - -summary-fastcheck-%: tools/ccanlint/ccanlint $(OBJFILES) - tools/ccanlint/ccanlint -x tests_pass_valgrind -x tests_compile_coverage -s ccan/$* - -ccan/%/info: ccan/%/_info - $(CC) $(CCAN_CFLAGS) -o $@ -x c $< - -libccan.a(%.o): ccan/%.o - $(AR) r $@ $< - -clean: tools-clean - $(RM) `find * -name '*.o'` `find * -name '.depends'` `find * -name '*.a'` `find * -name info` `find * -name '*.d'` - $(RM) inter-depends lib-depends test-depends ccan/*-Makefile - -# Creates a dependency from the tests to the object files which it needs. -inter-depends: $(ALL_DEPENDS) Makefile - 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 > $@ - -# Creates dependencies between tests, so if foo depends on bar, bar is tested -# first -test-depends: $(ALL_DEPENDS) Makefile - for f in $(ALL_DEPENDS); do echo check-`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),check-\1,p' < $$f`; done > $@ - -config.h: tools/configurator/configurator Makefile Makefile-ccan - @tools/configurator/configurator $(CC) $(CCAN_CFLAGS) > config.h - -include tools/Makefile --include inter-depends --include test-depends --include Makefile-web +# 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 -Wshadow=local +DEP_CFLAGS = -MMD -MP -MF$(@:%=%.d) -MT$@ +CCAN_CFLAGS := -g3 -ggdb $(WARN_CFLAGS) -DCCAN_STR_DEBUG=1 -I. $(CFLAGS) +CFLAGS_FORCE_C_SOURCE := -x c + +# 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 +EXCLUDE := altstack jmap jset nfs ogg_to_pcm tal/talloc wwviaudio +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 + $(PRE)$(CC) $(CCAN_CFLAGS) -I. -o $@ $(CFLAGS_FORCE_C_SOURCE) $< + +# 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) +TOOLS_CCAN_MODULES := asort err foreach hash htable list membuf noerr opt rbuf \ + 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 +LINT_OPTS.fast-ok := -s -x tests_pass_valgrind -x tests_compile_coverage +LINT_SRCS := $(filter-out $(LINT).c, $(wildcard tools/ccanlint/*.c tools/ccanlint/tests/*.c)) +LINT_DEPS := $(LINT_SRCS:%.c=%.d) $(LINT).d +LINT_CCAN_MODULES := autodata dgraph ilog lbalance ptr_valid strmap +LINT_CCAN_SRCS := $(wildcard $(LINT_CCAN_MODULES:%=ccan/%/*.c)) +LINT_OBJS := $(LINT_SRCS:%.c=%.o) $(LINT_CCAN_SRCS:%.c=%.o) $(TOOLS_OBJS) +ifneq ($(GCOV),) +LINT_GCOV = --gcov="$(GCOV)" +endif +$(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 +%.ok: $(LINT) %info + $(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 $@ + +check: $(MODULES:%=%/.ok) +fastcheck: $(MODULES:%=%/.fast-ok) + +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