ext: additional validations for valid HTTP responses
[kcar.git] / GNUmakefile
blob982c577afdbd66c9fa96b00f8d2e0fb30dbc4a2c
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all::
3 RUBY = ruby
4 RAKE = rake
5 RAGEL = ragel
6 GIT_URL = git://git.bogomips.org/kcar.git
7 RLFLAGS = -G2
9 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
10 @./GIT-VERSION-GEN
11 -include GIT-VERSION-FILE
12 -include local.mk
13 ifeq ($(DLEXT),) # "so" for Linux
14 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
15 endif
16 ifeq ($(RUBY_VERSION),)
17 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
18 endif
20 install: $(bins)
21 $(prep_setup_rb)
22 $(RM) -r .install-tmp
23 mkdir .install-tmp
24 cp -p bin/* .install-tmp
25 $(RUBY) setup.rb all
26 $(RM) $^
27 mv .install-tmp/* bin/
28 $(RM) -r .install-tmp
29 $(prep_setup_rb)
31 setup_rb_files := .config InstalledFiles
32 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
34 clean:
35 -$(MAKE) -C ext/kcar clean
36 $(RM) $(setup_rb_files) ext/kcar/Makefile
38 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog
39 manifest: $(pkg_extra)
40 $(RM) .manifest
41 $(MAKE) .manifest
43 .manifest:
44 (git ls-files && \
45 for i in $@ $(pkg_extra) $(man1_paths); \
46 do echo $$i; done) | LC_ALL=C sort > $@+
47 cmp $@+ $@ || mv $@+ $@
48 $(RM) $@+
50 NEWS: GIT-VERSION-FILE
51 $(RAKE) -s news_rdoc > $@+
52 mv $@+ $@
54 SINCE =
55 ChangeLog: LOG_VERSION = \
56 $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
57 echo $(GIT_VERSION) || git describe)
58 ifneq ($(SINCE),)
59 ChangeLog: log_range = v$(SINCE)..$(LOG_VERSION)
60 endif
61 ChangeLog: GIT-VERSION-FILE
62 @echo "ChangeLog from $(GIT_URL) ($(log_range))" > $@+
63 @echo >> $@+
64 git log $(log_range) | sed -e 's/^/ /' >> $@+
65 mv $@+ $@
67 news_atom := http://bogomips.org/kcar/NEWS.atom.xml
68 cgit_atom := http://git.bogomips.org/cgit/kcar.git/atom/?h=master
69 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
70 type="application/atom+xml"/>
72 # using rdoc 2.4.1+
73 doc: .document NEWS ChangeLog
74 for i in $(man1_bins); do > $$i; done
75 rdoc -Na -t "$(shell sed -ne '1s/^= //p' README)"
76 install -m644 COPYING doc/COPYING
77 install -m644 $(shell grep '^[A-Z]' .document) doc/
78 cd doc && for i in $(base_bins); do \
79 html=$$(echo $$i | sed 's/\.rb/_rb/')_1.html; \
80 sed -e '/"documentation">/r man1/'$$i'.1.html' \
81 < $$html > tmp && mv tmp $$html; done
82 $(RUBY) -i -p -e \
83 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
84 doc/ChangeLog.html
85 $(RUBY) -i -p -e \
86 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
87 doc/NEWS.html doc/README.html
88 $(RAKE) -s news_atom > doc/NEWS.atom.xml
89 cd doc && ln README.html tmp && mv tmp index.html
90 $(RM) $(man1_bins)
92 ifneq ($(VERSION),)
93 rfproject := rainbows
94 rfpackage := kcar
95 pkggem := pkg/$(rfpackage)-$(VERSION).gem
96 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
97 release_notes := release_notes-$(VERSION)
98 release_changes := release_changes-$(VERSION)
100 release-notes: $(release_notes)
101 release-changes: $(release_changes)
102 $(release_changes):
103 $(RAKE) -s release_changes > $@+
104 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
105 $(release_notes):
106 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
107 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
109 # ensures we're actually on the tagged $(VERSION), only used for release
110 verify:
111 test x"$(shell umask)" = x0022
112 git rev-parse --verify refs/tags/v$(VERSION)^{}
113 git diff-index --quiet HEAD^0
114 test `git rev-parse --verify HEAD^0` = \
115 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
117 fix-perms:
118 -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
119 -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
121 gem: $(pkggem)
123 install-gem: $(pkggem)
124 gem install $(CURDIR)/$<
126 $(pkggem): manifest fix-perms
127 gem build $(rfpackage).gemspec
128 mkdir -p pkg
129 mv $(@F) $@
131 $(pkgtgz): distdir = $(basename $@)
132 $(pkgtgz): HEAD = v$(VERSION)
133 $(pkgtgz): manifest fix-perms
134 @test -n "$(distdir)"
135 $(RM) -r $(distdir)
136 mkdir -p $(distdir)
137 tar c `cat .manifest` | (cd $(distdir) && tar x)
138 cd pkg && tar c $(basename $(@F)) | gzip -9 > $(@F)+
139 mv $@+ $@
141 package: $(pkgtgz) $(pkggem)
143 test-release: verify package $(release_notes) $(release_changes)
144 release: verify package $(release_notes) $(release_changes)
145 # make tgz release on RubyForge
146 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
147 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
148 # push gem to Gemcutter
149 gem push $(pkggem)
150 # in case of gem downloads from RubyForge releases page
151 -rubyforge add_file \
152 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
153 else
154 gem install-gem: GIT-VERSION-FILE
155 $(MAKE) $@ VERSION=$(GIT_VERSION)
156 endif
158 ext := ext/kcar/kcar_ext.$(DLEXT)
159 hdr := $(wildcard $(addprefix ext/kcar/,*.h))
160 ragel: $(ext)
161 ext/kcar/Makefile: ext/kcar/extconf.rb
162 cd $(@D) && $(RUBY) extconf.rb
164 ext/kcar/kcar.c: ext/kcar/kcar.rl ext/kcar/kcar_http_common.rl
165 cd $(@D) && $(RAGEL) kcar.rl -C $(RLFLAGS) -o $(@F)
167 $(ext): ext/kcar/kcar.c $(hdr) ext/kcar/Makefile
168 $(MAKE) -C $(@D)
170 all:: test
172 export STRESS BENCHMARK
173 build: $(ext)
174 test_units := $(wildcard test/test_*.rb)
175 test: test-unit
176 test-unit: $(test_units)
177 $(test_units): build
178 $(RUBY) -w -I lib:ext/kcar $@
180 .PHONY: .FORCE-GIT-VERSION-FILE doc manifest man test $(test_units)