forked from stb-tester/stb-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
411 lines (348 loc) · 13 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
SHELL := /bin/bash
# The default target of this Makefile is:
all:
prefix?=/usr/local
exec_prefix?=$(prefix)
bindir?=$(exec_prefix)/bin
libexecdir?=$(exec_prefix)/libexec
datarootdir?=$(prefix)/share
mandir?=$(datarootdir)/man
man1dir?=$(mandir)/man1
python_version?=3
pythondir?=$(prefix)/lib/python$(python_version)/site-packages
sysconfdir?=$(prefix)/etc
# Enable building/installing man page
enable_docs:=$(shell which rst2man >/dev/null 2>&1 && echo yes || echo no)
ifeq ($(enable_docs), no)
$(info Not building/installing documentation because 'rst2man' was not found)
endif
# Enable building/installing stbt virtual-stb
enable_virtual_stb?=no
INSTALL?=install
TAR ?= $(shell which gnutar >/dev/null 2>&1 && echo gnutar || echo tar)
MKTAR = $(TAR) --format=gnu --owner=root --group=root \
--mtime="$(shell git show -s --format=%ci HEAD)"
GZIP ?= gzip
PYLINT ?= pylint
PYTEST ?= pytest-3
CFLAGS?=-O2
# Generate version from 'git describe' when in git repository, and from
# VERSION file included in the dist tarball otherwise.
generate_version := $(shell \
GIT_DIR=.git git describe --always --dirty > VERSION.now 2>/dev/null && \
perl -pi -e 's/^v//' VERSION.now && \
{ cmp VERSION.now VERSION 2>/dev/null || mv VERSION.now VERSION; }; \
rm -f VERSION.now)
VERSION?=$(shell cat VERSION)
ESCAPED_VERSION=$(subst -,_,$(VERSION))
RELEASE?=1
.DELETE_ON_ERROR:
stbt-control-relay: \
%: %.in .stbt-prefix VERSION
sed -e 's,@VERSION@,$(VERSION),g' \
-e 's,@ESCAPED_VERSION@,$(ESCAPED_VERSION),g' \
-e 's,@RELEASE@,$(RELEASE),g' \
-e 's,@LIBEXECDIR@,$(libexecdir),g' \
$< > $@
INSTALL_PYLIB_FILES = \
_stbt/__init__.py \
_stbt/android.py \
_stbt/black.py \
_stbt/config.py \
_stbt/control.py \
_stbt/core.py \
_stbt/cv2_compat.py \
_stbt/diff.py \
_stbt/frameobject.py \
_stbt/grid.py \
_stbt/gst_hacks.py \
_stbt/gst_utils.py \
_stbt/imgproc_cache.py \
_stbt/imgutils.py \
_stbt/irnetbox.py \
_stbt/keyboard.py \
_stbt/libstbt.so \
_stbt/logging.py \
_stbt/match.py \
_stbt/motion.py \
_stbt/multipress.py \
_stbt/ocr.py \
_stbt/precondition.py \
_stbt/power.py \
_stbt/pylint_plugin.py \
_stbt/sqdiff.py \
_stbt/stbt_run.py \
_stbt/stbt-power.sh \
_stbt/stbt.conf \
_stbt/transition.py \
_stbt/types.py \
_stbt/utils.py \
_stbt/wait.py \
_stbt/x-key-mapping.conf \
_stbt/x11.py \
_stbt/xorg.conf.in \
_stbt/xxhash.py \
stbt_core/__init__.py \
stbt_core/pylint_plugin.py
INSTALL_CORE_SCRIPTS = \
stbt_config.py \
stbt_control.py \
stbt_lint.py \
stbt_match.py \
stbt_power.py \
stbt_run.py \
stbt-screenshot \
stbt-tv
all: $(INSTALL_CORE_SCRIPTS) $(INSTALL_PYLIB_FILES) etc/stbt.conf
INSTALL_VSTB_FILES = \
stbt_virtual_stb.py
install: install-core
install-core: all
$(INSTALL) -m 0755 -d \
$(DESTDIR)$(bindir) \
$(DESTDIR)$(pythondir)/stbt_core \
$(DESTDIR)$(pythondir)/_stbt \
$(DESTDIR)$(sysconfdir)/stbt \
$(DESTDIR)$(sysconfdir)/bash_completion.d \
$(DESTDIR)$(libexecdir)/stbt
sed -e 's,@VERSION@,$(VERSION),g' \
-e 's,@LIBEXECDIR@,$(libexecdir),g' \
bin/stbt >$(DESTDIR)$(bindir)/stbt
chmod 0755 $(DESTDIR)$(bindir)/stbt
$(INSTALL) -m 0644 stbt-completion \
$(DESTDIR)$(sysconfdir)/bash_completion.d/stbt
$(INSTALL) -m 0644 etc/stbt.conf \
$(DESTDIR)$(sysconfdir)/stbt/stbt.conf
$(INSTALL) -m 0755 $(INSTALL_CORE_SCRIPTS) \
$(DESTDIR)$(libexecdir)/stbt/
for filename in $(INSTALL_PYLIB_FILES); do \
[ -x "$$filename" ] && mode=0755 || mode=0644; \
$(INSTALL) -m $$mode $$filename $(DESTDIR)$(pythondir)/$$filename; \
done
printf "libexecdir = '%s'\nsysconfdir = '%s'\n" \
"$(libexecdir)" "$(sysconfdir)" > $(DESTDIR)$(pythondir)/_stbt/vars.py
chmod 0644 $(DESTDIR)$(pythondir)/_stbt/vars.py
install-virtual-stb: $(INSTALL_VSTB_FILES)
$(INSTALL) -m 0755 -d \
$(patsubst %,$(DESTDIR)$(libexecdir)/stbt/%,$(sort $(dir $(INSTALL_VSTB_FILES))))
for filename in $(INSTALL_VSTB_FILES); do \
[ -x "$$filename" ] && mode=0755 || mode=0644; \
$(INSTALL) -m $$mode $$filename $(DESTDIR)$(libexecdir)/stbt/$$filename; \
done
INSTALL_GPL_FILES = \
_stbt/control_gpl.py
install-gpl: $(INSTALL_GPL_FILES)
$(INSTALL) -m 0755 -d $(DESTDIR)$(pythondir)/_stbt
for filename in $(INSTALL_GPL_FILES); do \
[ -x "$$filename" ] && mode=0755 || mode=0644; \
$(INSTALL) -m $$mode $$filename $(DESTDIR)$(pythondir)/$$filename; \
done
etc/stbt.conf : _stbt/stbt.conf
# Comment out defaults for /etc/stbt/stbt.conf
mkdir -p etc
awk '/^$$/ { print }; /^#/ { print "#" $$0}; /^\[/ { print $$0 }; /^[^\[#]/ {print "# " $$0 }' _stbt/stbt.conf >$@
STBT_CONTROL_RELAY_PYLIB_FILES = \
_stbt/__init__.py \
_stbt/config.py \
_stbt/control.py \
_stbt/control_gpl.py \
_stbt/irnetbox.py \
_stbt/logging.py \
_stbt/stbt.conf \
_stbt/types.py \
_stbt/utils.py
install-stbt-control-relay: $(STBT_CONTROL_RELAY_PYLIB_FILES) stbt-control-relay
$(INSTALL) -m 0755 -d \
$(DESTDIR)$(bindir) \
$(DESTDIR)$(libexecdir)/stbt-control-relay/_stbt
$(INSTALL) -m 0755 stbt-control-relay $(DESTDIR)$(bindir)/
sed '1s,^#!/usr/bin/python\b,#!/usr/bin/python$(python_version),' \
stbt_control_relay.py \
> $(DESTDIR)$(libexecdir)/stbt-control-relay/stbt_control_relay.py
chmod 0755 $(DESTDIR)$(libexecdir)/stbt-control-relay/stbt_control_relay.py
for filename in $(STBT_CONTROL_RELAY_PYLIB_FILES); do \
$(INSTALL) -m 0644 $$filename \
$(DESTDIR)$(libexecdir)/stbt-control-relay/$$filename; \
done
uninstall:
rm -f $(DESTDIR)$(bindir)/stbt
rm -rf $(DESTDIR)$(libexecdir)/stbt
rm -f $(DESTDIR)$(man1dir)/stbt.1
rm -rf $(DESTDIR)$(pythondir)/stbt_core
rm -rf $(DESTDIR)$(pythondir)/_stbt
rm -f $(DESTDIR)$(sysconfdir)/stbt/stbt.conf
rm -f $(DESTDIR)$(sysconfdir)/bash_completion.d/stbt
-rmdir $(DESTDIR)$(sysconfdir)/stbt
-rmdir $(DESTDIR)$(sysconfdir)/bash_completion.d
clean:
git clean -Xfd || true
PYTHON_FILES := \
$(shell git ls-files '*.py' \
| grep -v -e ^setup.py \
-e ^vendor/)
check: check-pylint check-pytest check-integrationtests
check-pytest: all
PYTHONPATH=$$PWD:/usr/lib/python$(python_version)/dist-packages/cec \
STBT_CONFIG_FILE=$$PWD/tests/stbt.conf \
$(PYTEST) -vv -rs --doctest-modules $(PYTEST_OPTS) \
$$(printf "%s\n" $(PYTHON_FILES) |\
grep -v tests/vstb-example-html5/)
check-pythonpackage:
export STBT_CONFIG_FILE=$$PWD/tests/stbt.conf && \
$(PYTEST) -vv -rs $(PYTEST_OPTS) \
tests/subdirectory/test_load_image_from_subdirectory.py \
tests/test_android.py \
tests/test_config.py \
tests/test_core.py \
tests/test_grid.py \
tests/test_match.py \
tests/test_motion.py \
tests/test_multipress.py \
tests/test_transition.py && \
stbt_lint="pylint --load-plugins=_stbt.pylint_plugin" \
tests/run-tests.sh -i tests/test-stbt-lint.sh
check-integrationtests: install-for-test
export PATH="$$PWD/tests/test-install/bin:$$PATH" \
PYTHONPATH="$$PWD/tests/test-install/lib/python$(python_version)/site-packages:$$PYTHONPATH" && \
grep -hEo '^test_[a-zA-Z0-9_]+' \
$$(ls tests/test-*.sh | \
grep -v -e tests/test-virtual-stb.sh) |\
$(parallel) tests/run-tests.sh -i
check-pylint: all
PYTHONPATH=$$PWD PYLINT=$(PYLINT) extra/pylint.sh $(PYTHON_FILES)
ifeq ($(enable_virtual_stb), yes)
install: install-virtual-stb
check: check-virtual-stb
check-virtual-stb: install-for-test
export PATH="$$PWD/tests/test-install/bin:$$PATH" \
PYTHONPATH="$$PWD/tests/test-install/lib/python$(python_version)/site-packages:$$PYTHONPATH" && \
tests/run-tests.sh -i tests/test-virtual-stb.sh
else
$(info virtual-stb support disabled)
endif
install-for-test:
rm -rf tests/test-install && \
unset MAKEFLAGS prefix exec_prefix bindir libexecdir datarootdir \
mandir man1dir pythondir sysconfdir && \
make install prefix=$$PWD/tests/test-install
parallel ?= $(shell \
parallel --version 2>/dev/null | grep -q GNU && \
echo parallel --gnu -j +4 || echo xargs)
tests/ocr/menu.png: %.png: %.svg
rsvg-convert $< >$@
tests/buttons-on-blue-background.png: tests/buttons.svg
rsvg-convert $< >$@
tests/buttons.png: tests/buttons.svg
rsvg-convert <(sed 's/#0000ff/#ffffff/' $<) >$@
# Can only be run from within a git clone of stb-tester or VERSION (and the
# list of files) won't be set correctly.
dist: stb-tester-$(VERSION).tar.gz
DIST = $(shell git ls-files)
stb-tester-$(VERSION).tar.gz: $(DIST)
@$(TAR) --version 2>/dev/null | grep -q GNU || { \
printf 'Error: "make dist" requires GNU tar ' >&2; \
printf '(use "make dist TAR=gnutar").\n' >&2; \
exit 1; }
# Separate tar and gzip so we can pass "-n" for more deterministic
# tarball generation
$(MKTAR) -c --transform='s,^,stb-tester-$(VERSION)/,' \
-f stb-tester-$(VERSION).tar $^ && \
$(GZIP) -9fn stb-tester-$(VERSION).tar
# Force rebuild if installation directories change
sq = $(subst ','\'',$(1)) # function to escape single quotes (')
.stbt-prefix: flags = libexecdir=$(call sq,$(libexecdir)):\
sysconfdir=$(call sq,$(sysconfdir))
.stbt-prefix: FORCE
@if [ '$(flags)' != "$$(cat $@ 2>/dev/null)" ]; then \
[ -f $@ ] && echo "*** new $@" >&2; \
echo '$(flags)' > $@; \
fi
TAGS:
etags stbt_core/**.py _stbt/**.py
_stbt/libstbt.so : _stbt/sqdiff.c
$(CC) -shared -fPIC -O3 -o $@ _stbt/sqdiff.c $(CFLAGS)
### Documentation ############################################################
doc: docs/stbt.1
# Requires python-docutils
docs/stbt.1: docs/stbt.1.rst VERSION
sed -e 's/@VERSION@/$(VERSION)/g' $< |\
sed -e 's/(callable_,/(`callable_`,/' |\
rst2man > $@
ifeq ($(enable_docs), yes)
all: docs/stbt.1
install-core: install-docs
endif
install-docs: docs/stbt.1
$(INSTALL) -m 0755 -d $(DESTDIR)$(man1dir)
$(INSTALL) -m 0644 docs/stbt.1 $(DESTDIR)$(man1dir)
### Docker images for CI #####################################################
CI_DOCKER_IMAGES = ubuntu2004
$(CI_DOCKER_IMAGES:%=.circleci/.%.built): .circleci/.%.built: .circleci/%.dockerfile
docker build -t stbtester/circleci:$* -f .circleci/$*.dockerfile \
.circleci/ && \
touch $@
ci-docker-images: $(CI_DOCKER_IMAGES:%=.circleci/.%.built)
publish-ci-docker-images: $(CI_DOCKER_IMAGES:%=.circleci/.%.built)
set -x && \
for x in $(CI_DOCKER_IMAGES); do \
docker push stbtester/circleci:$$x; \
done
### PyPI Packaging ###########################################################
pypi-publish:
rm -rf dist/
python3 setup.py sdist
twine upload dist/*
### Debian Packaging #########################################################
ubuntu_releases ?= bionic
DPKG_OPTS?=
debian_base_release=1
debian_architecture=$(shell dpkg --print-architecture 2>/dev/null)
DPUT_HOST?=ppa:stb-tester/stb-tester
# In the following rules, "%" and "$*" stand for the release number: "1" when
# building a debian unstable package, or "1~trusty" or "1~utopic" (etc) when
# building an ubuntu package.
# deb: stb-tester_22-1_amd64.deb
deb: stb-tester_$(VERSION)-$(debian_base_release)_$(debian_architecture).deb
# Build debian source packages for debian unstable and all $(ubuntu_releases).
debsrc: \
debian-packages/stb-tester_$(VERSION)-$(debian_base_release).dsc \
$(ubuntu_releases:%=debian-packages/stb-tester_$(VERSION)-$(debian_base_release)~%.dsc)
# Publish all $(ubuntu_releases) source packages to stb-tester PPA
ppa-publish: $(ubuntu_releases:%=ppa-publish-$(debian_base_release)~%)
ppa-publish-%: debian-packages/stb-tester_$(VERSION)-%.dsc
dput $(DPUT_HOST) \
debian-packages/stb-tester_$(VERSION)-$*_source.changes
# Build debian source package
debian-packages/stb-tester_$(VERSION)-%.dsc: \
stb-tester-$(VERSION).tar.gz extra/debian/changelog.in
extra/debian/build-source-package.sh $(VERSION) $*
# Build debian binary package from source package
# stb-tester_22-1_amd64.deb: debian-packages/stb-tester_22-1.dsc
stb-tester_$(VERSION)-%_$(debian_architecture).deb: \
debian-packages/stb-tester_$(VERSION)-%.dsc
tmpdir=$$(mktemp -dt stb-tester-deb-build.XXXXXX) && \
dpkg-source -x $< $$tmpdir/source && \
(cd "$$tmpdir/source" && \
DEB_BUILD_OPTIONS=nocheck \
debuild -rfakeroot -b $(DPKG_OPTS)) && \
mv "$$tmpdir"/*.deb . && \
rm -rf "$$tmpdir"
### Fedora Packaging #########################################################
rpm_topdir?=$(HOME)/rpmbuild
src_rpm=stb-tester-$(ESCAPED_VERSION)-$(RELEASE)$(shell rpm -E %dist 2>/dev/null).src.rpm
srpm: $(src_rpm)
$(src_rpm): stb-tester-$(VERSION).tar.gz extra/fedora/stb-tester.spec
@printf "\n*** Building Fedora src rpm ***\n"
mkdir -p $(rpm_topdir)/SOURCES
cp stb-tester-$(VERSION).tar.gz $(rpm_topdir)/SOURCES
rpmbuild --define "_topdir $(rpm_topdir)" -bs extra/fedora/stb-tester.spec
mv $(rpm_topdir)/SRPMS/$(src_rpm) .
rpm: $(src_rpm)
sudo dnf builddep -y $<
rpmbuild --define "_topdir $(rpm_topdir)" --rebuild $<
mv $(rpm_topdir)/RPMS/*/stb-tester-* .
.PHONY: all clean deb dist doc install install-core uninstall
.PHONY: check check-integrationtests
.PHONY: check-pytest check-pylint install-for-test
.PHONY: ppa-publish pypi-publish rpm srpm
.PHONY: FORCE TAGS