Rainbows! 5.2.1
[rainbows.git] / pkg.mk
blob5af6a3e99f5bfbbd44a01bb8348efb7f1acf6ac4
1 RUBY = ruby
2 RAKE = rake
3 RSYNC = rsync
4 OLDDOC = olddoc
5 RDOC = rdoc
7 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
8 @./GIT-VERSION-GEN
9 -include GIT-VERSION-FILE
10 -include local.mk
11 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts RbConfig::CONFIG["DLEXT"]')
12 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
13 RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
14 lib := lib
16 ifeq ($(shell test -f script/isolate_for_tests && echo t),t)
17 isolate_libs := tmp/isolate/$(RUBY_ENGINE)-$(RUBY_VERSION)/isolate.mk
18 $(isolate_libs): script/isolate_for_tests
19 @$(RUBY) script/isolate_for_tests
20 -include $(isolate_libs)
21 lib := $(lib):$(ISOLATE_LIBS)
22 endif
24 ext := $(firstword $(wildcard ext/*))
25 ifneq ($(ext),)
26 ext_pfx := tmp/ext/$(RUBY_ENGINE)-$(RUBY_VERSION)
27 ext_h := $(wildcard $(ext)/*/*.h $(ext)/*.h)
28 ext_src := $(wildcard $(ext)/*.c $(ext_h))
29 ext_pfx_src := $(addprefix $(ext_pfx)/,$(ext_src))
30 ext_d := $(ext_pfx)/$(ext)/.d
31 $(ext)/extconf.rb: $(wildcard $(ext)/*.h)
32 @>> $@
33 $(ext_d):
34 @mkdir -p $(@D)
35 @> $@
36 $(ext_pfx)/$(ext)/%: $(ext)/% $(ext_d)
37 install -m 644 $< $@
38 $(ext_pfx)/$(ext)/Makefile: $(ext)/extconf.rb $(ext_d) $(ext_h)
39 $(RM) -f $(@D)/*.o
40 cd $(@D) && $(RUBY) $(CURDIR)/$(ext)/extconf.rb
41 ext_sfx := _ext.$(DLEXT)
42 ext_dl := $(ext_pfx)/$(ext)/$(notdir $(ext)_ext.$(DLEXT))
43 $(ext_dl): $(ext_src) $(ext_pfx_src) $(ext_pfx)/$(ext)/Makefile
44 @echo $^ == $@
45 $(MAKE) -C $(@D)
46 lib := $(lib):$(ext_pfx)/$(ext)
47 build: $(ext_dl)
48 else
49 build:
50 endif
52 pkg_extra += GIT-VERSION-FILE NEWS LATEST
53 NEWS: GIT-VERSION-FILE .olddoc.yml
54 $(OLDDOC) prepare
55 LATEST: NEWS
57 manifest:
58 $(RM) .manifest
59 $(MAKE) .manifest
61 .manifest: $(pkg_extra)
62 (git ls-files && for i in $@ $(pkg_extra); do echo $$i; done) | \
63 LC_ALL=C sort > $@+
64 cmp $@+ $@ || mv $@+ $@
65 $(RM) $@+
67 doc:: .document .olddoc.yml $(pkg_extra) $(PLACEHOLDERS)
68 -find lib -type f -name '*.rbc' -exec rm -f '{}' ';'
69 -find ext -type f -name '*.rbc' -exec rm -f '{}' ';'
70 $(RM) -r doc
71 $(RDOC) -f dark216
72 $(OLDDOC) merge
73 install -m644 COPYING doc/COPYING
74 install -m644 NEWS doc/NEWS
75 install -m644 NEWS.atom.xml doc/NEWS.atom.xml
76 install -m644 $(shell LC_ALL=C grep '^[A-Z]' .document) doc/
78 ifneq ($(VERSION),)
79 pkggem := pkg/$(rfpackage)-$(VERSION).gem
80 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
82 # ensures we're actually on the tagged $(VERSION), only used for release
83 verify:
84 test x"$(shell umask)" = x0022
85 git rev-parse --verify refs/tags/v$(VERSION)^{}
86 git diff-index --quiet HEAD^0
87 test $$(git rev-parse --verify HEAD^0) = \
88 $$(git rev-parse --verify refs/tags/v$(VERSION)^{})
90 fix-perms:
91 -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
92 -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
94 gem: $(pkggem)
96 install-gem: $(pkggem)
97 gem install $(CURDIR)/$<
99 $(pkggem): manifest fix-perms
100 gem build $(rfpackage).gemspec
101 mkdir -p pkg
102 mv $(@F) $@
104 $(pkgtgz): distdir = $(basename $@)
105 $(pkgtgz): HEAD = v$(VERSION)
106 $(pkgtgz): manifest fix-perms
107 @test -n "$(distdir)"
108 $(RM) -r $(distdir)
109 mkdir -p $(distdir)
110 tar cf - $$(cat .manifest) | (cd $(distdir) && tar xf -)
111 cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
112 mv $@+ $@
114 package: $(pkgtgz) $(pkggem)
116 release:: verify package
117 # push gem to RubyGems.org
118 gem push $(pkggem)
119 else
120 gem install-gem: GIT-VERSION-FILE
121 $(MAKE) $@ VERSION=$(GIT_VERSION)
122 endif
124 all:: test
125 test_units := $(wildcard test/test_*.rb)
126 test: test-unit
127 test-unit: $(test_units)
128 $(test_units): build
129 $(RUBY) -I $(lib) $@ $(RUBY_TEST_OPTS)
131 # this requires GNU coreutils variants
132 ifneq ($(RSYNC_DEST),)
133 publish_doc:
134 -git set-file-times
135 $(MAKE) doc
136 $(MAKE) doc_gz
137 $(RSYNC) -av doc/ $(RSYNC_DEST)/
138 git ls-files | xargs touch
139 endif
141 # Create gzip variants of the same timestamp as the original so nginx
142 # "gzip_static on" can serve the gzipped versions directly.
143 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.gz$$')
144 doc_gz:
145 for i in $(docs); do \
146 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
147 check-warnings:
148 @(for i in $$(git ls-files '*.rb'| grep -v '^setup\.rb$$'); \
149 do $(RUBY) -d -W2 -c $$i; done) | grep -v '^Syntax OK$$' || :
151 ifneq ($(PLACEHOLDERS),)
152 $(PLACEHOLDERS):
153 echo olddoc_placeholder > $@
154 endif
156 .PHONY: all .FORCE-GIT-VERSION-FILE doc test $(test_units) manifest
157 .PHONY: check-warnings