-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
286 lines (271 loc) · 10.2 KB
/
Makefile
File metadata and controls
286 lines (271 loc) · 10.2 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
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
.PHONY: help install install-dev-local uninstall uninstall-dev-local dev-install install-dev check-install-deps test test-quick clean distclean lint manual-tests
PREFIX ?= /usr/local
INSTALL_DIR = $(PREFIX)/bin
LIB_INSTALL_DIR = $(PREFIX)/lib/wayctl
DOC_INSTALL_DIR = $(PREFIX)/share/doc/wayctl
DOC_EXAMPLES_DIR = $(DOC_INSTALL_DIR)/examples
MAN_INSTALL_DIR = $(PREFIX)/share/man/man1
XDG_CONFIG_HOME ?= $(HOME)/.config
CONFIG_DIR = $(XDG_CONFIG_HOME)/wayctl
CONFIG_TEMPLATES = wayctl.toml wayctl_actions.toml pid_matchers.toml
DOC_FILES = README.md CHANGELOG.md LICENSE
MAN_PAGES = wayctl.1 wayctl-daemon.1
PYTHON = python3
SYSTEM_PYTHON := $(shell if [ -x /usr/bin/python3 ]; then echo /usr/bin/python3; else command -v python3; fi)
V ?= 0
Q = @
ifneq ($(V),0)
Q =
endif
help:
$(Q)echo "wayctl Makefile targets:"
$(Q)echo " make install Install launcher/modules, docs/examples, and manpages"
$(Q)echo " make install-dev-local Symlink launcher from venv into ~/.local/bin (dev/local use)"
$(Q)echo " make uninstall Remove wayctl launcher and installed module directory (keep user config)"
$(Q)echo " make uninstall-dev-local Remove symlink installed by install-dev-local"
$(Q)echo " make dev-install Set up local development environment with venv"
$(Q)echo " make test Run all pytest tests"
$(Q)echo " make test-quick Run quick focused tests"
$(Q)echo " make manual-tests Generate tests/tools/manual_tests.csv"
$(Q)echo " make lint Check for syntax errors"
$(Q)echo " make clean Remove __pycache__, .pyc, and pytest cache"
$(Q)echo " make distclean Remove venv in addition to clean artifacts"
$(Q)echo ""
$(Q)echo "Verbosity:"
$(Q)echo " make V=1 <target> Show executed shell commands"
$(Q)echo ""
$(Q)echo "Example system installation:"
$(Q)echo " sudo make install PREFIX=/usr/local"
$(Q)echo ""
$(Q)echo "Example user installation:"
$(Q)echo " make install PREFIX=~/.local"
check-install-deps:
$(Q)echo "Checking runtime dependencies in system Python ($(SYSTEM_PYTHON))..."
$(Q)printf '%s\n' \
"import os" \
"import re" \
"import sys" \
"from importlib.metadata import PackageNotFoundError, version" \
"" \
"req_file = os.environ.get('REQ_FILE', 'requirements.txt')" \
"missing = []" \
"" \
"with open(req_file, 'r', encoding='utf-8') as f:" \
" for raw in f:" \
" line = raw.strip()" \
" if not line or line.startswith('#'):" \
" continue" \
" if line.startswith(('-r', '--requirement', '-c', '--constraint', '-e', '--editable')):" \
" continue" \
"" \
" name_match = re.match(r'^([A-Za-z0-9_.-]+)', line)" \
" if not name_match:" \
" continue" \
" dist_name = name_match.group(1)" \
"" \
" found = False" \
" for candidate in (dist_name, dist_name.replace('-', '_')):" \
" try:" \
" version(candidate)" \
" found = True" \
" break" \
" except PackageNotFoundError:" \
" continue" \
"" \
" if not found:" \
" missing.append(dist_name)" \
"" \
"if missing:" \
" print('ERROR: Missing runtime dependencies in system Python:')" \
" for item in sorted(set(missing)):" \
" print(f' - {item}')" \
" print('Install them first with your OS packaging system (for example apt/dnf/pacman).')" \
" print('For development/testing, use a project venv via: make dev-install')" \
" sys.exit(1)" \
"" \
"print('✓ Runtime dependencies found in system Python')" \
| REQ_FILE=requirements.txt "$(SYSTEM_PYTHON)" -
install-dev-local: dev-install
$(Q)VENV_PYTHON="$(CURDIR)/venv/bin/python"; \
if [ ! -x "$$VENV_PYTHON" ]; then \
echo "ERROR: venv not found. Run: make dev-install"; \
exit 1; \
fi; \
mkdir -p "$(HOME)/.local/bin"; \
LAUNCHER="$(HOME)/.local/bin/wayctl"; \
printf '%s\n' \
'#!/usr/bin/env sh' \
'set -e' \
"exec \"$(CURDIR)/venv/bin/python\" \"$(CURDIR)/wayctl.py\" \"\$$@\"" \
> "$$LAUNCHER"; \
chmod +x "$$LAUNCHER"; \
echo "✓ launcher: $$LAUNCHER"; \
mkdir -p "$(CONFIG_DIR)"; \
for cfg in $(CONFIG_TEMPLATES); do \
TARGET="$(CONFIG_DIR)/$$cfg"; \
if [ -L "$$TARGET" ]; then \
ln -sf "$(CURDIR)/$$cfg" "$$TARGET"; \
echo " updated symlink: $$TARGET"; \
elif [ -f "$$TARGET" ]; then \
echo " keep existing file (not a symlink): $$TARGET"; \
else \
ln -s "$(CURDIR)/$$cfg" "$$TARGET"; \
echo " symlinked config: $$TARGET"; \
fi; \
done; \
MAN_LOCAL_DIR="$(HOME)/.local/share/man/man1"; \
mkdir -p "$$MAN_LOCAL_DIR"; \
for page in $(MAN_PAGES); do \
ln -sf "$(CURDIR)/man/man1/$$page" "$$MAN_LOCAL_DIR/$$page"; \
echo " symlinked manpage: $$MAN_LOCAL_DIR/$$page"; \
done; \
echo "✓ wayctl dev-local install complete"; \
echo " → ensure ~/.local/bin is in PATH (e.g. add to ~/.profile):"; \
echo " export PATH=\"\$$HOME/.local/bin:\$$PATH\""
uninstall-dev-local:
$(Q)LAUNCHER="$(HOME)/.local/bin/wayctl"; \
if [ -f "$$LAUNCHER" ]; then \
rm -f "$$LAUNCHER"; \
echo "✓ removed $$LAUNCHER"; \
else \
echo "wayctl not found at $$LAUNCHER"; \
fi; \
MAN_LOCAL_DIR="$(HOME)/.local/share/man/man1"; \
for page in $(MAN_PAGES); do \
if [ -L "$$MAN_LOCAL_DIR/$$page" ]; then \
rm -f "$$MAN_LOCAL_DIR/$$page"; \
echo "✓ removed manpage symlink: $$MAN_LOCAL_DIR/$$page"; \
fi; \
done; \
for cfg in $(CONFIG_TEMPLATES); do \
TARGET="$(CONFIG_DIR)/$$cfg"; \
if [ -L "$$TARGET" ]; then \
rm -f "$$TARGET"; \
echo "✓ removed config symlink: $$TARGET"; \
fi; \
done
install: check-install-deps
$(Q)if mkdir -p "$(INSTALL_DIR)" "$(LIB_INSTALL_DIR)" "$(DOC_EXAMPLES_DIR)" "$(MAN_INSTALL_DIR)"; then \
echo "Installing wayctl to $(INSTALL_DIR)/wayctl"; \
echo "Installing wayctl modules to $(LIB_INSTALL_DIR)"; \
echo "Installing docs/templates to $(DOC_INSTALL_DIR)"; \
echo "Installing manpages to $(MAN_INSTALL_DIR)"; \
rm -rf "$(LIB_INSTALL_DIR)/wayctl_core"; \
cp wayctl.py "$(LIB_INSTALL_DIR)/wayctl.py"; \
cp -R wayctl_core "$(LIB_INSTALL_DIR)/"; \
find "$(LIB_INSTALL_DIR)" -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true; \
for doc in $(DOC_FILES); do \
if [ -f "$$doc" ]; then \
cp "$$doc" "$(DOC_INSTALL_DIR)/$$doc"; \
fi; \
done; \
for cfg in $(CONFIG_TEMPLATES); do \
cp "$$cfg" "$(DOC_EXAMPLES_DIR)/$$cfg"; \
echo " installed example config: $(DOC_EXAMPLES_DIR)/$$cfg"; \
done; \
for page in $(MAN_PAGES); do \
cp "man/man1/$$page" "$(MAN_INSTALL_DIR)/$$page"; \
echo " installed manpage: $(MAN_INSTALL_DIR)/$$page"; \
done; \
case "$(PREFIX)" in \
"$(HOME)"/*) \
mkdir -p "$(CONFIG_DIR)"; \
echo "Ensuring user config directory $(CONFIG_DIR)"; \
for cfg in $(CONFIG_TEMPLATES); do \
if [ -f "$(CONFIG_DIR)/$$cfg" ]; then \
echo " keep existing config: $(CONFIG_DIR)/$$cfg"; \
else \
cp "$$cfg" "$(CONFIG_DIR)/$$cfg"; \
echo " installed default config: $(CONFIG_DIR)/$$cfg"; \
fi; \
done; \
;; \
*) \
echo "Skipping per-user config creation for global PREFIX=$(PREFIX)"; \
echo " templates: $(DOC_EXAMPLES_DIR)"; \
echo " copy to user config: ~/.config/wayctl/"; \
;; \
esac; \
printf '%s\n' \
'#!/usr/bin/env sh' \
'set -e' \
'WAYCTL_LIB_DIR="$(LIB_INSTALL_DIR)"' \
'if [ -n "$${PYTHONPATH:-}" ]; then' \
' export PYTHONPATH="$$WAYCTL_LIB_DIR:$$PYTHONPATH"' \
'else' \
' export PYTHONPATH="$$WAYCTL_LIB_DIR"' \
'fi' \
'exec "$(SYSTEM_PYTHON)" "$$WAYCTL_LIB_DIR/wayctl.py" "$$@"' \
> "$(INSTALL_DIR)/wayctl"; \
chmod +x "$(INSTALL_DIR)/wayctl"; \
echo "✓ wayctl installed successfully"; \
echo " launcher: $(INSTALL_DIR)/wayctl"; \
echo " modules: $(LIB_INSTALL_DIR)"; \
echo " docs: $(DOC_INSTALL_DIR)"; \
echo " man: $(MAN_INSTALL_DIR)"; \
else \
echo "ERROR: Cannot write to $(INSTALL_DIR), $(LIB_INSTALL_DIR), $(DOC_INSTALL_DIR), or $(MAN_INSTALL_DIR). Try:"; \
echo " sudo make install PREFIX=/usr/local"; \
echo " OR"; \
echo " make install PREFIX=~/.local"; \
exit 1; \
fi
uninstall:
$(Q)if [ -f "$(INSTALL_DIR)/wayctl" ] || [ -d "$(LIB_INSTALL_DIR)" ] || [ -d "$(DOC_INSTALL_DIR)" ] || [ -d "$(MAN_INSTALL_DIR)" ]; then \
if rm -f "$(INSTALL_DIR)/wayctl" && rm -rf "$(LIB_INSTALL_DIR)"; then \
rm -f "$(MAN_INSTALL_DIR)/wayctl.1" "$(MAN_INSTALL_DIR)/wayctl-daemon.1"; \
rm -rf "$(DOC_INSTALL_DIR)"; \
echo "✓ wayctl removed from $(INSTALL_DIR)/wayctl"; \
echo "✓ wayctl modules removed from $(LIB_INSTALL_DIR)"; \
echo "✓ wayctl docs removed from $(DOC_INSTALL_DIR)"; \
echo "✓ wayctl manpages removed from $(MAN_INSTALL_DIR)"; \
else \
echo "ERROR: Cannot remove installed files. Try:"; \
echo " sudo make uninstall PREFIX=/usr/local"; \
exit 1; \
fi; \
else \
echo "wayctl not found at $(INSTALL_DIR)/wayctl"; \
echo "modules not found at $(LIB_INSTALL_DIR)"; \
echo "docs not found at $(DOC_INSTALL_DIR)"; \
echo "manpages not found at $(MAN_INSTALL_DIR)"; \
fi
dev-install:
$(Q)echo "Setting up development environment..."
$(Q)if [ -d "venv" ]; then \
echo "venv already exists"; \
else \
$(PYTHON) -m venv venv; \
echo "✓ venv created"; \
fi
$(Q). venv/bin/activate && \
pip install -q -r requirements.txt && \
echo "✓ Dependencies installed"
$(Q)echo ""
$(Q)echo "To activate the environment, run:"
$(Q)echo " source venv/bin/activate"
install-dev: dev-install
test: dev-install
$(Q). venv/bin/activate && \
$(PYTHON) -m pytest --tb=short -q tests/ && \
echo ""
$(Q)echo "✓ All tests passed"
test-quick: dev-install
$(Q). venv/bin/activate && \
$(PYTHON) -m pytest -q tests/test_wayland_registry.py
manual-tests: dev-install
$(Q). venv/bin/activate && \
$(PYTHON) tests/tools/generate_manual_tests.py
lint: dev-install
$(Q). venv/bin/activate && \
$(PYTHON) -m py_compile wayctl.py wayctl_core/*.py wayctl_core/commands/*.py && \
echo "✓ No syntax errors found"
clean:
$(Q)echo "Cleaning up..."
$(Q)find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
$(Q)find . -type f -name "*.pyc" -delete
$(Q)rm -rf .pytest_cache
$(Q)echo "✓ Cleanup complete"
distclean: clean
$(Q)rm -rf venv
$(Q)echo "✓ Development environment removed"