GNUmakefile: add rcov target
[ruby_io_splice.git] / GNUmakefile
blob9b22bc494527a6e047dd11335a01bb0b547e9988
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all::
3 RUBY = ruby
4 RAKE = rake
5 GIT_URL = git://git.bogomips.org/ruby_io_splice.git
6 RSYNC = rsync
7 RCOV = rcov
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
20 install: $(bins)
21 $(prep_setup_rb)
22 $(RM) -r .install-tmp
23 mkdir .install-tmp
24 cp -p bin/* .install-tmp
25 $(RUBY) setup.rb all
26 $(RM) $^
27 mv .install-tmp/* bin/
28 $(RM) -r .install-tmp
29 $(prep_setup_rb)
31 setup_rb_files := .config InstalledFiles
32 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
34 clean:
35 -$(MAKE) -C ext/io_splice clean
36 $(RM) $(setup_rb_files) ext/io_splice/Makefile
38 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog
39 manifest: $(pkg_extra)
40 $(RM) .manifest
41 $(MAKE) .manifest
43 .manifest:
44 (git ls-files && \
45 for i in $@ $(pkg_extra); \
46 do echo $$i; done) | LC_ALL=C sort > $@+
47 cmp $@+ $@ || mv $@+ $@
48 $(RM) $@+
50 NEWS: GIT-VERSION-FILE
51 $(RAKE) -s news_rdoc > $@+
52 mv $@+ $@
54 SINCE =
55 ChangeLog: LOG_VERSION = \
56 $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
57 echo $(GIT_VERSION) || git describe)
58 ifneq ($(SINCE),)
59 ChangeLog: log_range = v$(SINCE)..$(LOG_VERSION)
60 endif
61 ChangeLog: GIT-VERSION-FILE
62 @echo "ChangeLog from $(GIT_URL) ($(log_range))" > $@+
63 @echo >> $@+
64 git log $(log_range) | sed -e 's/^/ /' >> $@+
65 mv $@+ $@
67 news_atom := http://bogomips.org/ruby_io_splice/NEWS.atom.xml
68 cgit_atom := http://git.bogomips.org/cgit/ruby_io_splice.git/atom/?h=master
69 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
70 type="application/atom+xml"/>
72 # using rdoc 2.5.x + workaround patch here:
73 # rubyforge.org/tracker/index.php?func=detail&aid=28230&group_id=627&atid=2472
74 doc: .document NEWS ChangeLog
75 rdoc -a -t "$(shell sed -ne '1s/^= //p' README)"
76 install -m644 COPYING doc/COPYING
77 install -m644 $(shell grep '^[A-Z]' .document) doc/
78 cd doc && for i in $(base_bins); do \
79 html=$$(echo $$i | sed 's/\.rb/_rb/')_1.html; \
80 sed -e '/"documentation">/r man1/'$$i'.1.html' \
81 < $$html > tmp && mv tmp $$html; done
82 $(RUBY) -i -p -e \
83 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
84 doc/ChangeLog.html
85 $(RUBY) -i -p -e \
86 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
87 doc/NEWS.html doc/README.html
88 $(RAKE) -s news_atom > doc/NEWS.atom.xml
89 cd doc && ln README.html tmp && mv tmp index.html
91 latest: NEWS
92 @awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' $<
94 # publishes docs to http://bogomips.org/ruby_io_splice/,
95 publish_doc:
96 -git set-file-times
97 $(RM) -r doc ChangeLog NEWS
98 $(MAKE) doc LOG_VERSION=$(shell git tag -l | tail -1)
99 awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' \
100 NEWS > doc/LATEST
101 find doc/images doc/js -type f | \
102 TZ=UTC xargs touch -d '1970-01-01 00:00:01' doc/rdoc.css
103 $(MAKE) doc_gz
104 chmod 644 $$(find doc -type f)
105 $(RSYNC) -av doc/ bogomips.org:/srv/bogomips/ruby_io_splice/
106 git ls-files | xargs touch
108 # Create gzip variants of the same timestamp as the original so nginx
109 # "gzip_static on" can serve the gzipped versions directly.
110 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
111 doc_gz:
112 touch doc/NEWS.atom.xml -d "$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
113 for i in $(docs); do \
114 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
116 ifneq ($(VERSION),)
117 rfproject := qrp
118 rfpackage := io_splice
119 pkggem := pkg/$(rfpackage)-$(VERSION).gem
120 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
121 release_notes := release_notes-$(VERSION)
122 release_changes := release_changes-$(VERSION)
124 release-notes: $(release_notes)
125 release-changes: $(release_changes)
126 $(release_changes):
127 $(RAKE) -s release_changes > $@+
128 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
129 $(release_notes):
130 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
131 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
133 # ensures we're actually on the tagged $(VERSION), only used for release
134 verify:
135 test x"$(shell umask)" = x0022
136 git rev-parse --verify refs/tags/v$(VERSION)^{}
137 git diff-index --quiet HEAD^0
138 test `git rev-parse --verify HEAD^0` = \
139 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
141 fix-perms:
142 -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
143 -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
145 gem: $(pkggem)
147 install-gem: $(pkggem)
148 gem install $(CURDIR)/$<
150 $(pkggem): manifest fix-perms
151 gem build $(rfpackage).gemspec
152 mkdir -p pkg
153 mv $(@F) $@
155 $(pkgtgz): distdir = $(basename $@)
156 $(pkgtgz): HEAD = v$(VERSION)
157 $(pkgtgz): manifest fix-perms
158 @test -n "$(distdir)"
159 $(RM) -r $(distdir)
160 mkdir -p $(distdir)
161 tar c `cat .manifest` | (cd $(distdir) && tar x)
162 cd pkg && tar c $(basename $(@F)) | gzip -9 > $(@F)+
163 mv $@+ $@
165 package: $(pkgtgz) $(pkggem)
167 test-release: verify package $(release_notes) $(release_changes)
168 release: verify package $(release_notes) $(release_changes)
169 # make tgz release on RubyForge
170 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
171 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
172 # push gem to Gemcutter
173 gem push $(pkggem)
174 # in case of gem downloads from RubyForge releases page
175 -rubyforge add_file \
176 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
177 else
178 gem install-gem: GIT-VERSION-FILE
179 $(MAKE) $@ VERSION=$(GIT_VERSION)
180 endif
182 ext := ext/io_splice/io_splice_ext.$(DLEXT)
183 ext/io_splice/Makefile: ext/io_splice/extconf.rb
184 cd $(@D) && $(RUBY) extconf.rb
185 $(ext): $(wildcard $(addprefix ext/io_splice/,*.c *.h)) ext/io_splice/Makefile
186 $(MAKE) -C $(@D)
188 all:: test
190 build: $(ext)
191 test: test-unit
192 rcov: build
193 $(RCOV) -I lib:ext/io_splice $(test_unit)
195 test_unit := $(wildcard test/test_*.rb)
196 $(test_unit): build
197 $(RUBY) -I lib:ext/io_splice $@ $(TEST_UNIT_OPTS)
198 test-unit: $(test_unit)
200 .PHONY: .FORCE-GIT-VERSION-FILE doc manifest man test $(test_unit)