initial commit + release
[kgio.git] / GNUmakefile
blob559bc75ca403d0abbee184c56cb6d2bb7472d3a0
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all::
3 RUBY = ruby
4 RAKE = rake
5 RSYNC = rsync
6 GIT_URL = git://git.bogomips.org/kgio.git
8 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
9 @./GIT-VERSION-GEN
10 -include GIT-VERSION-FILE
11 -include local.mk
12 ifeq ($(DLEXT),) # "so" for Linux
13 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
14 endif
15 ifeq ($(RUBY_VERSION),)
16 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
17 endif
19 install:
20 $(prep_setup_rb)
21 $(RM) -r .install-tmp
22 mkdir .install-tmp
23 $(RUBY) setup.rb all
24 $(RM) $^
25 $(RM) -r .install-tmp
26 $(prep_setup_rb)
28 setup_rb_files := .config InstalledFiles
29 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
31 clean:
32 -$(MAKE) -C ext/kgio clean
33 $(RM) $(setup_rb_files) ext/kgio/Makefile
35 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog
36 manifest: $(pkg_extra)
37 $(RM) .manifest
38 $(MAKE) .manifest
40 .manifest:
41 (git ls-files && \
42 for i in $@ $(pkg_extra) $(man1_paths); \
43 do echo $$i; done) | LC_ALL=C sort > $@+
44 cmp $@+ $@ || mv $@+ $@
45 $(RM) $@+
47 NEWS: GIT-VERSION-FILE
48 $(RAKE) -s news_rdoc > $@+
49 mv $@+ $@
51 latest: NEWS
52 @awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' $<
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://unicorn.bogomips.org/kgio/NEWS.atom.xml
68 cgit_atom := http://git.bogomips.org/cgit/kgio.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
73 doc: .document NEWS ChangeLog
74 rdoc -t "$(shell sed -ne '1s/^= //p' README)"
75 install -m644 COPYING doc/COPYING
76 install -m644 $(shell grep '^[A-Z]' .document) doc/
77 $(RUBY) -i -p -e \
78 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
79 doc/ChangeLog.html
80 $(RUBY) -i -p -e \
81 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
82 doc/NEWS.html doc/README.html
83 $(RAKE) -s news_atom > doc/NEWS.atom.xml
84 cd doc && ln README.html tmp && mv tmp index.html
86 ifneq ($(VERSION),)
87 rfproject := rainbows
88 rfpackage := kgio
89 pkggem := pkg/$(rfpackage)-$(VERSION).gem
90 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
91 release_notes := release_notes-$(VERSION)
92 release_changes := release_changes-$(VERSION)
94 release-notes: $(release_notes)
95 release-changes: $(release_changes)
96 $(release_changes):
97 $(RAKE) -s release_changes > $@+
98 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
99 $(release_notes):
100 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
101 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
103 # ensures we're actually on the tagged $(VERSION), only used for release
104 verify:
105 test x"$(shell umask)" = x0022
106 git rev-parse --verify refs/tags/v$(VERSION)^{}
107 git diff-index --quiet HEAD^0
108 test `git rev-parse --verify HEAD^0` = \
109 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
111 fix-perms:
112 -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
113 -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
115 gem: $(pkggem)
117 install-gem: $(pkggem)
118 gem install $(CURDIR)/$<
120 $(pkggem): manifest fix-perms
121 gem build $(rfpackage).gemspec
122 mkdir -p pkg
123 mv $(@F) $@
125 $(pkgtgz): distdir = $(basename $@)
126 $(pkgtgz): HEAD = v$(VERSION)
127 $(pkgtgz): manifest fix-perms
128 @test -n "$(distdir)"
129 $(RM) -r $(distdir)
130 mkdir -p $(distdir)
131 tar c `cat .manifest` | (cd $(distdir) && tar x)
132 cd pkg && tar c $(basename $(@F)) | gzip -9 > $(@F)+
133 mv $@+ $@
135 package: $(pkgtgz) $(pkggem)
137 test-release: verify package $(release_notes) $(release_changes)
138 release: verify package $(release_notes) $(release_changes)
139 # make tgz release on RubyForge
140 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
141 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
142 # push gem to Gemcutter
143 gem push $(pkggem)
144 # in case of gem downloads from RubyForge releases page
145 -rubyforge add_file \
146 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
147 else
148 gem install-gem: GIT-VERSION-FILE
149 $(MAKE) $@ VERSION=$(GIT_VERSION)
150 endif
152 ext := ext/kgio/kgio_ext.$(DLEXT)
153 ext/kgio/Makefile: ext/kgio/extconf.rb
154 cd $(@D) && $(RUBY) extconf.rb
156 $(ext): ext/kgio/kgio_ext.c ext/kgio/Makefile
157 $(MAKE) -C $(@D)
159 all:: test
161 build: $(ext)
162 test_units := $(wildcard test/test_*.rb)
163 test: test-unit
164 test-unit: $(test_units)
165 $(test_units): build
166 $(RUBY) -I lib:ext/kgio $@
168 # this requires GNU coreutils variants
169 publish_doc:
170 -git set-file-times
171 $(RM) -r doc ChangeLog NEWS
172 $(MAKE) doc LOG_VERSION=$(shell git tag -l | tail -1)
173 $(MAKE) -s latest > doc/LATEST
174 find doc/images doc/js -type f | \
175 TZ=UTC xargs touch -d '1970-01-01 00:00:00' doc/rdoc.css
176 $(MAKE) doc_gz
177 chmod 644 $$(find doc -type f)
178 $(RSYNC) -av doc/ unicorn.bogomips.org:/srv/unicorn/kgio/
179 git ls-files | xargs touch
181 # Create gzip variants of the same timestamp as the original so nginx
182 # "gzip_static on" can serve the gzipped versions directly.
183 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
184 doc_gz:
185 touch doc/NEWS.atom.xml -d "$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
186 for i in $(docs); do \
187 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
189 .PHONY: .FORCE-GIT-VERSION-FILE doc manifest man test $(test_units)