doc: latest news is available through finger
[unicorn.git] / GNUmakefile
blob235972170c4d5ca904322dadc8ec725605aa5c37
1 # use GNU Make to run tests in parallel, and without depending on Rubygems
2 all:: test
3 ruby = ruby
4 rake = rake
5 ragel = ragel
6 GIT_URL = $(shell git config --get remote.origin.url 2>/dev/null || \
7 echo git://git.bogomips.org/unicorn.git)
8 RLFLAGS = -G2
10 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
11 @./GIT-VERSION-GEN
12 -include GIT-VERSION-FILE
13 -include local.mk
14 ruby_bin := $(shell which $(ruby))
15 ifeq ($(DLEXT),) # "so" for Linux
16 DLEXT := $(shell $(ruby) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
17 endif
18 ifeq ($(RUBY_VERSION),)
19 RUBY_VERSION := $(shell $(ruby) -e 'puts RUBY_VERSION')
20 endif
22 # dunno how to implement this as concisely in Ruby, and hell, I love awk
23 awk_slow := awk '/def test_/{print FILENAME"--"$$2".n"}' 2>/dev/null
25 rails_vers := $(subst test/rails/app-,,$(wildcard test/rails/app-*))
26 slow_tests := test/unit/test_server.rb test/exec/test_exec.rb \
27 test/unit/test_signals.rb test/unit/test_upload.rb
28 log_suffix = .$(RUBY_VERSION).log
29 T_r := $(wildcard test/rails/test*.rb)
30 T := $(filter-out $(slow_tests) $(T_r), $(wildcard test/*/test*.rb))
31 T_n := $(shell $(awk_slow) $(slow_tests))
32 T_log := $(subst .rb,$(log_suffix),$(T))
33 T_n_log := $(subst .n,$(log_suffix),$(T_n))
34 T_r_log := $(subst .r,$(log_suffix),$(T_r))
35 test_prefix = $(CURDIR)/test/install-$(RUBY_VERSION)
37 ext := ext/unicorn_http
38 c_files := $(ext)/unicorn_http.c $(wildcard $(ext)/*.h)
39 rl_files := $(wildcard $(ext)/*.rl)
40 bins := $(wildcard bin/*)
41 rb_files := $(bins) $(shell find lib -type f -name '*.rb')
42 inst_deps := $(c_files) $(rb_files)
44 ragel: $(ext)/unicorn_http.c
45 $(ext)/unicorn_http.c: $(rl_files)
46 cd $(@D) && $(ragel) unicorn_http.rl -C $(RLFLAGS) -o $(@F)
47 $(ruby) -i -p -e '$$_.gsub!(%r{[ \t]*$$},"")' $@
48 $(ext)/Makefile: $(ext)/extconf.rb $(c_files)
49 cd $(@D) && $(ruby) extconf.rb
50 $(ext)/unicorn_http.$(DLEXT): $(ext)/Makefile
51 $(MAKE) -C $(@D)
52 lib/unicorn_http.$(DLEXT): $(ext)/unicorn_http.$(DLEXT)
53 @mkdir -p lib
54 install -m644 $< $@
55 http: lib/unicorn_http.$(DLEXT)
57 $(test_prefix)/.stamp: $(inst_deps)
58 mkdir -p $(test_prefix)/.ccache
59 tar c `cat .manifest` | (cd $(test_prefix) && tar x)
60 $(MAKE) -C $(test_prefix) clean
61 $(MAKE) -C $(test_prefix) http shebang
62 > $@
64 # this is only intended to be run within $(test_prefix)
65 shebang: $(bins)
66 $(ruby) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
68 t_log := $(T_log) $(T_n_log)
69 test: $(T) $(T_n)
70 @cat $(t_log) | $(ruby) test/aggregate.rb
71 @$(RM) $(t_log)
73 test-exec: $(wildcard test/exec/test_*.rb)
74 test-unit: $(wildcard test/unit/test_*.rb)
75 $(slow_tests): $(test_prefix)/.stamp
76 @$(MAKE) $(shell $(awk_slow) $@)
78 TEST_OPTS = -v
79 check_test = grep '0 failures, 0 errors' $(t) >/dev/null
80 ifndef V
81 quiet_pre = @echo '* $(arg)$(extra)';
82 quiet_post = >$(t) 2>&1 && $(check_test)
83 else
84 # we can't rely on -o pipefail outside of bash 3+,
85 # so we use a stamp file to indicate success and
86 # have rm fail if the stamp didn't get created
87 stamp = $@$(log_suffix).ok
88 quiet_pre = @echo $(ruby) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
89 quiet_post = && > $(stamp) )2>&1 | tee $(t); \
90 rm $(stamp) 2>/dev/null && $(check_test)
91 endif
93 # TRACER='strace -f -o $(t).strace -s 100000'
94 run_test = $(quiet_pre) \
95 setsid $(TRACER) $(ruby) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
96 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
98 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
99 %.n: t = $(subst .n,$(log_suffix),$@)
100 %.n: export PATH := $(test_prefix)/bin:$(PATH)
101 %.n: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
102 %.n: $(test_prefix)/.stamp
103 $(run_test)
105 $(T): arg = $@
106 $(T): t = $(subst .rb,$(log_suffix),$@)
107 $(T): export PATH := $(test_prefix)/bin:$(PATH)
108 $(T): export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
109 $(T): $(test_prefix)/.stamp
110 $(run_test)
112 install: $(bins) $(ext)/unicorn_http.c
113 $(prep_setup_rb)
114 $(RM) -r .install-tmp
115 mkdir .install-tmp
116 cp -p bin/* .install-tmp
117 $(ruby) setup.rb all
118 $(RM) $^
119 mv .install-tmp/* bin/
120 $(RM) -r .install-tmp
121 $(prep_setup_rb)
123 setup_rb_files := .config InstalledFiles
124 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
126 clean:
127 -$(MAKE) -C $(ext) clean
128 -$(MAKE) -C Documentation clean
129 $(RM) $(ext)/Makefile lib/unicorn_http.$(DLEXT)
130 $(RM) $(setup_rb_files) $(t_log)
131 $(RM) -r $(test_prefix) man
133 man:
134 $(MAKE) -C Documentation install-man
135 .manifest: GIT-VERSION-FILE NEWS ChangeLog $(ext)/unicorn_http.c
136 $(MAKE) man
137 (git ls-files && \
138 for i in $@ $^ $(wildcard man/*/*.1); \
139 do echo $$i; done) | LC_ALL=C sort > $@+
140 cmp $@+ $@ || mv $@+ $@
141 $(RM) $@+
143 NEWS: GIT-VERSION-FILE
144 $(rake) -s news_rdoc > $@+
145 mv $@+ $@
147 ChangeLog: GIT-VERSION-FILE
148 @echo "ChangeLog from $(GIT_URL) ($(GIT_VERSION))" > $@+
149 @echo >> $@+
150 git log | sed -e 's/^/ /' >> $@+
151 mv $@+ $@
153 news_atom := http://unicorn.bogomips.org/NEWS.atom.xml
154 cgit_atom := http://git.bogomips.org/cgit/unicorn.git/atom/?h=master
155 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
156 type="application/atom+xml"/>
158 # using rdoc 2.4.1+
159 doc: .document $(ext)/unicorn_http.c NEWS ChangeLog
160 > unicorn.1 && > unicorn_rails.1
161 rdoc -Na -t "$(shell sed -ne '1s/^= //p' README)"
162 install -m644 $(shell grep '^[A-Z]' .document) doc/
163 $(MAKE) -C Documentation install-html
164 cd doc && for i in unicorn unicorn_rails; do \
165 sed -e '/"documentation">/r man1/'$$i'.1.html' \
166 < $${i}_1.html > tmp && mv tmp $${i}_1.html; done
167 $(ruby) -i -p -e \
168 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
169 doc/ChangeLog.html
170 $(ruby) -i -p -e \
171 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
172 doc/NEWS.html doc/README.html
173 $(rake) -s news_atom > doc/NEWS.atom.xml
174 cd doc && ln README.html tmp && mv tmp index.html
175 $(RM) unicorn.1 unicorn_rails.1
177 rails_git_url = git://github.com/rails/rails.git
178 rails_git := vendor/rails.git
179 $(rails_git)/info/cloned-stamp:
180 git clone --mirror -q $(rails_git_url) $(rails_git)
181 > $@
183 rails_tests := $(addsuffix .r,$(addprefix $(T_r).,$(rails_vers)))
184 test-rails: $(rails_tests)
185 $(T_r).%.r: t = $(addsuffix $(log_suffix),$@)
186 $(T_r).%.r: rv = $(subst .r,,$(subst $(T_r).,,$@))
187 $(T_r).%.r: extra = ' 'v$(rv)
188 $(T_r).%.r: arg = $(T_r)
189 $(T_r).%.r: export PATH := $(test_prefix)/bin:$(PATH)
190 $(T_r).%.r: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
191 $(T_r).%.r: export UNICORN_RAILS_TEST_VERSION = $(rv)
192 $(T_r).%.r: export RAILS_GIT_REPO = $(CURDIR)/$(rails_git)
193 $(T_r).%.r: $(test_prefix)/.stamp $(rails_git)/info/cloned-stamp
194 $(run_test)
196 ifneq ($(VERSION),)
197 rfproject := mongrel
198 rfpackage := unicorn
199 pkggem := pkg/$(rfpackage)-$(VERSION).gem
200 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
201 release_notes := release_notes-$(VERSION)
202 release_changes := release_changes-$(VERSION)
204 release-notes: $(release_notes)
205 release-changes: $(release_changes)
206 $(release_changes):
207 $(rake) -s release_changes > $@+
208 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
209 $(release_notes):
210 GIT_URL=$(GIT_URL) $(rake) -s release_notes > $@+
211 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
213 # ensures we're actually on the tagged $(VERSION), only used for release
214 verify:
215 git rev-parse --verify refs/tags/v$(VERSION)^{}
216 git diff-index --quiet HEAD^0
217 test `git rev-parse --verify HEAD^0` = \
218 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
220 $(pkggem): .manifest
221 gem build $(rfpackage).gemspec
222 mkdir -p pkg
223 mv $(@F) $@
225 $(pkgtgz): distdir = $(basename $@)
226 $(pkgtgz): HEAD = v$(VERSION)
227 $(pkgtgz): .manifest
228 @test -n "$(distdir)"
229 $(RM) -r $(distdir)
230 mkdir -p $(distdir)
231 tar c `cat .manifest` | (cd $(distdir) && tar x)
232 cd pkg && tar c $(basename $(@F)) | gzip -9 > $(@F)+
233 mv $@+ $@
235 package: $(pkgtgz) $(pkggem)
237 release: verify package $(release_notes) $(release_changes)
238 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
239 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
240 rubyforge add_file \
241 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
242 endif
244 .PHONY: .FORCE-GIT-VERSION-FILE doc $(T) $(slow_tests) .manifest man