forked from weewx/weewx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
304 lines (266 loc) · 10.1 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# -*- makefile -*-
# this makefile controls the build and packaging of weewx
# Copyright 2013 Matthew Wall
# if you do not want to sign the packages, set SIGN to 0
SIGN=1
# WWW server
WEEWX_COM=weewx.com
# location of the html documentation
WEEWX_HTMLDIR=/var/www/html
# location of weewx downloads
WEEWX_DOWNLOADS=$(WEEWX_HTMLDIR)/downloads
# location for staging weewx package uploads
WEEWX_STAGING=$(WEEWX_HTMLDIR)/downloads/development_versions
# extract version to be used in package controls and labels
VERSION=$(shell grep "__version__.*=" bin/weewx/__init__.py | sed -e 's/__version__=//' | sed -e 's/"//g')
# just the major.minor part of the version
MMVERSION:=$(shell echo "$(VERSION)" | sed -e 's%.[0-9a-z]*$$%%')
CWD = $(shell pwd)
BLDDIR=build
DSTDIR=dist
PYTHON=python
all: help
help: info
@echo "options include:"
@echo " info display values of variables we care about"
@echo " install run the generic python install"
@echo " version get version from __init__ and insert elsewhere"
@echo ""
@echo " readme.txt create README.txt suitable for distribution"
@echo " deb-changelog prepend stub changelog entry for deb"
@echo " rpm-changelog prepend stub changelog entry for rpm"
@echo ""
@echo " src-package create source tarball suitable for distribution"
@echo " deb-package create .deb package"
@echo " rpm-package create .rpm package"
@echo ""
@echo " check-deb check the deb package"
@echo " check-rpm check the rpm package"
@echo " check-docs run weblint on the docs"
@echo ""
@echo " upload-src upload the src package"
@echo " upload-deb upload the deb package"
@echo " upload-rhel upload the redhat rpm package"
@echo " upload-suse upload the suse rpm package"
@echo " upload-readme upload the README.txt"
@echo ""
@echo " upload-docs upload docs to weewx.com"
@echo ""
@echo " release rearrange files on the download server"
@echo ""
@echo " test run all unit tests"
@echo " SUITE=path/to/foo.py to run only foo tests"
info:
@echo " VERSION: $(VERSION)"
@echo " MMVERSION: $(MMVERSION)"
@echo " CWD: $(CWD)"
@echo " UPLOADDIR: $(UPLOADDIR)"
@echo " USER: $(USER)"
@echo " WWW SERVER: $(WEEWX_COM)"
realclean:
rm -f MANIFEST
rm -rf build
rm -rf dist
check-docs:
weblint docs/*.htm
# if no suite is specified, find all test suites in the source tree
ifndef SUITE
SUITE=`find bin -name "test_*.py"`
endif
test:
@rm -f $(BLDDIR)/test-results
@mkdir -p $(BLDDIR)
@for f in $(SUITE); do \
echo running $$f; \
echo $$f >> $(BLDDIR)/test-results; \
PYTHONPATH="bin:examples" $(PYTHON) $$f >> $(BLDDIR)/test-results 2>&1; \
echo >> $(BLDDIR)/test-results; \
done
@grep "ERROR:\|FAIL:" $(BLDDIR)/test-results || echo "no failures"
@echo "see $(BLDDIR)/test-results"
MYSQLSETUP="create user 'weewx'@'localhost' identified by 'weewx';\n\
grant all on *.* to 'weewx'@'localhost';\n"
test-setup:
echo $(MYSQLSETUP) | mysql --user=root -p
TESTDIR=/var/tmp/weewx_test
MYSQLCLEAN="drop database test_weewx;\n\
drop database test_alt_weewx;\n\
drop database test_sim;\n"
test-clean:
rm -rf $(TESTDIR)
echo $(MYSQLCLEAN) | mysql --user=weewx --password=weewx --force >/dev/null 2>&1
install:
./setup.py --install
SRCPKG=weewx-$(VERSION).tar.gz
src-package $(DSTDIR)/$(SRCPKG): MANIFEST.in
rm -f MANIFEST
./setup.py sdist
# upload the source tarball to the web site
upload-src:
scp $(DSTDIR)/$(SRCPKG) $(USER)@$(WEEWX_COM):$(WEEWX_STAGING)
# upload docs to the web site
upload-docs:
rsync -arv docs $(USER)@$(WEEWX_COM):$(WEEWX_HTMLDIR)
# create the README.txt for uploading
README_HEADER="\
--------------------\n\
weewx packages \n\
--------------------\n\
\n\
$(DEBPKG)\n\
for Debian, Ubuntu, Mint, including Raspberry Pi\n\
\n\
weewx-$(RPMVER).rhel.$(RPMARCH).rpm\n\
for Redhat, CentOS, Fedora\n\
\n\
weewx-$(RPMVER).suse.$(RPMARCH).rpm\n\
for SuSE, OpenSuSE\n\
\n\
$(SRCPKG)\n\
for all operating systems including Linux, BSD, MacOSX\n\
this is the best choice if you intend to customize weewx\n\
\n\
--------------------\n\
weewx change history\n\
--------------------\n"
readme.txt: docs/changes.txt
mkdir -p $(DSTDIR)
rm -f $(DSTDIR)/README.txt
echo $(README_HEADER) > $(DSTDIR)/README.txt
pkg/mkchangelog.pl --ifile docs/changes.txt >> $(DSTDIR)/README.txt
upload-readme: readme.txt
scp $(DSTDIR)/README.txt $(USER)@$(WEEWX_COM):$(WEEWX_STAGING)
# update the version in all relevant places
VDOCS=readme.htm customizing.htm devnotes.htm hardware.htm usersguide.htm upgrading.htm utilities.htm
version:
for f in $(VDOCS); do \
sed -e 's/^Version: [0-9].*/Version: $(MMVERSION)/' docs/$$f > docs/$$f.tmp; \
mv docs/$$f.tmp docs/$$f; \
done
sed -e 's/version =.*/version = $(VERSION)/' weewx.conf > weewx.conf.tmp; mv weewx.conf.tmp weewx.conf
DEBREVISION=1
DEBVER=$(VERSION)-$(DEBREVISION)
# add a skeleton entry to deb changelog
deb-changelog:
if [ "`grep $(DEBVER) pkg/debian/changelog`" = "" ]; then \
pkg/mkchangelog.pl --action stub --format debian --release-version $(DEBVER) > pkg/debian/changelog.new; \
cat pkg/debian/changelog >> pkg/debian/changelog.new; \
mv pkg/debian/changelog.new pkg/debian/changelog; \
fi
# use dpkg-buildpackage to create the debian package
# -us -uc - skip gpg signature on .dsc and .changes
# the latest version in the debian changelog must match the packaging version
DEBARCH=all
DEBBLDDIR=$(BLDDIR)/weewx-$(VERSION)
DEBPKG=weewx_$(DEBVER)_$(DEBARCH).deb
ifneq ("$(SIGN)","1")
DPKG_OPT=-us -uc
endif
deb-package: $(DSTDIR)/$(SRCPKG)
mkdir -p $(BLDDIR)
cp $(DSTDIR)/$(SRCPKG) $(BLDDIR)
(cd $(BLDDIR); tar xvfz $(SRCPKG))
(cd $(BLDDIR); mv $(SRCPKG) weewx_$(VERSION).orig.tar.gz)
rm -rf $(DEBBLDDIR)/debian
mkdir -m 0755 $(DEBBLDDIR)/debian
mkdir -m 0755 $(DEBBLDDIR)/debian/source
cp pkg/debian/changelog $(DEBBLDDIR)/debian
cp pkg/debian/compat $(DEBBLDDIR)/debian
cp pkg/debian/conffiles $(DEBBLDDIR)/debian
cp pkg/debian/config $(DEBBLDDIR)/debian
cp pkg/debian/control $(DEBBLDDIR)/debian
cp pkg/debian/copyright $(DEBBLDDIR)/debian
cp pkg/debian/postinst $(DEBBLDDIR)/debian
cp pkg/debian/postrm $(DEBBLDDIR)/debian
cp pkg/debian/preinst $(DEBBLDDIR)/debian
cp pkg/debian/prerm $(DEBBLDDIR)/debian
cp pkg/debian/rules $(DEBBLDDIR)/debian
cp pkg/debian/source/format $(DEBBLDDIR)/debian/source
cp pkg/debian/templates $(DEBBLDDIR)/debian
(cd $(DEBBLDDIR); dpkg-buildpackage $(DPKG_OPT))
mkdir -p $(DSTDIR)
mv $(BLDDIR)/$(DEBPKG) $(DSTDIR)
# run lintian on the deb package
check-deb:
lintian -Ivi $(DSTDIR)/$(DEBPKG)
upload-deb:
scp $(DSTDIR)/$(DEBPKG) $(USER)@$(WEEWX_COM):$(WEEWX_STAGING)
RPMREVISION=1
RPMVER=$(VERSION)-$(RPMREVISION)
# add a skeleton entry to rpm changelog
rpm-changelog:
if [ "`grep $(RPMVER) pkg/changelog.rpm`" = "" ]; then \
pkg/mkchangelog.pl --action stub --format redhat --release-version $(RPMVER) > pkg/changelog.rpm.new; \
cat pkg/changelog.rpm >> pkg/changelog.rpm.new; \
mv pkg/changelog.rpm.new pkg/changelog.rpm; \
fi
# use rpmbuild to create the rpm package
RPMARCH=noarch
RPMOS=$(shell if [ -f /etc/SuSE-release ]; then echo .suse; else echo .rhel; fi)
RPMBLDDIR=$(BLDDIR)/weewx-$(RPMVER)$(RPMOS).$(RPMARCH)
RPMPKG=weewx-$(RPMVER)$(RPMOS).$(RPMARCH).rpm
rpm-package: $(DSTDIR)/$(SRCPKG)
rm -rf $(RPMBLDDIR)
mkdir -p -m 0755 $(RPMBLDDIR)
mkdir -p -m 0755 $(RPMBLDDIR)/BUILD
mkdir -p -m 0755 $(RPMBLDDIR)/BUILDROOT
mkdir -p -m 0755 $(RPMBLDDIR)/RPMS
mkdir -p -m 0755 $(RPMBLDDIR)/SOURCES
mkdir -p -m 0755 $(RPMBLDDIR)/SPECS
mkdir -p -m 0755 $(RPMBLDDIR)/SRPMS
sed -e 's%Version:.*%Version: $(VERSION)%' \
pkg/weewx.spec.in > $(RPMBLDDIR)/SPECS/weewx.spec
cat pkg/changelog.rpm >> $(RPMBLDDIR)/SPECS/weewx.spec
cp dist/weewx-$(VERSION).tar.gz $(RPMBLDDIR)/SOURCES
rpmbuild -ba --clean --define '_topdir $(CWD)/$(RPMBLDDIR)' --target noarch $(CWD)/$(RPMBLDDIR)/SPECS/weewx.spec
mkdir -p $(DSTDIR)
mv $(RPMBLDDIR)/RPMS/$(RPMARCH)/$(RPMPKG) $(DSTDIR)
# mv $(RPMBLDDIR)/SRPMS/weewx-$(RPMVER)$(RPMOS).src.rpm $(DSTDIR)
ifeq ("$(SIGN)","1")
rpm --addsign $(DSTDIR)/$(RPMPKG)
# rpm --addsign $(DSTDIR)/weewx-$(RPMVER)$(RPMOS).src.rpm
endif
# run rpmlint on the redhat package
check-rpm:
rpmlint $(DSTDIR)/$(RPMPKG)
upload-rpm:
scp $(DSTDIR)/$(RPMPKG) $(USER)@$(WEEWX_COM):$(WEEWX_STAGING)
upload-rhel:
make upload-rpm RPMOS=.rhel
upload-suse:
make upload-rpm RPMOS=.suse
# shortcut to upload all packages from a single machine
DEB_PKG=weewx_$(DEBVER)_$(DEBARCH).deb
RHEL_PKG=weewx-$(RPMVER).rhel.$(RPMARCH).rpm
SUSE_PKG=weewx-$(RPMVER).suse.$(RPMARCH).rpm
upload-pkgs:
scp $(DSTDIR)/$(DEB_PKG) $(DSTDIR)/$(RHEL_PKG) $(DSTDIR)/$(SUSE_PKG) $(USER)@$(WEEWX_COM):$(WEEWX_STAGING)
# move files from the upload directory to the release directory and set up the
# symlinks to them from the download root directory
DEVDIR=$(WEEWX_DOWNLOADS)/development_versions
RELDIR=$(WEEWX_DOWNLOADS)/released_versions
ARTIFACTS=$(DEB_PKG) $(RHEL_PKG) $(SUSE_PKG) $(SRCPKG)
release:
ssh $(USER)@$(WEEWX_COM) "for f in $(ARTIFACTS); do if [ -f $(DEVDIR)/\$$f ]; then mv $(DEVDIR)/\$$f $(RELDIR); fi; done"
ssh $(USER)@$(WEEWX_COM) "rm -f $(WEEWX_DOWNLOADS)/weewx*"
ssh $(USER)@$(WEEWX_COM) "for f in $(ARTIFACTS); do if [ -f $(RELDIR)/\$$f ]; then ln -s released_versions/\$$f $(WEEWX_DOWNLOADS); fi; done"
ssh $(USER)@$(WEEWX_COM) "if [ -f $(DEVDIR)/README.txt ]; then mv $(DEVDIR)/README.txt $(WEEWX_DOWNLOADS); fi"
ssh $(USER)@$(WEEWX_COM) "chmod 644 $(WEEWX_DOWNLOADS)/released_versions/*"
# make local copy of the published apt repository
pull-apt-repo:
mkdir -p ~/.aptly
rsync -arv $(USER)@$(WEEWX_COM):$(WEEWX_HTMLDIR)/aptly-test/ ~/.aptly
# add the latest version to the local apt repo using aptly
update-apt-repo:
aptly repo add weewx $(DSTDIR)/$(DEBPKG)
aptly snapshot create weewx-$(VERSION) from repo weewx
aptly -architectures="all" publish switch squeeze weewx-$(VERSION)
# publish apt repo changes to the public weewx apt repo
push-apt-repo:
rsync -arv ~/.aptly/ $(USER)@$(WEEWX_COM):$(WEEWX_HTMLDIR)/aptly-test
# run perlcritic to ensure clean perl code. put these in ~/.perlcriticrc:
# [-CodeLayout::RequireTidyCode]
# [-Modules::ProhibitExcessMainComplexity]
# [-Modules::RequireVersionVar]
critic:
perlcritic -1 --verbose 8 pkg/mkchangelog.pl