kcar 0.1.2 - one bugfix for one liners
[kcar.git] / GNUmakefile
blob6902760580c2b7d2c77954724a81ca9faf7cbc23
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
8 RSYNC = rsync
10 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
11 @./GIT-VERSION-GEN
12 -include GIT-VERSION-FILE
13 -include local.mk
14 ifeq ($(DLEXT),) # "so" for Linux
15 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
16 endif
17 ifeq ($(RUBY_VERSION),)
18 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
19 endif
21 install: $(bins)
22 $(prep_setup_rb)
23 $(RM) -r .install-tmp
24 mkdir .install-tmp
25 cp -p bin/* .install-tmp
26 $(RUBY) setup.rb all
27 $(RM) $^
28 mv .install-tmp/* bin/
29 $(RM) -r .install-tmp
30 $(prep_setup_rb)
32 setup_rb_files := .config InstalledFiles
33 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
35 clean:
36 -$(MAKE) -C ext/kcar clean
37 $(RM) $(setup_rb_files) ext/kcar/Makefile
39 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog ext/kcar/kcar.c
40 manifest: $(pkg_extra)
41 $(RM) .manifest
42 $(MAKE) .manifest
44 .manifest:
45 (git ls-files && \
46 for i in $@ $(pkg_extra) $(man1_paths); \
47 do echo $$i; done) | LC_ALL=C sort > $@+
48 cmp $@+ $@ || mv $@+ $@
49 $(RM) $@+
51 NEWS: GIT-VERSION-FILE
52 $(RAKE) -s news_rdoc > $@+
53 mv $@+ $@
55 latest: NEWS
56 @awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' $<
58 SINCE = 0.1.0
59 ChangeLog: LOG_VERSION = \
60 $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
61 echo $(GIT_VERSION) || git describe)
62 ifneq ($(SINCE),)
63 ChangeLog: log_range = v$(SINCE)..$(LOG_VERSION)
64 endif
65 ChangeLog: GIT-VERSION-FILE
66 @echo "ChangeLog from $(GIT_URL) ($(log_range))" > $@+
67 @echo >> $@+
68 git log $(log_range) | sed -e 's/^/ /' >> $@+
69 mv $@+ $@
71 news_atom := http://bogomips.org/kcar/NEWS.atom.xml
72 cgit_atom := http://git.bogomips.org/cgit/kcar.git/atom/?h=master
73 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
74 type="application/atom+xml"/>
76 # using rdoc 2.5.x
77 doc: .document NEWS ChangeLog
78 rdoc -a -t "$(shell sed -ne '1s/^= //p' README)"
79 install -m644 COPYING doc/COPYING
80 install -m644 $(shell grep '^[A-Z]' .document) doc/
81 $(RUBY) -i -p -e \
82 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
83 doc/ChangeLog.html
84 $(RUBY) -i -p -e \
85 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
86 doc/NEWS.html doc/README.html
87 $(RAKE) -s news_atom > doc/NEWS.atom.xml
88 cd doc && ln README.html tmp && mv tmp index.html
90 ifneq ($(VERSION),)
91 rfproject := rainbows
92 rfpackage := kcar
93 pkggem := pkg/$(rfpackage)-$(VERSION).gem
94 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
95 release_notes := release_notes-$(VERSION)
96 release_changes := release_changes-$(VERSION)
98 release-notes: $(release_notes)
99 release-changes: $(release_changes)
100 $(release_changes):
101 $(RAKE) -s release_changes > $@+
102 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
103 $(release_notes):
104 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
105 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
107 # ensures we're actually on the tagged $(VERSION), only used for release
108 verify:
109 test x"$(shell umask)" = x0022
110 git rev-parse --verify refs/tags/v$(VERSION)^{}
111 git diff-index --quiet HEAD^0
112 test `git rev-parse --verify HEAD^0` = \
113 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
115 fix-perms:
116 -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
117 -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
119 gem: $(pkggem)
121 install-gem: $(pkggem)
122 gem install $(CURDIR)/$<
124 $(pkggem): manifest fix-perms
125 gem build $(rfpackage).gemspec
126 mkdir -p pkg
127 mv $(@F) $@
129 $(pkgtgz): distdir = $(basename $@)
130 $(pkgtgz): HEAD = v$(VERSION)
131 $(pkgtgz): manifest fix-perms
132 @test -n "$(distdir)"
133 $(RM) -r $(distdir)
134 mkdir -p $(distdir)
135 tar c `cat .manifest` | (cd $(distdir) && tar x)
136 cd pkg && tar c $(basename $(@F)) | gzip -9 > $(@F)+
137 mv $@+ $@
139 package: $(pkgtgz) $(pkggem)
141 test-release: verify package $(release_notes) $(release_changes)
142 release: verify package $(release_notes) $(release_changes)
143 # make tgz release on RubyForge
144 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
145 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
146 # push gem to Gemcutter
147 gem push $(pkggem)
148 # in case of gem downloads from RubyForge releases page
149 -rubyforge add_file \
150 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
151 else
152 gem install-gem: GIT-VERSION-FILE
153 $(MAKE) $@ VERSION=$(GIT_VERSION)
154 endif
156 ext := ext/kcar/kcar_ext.$(DLEXT)
157 hdr := $(wildcard $(addprefix ext/kcar/,*.h))
158 ragel: $(ext)
159 ext/kcar/Makefile: ext/kcar/extconf.rb
160 cd $(@D) && $(RUBY) extconf.rb
162 ext/kcar/kcar.c: ext/kcar/kcar.rl ext/kcar/kcar_http_common.rl
163 cd $(@D) && $(RAGEL) kcar.rl -C $(RLFLAGS) -o $(@F)
165 $(ext): ext/kcar/kcar.c $(hdr) ext/kcar/Makefile
166 $(MAKE) -C $(@D)
168 all:: test
170 build: $(ext)
171 test_units := $(wildcard test/test_*.rb)
172 test: test-unit
173 test-unit: $(test_units)
174 $(test_units): build
175 $(RUBY) -w -I lib:ext/kcar $@
177 # this requires GNU coreutils variants
178 publish_doc:
179 -git set-file-times
180 $(RM) -r doc ChangeLog NEWS
181 $(MAKE) doc LOG_VERSION=$(shell git tag -l | tail -1)
182 $(MAKE) -s latest > doc/LATEST
183 find doc/images doc/js -type f | \
184 TZ=UTC xargs touch -d '1970-01-01 00:00:00' doc/rdoc.css
185 $(MAKE) doc_gz
186 chmod 644 $$(find doc -type f)
187 $(RSYNC) -av doc/ dcvr:/srv/bogomips/kcar/
188 git ls-files | xargs touch
190 # Create gzip variants of the same timestamp as the original so nginx
191 # "gzip_static on" can serve the gzipped versions directly.
192 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
193 doc_gz:
194 touch doc/NEWS.atom.xml -d "$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
195 for i in $(docs); do \
196 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
198 .PHONY: .FORCE-GIT-VERSION-FILE doc manifest man test $(test_units)