1 # use GNU Make to run tests in parallel, and without depending on Rubygems
6 GIT_URL
= $(shell git config
--get remote.
origin.url
2>/dev
/null || \
7 echo git
://git.bogomips.org
/unicorn.git
)
10 GIT-VERSION-FILE
: .FORCE-GIT-VERSION-FILE
12 -include GIT-VERSION-FILE
14 ruby_bin
:= $(shell which
$(ruby
))
15 ifeq ($(DLEXT
),) # "so" for Linux
16 DLEXT
:= $(shell $(ruby
) -rrbconfig
-e
'puts Config::CONFIG["DLEXT"]')
18 ifeq ($(RUBY_VERSION
),)
19 RUBY_VERSION
:= $(shell $(ruby
) -e
'puts RUBY_VERSION')
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
52 lib
/unicorn_http.
$(DLEXT
): $(ext
)/unicorn_http.
$(DLEXT
)
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
64 # this is only intended to be run within $(test_prefix)
66 $(ruby
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
68 t_log
:= $(T_log
) $(T_n_log
)
70 @cat
$(t_log
) |
$(ruby
) test/aggregate.rb
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
) $@
)
79 check_test
= grep
'0 failures, 0 errors' $(t
) >/dev
/null
81 quiet_pre
= @echo
'* $(arg)$(extra)';
82 quiet_post
= >$(t
) 2>&1 && $(check_test
)
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
)
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
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
112 install: $(bins
) $(ext
)/unicorn_http.c
114 $(RM
) -r .install-tmp
116 cp
-p bin
/* .install-tmp
119 mv .install-tmp
/* bin
/
120 $(RM
) -r .install-tmp
123 setup_rb_files
:= .config InstalledFiles
124 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C
$(ext
) 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
134 $(MAKE
) -C Documentation install-man
135 .manifest
: GIT-VERSION-FILE NEWS ChangeLog
$(ext
)/unicorn_http.c
138 for i in
$@
$^
$(wildcard man
/*/*.1); \
139 do echo
$$i; done
) | LC_ALL
=C
sort > $@
+
140 cmp
$@
+ $@ || mv
$@
+ $@
143 NEWS
: GIT-VERSION-FILE
144 $(rake
) -s news_rdoc
> $@
+
147 ChangeLog
: GIT-VERSION-FILE
148 @echo
"ChangeLog from $(GIT_URL) ($(GIT_VERSION))" > $@
+
150 git log | sed
-e
's/^/ /' >> $@
+
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"/>
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
168 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
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
)
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
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
)
207 $(rake
) -s release_changes
> $@
+
208 $(VISUAL
) $@
+ && test -s
$@
+ && mv
$@
+ $@
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
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)^{}`
221 gem build
$(rfpackage
).gemspec
225 $(pkgtgz
): distdir
= $(basename $@
)
226 $(pkgtgz
): HEAD
= v
$(VERSION
)
228 @
test -n
"$(distdir)"
231 tar c
`cat .manifest` |
(cd
$(distdir
) && tar x
)
232 cd pkg
&& tar c
$(basename $(@F
)) | gzip
-9 > $(@F
)+
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
)
241 $(rfproject
) $(rfpackage
) $(VERSION
) $(pkgtgz
)
244 .PHONY
: .FORCE-GIT-VERSION-FILE doc
$(T
) $(slow_tests
) .manifest man