Process management cleanups
[unicorn.git] / GNUmakefile
blob63a5bd01afd9a62c9f4b832124636a5198098e7a
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 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
35 $(MAKE) -C $(@D)
36 lib/unicorn/http11.$(DLEXT): ext/unicorn/http11/http11.$(DLEXT)
37 @mkdir -p lib
38 install -m644 $< $@
39 http11: lib/unicorn/http11.$(DLEXT)
41 $(test_prefix)/.stamp: $(inst_deps)
42 $(MAKE) clean-http11
43 $(MAKE) install-test
44 > $@
46 install-test:
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)
52 shebang: bin/unicorn
53 $(ruby) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $<
55 t_log := $(T_log) $(T_n_log)
56 test: $(T) $(T_n)
57 @cat $(t_log) | $(ruby) test/aggregate.rb
58 @$(RM) $(t_log)
60 slow-tests: $(slow_tests)
61 $(slow_tests):
62 @$(MAKE) $(shell $(awk_slow) $@)
64 TEST_OPTS = -v
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
74 $(run_test)
76 $(T): arg = $@
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
81 $(run_test)
83 install: bin/unicorn
84 $(prep_setup_rb)
85 git diff --quiet $<
86 $(ruby) setup.rb all
87 git checkout $<
88 $(prep_setup_rb)
90 clean-http11:
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
97 clean: clean-http11
98 $(RM) $(setup_rb_files)
99 $(RM) $(t_log)
100 $(RM) -r $(test_prefix)
102 Manifest:
103 git ls-files > $@+
104 cmp $@+ $@ || mv $@+ $@
105 $(RM) -f $@+
107 # using rdoc 2.4.1
108 doc: .document
109 rdoc -Na -m README -t "$(shell sed -ne '1s/^= //p' README)"
111 .PHONY: doc $(T) $(slow_tests) Manifest