1 # use GNU Make to run tests in parallel, and without depending on Rubygems
5 ruby_bin
:= $(shell which
$(ruby
))
6 ifeq ($(DLEXT
),) # "so" for Linux
7 DLEXT
:= $(shell $(ruby
) -rrbconfig
-e
'puts Config::CONFIG["DLEXT"]')
9 ifeq ($(RUBY_VERSION
),)
10 RUBY_VERSION
:= $(shell $(ruby
) -e
'puts RUBY_VERSION')
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 slow_tests
:= test/unit
/test_server.rb
test/exec
/test_exec.rb
17 log_suffix
= .
$(RUBY_VERSION
).log
18 T
:= $(filter-out $(slow_tests
),$(wildcard test/*/test*.rb
))
19 T_n
:= $(shell $(awk_slow
) $(slow_tests
))
20 T_log
:= $(subst .rb
,$(log_suffix
),$(T
))
21 T_n_log
:= $(subst .n
,$(log_suffix
),$(T_n
))
22 test_prefix
= $(CURDIR
)/test/install-
$(RUBY_VERSION
)
24 http11_deps
:= $(addprefix ext
/unicorn
/http11
/, \
25 ext_help.h http11.c http11_parser.c http11_parser.h \
26 http11_parser.rl http11_parser_common.rl
)
27 inst_deps
:= $(wildcard bin
/*) $(wildcard lib
/*.rb
) \
28 $(wildcard lib
/*/*.rb
) $(http11_deps
)
30 ext
/unicorn
/http11
/http11_parser.c
: ext
/unicorn
/http11
/http11_parser.rl
31 cd
$(@D
) && ragel
$(<F
) -C
-G2
-o
$(@F
)
32 ext
/unicorn
/http11
/Makefile
: ext
/unicorn
/http11
/extconf.rb
33 cd
$(@D
) && $(ruby
) $(<F
)
34 ext
/unicorn
/http11
/http11.
$(DLEXT
): $(http11_deps
) ext
/unicorn
/http11
/Makefile
36 lib
/unicorn
/http11.
$(DLEXT
): ext
/unicorn
/http11
/http11.
$(DLEXT
)
39 http11
: lib
/unicorn
/http11.
$(DLEXT
)
41 $(test_prefix
)/.stamp
: $(inst_deps
)
47 mkdir
-p
$(test_prefix
)/.ccache
48 tar c bin ext lib GNUmakefile |
(cd
$(test_prefix
) && tar x
)
49 $(MAKE
) -C
$(test_prefix
) http11 shebang
51 # this is only intended to be run within $(test_prefix)
53 $(ruby
) -i
-p
-e
'$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $<
55 t_log
:= $(T_log
) $(T_n_log
)
57 @cat
$(t_log
) |
$(ruby
) test/aggregate.rb
60 slow-tests
: $(slow_tests
)
62 @
$(MAKE
) $(shell $(awk_slow
) $@
)
65 run_test
= @echo
'*** $(arg) ***'; \
66 setsid
$(ruby
) $(arg
) $(TEST_OPTS
) >$(t
) 2>&1 || \
67 (cat
>&2 < $(t
); exit
1)
69 %.n
: arg
= $(subst .n
,,$(subst --, -n
,$@
))
70 %.n
: t
= $(subst .n
,$(log_suffix
),$@
)
71 %.n
: export PATH
:= $(test_prefix
)/bin
:$(PATH
)
72 %.n
: export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
73 %.n
: $(test_prefix
)/.stamp
77 $(T
): t
= $(subst .rb
,$(log_suffix
),$@
)
78 $(T
): export PATH
:= $(test_prefix
)/bin
:$(PATH
)
79 $(T
): export RUBYLIB
:= $(test_prefix
)/lib
:$(RUBYLIB
)
80 $(T
): $(test_prefix
)/.stamp
91 -$(MAKE
) -C ext
/unicorn
/http11
clean
92 $(RM
) ext
/unicorn
/http11
/Makefile lib
/unicorn
/http11.
$(DLEXT
)
94 setup_rb_files
:= .config InstalledFiles
95 prep_setup_rb
:= @
-$(RM
) $(setup_rb_files
);$(MAKE
) -C ext
/unicorn
/http11
clean
98 $(RM
) $(setup_rb_files
)
100 $(RM
) -r
$(test_prefix
)
104 cmp
$@
+ $@ || mv
$@
+ $@
107 .PHONY
: $(T
) $(slow_tests
) Manifest