launcher: no point in sync-ing $stdin
[unicorn.git] / GNUmakefile
blobcada45168ebd9740ea567446eaeb17ac66e7040b
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all:: test
4 ruby = ruby
5 rake = rake
6 ragel = ragel
8 GIT_URL = git://git.bogomips.org/unicorn.git
9 RLFLAGS = -G2
11 # lower-case vars are deprecated
12 RUBY = $(ruby)
13 RAKE = $(rake)
14 RAGEL = $(ragel)
16 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
17 @./GIT-VERSION-GEN
18 -include GIT-VERSION-FILE
19 -include local.mk
20 ruby_bin := $(shell which $(RUBY))
21 ifeq ($(DLEXT),) # "so" for Linux
22 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
23 endif
24 ifeq ($(RUBY_VERSION),)
25 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
26 endif
28 # dunno how to implement this as concisely in Ruby, and hell, I love awk
29 awk_slow := awk '/def test_/{print FILENAME"--"$$2".n"}' 2>/dev/null
31 rails_vers := $(subst test/rails/app-,,$(wildcard test/rails/app-*))
32 slow_tests := test/unit/test_server.rb test/exec/test_exec.rb \
33 test/unit/test_signals.rb test/unit/test_upload.rb
34 log_suffix = .$(RUBY_VERSION).log
35 T_r := $(wildcard test/rails/test*.rb)
36 T := $(filter-out $(slow_tests) $(T_r), $(wildcard test/*/test*.rb))
37 T_n := $(shell $(awk_slow) $(slow_tests))
38 T_log := $(subst .rb,$(log_suffix),$(T))
39 T_n_log := $(subst .n,$(log_suffix),$(T_n))
40 T_r_log := $(subst .r,$(log_suffix),$(T_r))
41 test_prefix = $(CURDIR)/test/install-$(RUBY_VERSION)
43 ext := ext/unicorn_http
44 c_files := $(ext)/unicorn_http.c $(wildcard $(ext)/*.h)
45 rl_files := $(wildcard $(ext)/*.rl)
46 base_bins := unicorn unicorn_rails
47 bins := $(addprefix bin/, $(base_bins))
48 man1_bins := $(addsuffix .1, $(base_bins))
49 man1_paths := $(addprefix man/man1/, $(man1_bins))
50 rb_files := $(bins) $(shell find lib ext -type f -name '*.rb')
51 inst_deps := $(c_files) $(rb_files) GNUmakefile test/test_helper.rb
53 ragel: $(ext)/unicorn_http.c
54 $(ext)/unicorn_http.c: $(rl_files)
55 cd $(@D) && $(RAGEL) unicorn_http.rl -C $(RLFLAGS) -o $(@F)
56 $(ext)/Makefile: $(ext)/extconf.rb $(c_files)
57 cd $(@D) && $(RUBY) extconf.rb
58 $(ext)/unicorn_http.$(DLEXT): $(ext)/Makefile
59 $(MAKE) -C $(@D)
60 lib/unicorn_http.$(DLEXT): $(ext)/unicorn_http.$(DLEXT)
61 @mkdir -p lib
62 install -m644 $< $@
63 http: lib/unicorn_http.$(DLEXT)
65 $(test_prefix)/.stamp: $(inst_deps)
66 mkdir -p $(test_prefix)/.ccache
67 tar cf - $(inst_deps) GIT-VERSION-GEN | \
68 (cd $(test_prefix) && tar xf -)
69 $(MAKE) -C $(test_prefix) clean
70 $(MAKE) -C $(test_prefix) http shebang
71 > $@
73 # this is only intended to be run within $(test_prefix)
74 shebang: $(bins)
75 $(RUBY) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
77 t_log := $(T_log) $(T_n_log)
78 test: $(T) $(T_n)
79 @cat $(t_log) | $(RUBY) test/aggregate.rb
80 @$(RM) $(t_log)
82 test-exec: $(wildcard test/exec/test_*.rb)
83 test-unit: $(wildcard test/unit/test_*.rb)
84 $(slow_tests): $(test_prefix)/.stamp
85 @$(MAKE) $(shell $(awk_slow) $@)
87 TEST_OPTS = -v
88 check_test = grep '0 failures, 0 errors' $(t) >/dev/null
89 ifndef V
90 quiet_pre = @echo '* $(arg)$(extra)';
91 quiet_post = >$(t) 2>&1 && $(check_test)
92 else
93 # we can't rely on -o pipefail outside of bash 3+,
94 # so we use a stamp file to indicate success and
95 # have rm fail if the stamp didn't get created
96 stamp = $@$(log_suffix).ok
97 quiet_pre = @echo $(RUBY) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
98 quiet_post = && > $(stamp) )2>&1 | tee $(t); \
99 rm $(stamp) 2>/dev/null && $(check_test)
100 endif
102 # not all systems have setsid(8), we need it because we spam signals
103 # stupidly in some tests...
104 rb_setsid := $(RUBY) -e 'Process.setsid' -e 'exec *ARGV'
106 # TRACER='strace -f -o $(t).strace -s 100000'
107 run_test = $(quiet_pre) \
108 $(rb_setsid) $(TRACER) $(RUBY) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
109 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
111 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
112 %.n: t = $(subst .n,$(log_suffix),$@)
113 %.n: export PATH := $(test_prefix)/bin:$(PATH)
114 %.n: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
115 %.n: $(test_prefix)/.stamp
116 $(run_test)
118 $(T): arg = $@
119 $(T): t = $(subst .rb,$(log_suffix),$@)
120 $(T): export PATH := $(test_prefix)/bin:$(PATH)
121 $(T): export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
122 $(T): $(test_prefix)/.stamp
123 $(run_test)
125 install: $(bins) $(ext)/unicorn_http.c
126 $(prep_setup_rb)
127 $(RM) lib/unicorn_http.$(DLEXT)
128 $(RM) -r .install-tmp
129 mkdir .install-tmp
130 cp -p bin/* .install-tmp
131 $(RUBY) setup.rb all
132 $(RM) $^
133 mv .install-tmp/* bin/
134 $(RM) -r .install-tmp
135 $(prep_setup_rb)
137 setup_rb_files := .config InstalledFiles
138 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
140 clean:
141 -$(MAKE) -C $(ext) clean
142 -$(MAKE) -C Documentation clean
143 $(RM) $(ext)/Makefile lib/unicorn_http.$(DLEXT)
144 $(RM) $(setup_rb_files) $(t_log)
145 $(RM) -r $(test_prefix) man
147 man:
148 $(MAKE) -C Documentation install-man
150 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog $(ext)/unicorn_http.c
151 manifest: $(pkg_extra) man
152 $(RM) .manifest
153 $(MAKE) .manifest
155 .manifest:
156 (git ls-files && \
157 for i in $@ $(pkg_extra) $(man1_paths); \
158 do echo $$i; done) | LC_ALL=C sort > $@+
159 cmp $@+ $@ || mv $@+ $@
160 $(RM) $@+
162 NEWS: GIT-VERSION-FILE
163 $(RAKE) -s news_rdoc > $@+
164 mv $@+ $@
166 SINCE = 0.94.0
167 ChangeLog: LOG_VERSION = \
168 $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
169 echo $(GIT_VERSION) || git describe)
170 ChangeLog: log_range = v$(SINCE)..$(LOG_VERSION)
171 ChangeLog: GIT-VERSION-FILE
172 @echo "ChangeLog from $(GIT_URL) ($(log_range))" > $@+
173 @echo >> $@+
174 git log $(log_range) | sed -e 's/^/ /' >> $@+
175 mv $@+ $@
177 news_atom := http://unicorn.bogomips.org/NEWS.atom.xml
178 cgit_atom := http://git.bogomips.org/cgit/unicorn.git/atom/?h=master
179 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
180 type="application/atom+xml"/>
182 # using rdoc 2.4.1+
183 doc: .document $(ext)/unicorn_http.c NEWS ChangeLog
184 for i in $(man1_bins); do > $$i; done
185 find bin lib -type f -name '*.rbc' -exec rm -f '{}' ';'
186 rdoc -Na -t "$(shell sed -ne '1s/^= //p' README)"
187 install -m644 COPYING doc/COPYING
188 install -m644 $(shell grep '^[A-Z]' .document) doc/
189 $(MAKE) -C Documentation install-html install-man
190 install -m644 $(man1_paths) doc/
191 cd doc && for i in $(base_bins); do \
192 sed -e '/"documentation">/r man1/'$$i'.1.html' \
193 < $${i}_1.html > tmp && mv tmp $${i}_1.html; done
194 $(RUBY) -i -p -e \
195 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
196 doc/ChangeLog.html
197 $(RUBY) -i -p -e \
198 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
199 doc/NEWS.html doc/README.html
200 $(RAKE) -s news_atom > doc/NEWS.atom.xml
201 cd doc && ln README.html tmp && mv tmp index.html
202 $(RM) $(man1_bins)
204 rails_git_url = git://github.com/rails/rails.git
205 rails_git := vendor/rails.git
206 $(rails_git)/info/cloned-stamp:
207 git clone --mirror -q $(rails_git_url) $(rails_git)
208 > $@
210 rails_tests := $(addsuffix .r,$(addprefix $(T_r).,$(rails_vers)))
211 test-rails: $(rails_tests)
212 $(T_r).%.r: t = $(addsuffix $(log_suffix),$@)
213 $(T_r).%.r: rv = $(subst .r,,$(subst $(T_r).,,$@))
214 $(T_r).%.r: extra = ' 'v$(rv)
215 $(T_r).%.r: arg = $(T_r)
216 $(T_r).%.r: export PATH := $(test_prefix)/bin:$(PATH)
217 $(T_r).%.r: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
218 $(T_r).%.r: export UNICORN_RAILS_TEST_VERSION = $(rv)
219 $(T_r).%.r: export RAILS_GIT_REPO = $(CURDIR)/$(rails_git)
220 $(T_r).%.r: $(test_prefix)/.stamp $(rails_git)/info/cloned-stamp
221 $(run_test)
223 ifneq ($(VERSION),)
224 rfproject := mongrel
225 rfpackage := unicorn
226 pkggem := pkg/$(rfpackage)-$(VERSION).gem
227 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
228 release_notes := release_notes-$(VERSION)
229 release_changes := release_changes-$(VERSION)
231 release-notes: $(release_notes)
232 release-changes: $(release_changes)
233 $(release_changes):
234 $(RAKE) -s release_changes > $@+
235 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
236 $(release_notes):
237 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
238 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
240 # ensures we're actually on the tagged $(VERSION), only used for release
241 verify:
242 test x"$(shell umask)" = x0022
243 git rev-parse --verify refs/tags/v$(VERSION)^{}
244 git diff-index --quiet HEAD^0
245 test `git rev-parse --verify HEAD^0` = \
246 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
248 fix-perms:
249 git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
250 git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
252 gem: $(pkggem)
254 install-gem: $(pkggem)
255 gem install $(CURDIR)/$<
257 $(pkggem): manifest fix-perms
258 gem build $(rfpackage).gemspec
259 mkdir -p pkg
260 mv $(@F) $@
262 $(pkgtgz): distdir = $(basename $@)
263 $(pkgtgz): HEAD = v$(VERSION)
264 $(pkgtgz): manifest fix-perms
265 @test -n "$(distdir)"
266 $(RM) -r $(distdir)
267 mkdir -p $(distdir)
268 tar cf - `cat .manifest` | (cd $(distdir) && tar xf -)
269 cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
270 mv $@+ $@
272 package: $(pkgtgz) $(pkggem)
274 release: verify package $(release_notes) $(release_changes)
275 # make tgz release on RubyForge
276 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
277 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
278 # push gem to Gemcutter
279 gem push $(pkggem)
280 # in case of gem downloads from RubyForge releases page
281 -rubyforge add_file \
282 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
283 else
284 gem install-gem: GIT-VERSION-FILE
285 $(MAKE) $@ VERSION=$(GIT_VERSION)
286 endif
288 .PHONY: .FORCE-GIT-VERSION-FILE doc $(T) $(slow_tests) manifest man