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