GNUmakefile: kill trailing whitespace after ragel
[unicorn.git] / GNUmakefile
blob3d3bde98bfee3bc1c492716cb7bba8ecb5571390
1 # use GNU Make to run tests in parallel, and without depending on Rubygems
2 all:: test
3 ruby = ruby
4 -include local.mk
5 ruby_bin := $(shell which $(ruby))
6 ifeq ($(DLEXT),) # "so" for Linux
7 DLEXT := $(shell $(ruby) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
8 endif
9 ifeq ($(RUBY_VERSION),)
10 RUBY_VERSION := $(shell $(ruby) -e 'puts RUBY_VERSION')
11 endif
13 # dunno how to implement this as concisely in Ruby, and hell, I love awk
14 awk_slow := awk '/def test_/{print FILENAME"--"$$2".n"}' 2>/dev/null
16 rails_vers := $(subst test/rails/app-,,$(wildcard test/rails/app-*))
17 slow_tests := test/unit/test_server.rb test/exec/test_exec.rb
18 log_suffix = .$(RUBY_VERSION).log
19 T_r := $(wildcard test/rails/test*.rb)
20 T := $(filter-out $(slow_tests) $(T_r), $(wildcard test/*/test*.rb))
21 T_n := $(shell $(awk_slow) $(slow_tests))
22 T_log := $(subst .rb,$(log_suffix),$(T))
23 T_n_log := $(subst .n,$(log_suffix),$(T_n))
24 T_r_log := $(subst .r,$(log_suffix),$(T_r))
25 test_prefix = $(CURDIR)/test/install-$(RUBY_VERSION)
27 http11_deps := $(addprefix ext/unicorn/http11/, \
28 ext_help.h http11.c http11_parser.c http11_parser.h \
29 http11_parser.rl http11_parser_common.rl)
30 inst_deps := $(wildcard bin/*) $(wildcard lib/*.rb) \
31 $(wildcard lib/*/*.rb) $(http11_deps)
33 ext/unicorn/http11/http11_parser.c: $(wildcard ext/unicorn/http11/*.rl)
34 cd $(@D) && ragel http11_parser.rl -C -G2 -o $(@F)
35 $(ruby) -i -p -e '$$_.gsub!(%r{[ \t]*$$},"")' $@
36 ext/unicorn/http11/Makefile: ext/unicorn/http11/extconf.rb $(http11_deps)
37 cd $(@D) && $(ruby) $(<F)
38 ext/unicorn/http11/http11.$(DLEXT): ext/unicorn/http11/Makefile
39 $(MAKE) -C $(@D)
40 lib/unicorn/http11.$(DLEXT): ext/unicorn/http11/http11.$(DLEXT)
41 @mkdir -p lib
42 install -m644 $< $@
43 http11: lib/unicorn/http11.$(DLEXT)
45 $(test_prefix)/.stamp: install-test
46 > $@
48 install-test: $(inst_deps)
49 test -n "$(test_prefix)"
50 mkdir -p $(test_prefix)/.ccache
51 tar c bin ext lib GNUmakefile | (cd $(test_prefix) && tar x)
52 $(MAKE) -C $(test_prefix) clean
53 $(MAKE) -C $(test_prefix) http11 shebang
55 # this is only intended to be run within $(test_prefix)
56 shebang: bin/unicorn bin/unicorn_rails
57 $(ruby) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
59 t_log := $(T_log) $(T_n_log)
60 test: $(T) $(T_n)
61 @cat $(t_log) | $(ruby) test/aggregate.rb
62 @$(RM) $(t_log)
64 test-exec: $(wildcard test/exec/test_*.rb)
65 test-unit: $(wildcard test/unit/test_*.rb)
66 $(slow_tests): $(test_prefix)/.stamp
67 @$(MAKE) $(shell $(awk_slow) $@)
69 TEST_OPTS = -v
70 TEST_OPTS = -v
71 ifndef V
72 quiet_pre = @echo '* $(arg)$(extra)';
73 quiet_post = >$(t) 2>&1
74 else
75 # we can't rely on -o pipefail outside of bash 3+,
76 # so we use a stamp file to indicate success and
77 # have rm fail if the stamp didn't get created
78 stamp = $@$(log_suffix).ok
79 quiet_pre = @echo $(ruby) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
80 quiet_post = && > $(stamp) )>&2 | tee $(t); rm $(stamp) 2>/dev/null
81 endif
82 run_test = $(quiet_pre) setsid $(ruby) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
83 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
85 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
86 %.n: t = $(subst .n,$(log_suffix),$@)
87 %.n: export PATH := $(test_prefix)/bin:$(PATH)
88 %.n: export RUBYLIB := $(test_prefix)/lib:$(RUBYLIB)
89 %.n: $(test_prefix)/.stamp
90 $(run_test)
92 $(T): arg = $@
93 $(T): t = $(subst .rb,$(log_suffix),$@)
94 $(T): export PATH := $(test_prefix)/bin:$(PATH)
95 $(T): export RUBYLIB := $(test_prefix)/lib:$(RUBYLIB)
96 $(T): $(test_prefix)/.stamp
97 $(run_test)
99 install: bin/unicorn bin/unicorn_rails
100 $(prep_setup_rb)
101 $(RM) -r .install-tmp
102 mkdir .install-tmp
103 cp -p $^ .install-tmp
104 $(ruby) setup.rb all
105 $(RM) $^
106 mv $(addprefix .install-tmp/,$(^F)) bin/
107 $(RM) -r .install-tmp
108 $(prep_setup_rb)
110 clean-http11:
111 -$(MAKE) -C ext/unicorn/http11 clean
112 $(RM) ext/unicorn/http11/Makefile lib/unicorn/http11.$(DLEXT)
114 setup_rb_files := .config InstalledFiles
115 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C ext/unicorn/http11 clean
117 clean: clean-http11
118 $(RM) $(setup_rb_files)
119 $(RM) $(t_log)
120 $(RM) -r $(test_prefix)
122 Manifest:
123 git ls-files > $@+
124 cmp $@+ $@ || mv $@+ $@
125 $(RM) -f $@+
127 # using rdoc 2.4.1
128 doc: .document
129 rdoc -Na -m README -t "$(shell sed -ne '1s/^= //p' README)"
131 rails_git_url = git://github.com/rails/rails.git
132 rails_git := vendor/rails.git
133 $(rails_git)/info/cloned-stamp:
134 git clone --mirror -q $(rails_git_url) $(rails_git)
135 > $@
137 rails_tests := $(addsuffix .r,$(addprefix $(T_r).,$(rails_vers)))
138 test-rails: $(rails_tests)
139 $(T_r).%.r: t = $(addsuffix $(log_suffix),$@)
140 $(T_r).%.r: rv = $(subst .r,,$(subst $(T_r).,,$@))
141 $(T_r).%.r: extra = ' 'v$(rv)
142 $(T_r).%.r: arg = $(T_r)
143 $(T_r).%.r: export PATH := $(test_prefix)/bin:$(PATH)
144 $(T_r).%.r: export RUBYLIB := $(test_prefix)/lib:$(RUBYLIB)
145 $(T_r).%.r: export UNICORN_RAILS_TEST_VERSION = $(rv)
146 $(T_r).%.r: export RAILS_GIT_REPO = $(CURDIR)/$(rails_git)
147 $(T_r).%.r: $(test_prefix)/.stamp $(rails_git)/info/cloned-stamp
148 $(run_test)
150 .PHONY: doc $(T) $(slow_tests) Manifest