*epoll: refactor common loop code
[rainbows.git] / pkg.mk
blobfd8dc0c1da652204f53cf49015db2a2960750d18
1 RUBY = ruby
2 RAKE = rake
3 RSYNC = rsync
5 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
6 @./GIT-VERSION-GEN
7 -include GIT-VERSION-FILE
8 -include local.mk
9 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
10 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
11 RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
12 lib := lib
14 ifeq ($(shell test -f script/isolate_for_tests && echo t),t)
15 isolate_libs := tmp/isolate/$(RUBY_ENGINE)-$(RUBY_VERSION)/isolate.mk
16 $(isolate_libs): script/isolate_for_tests
17 @$(RUBY) script/isolate_for_tests
18 -include $(isolate_libs)
19 lib := $(lib):$(ISOLATE_LIBS)
20 endif
22 ext := $(firstword $(wildcard ext/*))
23 ifneq ($(ext),)
24 ext_pfx := tmp/ext/$(RUBY_ENGINE)-$(RUBY_VERSION)
25 ext_h := $(wildcard $(ext)/*/*.h $(ext)/*.h)
26 ext_src := $(wildcard $(ext)/*.c $(ext_h))
27 ext_pfx_src := $(addprefix $(ext_pfx)/,$(ext_src))
28 ext_d := $(ext_pfx)/$(ext)/.d
29 $(ext)/extconf.rb: $(wildcard $(ext)/*.h)
30 @>> $@
31 $(ext_d):
32 @mkdir -p $(@D)
33 @> $@
34 $(ext_pfx)/$(ext)/%: $(ext)/% $(ext_d)
35 install -m 644 $< $@
36 $(ext_pfx)/$(ext)/Makefile: $(ext)/extconf.rb $(ext_d) $(ext_h)
37 $(RM) -f $(@D)/*.o
38 cd $(@D) && $(RUBY) $(CURDIR)/$(ext)/extconf.rb
39 ext_sfx := _ext.$(DLEXT)
40 ext_dl := $(ext_pfx)/$(ext)/$(notdir $(ext)_ext.$(DLEXT))
41 $(ext_dl): $(ext_src) $(ext_pfx_src) $(ext_pfx)/$(ext)/Makefile
42 @echo $^ == $@
43 $(MAKE) -C $(@D)
44 lib := $(lib):$(ext_pfx)/$(ext)
45 build: $(ext_dl)
46 endif
48 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog LATEST
49 ChangeLog: GIT-VERSION-FILE .wrongdoc.yml
50 wrongdoc prepare
52 manifest:
53 $(RM) .manifest
54 $(MAKE) .manifest
56 .manifest: ChangeLog
57 (git ls-files && for i in $@ $(pkg_extra); do echo $$i; done) | \
58 LC_ALL=C sort > $@+
59 cmp $@+ $@ || mv $@+ $@
60 $(RM) $@+
62 doc:: .document .wrongdoc.yml
63 find lib -type f -name '*.rbc' -exec rm -f '{}' ';'
64 -find ext -type f -name '*.rbc' -exec rm -f '{}' ';'
65 $(RM) -r doc
66 wrongdoc all
67 install -m644 COPYING doc/COPYING
68 install -m644 $(shell grep '^[A-Z]' .document) doc/
70 ifneq ($(VERSION),)
71 pkggem := pkg/$(rfpackage)-$(VERSION).gem
72 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
73 release_notes := release_notes-$(VERSION)
74 release_changes := release_changes-$(VERSION)
76 release-notes: $(release_notes)
77 release-changes: $(release_changes)
78 $(release_changes):
79 wrongdoc release_changes > $@+
80 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
81 $(release_notes):
82 wrongdoc release_notes > $@+
83 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
85 # ensures we're actually on the tagged $(VERSION), only used for release
86 verify:
87 test x"$(shell umask)" = x0022
88 git rev-parse --verify refs/tags/v$(VERSION)^{}
89 git diff-index --quiet HEAD^0
90 test $$(git rev-parse --verify HEAD^0) = \
91 $$(git rev-parse --verify refs/tags/v$(VERSION)^{})
93 fix-perms:
94 -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
95 -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
97 gem: $(pkggem)
99 install-gem: $(pkggem)
100 gem install $(CURDIR)/$<
102 $(pkggem): manifest fix-perms
103 gem build $(rfpackage).gemspec
104 mkdir -p pkg
105 mv $(@F) $@
107 $(pkgtgz): distdir = $(basename $@)
108 $(pkgtgz): HEAD = v$(VERSION)
109 $(pkgtgz): manifest fix-perms
110 @test -n "$(distdir)"
111 $(RM) -r $(distdir)
112 mkdir -p $(distdir)
113 tar cf - $$(cat .manifest) | (cd $(distdir) && tar xf -)
114 cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
115 mv $@+ $@
117 package: $(pkgtgz) $(pkggem)
119 test-release:: verify package $(release_notes) $(release_changes)
120 # make tgz release on RubyForge
121 @echo rubyforge add_release -f \
122 -n $(release_notes) -a $(release_changes) \
123 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
124 @echo gem push $(pkggem)
125 @echo rubyforge add_file \
126 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
127 release:: verify package $(release_notes) $(release_changes)
128 # make tgz release on RubyForge
129 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
130 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
131 # push gem to RubyGems.org
132 gem push $(pkggem)
133 # in case of gem downloads from RubyForge releases page
134 rubyforge add_file \
135 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
136 else
137 gem install-gem: GIT-VERSION-FILE
138 $(MAKE) $@ VERSION=$(GIT_VERSION)
139 endif
141 all:: test
142 test_units := $(wildcard test/test_*.rb)
143 test: test-unit
144 test-unit: $(test_units)
145 $(test_units): build
146 $(RUBY) -I $(lib) $@
148 # this requires GNU coreutils variants
149 ifneq ($(RSYNC_DEST),)
150 publish_doc:
151 -git set-file-times
152 $(MAKE) doc
153 find doc/images -type f | \
154 TZ=UTC xargs touch -d '1970-01-01 00:00:06' doc/rdoc.css
155 $(MAKE) doc_gz
156 $(RSYNC) -av doc/ $(RSYNC_DEST)/
157 git ls-files | xargs touch
158 endif
160 # Create gzip variants of the same timestamp as the original so nginx
161 # "gzip_static on" can serve the gzipped versions directly.
162 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
163 doc_gz:
164 for i in $(docs); do \
165 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
167 .PHONY: all .FORCE-GIT-VERSION-FILE doc test $(test_units) manifest