String#hash is not stable across processes :<
[metropolis.git] / GNUmakefile
blobe03543426ff98f4eb0b9fb04c9ffa199434e3dfa
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/metropolis.git
6 RSYNC = rsync
8 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
9 @./GIT-VERSION-GEN
10 -include GIT-VERSION-FILE
11 -include local.mk
12 ifeq ($(RUBY_VERSION),)
13 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
14 endif
16 install: $(bins)
17 $(prep_setup_rb)
18 $(RM) -r .install-tmp
19 mkdir .install-tmp
20 cp -p bin/* .install-tmp
21 $(RUBY) setup.rb all
22 $(RM) $^
23 mv .install-tmp/* bin/
24 $(RM) -r .install-tmp
25 $(prep_setup_rb)
27 setup_rb_files := .config InstalledFiles
28 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
30 clean:
31 $(RM) $(setup_rb_files)
33 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog
34 manifest: $(pkg_extra)
35 $(RM) .manifest
36 $(MAKE) .manifest
38 .manifest:
39 (git ls-files && \
40 for i in $@ $(pkg_extra) $(man1_paths); \
41 do echo $$i; done) | LC_ALL=C sort > $@+
42 cmp $@+ $@ || mv $@+ $@
43 $(RM) $@+
45 NEWS: GIT-VERSION-FILE
46 $(RAKE) -s news_rdoc > $@+
47 mv $@+ $@
49 latest: NEWS
50 @awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' $<
52 SINCE =
53 ChangeLog: LOG_VERSION = \
54 $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
55 echo $(GIT_VERSION) || git describe)
56 ifneq ($(SINCE),)
57 ChangeLog: log_range = v$(SINCE)..$(LOG_VERSION)
58 endif
59 ChangeLog: GIT-VERSION-FILE
60 @echo "ChangeLog from $(GIT_URL) ($(log_range))" > $@+
61 @echo >> $@+
62 git log $(log_range) | sed -e 's/^/ /' >> $@+
63 mv $@+ $@
65 news_atom := http://metropolis.bogomips.org/NEWS.atom.xml
66 cgit_atom := http://git.bogomips.org/cgit/metropolis.git/atom/?h=master
67 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
68 type="application/atom+xml"/>
70 # using rdoc 2.5.x
71 doc: .document NEWS ChangeLog
72 rdoc -t "$(shell sed -ne '1s/^= //p' README)"
73 install -m644 COPYING doc/COPYING
74 install -m644 $(shell grep '^[A-Z]' .document) doc/
75 $(RUBY) -i -p -e \
76 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
77 doc/ChangeLog.html
78 $(RUBY) -i -p -e \
79 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
80 doc/NEWS.html doc/README.html
81 $(RAKE) -s news_atom > doc/NEWS.atom.xml
82 cd doc && ln README.html tmp && mv tmp index.html
84 ifneq ($(VERSION),)
85 rfproject := rainbows
86 rfpackage := metropolis
87 pkggem := pkg/$(rfpackage)-$(VERSION).gem
88 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
89 release_notes := release_notes-$(VERSION)
90 release_changes := release_changes-$(VERSION)
92 release-notes: $(release_notes)
93 release-changes: $(release_changes)
94 $(release_changes):
95 $(RAKE) -s release_changes > $@+
96 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
97 $(release_notes):
98 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
99 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
101 # ensures we're actually on the tagged $(VERSION), only used for release
102 verify:
103 test x"$(shell umask)" = x0022
104 git rev-parse --verify refs/tags/v$(VERSION)^{}
105 git diff-index --quiet HEAD^0
106 test `git rev-parse --verify HEAD^0` = \
107 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
109 fix-perms:
110 -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
111 -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
113 gem: $(pkggem)
115 install-gem: $(pkggem)
116 gem install $(CURDIR)/$<
118 $(pkggem): manifest fix-perms
119 gem build $(rfpackage).gemspec
120 mkdir -p pkg
121 mv $(@F) $@
123 $(pkgtgz): distdir = $(basename $@)
124 $(pkgtgz): HEAD = v$(VERSION)
125 $(pkgtgz): manifest fix-perms
126 @test -n "$(distdir)"
127 $(RM) -r $(distdir)
128 mkdir -p $(distdir)
129 tar cf - `cat .manifest` | (cd $(distdir) && tar x)
130 cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
131 mv $@+ $@
133 package: $(pkgtgz) $(pkggem)
135 test-release: verify package $(release_notes) $(release_changes)
136 release: verify package $(release_notes) $(release_changes)
137 # make tgz release on RubyForge
138 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
139 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
140 # push gem to RubyGems.org
141 gem push $(pkggem)
142 # in case of gem downloads from RubyForge releases page
143 -rubyforge add_file \
144 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
145 $(RAKE) raa_update VERSION=$(VERSION)
146 $(RAKE) publish_news VERSION=$(VERSION)
147 else
148 gem install-gem: GIT-VERSION-FILE
149 $(MAKE) $@ VERSION=$(GIT_VERSION)
150 endif
152 all:: test
154 test_units := $(wildcard test/test_*.rb)
155 test: test-unit
156 test-unit: $(test_units)
157 $(test_units):
158 $(RUBY) -I lib $@
160 # this requires GNU coreutils variants
161 publish_doc:
162 -git set-file-times
163 $(RM) -r doc ChangeLog NEWS
164 $(MAKE) doc LOG_VERSION=$(shell git tag -l | tail -1)
165 $(MAKE) -s latest > doc/LATEST
166 find doc/images doc/js -type f | \
167 TZ=UTC xargs touch -d '1970-01-01 00:00:00' doc/rdoc.css
168 $(MAKE) doc_gz
169 chmod 644 $$(find doc -type f)
170 $(RSYNC) -av doc/ metropolis.bogomips.org:/srv/metropolis/
171 git ls-files | xargs touch
173 # Create gzip variants of the same timestamp as the original so nginx
174 # "gzip_static on" can serve the gzipped versions directly.
175 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
176 doc_gz:
177 touch doc/NEWS.atom.xml -d "$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
178 for i in $(docs); do \
179 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
181 .PHONY: .FORCE-GIT-VERSION-FILE doc manifest man test $(test_units)