doc: replace pandoc-"Markdown" with real manpages
[unicorn.git] / GNUmakefile
blob94c46ee8c5b12237f8b13fcb49e20b4c701f3248
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all:: test
4 RLFLAGS = -G2
6 MRI = ruby
7 RUBY = ruby
8 RAKE = rake
9 RAGEL = ragel
10 RSYNC = rsync
11 OLDDOC = olddoc
12 RDOC = rdoc
14 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
15 @./GIT-VERSION-GEN
16 -include GIT-VERSION-FILE
17 -include local.mk
18 ruby_bin := $(shell which $(RUBY))
19 ifeq ($(DLEXT),) # "so" for Linux
20 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts RbConfig::CONFIG["DLEXT"]')
21 endif
22 ifeq ($(RUBY_VERSION),)
23 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
24 endif
26 RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
28 MYLIBS = $(RUBYLIB)
30 # dunno how to implement this as concisely in Ruby, and hell, I love awk
31 awk_slow := awk '/def test_/{print FILENAME"--"$$2".n"}' 2>/dev/null
33 slow_tests := test/unit/test_server.rb test/exec/test_exec.rb \
34 test/unit/test_signals.rb test/unit/test_upload.rb
35 log_suffix = .$(RUBY_ENGINE).$(RUBY_VERSION).log
36 T := $(filter-out $(slow_tests), $(wildcard test/*/test*.rb))
37 T_n := $(shell $(awk_slow) $(slow_tests))
38 T_log := $(subst .rb,$(log_suffix),$(T))
39 T_n_log := $(subst .n,$(log_suffix),$(T_n))
40 test_prefix = $(CURDIR)/test/$(RUBY_ENGINE)-$(RUBY_VERSION)
42 ext := ext/unicorn_http
43 c_files := $(ext)/unicorn_http.c $(ext)/httpdate.c $(wildcard $(ext)/*.h)
44 rl_files := $(wildcard $(ext)/*.rl)
45 base_bins := unicorn unicorn_rails
46 bins := $(addprefix bin/, $(base_bins))
47 man1_rdoc := $(addsuffix _1, $(base_bins))
48 man1_bins := $(addsuffix .1, $(base_bins))
49 man1_paths := $(addprefix man/man1/, $(man1_bins))
50 rb_files := $(bins) $(shell find lib ext -type f -name '*.rb')
51 inst_deps := $(c_files) $(rb_files) GNUmakefile test/test_helper.rb
53 ragel: $(ext)/unicorn_http.c
54 $(ext)/unicorn_http.c: $(rl_files)
55 cd $(@D) && $(RAGEL) unicorn_http.rl -C $(RLFLAGS) -o $(@F)
56 $(ext)/Makefile: $(ext)/extconf.rb $(c_files)
57 cd $(@D) && $(RUBY) extconf.rb
58 $(ext)/unicorn_http.$(DLEXT): $(ext)/Makefile
59 $(MAKE) -C $(@D)
60 http: $(ext)/unicorn_http.$(DLEXT)
62 # only used for tests
63 http-install: $(ext)/unicorn_http.$(DLEXT)
64 install -m644 $< lib/
66 test-install: $(test_prefix)/.stamp
67 $(test_prefix)/.stamp: $(inst_deps)
68 mkdir -p $(test_prefix)/.ccache
69 tar cf - $(inst_deps) GIT-VERSION-GEN | \
70 (cd $(test_prefix) && tar xf -)
71 $(MAKE) -C $(test_prefix) clean
72 $(MAKE) -C $(test_prefix) http-install shebang RUBY="$(RUBY)"
73 > $@
75 # this is only intended to be run within $(test_prefix)
76 shebang: $(bins)
77 $(MRI) -i -p -e '$$_.gsub!(%r{^#!.*$$},"#!$(ruby_bin)")' $^
79 t_log := $(T_log) $(T_n_log)
80 test: $(T) $(T_n)
81 @cat $(t_log) | $(MRI) test/aggregate.rb
82 @$(RM) $(t_log)
84 test-exec: $(wildcard test/exec/test_*.rb)
85 test-unit: $(wildcard test/unit/test_*.rb)
86 $(slow_tests): $(test_prefix)/.stamp
87 @$(MAKE) $(shell $(awk_slow) $@)
89 # ensure we can require just the HTTP parser without the rest of unicorn
90 test-require: $(ext)/unicorn_http.$(DLEXT)
91 $(RUBY) --disable-gems -I$(ext) -runicorn_http -e Unicorn
93 test-integration: $(test_prefix)/.stamp
94 $(MAKE) -C t
96 check: test-require test test-integration
97 test-all: check
99 TEST_OPTS = -v
100 check_test = grep '0 failures, 0 errors' $(t) >/dev/null
101 ifndef V
102 quiet_pre = @echo '* $(arg)$(extra)';
103 quiet_post = >$(t) 2>&1 && $(check_test)
104 else
105 # we can't rely on -o pipefail outside of bash 3+,
106 # so we use a stamp file to indicate success and
107 # have rm fail if the stamp didn't get created
108 stamp = $@$(log_suffix).ok
109 quiet_pre = @echo $(RUBY) $(arg) $(TEST_OPTS); ! test -f $(stamp) && (
110 quiet_post = && > $(stamp) )2>&1 | tee $(t); \
111 rm $(stamp) 2>/dev/null && $(check_test)
112 endif
114 # not all systems have setsid(8), we need it because we spam signals
115 # stupidly in some tests...
116 rb_setsid := $(RUBY) -e 'Process.setsid' -e 'exec *ARGV'
118 # TRACER='strace -f -o $(t).strace -s 100000'
119 run_test = $(quiet_pre) \
120 $(rb_setsid) $(TRACER) $(RUBY) -w $(arg) $(TEST_OPTS) $(quiet_post) || \
121 (sed "s,^,$(extra): ," >&2 < $(t); exit 1)
123 %.n: arg = $(subst .n,,$(subst --, -n ,$@))
124 %.n: t = $(subst .n,$(log_suffix),$@)
125 %.n: export PATH := $(test_prefix)/bin:$(PATH)
126 %.n: export RUBYLIB := $(test_prefix)/lib:$(MYLIBS)
127 %.n: $(test_prefix)/.stamp
128 $(run_test)
130 $(T): arg = $@
131 $(T): t = $(subst .rb,$(log_suffix),$@)
132 $(T): export PATH := $(test_prefix)/bin:$(PATH)
133 $(T): export RUBYLIB := $(test_prefix)/lib:$(MYLIBS)
134 $(T): $(test_prefix)/.stamp
135 $(run_test)
137 install: $(bins) $(ext)/unicorn_http.c
138 $(prep_setup_rb)
139 $(RM) -r .install-tmp
140 mkdir .install-tmp
141 cp -p bin/* .install-tmp
142 $(RUBY) setup.rb all
143 $(RM) $^
144 mv .install-tmp/* bin/
145 $(RM) -r .install-tmp
146 $(prep_setup_rb)
148 setup_rb_files := .config InstalledFiles
149 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
151 clean:
152 -$(MAKE) -C $(ext) clean
153 $(RM) $(ext)/Makefile
154 $(RM) $(setup_rb_files) $(t_log)
155 $(RM) -r $(test_prefix) man
156 $(RM) $(man1) $(html1)
158 man1 := $(addprefix Documentation/, unicorn.1 unicorn_rails.1)
159 html1 := $(addsuffix .html, $(man1))
160 man :
161 mkdir -p man/man1
162 install -m 644 $(man1) man/man1
164 html : $(html1)
165 mkdir -p doc/man1
166 install -m 644 $(html1) doc/man1
168 %.1.html: %.1
169 $(OLDDOC) man2html -o $@ ./$<
171 pkg_extra := GIT-VERSION-FILE lib/unicorn/version.rb LATEST NEWS \
172 $(ext)/unicorn_http.c $(man1_paths)
174 NEWS:
175 $(OLDDOC) prepare
177 .manifest: $(ext)/unicorn_http.c man NEWS
178 (git ls-files && for i in $@ $(pkg_extra); do echo $$i; done) | \
179 LC_ALL=C sort > $@+
180 cmp $@+ $@ || mv $@+ $@
181 $(RM) $@+
183 PLACEHOLDERS = $(man1_rdoc)
184 doc: .document $(ext)/unicorn_http.c man html .olddoc.yml $(PLACEHOLDERS)
185 find bin lib -type f -name '*.rbc' -exec rm -f '{}' ';'
186 $(RM) -r doc
187 $(OLDDOC) prepare
188 $(RDOC) -f dark216
189 $(OLDDOC) merge
190 install -m644 COPYING doc/COPYING
191 install -m644 NEWS.atom.xml doc/NEWS.atom.xml
192 install -m644 $(shell LC_ALL=C grep '^[A-Z]' .document) doc/
193 install -m644 $(man1_paths) doc/
194 tar cf - $$(git ls-files examples/) | (cd doc && tar xf -)
196 # publishes docs to https://bogomips.org/unicorn/
197 publish_doc:
198 -git set-file-times
199 $(MAKE) doc
200 $(MAKE) doc_gz
201 chmod 644 $$(find doc -type f)
202 $(RSYNC) -av doc/ bogomips.org:/srv/bogomips/unicorn/
203 git ls-files | xargs touch
205 # Create gzip variants of the same timestamp as the original so nginx
206 # "gzip_static on" can serve the gzipped versions directly.
207 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.gz$$')
208 doc_gz:
209 for i in $(docs); do \
210 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
212 ifneq ($(VERSION),)
213 rfpackage := unicorn
214 pkggem := pkg/$(rfpackage)-$(VERSION).gem
215 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
217 # ensures we're actually on the tagged $(VERSION), only used for release
218 verify:
219 test x"$(shell umask)" = x0022
220 git rev-parse --verify refs/tags/v$(VERSION)^{}
221 git diff-index --quiet HEAD^0
222 test `git rev-parse --verify HEAD^0` = \
223 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
225 fix-perms:
226 git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
227 git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
229 gem: $(pkggem)
231 install-gem: $(pkggem)
232 gem install --local $(CURDIR)/$<
234 $(pkggem): .manifest fix-perms
235 gem build $(rfpackage).gemspec
236 mkdir -p pkg
237 mv $(@F) $@
239 $(pkgtgz): distdir = $(basename $@)
240 $(pkgtgz): HEAD = v$(VERSION)
241 $(pkgtgz): .manifest fix-perms
242 @test -n "$(distdir)"
243 $(RM) -r $(distdir)
244 mkdir -p $(distdir)
245 tar cf - $$(cat .manifest) | (cd $(distdir) && tar xf -)
246 cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
247 mv $@+ $@
249 package: $(pkgtgz) $(pkggem)
251 release: verify package
252 # push gem to Gemcutter
253 gem push $(pkggem)
254 else
255 gem install-gem: GIT-VERSION-FILE
256 $(MAKE) $@ VERSION=$(GIT_VERSION)
257 endif
259 $(PLACEHOLDERS):
260 echo olddoc_placeholder > $@
262 check-warnings:
263 @(for i in $$(git ls-files '*.rb' bin | grep -v '^setup\.rb$$'); \
264 do $(RUBY) --disable-gems -d -W2 -c \
265 $$i; done) | grep -v '^Syntax OK$$' || :
267 .PHONY: .FORCE-GIT-VERSION-FILE doc $(T) $(slow_tests) man
268 .PHONY: test-install