Zbatery 0.4.0 - Rainbows! 1.0.x sync
[zbatery.git] / GNUmakefile
blob3c2fb29a2b238ce20c0b025c6b824047cd1d7f8d
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all::
3 MRI = ruby
4 RUBY = ruby
5 RAKE = rake
6 RSYNC = rsync
7 GIT_URL = git://git.bogomips.org/zbatery.git
9 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
10 @./GIT-VERSION-GEN
11 -include GIT-VERSION-FILE
12 -include local.mk
13 ifeq ($(DLEXT),) # "so" for Linux
14 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
15 endif
16 ifeq ($(RUBY_VERSION),)
17 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
18 endif
19 RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
21 base_bins := zbatery
22 bins := $(addprefix bin/, $(base_bins))
23 man1_rdoc := $(addsuffix _1, $(base_bins))
24 man1_bins := $(addsuffix .1, $(base_bins))
25 man1_paths := $(addprefix man/man1/, $(man1_bins))
27 install: $(bins)
28 $(prep_setup_rb)
29 $(RM) -r .install-tmp
30 mkdir .install-tmp
31 cp -p bin/* .install-tmp
32 $(RUBY) setup.rb all
33 $(RM) $^
34 mv .install-tmp/* bin/
35 $(RM) -r .install-tmp
36 $(prep_setup_rb)
38 setup_rb_files := .config InstalledFiles
39 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
41 clean:
42 -$(MAKE) -C $(ext) clean
43 -$(MAKE) -C Documentation clean
44 $(RM) $(setup_rb_files) $(t_log)
46 man:
47 $(MAKE) -C Documentation install-man
49 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog
50 manifest: $(pkg_extra) man
51 $(RM) .manifest
52 $(MAKE) .manifest
54 .manifest:
55 (git ls-files && \
56 for i in $@ $(pkg_extra) $(man1_paths); \
57 do echo $$i; done) | LC_ALL=C sort > $@+
58 cmp $@+ $@ || mv $@+ $@
59 $(RM) $@+
61 NEWS: GIT-VERSION-FILE
62 $(RAKE) -s news_rdoc > $@+
63 mv $@+ $@
65 SINCE = 0.3.1
66 ChangeLog: LOG_VERSION = \
67 $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
68 echo $(GIT_VERSION) || git describe)
69 ifneq ($(SINCE),)
70 ChangeLog: log_range = v$(SINCE)..$(LOG_VERSION)
71 endif
72 ChangeLog: GIT-VERSION-FILE
73 @echo "ChangeLog from $(GIT_URL) ($(log_range))" > $@+
74 @echo >> $@+
75 git log $(log_range) | sed -e 's/^/ /' >> $@+
76 mv $@+ $@
78 news_atom := http://zbatery.bogomip.org/NEWS.atom.xml
79 cgit_atom := http://git.bogomips.org/cgit/zbatery.git/atom/?h=master
80 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
81 type="application/atom+xml"/>
83 # using rdoc 2.5.x+
84 doc: .document NEWS ChangeLog
85 for i in $(man1_rdoc); do echo > $$i; done
86 find bin lib -type f -name '*.rbc' -exec rm -f '{}' ';'
87 rdoc -t "$(shell sed -ne '1s/^= //p' README)"
88 install -m644 COPYING doc/COPYING
89 install -m644 $(shell grep '^[A-Z]' .document) doc/
90 $(MAKE) -C Documentation install-html install-man
91 install -m644 $(man1_paths) doc/
92 cd doc && for i in $(base_bins); do \
93 $(RM) 1.html $${i}.1.html; \
94 sed -e '/"documentation">/r man1/'$$i'.1.html' \
95 < $${i}_1.html > tmp && mv tmp $${i}_1.html; \
96 ln $${i}_1.html $${i}.1.html; \
97 done
98 $(MRI) -i -p -e \
99 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
100 doc/ChangeLog.html
101 $(MRI) -i -p -e \
102 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
103 doc/NEWS.html doc/README.html
104 $(RAKE) -s news_atom > doc/NEWS.atom.xml
105 cd doc && ln README.html tmp && mv tmp index.html
106 $(RM) $(man1_rdoc)
108 # publishes docs to http://zbatery.bogomip.org/
109 publish_doc:
110 -git set-file-times
111 $(RM) -r doc ChangeLog NEWS
112 $(MAKE) doc LOG_VERSION=$(shell git tag -l | tail -1)
113 awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' \
114 < NEWS > doc/LATEST
115 find doc/images doc/js -type f | \
116 TZ=UTC xargs touch -d '1970-01-01 00:00:01' doc/rdoc.css
117 $(MAKE) doc_gz
118 chmod 644 $$(find doc -type f)
119 $(RSYNC) -av doc/ zbatery.bogomip.org:/srv/zbatery/
120 git ls-files | xargs touch
122 # Create gzip variants of the same timestamp as the original so nginx
123 # "gzip_static on" can serve the gzipped versions directly.
124 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
125 doc_gz:
126 touch doc/NEWS.atom.xml -d "$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
127 for i in $(docs); do \
128 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
130 ifneq ($(VERSION),)
131 rfproject := rainbows
132 rfpackage := zbatery
133 pkggem := pkg/$(rfpackage)-$(VERSION).gem
134 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
135 release_notes := release_notes-$(VERSION)
136 release_changes := release_changes-$(VERSION)
138 release-notes: $(release_notes)
139 release-changes: $(release_changes)
140 $(release_changes):
141 $(RAKE) -s release_changes > $@+
142 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
143 $(release_notes):
144 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
145 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
147 # ensures we're actually on the tagged $(VERSION), only used for release
148 verify:
149 test x"$(shell umask)" = x0022
150 git rev-parse --verify refs/tags/v$(VERSION)^{}
151 git diff-index --quiet HEAD^0
152 test `git rev-parse --verify HEAD^0` = \
153 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
155 fix-perms:
156 -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
157 -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
159 gem: $(pkggem)
161 install-gem: $(pkggem)
162 gem install $(CURDIR)/$<
164 $(pkggem): manifest fix-perms
165 gem build $(rfpackage).gemspec
166 mkdir -p pkg
167 mv $(@F) $@
169 $(pkgtgz): distdir = $(basename $@)
170 $(pkgtgz): HEAD = v$(VERSION)
171 $(pkgtgz): manifest fix-perms
172 @test -n "$(distdir)"
173 $(RM) -r $(distdir)
174 mkdir -p $(distdir)
175 tar c `cat .manifest` | (cd $(distdir) && tar x)
176 cd pkg && tar c $(basename $(@F)) | gzip -9 > $(@F)+
177 mv $@+ $@
179 package: $(pkgtgz) $(pkggem)
181 release: verify package $(release_notes) $(release_changes)
182 # make tgz release on RubyForge
183 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
184 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
185 # push gem to RubyGems.org
186 gem push $(pkggem)
187 # in case of gem downloads from RubyForge releases page
188 -rubyforge add_file \
189 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
190 $(RAKE) raa_update VERSION=$(VERSION)
191 $(RAKE) fm_update VERSION=$(VERSION)
192 else
193 gem install-gem: GIT-VERSION-FILE
194 $(MAKE) $@ VERSION=$(GIT_VERSION)
195 endif
197 all:: test
198 test:
199 $(MAKE) -C t
201 .PHONY: .FORCE-GIT-VERSION-FILE doc manifest man test