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