Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
160 lines (135 loc) · 6.76 KB
/
Copy pathMakefile
File metadata and controls
160 lines (135 loc) · 6.76 KB
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
# MX Options: build, test, install.
#
# make compile everything and check the translations
# make test run the unit tests
# make install-user install for the current user under ~/.local (no root needed)
# make enable start the service now and at every login
# sudo make install install for every user under /usr/local
# sudo make udev install the device access rules (once; see README, "Permissions")
# make uninstall-user remove the per-user installation
# sudo make uninstall remove the system-wide installation
# make deb build the Debian/Ubuntu package into dist/ (needs only Python)
# make deb-test install that package inside Debian and run the tests there (no root, no container engine)
# make rpm build the RPM inside Fedora, install it there and run the tests
# make dist build the files of a release into dist/ (after its tag is on GitHub)
# make aur publish packaging/aur to the AUR (needs an AUR account with your SSH key)
#
# Packagers: make DESTDIR=... PREFIX=/usr udevdir=/usr/lib/udev/rules.d install
PREFIX ?= /usr/local
DESTDIR ?=
PYTHON ?= python3
bindir = $(PREFIX)/bin
libdir = $(PREFIX)/lib/mxoptions
datadir = $(PREFIX)/share
docdir = $(datadir)/doc/mxoptions
licensedir = $(datadir)/licenses/mxoptions
unitdir = $(PREFIX)/lib/systemd/user
udevdir = /etc/udev/rules.d
# empty: leave the udev rules out (a per-user installation cannot place them)
UDEV = yes
user_prefix = $(HOME)/.local
user_unitdir = $(or $(XDG_CONFIG_HOME),$(HOME)/.config)/systemd/user
python_path = $(shell command -v $(PYTHON))
substitute = sed -e 's|@BINDIR@|$(bindir)|g' -e 's|@LIBDIR@|$(libdir)|g' -e 's|@DOCDIR@|$(docdir)|g' \
-e 's|@PYTHON@|$(python_path)|g'
.PHONY: all build test check wheel deb deb-test rpm dist aur run screenshots install install-user uninstall uninstall-user enable disable udev clean
all: build
build:
$(PYTHON) -m compileall -q mxoptions
$(PYTHON) tools/check_i18n.py
test:
$(PYTHON) -m unittest discover -s tests
check: build test
wheel:
$(PYTHON) -m build --wheel --no-isolation --outdir dist
# The Debian package: the files as "install" lays them out under /usr, wrapped up by tools/make_deb.py.
# The RPM is built from packaging/rpm/mxoptions.spec, on a system that has rpmbuild or with "make rpm".
deb: build
rm -rf build/deb
$(MAKE) install DESTDIR="$(CURDIR)/build/deb" PREFIX=/usr udevdir=/usr/lib/udev/rules.d
$(PYTHON) tools/make_deb.py build/deb dist
rm -rf build
# Trying the packages where they belong. tools/distro.py fetches the distribution's official image and
# enters it through a user namespace; what gets installed there is kept for the next run.
DEBIAN ?= debian:trixie-slim
FEDORA ?= fedora:42
deb-test: deb
$(PYTHON) tools/distro.py $(DEBIAN) -- sh packaging/deb/check.sh
rpm: build
$(PYTHON) tools/distro.py $(FEDORA) -- sh packaging/rpm/build.sh
# What a release on GitHub carries: the Arch package (built by packaging/aur/PKGBUILD from the
# tagged source archive, so the tag has to be pushed first), the wheel, and their checksums.
dist:
@version=$$($(PYTHON) -c 'import mxoptions; print(mxoptions.__version__)'); \
grep -qx "pkgver=$$version" packaging/aur/PKGBUILD || { \
echo "packaging/aur/PKGBUILD is not at $$version: set pkgver and sha256sums for the pushed tag" >&2; exit 1; }
rm -rf dist build
mkdir -p dist build/makepkg
$(PYTHON) -m build --wheel --no-isolation --outdir dist
cd packaging/aur && PKGDEST="$(CURDIR)/dist" BUILDDIR="$(CURDIR)/build/makepkg" SRCDEST="$(CURDIR)/build/makepkg" makepkg -f
rm -rf build *.egg-info
cd dist && sha256sum * > SHA256SUMS
run:
$(PYTHON) main.py
screenshots:
$(PYTHON) tools/screenshots.py docs/screenshots
install: build
install -d "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(unitdir)"
rm -rf "$(DESTDIR)$(libdir)/mxoptions"
cp -r mxoptions "$(DESTDIR)$(libdir)/mxoptions"
find "$(DESTDIR)$(libdir)/mxoptions" -name __pycache__ -prune -exec rm -rf {} +
$(PYTHON) -m compileall -q -d "$(libdir)/mxoptions" "$(DESTDIR)$(libdir)/mxoptions"
$(substitute) data/mxoptions.in > "$(DESTDIR)$(bindir)/mxoptions"
chmod 755 "$(DESTDIR)$(bindir)/mxoptions"
$(substitute) data/mxoptions.service.in > "$(DESTDIR)$(unitdir)/mxoptions.service"
install -d "$(DESTDIR)$(datadir)/applications"
sed -e 's|^Exec=mxoptions|Exec=$(bindir)/mxoptions|' data/mxoptions.desktop > "$(DESTDIR)$(datadir)/applications/mxoptions.desktop"
install -Dm644 mxoptions/assets/icon.svg "$(DESTDIR)$(datadir)/icons/hicolor/scalable/apps/mxoptions.svg"
install -Dm644 README.md "$(DESTDIR)$(docdir)/README.md"
install -Dm644 docs/API.md "$(DESTDIR)$(docdir)/API.md"
install -Dm644 LICENSE "$(DESTDIR)$(licensedir)/LICENSE"
ifeq ($(UDEV),yes)
install -Dm644 data/70-mxoptions.rules "$(DESTDIR)$(udevdir)/70-mxoptions.rules"
endif
uninstall:
rm -rf "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)" "$(DESTDIR)$(licensedir)"
rm -f "$(DESTDIR)$(bindir)/mxoptions" "$(DESTDIR)$(unitdir)/mxoptions.service" \
"$(DESTDIR)$(datadir)/applications/mxoptions.desktop" \
"$(DESTDIR)$(datadir)/icons/hicolor/scalable/apps/mxoptions.svg"
ifeq ($(UDEV),yes)
rm -f "$(DESTDIR)$(udevdir)/70-mxoptions.rules"
endif
install-user:
$(MAKE) install PREFIX="$(user_prefix)" unitdir="$(user_unitdir)" UDEV=
-systemctl --user daemon-reload
@echo
@echo "Installed under $(user_prefix). Next:"
@echo " make enable start it now and at every login"
@echo " sudo make udev only if the program cannot reach the mouse (see README, Permissions)"
uninstall-user: disable
$(MAKE) uninstall PREFIX="$(user_prefix)" unitdir="$(user_unitdir)" UDEV=
rm -f "$(or $(XDG_DATA_HOME),$(HOME)/.local/share)"/icons/hicolor/scalable/status/mxoptions-tray-*.svg # written by the program for its tray icon
-systemctl --user daemon-reload
enable:
systemctl --user daemon-reload
systemctl --user enable --now mxoptions.service
disable:
-systemctl --user disable --now mxoptions.service
udev:
install -Dm644 data/70-mxoptions.rules "$(DESTDIR)$(udevdir)/70-mxoptions.rules"
-udevadm control --reload-rules
-udevadm trigger --subsystem-match=hidraw
-udevadm trigger --sysname-match=uinput
# The AUR keeps every package in a git repository of its own; pushing to it publishes.
aur:
cd packaging/aur && makepkg --printsrcinfo | diff -q - .SRCINFO
rm -rf build/aur
git clone ssh://aur@aur.archlinux.org/mxoptions.git build/aur
cp packaging/aur/PKGBUILD packaging/aur/.SRCINFO packaging/aur/mxoptions.install build/aur/
cd build/aur && git add PKGBUILD .SRCINFO mxoptions.install \
&& git commit -m "mxoptions $$(sed -n 's/^\tpkgver = //p' .SRCINFO)-$$(sed -n 's/^\tpkgrel = //p' .SRCINFO)" \
&& git push origin HEAD:master
rm -rf build
clean:
rm -rf build dist *.egg-info packaging/aur/pkg packaging/aur/src
find . -name __pycache__ -prune -exec rm -rf {} +