dev: remove isolate dependency
[unicorn.git] / GNUmakefile
blob50819fc2b12e546808bce50e8f65978bada70d1a
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all:: test
4 RLFLAGS = -G2
6 MRI = ruby
7 RUBY = ruby
8 RAKE = rake
9 RAGEL = ragel
10 RSYNC = rsync
12 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
13 @./GIT-VERSION-GEN
14 -include GIT-VERSION-FILE
15 -include local.mk
16 ruby_bin := $(shell which $(RUBY))
17 ifeq ($(DLEXT),) # "so" for Linux
18 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts RbConfig::CONFIG["DLEXT"]')
19 endif
20 ifeq ($(RUBY_VERSION),)
21 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
22 endif
24 RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
26 MYLIBS = $(RUBYLIB)
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 slow_tests := test/unit/test_server.rb test/exec/test_exec.rb \
32 test/unit/test_signals.rb test/unit/test_upload.rb
33 log_suffix = .$(RUBY_ENGINE).$(RUBY_VERSION).log
34 T := $(filter-out $(slow_tests), $(wildcard test/*/test*.rb))
35 T_n := $(shell $(awk_slow) $(slow_tests))
36 T_log := $(subst .rb,$(log_suffix),$(T))
37 T_n_log := $(subst .n,$(log_suffix),$(T_n))
38 test_prefix = $(CURDIR)/test/$(RUBY_ENGINE)-$(RUBY_VERSION)
40 ext := ext/unicorn_http
41 c_files := $(ext)/unicorn_http.c $(ext)/httpdate.c $(wildcard $(ext)/*.h)
42 rl_files := $(wildcard $(ext)/*.rl)
43 base_bins := unicorn unicorn_rails
44 bins := $(addprefix bin/, $(base_bins))
45 man1_rdoc := $(addsuffix _1, $(base_bins))
46 man1_bins := $(addsuffix .1, $(base_bins))
47 man1_paths := $(addprefix man/man1/, $(man1_bins))
48 rb_files := $(bins) $(shell find lib ext -type f -name '*.rb')
49 inst_deps := $(c_files) $(rb_files) GNUmakefile test/test_helper.rb
51 ragel: $(ext)/unicorn_http.c
52 $(ext)/unicorn_http.c: $(rl_files)
53 cd $(@D) && $(RAGEL) unicorn_http.rl -C $(RLFLAGS) -o $(@F)
54 $(ext)/Makefile: $(ext)/extconf.rb $(c_files)
55 cd $(@D) && $(RUBY) extconf.rb
56 $(ext)/unicorn_http.$(DLEXT): $(ext)/Makefile
57 $(MAKE) -C $(@D)
58 lib/unicorn_http.$(DLEXT): $(ext)/unicorn_http.$(DLEXT)
59 @mkdir -p lib
60 install -m644 $< $@
61 http: lib/unicorn_http.$(DLEXT)
63 test-install: $(test_prefix)/.stamp
64 $(test_prefix)/.stamp: $(inst_deps)
65 mkdir -p $(test_prefix)/.ccache
66 tar cf - $(inst_deps) GIT-VERSION-GEN | \
67 (cd $(test_prefix) && tar xf -)
68 $(MAKE) -C $(test_prefix) clean
69 $(MAKE) -C $(test_prefix) http shebang RUBY="$(RUBY)"
70 > $@
72 # this is only intended to be run within $(test_prefix)
73 shebang: $(bins)
74 $(MRI) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
76 t_log := $(T_log) $(T_n_log)
77 test: $(T) $(T_n)
78 @cat $(t_log) | $(MRI) test/aggregate.rb
79 @$(RM) $(t_log)
81 test-exec: $(wildcard test/exec/test_*.rb)
82 test-unit: $(wildcard test/unit/test_*.rb)
83 $(slow_tests): $(test_prefix)/.stamp
84 @$(MAKE) $(shell $(awk_slow) $@)
86 test-integration: $(test_prefix)/.stamp
87 $(MAKE) -C t
89 check: test test-integration
90 test-all: check
92 TEST_OPTS = -v
93 check_test = grep '0 failures, 0 errors' $(t) >/dev/null
94 ifndef V
95 quiet_pre = @echo '* $(arg)$(extra)';
96 quiet_post = >$(t) 2>&1 && $(check_test)
97 else
98 # we can't rely on -o pipefail outside of bash 3+,
99 # so we use a stamp file to indicate success and
100 # have rm fail if the stamp didn't get created
101 stamp = $@$(log_suffix).ok
102 quiet_pre = @echo $(RUBY) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
103 quiet_post = && > $(stamp) )2>&1 | tee $(t); \
104 rm $(stamp) 2>/dev/null && $(check_test)
105 endif
107 # not all systems have setsid(8), we need it because we spam signals
108 # stupidly in some tests...
109 rb_setsid := $(RUBY) -e 'Process.setsid' -e 'exec *ARGV'
111 # TRACER='strace -f -o $(t).strace -s 100000'
112 run_test = $(quiet_pre) \
113 $(rb_setsid) $(TRACER) $(RUBY) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
114 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
116 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
117 %.n: t = $(subst .n,$(log_suffix),$@)
118 %.n: export PATH := $(test_prefix)/bin:$(PATH)
119 %.n: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(MYLIBS)
120 %.n: $(test_prefix)/.stamp
121 $(run_test)
123 $(T): arg = $@
124 $(T): t = $(subst .rb,$(log_suffix),$@)
125 $(T): export PATH := $(test_prefix)/bin:$(PATH)
126 $(T): export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(MYLIBS)
127 $(T): $(test_prefix)/.stamp
128 $(run_test)
130 install: $(bins) $(ext)/unicorn_http.c
131 $(prep_setup_rb)
132 $(RM) lib/unicorn_http.$(DLEXT)
133 $(RM) -r .install-tmp
134 mkdir .install-tmp
135 cp -p bin/* .install-tmp
136 $(RUBY) setup.rb all
137 $(RM) $^
138 mv .install-tmp/* bin/
139 $(RM) -r .install-tmp
140 $(prep_setup_rb)
142 setup_rb_files := .config InstalledFiles
143 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
145 clean:
146 -$(MAKE) -C $(ext) clean
147 -$(MAKE) -C Documentation clean
148 $(RM) $(ext)/Makefile lib/unicorn_http.$(DLEXT)
149 $(RM) $(setup_rb_files) $(t_log)
150 $(RM) -r $(test_prefix) man
152 man html:
153 $(MAKE) -C Documentation install-$@
155 pkg_extra := GIT-VERSION-FILE lib/unicorn/version.rb ChangeLog LATEST NEWS \
156 $(ext)/unicorn_http.c $(man1_paths)
158 ChangeLog: GIT-VERSION-FILE .wrongdoc.yml
159 wrongdoc prepare
161 .manifest: ChangeLog $(ext)/unicorn_http.c man
162 (git ls-files && for i in $@ $(pkg_extra); do echo $$i; done) | \
163 LC_ALL=C sort > $@+
164 cmp $@+ $@ || mv $@+ $@
165 $(RM) $@+
167 doc: .document $(ext)/unicorn_http.c man html .wrongdoc.yml
168 for i in $(man1_rdoc); do echo > $$i; done
169 find bin lib -type f -name '*.rbc' -exec rm -f '{}' ';'
170 $(RM) -r doc
171 wrongdoc all
172 install -m644 COPYING doc/COPYING
173 install -m644 $(shell LC_ALL=C grep '^[A-Z]' .document) doc/
174 install -m644 $(man1_paths) doc/
175 tar cf - $$(git ls-files examples/) | (cd doc && tar xf -)
176 $(RM) $(man1_rdoc)
178 # publishes docs to http://unicorn.bogomips.org
179 publish_doc:
180 -git set-file-times
181 $(MAKE) doc
182 find doc/images -type f | \
183 TZ=UTC xargs touch -d '1970-01-01 00:00:02' doc/rdoc.css
184 $(MAKE) doc_gz
185 chmod 644 $$(find doc -type f)
186 $(RSYNC) -av doc/ unicorn.bogomips.org:/srv/unicorn/
187 git ls-files | xargs touch
189 # Create gzip variants of the same timestamp as the original so nginx
190 # "gzip_static on" can serve the gzipped versions directly.
191 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
192 doc_gz:
193 for i in $(docs); do \
194 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
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 wrongdoc release_changes > $@+
208 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
209 $(release_notes):
210 wrongdoc release_notes > $@+
211 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
213 # ensures we're actually on the tagged $(VERSION), only used for release
214 verify:
215 test x"$(shell umask)" = x0022
216 git rev-parse --verify refs/tags/v$(VERSION)^{}
217 git diff-index --quiet HEAD^0
218 test `git rev-parse --verify HEAD^0` = \
219 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
221 fix-perms:
222 git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
223 git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
225 gem: $(pkggem)
227 install-gem: $(pkggem)
228 gem install $(CURDIR)/$<
230 $(pkggem): .manifest fix-perms
231 gem build $(rfpackage).gemspec
232 mkdir -p pkg
233 mv $(@F) $@
235 $(pkgtgz): distdir = $(basename $@)
236 $(pkgtgz): HEAD = v$(VERSION)
237 $(pkgtgz): .manifest fix-perms
238 @test -n "$(distdir)"
239 $(RM) -r $(distdir)
240 mkdir -p $(distdir)
241 tar cf - $$(cat .manifest) | (cd $(distdir) && tar xf -)
242 cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
243 mv $@+ $@
245 package: $(pkgtgz) $(pkggem)
247 release: verify package $(release_notes) $(release_changes)
248 # make tgz release on RubyForge
249 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
250 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
251 # push gem to Gemcutter
252 gem push $(pkggem)
253 # in case of gem downloads from RubyForge releases page
254 -rubyforge add_file \
255 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
256 $(RAKE) fm_update VERSION=$(VERSION)
257 else
258 gem install-gem: GIT-VERSION-FILE
259 $(MAKE) $@ VERSION=$(GIT_VERSION)
260 endif
262 .PHONY: .FORCE-GIT-VERSION-FILE doc $(T) $(slow_tests) man
263 .PHONY: test-install