Epoll#dup and Epoll#clone inherit close-on-exec
[sleepy_penguin.git] / GNUmakefile
blobdd6f8a9f585e2780c3dc944d4e7df221ce0f79a2
1 # use GNU Make to run tests in parallel, and without depending on RubyGems
2 all::
3 RUBY = ruby
4 RAKE = rake
5 RSYNC = rsync
6 GIT_URL = git://git.bogomips.org/sleepy_penguin.git
8 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
9 @./GIT-VERSION-GEN
10 -include GIT-VERSION-FILE
11 -include local.mk
12 ifeq ($(DLEXT),) # "so" for Linux
13 DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
14 endif
15 ifeq ($(RUBY_VERSION),)
16 RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
17 endif
19 install:
20 $(prep_setup_rb)
21 $(RM) -r .install-tmp
22 mkdir .install-tmp
23 $(RUBY) setup.rb all
24 $(RM) $^
25 $(RM) -r .install-tmp
26 $(prep_setup_rb)
28 setup_rb_files := .config InstalledFiles
29 prep_setup_rb := @-$(RM) $(setup_rb_files);$(MAKE) -C $(ext) clean
31 clean:
32 -$(MAKE) -C ext/sleepy_penguin clean
33 $(RM) $(setup_rb_files) ext/sleepy_penguin/Makefile
35 pkg_extra := GIT-VERSION-FILE NEWS ChangeLog
36 manifest: $(pkg_extra)
37 $(RM) .manifest
38 $(MAKE) .manifest
40 .manifest:
41 (git ls-files && \
42 for i in $@ $(pkg_extra); \
43 do echo $$i; done) | LC_ALL=C sort > $@+
44 cmp $@+ $@ || mv $@+ $@
45 $(RM) $@+
47 NEWS: GIT-VERSION-FILE
48 $(RAKE) -s news_rdoc > $@+
49 mv $@+ $@
51 latest: NEWS
52 @awk 'BEGIN{RS="=== ";ORS=""}NR==2{sub(/\n$$/,"");print RS""$$0 }' $<
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/sleepy_penguin/NEWS.atom.xml
68 cgit_atom := http://git.bogomips.org/cgit/sleepy_penguin.git/atom/?h=master
69 atom = <link rel="alternate" title="Atom feed" href="$(1)" \
70 type="application/atom+xml"/>
72 # using rdoc 2.5.x
73 doc: .document NEWS ChangeLog
74 rdoc -t "$(shell sed -ne '1s/^= //p' README)"
75 install -m644 COPYING doc/COPYING
76 install -m644 $(shell grep '^[A-Z]' .document) doc/
77 $(RUBY) -i -p -e \
78 '$$_.gsub!("</title>",%q{\&$(call atom,$(cgit_atom))})' \
79 doc/ChangeLog.html
80 $(RUBY) -i -p -e \
81 '$$_.gsub!("</title>",%q{\&$(call atom,$(news_atom))})' \
82 doc/NEWS.html doc/README.html
83 $(RAKE) -s news_atom > doc/NEWS.atom.xml
84 cd doc && ln README.html tmp && mv tmp index.html
86 ifneq ($(VERSION),)
87 rfproject := rainbows
88 rfpackage := sleepy_penguin
89 pkggem := pkg/$(rfpackage)-$(VERSION).gem
90 pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
91 release_notes := release_notes-$(VERSION)
92 release_changes := release_changes-$(VERSION)
94 release-notes: $(release_notes)
95 release-changes: $(release_changes)
96 $(release_changes):
97 $(RAKE) -s release_changes > $@+
98 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
99 $(release_notes):
100 GIT_URL=$(GIT_URL) $(RAKE) -s release_notes > $@+
101 $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
103 # ensures we're actually on the tagged $(VERSION), only used for release
104 verify:
105 test x"$(shell umask)" = x0022
106 git rev-parse --verify refs/tags/v$(VERSION)^{}
107 git diff-index --quiet HEAD^0
108 test `git rev-parse --verify HEAD^0` = \
109 `git rev-parse --verify refs/tags/v$(VERSION)^{}`
111 fix-perms:
112 -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
113 -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
115 gem: $(pkggem)
117 install-gem: $(pkggem)
118 gem install $(CURDIR)/$<
120 $(pkggem): manifest fix-perms
121 gem build $(rfpackage).gemspec
122 mkdir -p pkg
123 mv $(@F) $@
125 $(pkgtgz): distdir = $(basename $@)
126 $(pkgtgz): HEAD = v$(VERSION)
127 $(pkgtgz): manifest fix-perms
128 @test -n "$(distdir)"
129 $(RM) -r $(distdir)
130 mkdir -p $(distdir)
131 tar c `cat .manifest` | (cd $(distdir) && tar x)
132 cd pkg && tar c $(basename $(@F)) | gzip -9 > $(@F)+
133 mv $@+ $@
135 package: $(pkgtgz) $(pkggem)
137 test-release: verify package $(release_notes) $(release_changes)
138 release: verify package $(release_notes) $(release_changes)
139 # make tgz release on RubyForge
140 rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
141 $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
142 # push gem to Gemcutter
143 gem push $(pkggem)
144 # in case of gem downloads from RubyForge releases page
145 -rubyforge add_file \
146 $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
147 else
148 gem install-gem: GIT-VERSION-FILE
149 $(MAKE) $@ VERSION=$(GIT_VERSION)
150 endif
152 extdir := ext/sleepy_penguin
153 ext := $(extdir)/sleepy_penguin_ext.$(DLEXT)
154 $(extdir)/Makefile: $(extdir)/extconf.rb
155 cd $(@D) && $(RUBY) extconf.rb
157 $(ext): $(wildcard $(extdir)/*.c) $(wildcard $(extdir)/*.h) $(extdir)/Makefile
158 $(MAKE) -C $(@D)
160 all:: test
162 build: $(ext)
163 test_units := $(wildcard test/test_*.rb)
164 test: test-unit
165 test-unit: $(test_units)
166 $(test_units): build
167 $(RUBY) -I lib:$(extdir) $@
169 # this requires GNU coreutils variants
170 publish_doc:
171 -git set-file-times
172 $(RM) -r doc ChangeLog NEWS
173 $(MAKE) doc LOG_VERSION=$(shell git tag -l | tail -1)
174 $(MAKE) -s latest > doc/LATEST
175 find doc/images doc/js -type f | \
176 TZ=UTC xargs touch -d '1970-01-01 00:00:00' doc/rdoc.css
177 $(MAKE) doc_gz
178 chmod 644 $$(find doc -type f)
179 $(RSYNC) -av doc/ bogomips.org:/srv/bogomips/sleepy_penguin/
180 git ls-files | xargs touch
182 # Create gzip variants of the same timestamp as the original so nginx
183 # "gzip_static on" can serve the gzipped versions directly.
184 doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
185 doc_gz:
186 touch doc/NEWS.atom.xml -d "$$(awk 'NR==1{print $$4,$$5,$$6}' NEWS)"
187 for i in $(docs); do \
188 gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
190 .PHONY: .FORCE-GIT-VERSION-FILE doc manifest man test $(test_units)