]> git.ozlabs.org Git - ccan/blobdiff - Makefile
base32: add ability to substitute character set.
[ccan] / Makefile
index 222a9b22146c516476d9ae2ae816a00636c5ad25..c507b746651c57243f7fa0834d6c132bef5415cb 100644 (file)
--- a/Makefile
+++ b/Makefile
-# Hacky makefile to compile everything and run the tests in some kind of sane order.
-# V=--verbose for verbose tests.
-
-# This can be overridden on cmdline to generate pages elsewhere.
-WEBDIR=~/www/html/ccan/
-
-ALL=$(patsubst ccan/%/test, %, $(wildcard ccan/*/test))
-ALL_DIRS=$(patsubst %, ccan/%, $(ALL))
-ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
-ALL_PAGES=$(patsubst ccan/%, $(WEBDIR)/info/%.html, $(ALL_DIRS))
-DIRECT_TARBALLS=$(patsubst ccan/%, $(WEBDIR)/tarballs/%.tar.bz2, $(ALL_DIRS))
-DEPEND_TARBALLS=$(patsubst ccan/%, $(WEBDIR)/tarballs/with-deps/%.tar.bz2, $(ALL_DIRS))
-WEB_SUBDIRS=$(WEBDIR)/tarballs $(WEBDIR)/junkcode $(WEBDIR)/tarballs/with-deps $(WEBDIR)/info
-JUNKDIRS=$(wildcard junkcode/*)
-JUNKPAGES=$(JUNKDIRS:%=$(WEBDIR)/%.html)
-JUNKBALLS=$(JUNKDIRS:%=$(WEBDIR)/%.tar.bz2)
-
-include Makefile-ccan
-
-check: $(ALL_DIRS:%=test-%)
-       echo $(ALL_DIRS)
-
-distclean: clean
-       rm -f $(ALL_DEPENDS)
-       rm -rf $(WEBDIR)
-
-webpages: $(WEB_SUBDIRS) $(WEBDIR)/junkcode $(ALL_PAGES) $(WEBDIR)/list.html $(WEBDIR)/index.html $(WEBDIR)/upload.html $(WEBDIR)/uploader.php $(WEBDIR)/example-config.h $(WEBDIR)/ccan.jpg $(DIRECT_TARBALLS) $(DEPEND_TARBALLS) $(WEBDIR)/ccan.tar.bz2 $(WEBDIR)/Makefile-ccan $(JUNKPAGES) $(JUNKBALLS)
-
-$(WEB_SUBDIRS):
-       mkdir -p $@
-
-$(WEBDIR)/junkcode/%.tar.bz2: junkcode/% $(WEBDIR)/junkcode
-       tar cvfj $@ `bzr ls --versioned --kind=file $<`
-
-$(WEBDIR)/junkcode/%.html: $(WEBDIR)/junkcode/%.tar.bz2
-       cd $(WEBDIR) && tar xfj junkcode/$*.tar.bz2
-       php5 web/staticjunkcode.php junkcode/$* $* > $@
-
-# Override implicit attempt to link directory.
-$(ALL_DIRS):
-       @touch $@
-
-$(WEBDIR)/ccan.tar.bz2:
-       tar cvfj $@ `bzr ls --versioned --kind=file ccan`
-
-$(ALL_PAGES): tools/doc_extract web/staticmoduleinfo.php
-
-$(WEBDIR)/list.html: web/staticall.php tools/doc_extract $(DIRECT_TARBALLS) $(DEPEND_TARBALLS) $(WEBDIR)/ccan.tar.bz2 $(JUNKBALLS)
-       php5 web/staticall.php ccan/ junkcode/ $(WEBDIR) > $@
-
-$(WEBDIR)/upload.html: web/staticupload.php
-       php5 web/staticupload.php > $@
-
-# cpp inserts gratuitous linebreaks at start of file, makes for php problems.
-$(WEBDIR)/uploader.php: web/uploader.php.cpp
-       cpp -w -C -P $< | grep . > $@
-
-$(WEBDIR)/index.html: web/staticindex.php
-       php5 web/staticindex.php > $@
-
-$(WEBDIR)/example-config.h: config.h
-       cp $< $@
-
-$(WEBDIR)/Makefile-ccan: Makefile-ccan
-       cp $< $@
-
-$(WEBDIR)/ccan.jpg: web/ccan.jpg
-       cp $< $@
-
-$(WEBDIR)/info/%.html: ccan/% ccan/%/test $(WEBDIR)/tarballs/%.tar.bz2 $(WEBDIR)/tarballs/with-deps/%.tar.bz2
-       URLPREFIX=../ php5 web/staticmoduleinfo.php ccan/$* > $@
-
-$(WEBDIR)/tarballs/%.tar.bz2: ccan/% ccan/%/test
-       tar -c -v -j -f $@ `bzr ls --versioned --kind=file ccan/$*`
-
-$(WEBDIR)/tarballs/with-deps/%.tar.bz2: ccan/% ccan/%/test tools/ccan_depends
-       tar cvfj $@ $$(echo ccan/$* $$(tools/ccan_depends ccan/$*) | xargs -n 1 bzr ls --versioned --kind=file)
-
-$(ALL_DEPENDS): %/.depends: tools/ccan_depends
-       tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
-
-test-ccan/%: tools/run_tests libccan.a(%.o)
-       @echo Testing $*...
-       @if tools/run_tests $(V) ccan/$* | grep ^'not ok'; then exit 1; else exit 0; fi
-
-# Some don't have object files.
-test-ccan/%:: tools/run_tests
-       @echo Testing $*...
-       @if tools/run_tests $(V) ccan/$* | grep ^'not ok'; then exit 1; else exit 0; fi
-
-ccanlint: tools/ccanlint/ccanlint
-
-clean: tools-clean
-       $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'`  `find . -name _info`
-       $(RM) inter-depends lib-depends test-depends
-
-# Only list a dependency if there are object files to build.
-inter-depends: $(ALL_DEPENDS)
-       for f in $(ALL_DEPENDS); do echo test-ccan/$$(basename $$(dirname $$f) ): $$(for dir in $$(cat $$f); do [ "$$(echo $$dir/[a-z]*.c)" = "$$dir/[a-z]*.c" ] || echo libccan.a\("$$(basename $$dir)".o\); done); done > $@
-
-test-depends: $(ALL_DEPENDS)
-       for f in $(ALL_DEPENDS); do echo test-ccan/`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),test-ccan/\1,p' < $$f`; done > $@
-
-include tools/Makefile
--include inter-depends
--include test-depends
+# 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)
+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 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