]> git.ozlabs.org Git - ccan/blob - Makefile
8a4077287a3181b39f3606e3e1fe2223381f5de8
[ccan] / Makefile
1 # Hacky makefile to compile everything and run the tests in some kind
2 # of sane order.
3
4 # Main targets:
5
6 # check: run tests on all ccan modules (use 'make check V=--verbose' for more)
7 #        Includes building libccan.a.
8 # tools: build useful tools in tools/ dir.
9 #        Especially tools/ccanlint/ccanlint and tools/namespacize.
10 # distclean: destroy everything back to pristine state
11
12 # This can be overridden on cmdline to generate pages elsewhere.
13 WEBDIR=~/www/html/ccan/
14
15 ALL=$(patsubst ccan/%/test, %, $(wildcard ccan/*/test))
16 ALL_DIRS=$(patsubst %, ccan/%, $(ALL))
17 ALL_DEPENDS=$(patsubst %, ccan/%/.depends, $(ALL))
18 ALL_PAGES=$(patsubst ccan/%, $(WEBDIR)/info/%.html, $(ALL_DIRS))
19 DIRECT_TARBALLS=$(patsubst ccan/%, $(WEBDIR)/tarballs/%.tar.bz2, $(ALL_DIRS))
20 DEPEND_TARBALLS=$(patsubst ccan/%, $(WEBDIR)/tarballs/with-deps/%.tar.bz2, $(ALL_DIRS))
21 WEB_SUBDIRS=$(WEBDIR)/tarballs $(WEBDIR)/junkcode $(WEBDIR)/tarballs/with-deps $(WEBDIR)/info
22 JUNKDIRS=$(wildcard junkcode/*)
23 JUNKPAGES=$(JUNKDIRS:%=$(WEBDIR)/%.html)
24 JUNKBALLS=$(JUNKDIRS:%=$(WEBDIR)/%.tar.bz2)
25
26 include Makefile-ccan
27
28 check: $(ALL_DIRS:%=test-%)
29         echo $(ALL_DIRS)
30
31 distclean: clean
32         rm -f $(ALL_DEPENDS)
33         rm -rf $(WEBDIR)
34
35 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)
36
37 $(WEB_SUBDIRS):
38         mkdir -p $@
39
40 $(WEBDIR)/junkcode/%.tar.bz2: junkcode/% $(WEBDIR)/junkcode
41         tar cvfj $@ `bzr ls --versioned --kind=file $<`
42
43 $(WEBDIR)/junkcode/%.html: $(WEBDIR)/junkcode/%.tar.bz2
44         cd $(WEBDIR) && tar xfj junkcode/$*.tar.bz2
45         php5 web/staticjunkcode.php junkcode/$* $* > $@
46
47 # Override implicit attempt to link directory.
48 $(ALL_DIRS):
49         @touch $@
50
51 $(WEBDIR)/ccan.tar.bz2: config.h Makefile Makefile-ccan $(shell bzr ls --versioned --kind=file ccan) $(shell bzr ls --versioned --kind=file tools)
52         tar cvfj $@ $^
53
54 $(ALL_PAGES): tools/doc_extract web/staticmoduleinfo.php
55
56 $(WEBDIR)/list.html: web/staticall.php tools/doc_extract $(DIRECT_TARBALLS) $(DEPEND_TARBALLS) $(WEBDIR)/ccan.tar.bz2 $(JUNKBALLS)
57         php5 web/staticall.php ccan/ junkcode/ $(WEBDIR) > $@
58
59 $(WEBDIR)/upload.html: web/staticupload.php
60         php5 web/staticupload.php > $@
61
62 # cpp inserts gratuitous linebreaks at start of file, makes for php problems.
63 $(WEBDIR)/uploader.php: web/uploader.php.cpp
64         cpp -w -C -P $< | grep . > $@
65
66 $(WEBDIR)/index.html: web/staticindex.php
67         php5 web/staticindex.php > $@
68
69 $(WEBDIR)/example-config.h: config.h
70         cp $< $@
71
72 $(WEBDIR)/Makefile-ccan: Makefile-ccan
73         cp $< $@
74
75 $(WEBDIR)/ccan.jpg: web/ccan.jpg
76         cp $< $@
77
78 $(WEBDIR)/info/%.html: ccan/% ccan/%/test $(WEBDIR)/tarballs/%.tar.bz2 $(WEBDIR)/tarballs/with-deps/%.tar.bz2
79         URLPREFIX=../ php5 web/staticmoduleinfo.php ccan/$* > $@
80
81 $(WEBDIR)/tarballs/%.tar.bz2: ccan/% ccan/%/test
82         tar -c -v -j -f $@ `bzr ls --versioned --kind=file ccan/$*`
83
84 $(WEBDIR)/tarballs/with-deps/%.tar.bz2: ccan/% ccan/%/test tools/ccan_depends
85         tar cvfj $@ $$(echo ccan/$* $$(tools/ccan_depends ccan/$*) | xargs -n 1 bzr ls --versioned --kind=file)
86
87 $(ALL_DEPENDS): %/.depends: tools/ccan_depends
88         tools/ccan_depends $* > $@ || ( rm -f $@; exit 1 )
89
90 test-ccan/%: tools/run_tests libccan.a(%.o)
91         @echo Testing $*...
92         @if tools/run_tests $(V) ccan/$* | grep ^'not ok'; then exit 1; else exit 0; fi
93
94 # Some don't have object files.
95 test-ccan/%:: tools/run_tests
96         @echo Testing $*...
97         @if tools/run_tests $(V) ccan/$* | grep ^'not ok'; then exit 1; else exit 0; fi
98
99 clean: tools-clean
100         $(RM) `find . -name '*.o'` `find . -name '.depends'` `find . -name '*.a'`  `find . -name _info`
101         $(RM) inter-depends lib-depends test-depends
102
103 # Only list a dependency if there are object files to build.
104 inter-depends: $(ALL_DEPENDS)
105         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 > $@
106
107 test-depends: $(ALL_DEPENDS)
108         for f in $(ALL_DEPENDS); do echo test-ccan/`basename \`dirname $$f\``: `sed -n 's,ccan/\(.*\),test-ccan/\1,p' < $$f`; done > $@
109
110 include tools/Makefile
111 -include inter-depends
112 -include test-depends