-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMakefile
359 lines (282 loc) · 13.5 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
PREFIX ?= $(HOME)/.local
CACHE_DIR ?= .cache
ROOTFS ?= $(CACHE_DIR)/rootfs
GODOT_VERSION ?= 4.0.1
GODOT_RELEASE ?= stable
GODOT_REVISION := $(GODOT_VERSION).$(GODOT_RELEASE)
GODOT ?= /usr/bin/godot
GAMESCOPE ?= /usr/bin/gamescope
# Addon dependencies
ALL_ADDONS := addons/godot-xlib/bin/libxlib.linux.template_debug.x86_64.so \
addons/godot-evdev/bin/libevdev.linux.template_debug.x86_64.so \
addons/godot-pty/bin/libpty.linux.template_debug.x86_64.so \
addons/godot-opensd/bin/libopensd.linux.template_debug.x86_64.so
EXPORT_TEMPLATE := $(HOME)/.local/share/godot/export_templates/$(GODOT_REVISION)/linux_debug.x86_64
#EXPORT_TEMPLATE_URL ?= https://downloads.tuxfamily.org/godotengine/$(GODOT_VERSION)/Godot_v$(GODOT_VERSION)-$(GODOT_RELEASE)_export_templates.tpz
EXPORT_TEMPLATE_URL ?= https://github.com/godotengine/godot/releases/download/$(GODOT_VERSION)-$(GODOT_RELEASE)/Godot_v$(GODOT_VERSION)-$(GODOT_RELEASE)_export_templates.tpz
ALL_GDSCRIPT := $(shell find ./ -name '*.gd')
ALL_SCENES := $(shell find ./ -name '*.tscn')
# Docker image variables
IMAGE_NAME ?= ghcr.io/shadowblip/opengamepadui-builder
IMAGE_TAG ?= latest
# Remote debugging variables
SSH_USER ?= deck
SSH_HOST ?= 192.168.0.65
SSH_MOUNT_PATH ?= /tmp/remote
SSH_DATA_PATH ?= /home/$(SSH_USER)/Projects
# systemd-sysext variables
SYSEXT_ID ?= steamos
SYSEXT_VERSION_ID ?= 3.4.6
# Include any user defined settings
-include settings.mk
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: install
install: rootfs ## Install OpenGamepadUI (default: ~/.local)
cd $(ROOTFS) && make install PREFIX=$(PREFIX)
.PHONY: uninstall
uninstall: ## Uninstall OpenGamepadUI
cd $(ROOTFS) && make uninstall PREFIX=$(PREFIX)
##@ Systemd Extension
.PHONY: enable-ext
enable-ext: ## Enable systemd extensions
mkdir -p $(HOME)/.var/lib/extensions
sudo ln -s $(HOME)/.var/lib/extensions /var/lib/extensions
sudo systemctl enable systemd-sysext
sudo systemctl start systemd-sysext
systemd-sysext status
.PHONY: disable-ext
disable-ext: ## Disable systemd extensions
sudo systemctl stop systemd-sysext
sudo systemctl disable systemd-sysext
.PHONY: install-ext
install-ext: systemd-sysext ## Install OpenGamepadUI as a systemd extension
cp dist/opengamepadui.raw $(HOME)/.var/lib/extensions
sudo systemd-sysext refresh
systemd-sysext status
.PHONY: uninstall-ext
uninstall-ext: ## Uninstall the OpenGamepadUI systemd extension
rm -rf $(HOME)/.var/lib/extensions
sudo systemd-sysext refresh
systemd-sysext status
##@ Development
.PHONY: test
test: addons ## Run all unit tests
$(GODOT) --path $(PWD) --headless --debug \
--remote-debug tcp://127.0.0.1:6007 \
res://core/systems/testing/run_tests.tscn
.PHONY: build
build: build/opengamepad-ui.x86_64 ## Build and export the project
build/opengamepad-ui.x86_64: $(ALL_ADDONS) $(ALL_GDSCRIPT) $(ALL_SCENES) $(EXPORT_TEMPLATE)
mkdir -p build
$(GODOT) --headless --export-debug "Linux/X11"
.PHONY: update-pack
update-pack: build/update.pck ## Build and export update pack
build/update.pck: $(ALL_ADDONS) $(ALL_GDSCRIPT) $(ALL_SCENES) $(EXPORT_TEMPLATE)
mkdir -p build
$(GODOT) --headless --export-pack "Linux/X11 (Update Pack)" $@
.PHONY: plugins
plugins: build/plugins.zip ## Build and export plugins
build/plugins.zip: $(ALL_ADDONS) $(ALL_GDSCRIPT) $(ALL_SCENES) $(EXPORT_TEMPLATE)
mkdir -p build
$(GODOT) --headless --export-pack "Linux/X11 (Plugins)" $@
.PHONY: import
import: ## Import project assets
@echo "Importing project assets. This will take some time..."
timeout --foreground 60 $(GODOT) --headless --editor . || echo "Finished"
.PHONY: addons
addons: $(ALL_ADDONS) ## Build GDExtension add-ons
XLIB_FILES := $(shell find ./addons/godot-xlib -regex '.*\(cpp\|h\|hpp\)$$')
addons/godot-xlib/bin/libxlib.linux.template_debug.x86_64.so: $(XLIB_FILES)
cd ./addons/godot-xlib && make build
EVDEV_FILES := $(shell find ./addons/godot-evdev -regex '.*\(cpp\|h\|hpp\)$$')
addons/godot-evdev/bin/libevdev.linux.template_debug.x86_64.so: $(EVDEV_FILES)
cd ./addons/godot-evdev && make build
PTY_FILES := $(shell find ./addons/godot-pty -regex '.*\(cpp\|h\|hpp\)$$')
addons/godot-pty/bin/libpty.linux.template_debug.x86_64.so: $(PTY_FILES)
cd ./addons/godot-pty && make build
OPENSD_FILES := $(shell find ./addons/godot-opensd -regex '.*\(cpp\|h\|hpp\)$$')
addons/godot-opensd/bin/libopensd.linux.template_debug.x86_64.so: $(OPENSD_FILES)
cd ./addons/godot-opensd && make build
.PHONY: edit
edit: ## Open the project in the Godot editor
$(GODOT) --editor .
.PHONY: clean
clean: ## Remove build artifacts
rm -rf build
rm -rf $(ROOTFS)
rm -rf $(CACHE_DIR)
rm -rf dist
cd ./addons/godot-xlib && make clean
cd ./addons/godot-evdev && make clean
cd ./addons/godot-pty && make clean
cd ./addons/godot-opensd && make clean
.PHONY: run run-force
run: addons build/opengamepad-ui.x86_64 run-force ## Run the project in gamescope
run-force:
$(GAMESCOPE) -w 1920 -h 1080 -f -e \
--xwayland-count 2 -- ./build/opengamepad-ui.x86_64
$(EXPORT_TEMPLATE):
mkdir -p $(HOME)/.local/share/godot/export_templates
@echo "Downloading export templates"
wget $(EXPORT_TEMPLATE_URL) -O $(HOME)/.local/share/godot/export_templates/templates.zip
@echo "Extracting export templates"
unzip $(HOME)/.local/share/godot/export_templates/templates.zip -d $(HOME)/.local/share/godot/export_templates/
rm $(HOME)/.local/share/godot/export_templates/templates.zip
mv $(HOME)/.local/share/godot/export_templates/templates $(@D)
.PHONY: debug
debug: addons ## Run the project in debug mode in gamescope
$(GAMESCOPE) -e --xwayland-count 2 -- \
$(GODOT) --path $(PWD) --remote-debug tcp://127.0.0.1:6007 \
--position 320,140 res://entrypoint.tscn
.PHONY: debug-qam
debug-qam: addons ## Run the project in debug mode in gamescope with --only-qam
$(GAMESCOPE) -e --xwayland-count 2 -- \
$(GODOT) --path $(PWD) --remote-debug tcp://127.0.0.1:6007 \
--position 320,140 res://entrypoint.tscn --only-qam -- steam -gamepadui -steamos3 -steampal -steamdeck
.PHONY: inspect
inspect: addons ## Launch Gamescope inspector
$(GODOT) --path $(PWD) res://core/ui/menu/debug/gamescope_inspector.tscn
.PHONY: signing-keys
signing-keys: assets/crypto/keys/opengamepadui.pub ## Generate a signing keypair to sign packages
assets/crypto/keys/opengamepadui.key:
@echo "Generating signing keys"
mkdir -p assets/crypto/keys
openssl genrsa -out $@ 4096
assets/crypto/keys/opengamepadui.pub: assets/crypto/keys/opengamepadui.key
openssl rsa -in $^ -outform PEM -pubout -out $@
##@ Remote Debugging
.PHONY: deploy
deploy: dist-archive $(SSH_MOUNT_PATH)/.mounted ## Build, deploy, and tunnel to a remote device
cp dist/opengamepadui.tar.gz $(SSH_MOUNT_PATH)
cd $(SSH_MOUNT_PATH) && tar xvfz opengamepadui.tar.gz
.PHONY: deploy-pack
deploy-pack: dist/update.pck.sig ## Build and deploy update pack to remote device
ssh $(SSH_USER)@$(SSH_HOST) mkdir -p .local/share/opengamepadui/updates
scp dist/update.pck $(SSH_USER)@$(SSH_HOST):~/.local/share/opengamepadui/updates
scp dist/update.pck.sig $(SSH_USER)@$(SSH_HOST):~/.local/share/opengamepadui/updates
.PHONY: deploy-ext
deploy-ext: dist-ext ## Build and deploy systemd extension to remote device
ssh $(SSH_USER)@$(SSH_HOST) mkdir -p .var/lib/extensions .config/systemd/user
scp dist/opengamepadui.raw $(SSH_USER)@$(SSH_HOST):~/.var/lib/extensions
scp rootfs/usr/lib/systemd/user/systemd-sysext-updater.service $(SSH_USER)@$(SSH_HOST):~/.config/systemd/user
ssh -t $(SSH_USER)@$(SSH_HOST) systemctl --user enable systemd-sysext-updater
ssh -t $(SSH_USER)@$(SSH_HOST) systemctl --user start systemd-sysext-updater
sleep 3
ssh -t $(SSH_USER)@$(SSH_HOST) sudo systemd-sysext refresh
ssh $(SSH_USER)@$(SSH_HOST) systemd-sysext status
.PHONY: enable-debug
enable-debug: ## Set OpenGamepadUI command to use remote debug on target device
ssh $(SSH_USER)@$(SSH_HOST) mkdir -p .config/environment.d
echo 'OGUICMD="opengamepadui --remote-debug tcp://127.0.0.1:6007"' | \
ssh $(SSH_USER)@$(SSH_HOST) bash -c \
'cat > .config/environment.d/opengamepadui-session.conf'
.PHONY: tunnel
tunnel: ## Create an SSH tunnel to allow remote debugging
ssh $(SSH_USER)@$(SSH_HOST) -N -f -R 6007:localhost:6007
# Mounts the remote device and creates an SSH tunnel for remote debugging
$(SSH_MOUNT_PATH)/.mounted:
mkdir -p $(SSH_MOUNT_PATH)
sshfs -o default_permissions $(SSH_USER)@$(SSH_HOST):$(SSH_DATA_PATH) $(SSH_MOUNT_PATH)
$(MAKE) tunnel
touch $(SSH_MOUNT_PATH)/.mounted
##@ Distribution
.PHONY: rootfs
rootfs: build/opengamepad-ui.x86_64
rm -rf $(ROOTFS)
mkdir -p $(ROOTFS)
cp -r rootfs/* $(ROOTFS)
mkdir -p $(ROOTFS)/usr/share/opengamepadui
cp -r build/*.so $(ROOTFS)/usr/share/opengamepadui
cp -r build/opengamepad-ui.x86_64 $(ROOTFS)/usr/share/opengamepadui
touch $(ROOTFS)/.gdignore
.PHONY: dist
dist: dist/opengamepadui.tar.gz dist/opengamepadui.raw dist/update.pck.sig ## Create all redistributable versions of the project
cd dist && sha256sum opengamepadui.tar.gz > opengamepadui.tar.gz.sha256.txt
cd dist && sha256sum update.pck > update.pck.sha256.txt
cd dist && sha256sum opengamepadui.raw > opengamepadui.raw.sha256.txt
.PHONY: dist-archive
dist-archive: dist/opengamepadui.tar.gz ## Create a redistributable tar.gz of the project
dist/opengamepadui.tar.gz: rootfs
@echo "Building redistributable tar.gz archive"
mkdir -p dist
mv $(ROOTFS) $(CACHE_DIR)/opengamepadui
cd $(CACHE_DIR) && tar cvfz opengamepadui.tar.gz opengamepadui
mv $(CACHE_DIR)/opengamepadui.tar.gz dist
mv $(CACHE_DIR)/opengamepadui $(ROOTFS)
.PHONY: dist-update-pack
dist-update-pack: dist/update.pck ## Create an update pack archive
dist/update.pck: update-pack
@echo "Building redistributable update pack"
mkdir -p dist
cp build/update.pck $@
dist/update.pck.sig: dist/update.pck assets/crypto/keys/opengamepadui.key
@echo "Signing update pack $<"
openssl dgst -sha256 -sign assets/crypto/keys/opengamepadui.key -out $@ $<
# https://blogs.igalia.com/berto/2022/09/13/adding-software-to-the-steam-deck-with-systemd-sysext/
.PHONY: dist-ext
dist-ext: dist/opengamepadui.raw ## Create a systemd-sysext extension archive
dist/opengamepadui.raw: dist/opengamepadui.tar.gz $(CACHE_DIR)/opengamepadui-session.tar.gz $(CACHE_DIR)/RyzenAdj/build/ryzenadj
@echo "Building redistributable systemd extension"
mkdir -p dist
rm -rf dist/opengamepadui.raw $(CACHE_DIR)/opengamepadui.raw
cp dist/opengamepadui.tar.gz $(CACHE_DIR)
cd $(CACHE_DIR) && tar xvfz opengamepadui.tar.gz opengamepadui/usr
mkdir -p $(CACHE_DIR)/opengamepadui/usr/lib/extension-release.d
echo ID=$(SYSEXT_ID) > $(CACHE_DIR)/opengamepadui/usr/lib/extension-release.d/extension-release.opengamepadui
echo VERSION_ID=$(SYSEXT_VERSION_ID) >> $(CACHE_DIR)/opengamepadui/usr/lib/extension-release.d/extension-release.opengamepadui
@# Copy opengamepadui-session into the extension
cd $(CACHE_DIR) && tar xvfz opengamepadui-session.tar.gz
cp -r $(CACHE_DIR)/OpenGamepadUI-session-main/usr/* $(CACHE_DIR)/opengamepadui/usr
@# Copy ryzenadj files into the extension
install -Dsm 755 $(CACHE_DIR)/RyzenAdj/build/ryzenadj $(CACHE_DIR)/opengamepadui/usr/bin/ryzenadj
install -Dsm 744 $(CACHE_DIR)/RyzenAdj/build/libryzenadj.so $(CACHE_DIR)/opengamepadui/usr/lib/libryzenadj.so
install -Dm 644 $(CACHE_DIR)/RyzenAdj/lib/ryzenadj.h $(CACHE_DIR)/opengamepadui/usr/include/ryzenadj.h
@# Build the extension archive
cd $(CACHE_DIR) && mksquashfs opengamepadui opengamepadui.raw
rm -rf $(CACHE_DIR)/opengamepadui $(CACHE_DIR)/OpenGamepadUI-session-main
mv $(CACHE_DIR)/opengamepadui.raw $@
$(CACHE_DIR)/RyzenAdj/build/ryzenadj:
rm -Rf $(CACHE_DIR)/RyzenAdj
@# Copy ryzenadj into the extension
git clone https://github.com/FlyGoat/RyzenAdj.git $(CACHE_DIR)/RyzenAdj
mkdir -p $(CACHE_DIR)/RyzenAdj/build
cd $(CACHE_DIR)/RyzenAdj/build && cmake -DCMAKE_BUILD_TYPE=Release .. && make
$(CACHE_DIR)/opengamepadui-session.tar.gz:
wget -O $@ https://github.com/ShadowBlip/OpenGamepadUI-session/archive/refs/heads/main.tar.gz
# Refer to .releaserc.yaml for release configuration
.PHONY: release
release: ## Publish a release with semantic release
npx semantic-release
# E.g. make in-docker TARGET=build
.PHONY: in-docker
in-docker: docker-builder
@# Run the given make target inside Docker
docker run -it --rm \
-v $(PWD):/src \
--workdir /src \
-e HOME=/home/build \
--user $(shell id -u):$(shell id -g) \
$(IMAGE_NAME):$(IMAGE_TAG) \
make $(TARGET)
.PHONY: docker-builder
docker-builder:
@# Pull any existing image to cache it
docker pull $(IMAGE_NAME):$(IMAGE_TAG) || echo "No remote image to pull"
@# Build the Docker image that will build the project
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) -f docker/Dockerfile ./docker
.PHONY: docker-builder-push
docker-builder-push: docker-builder
docker push $(IMAGE_NAME):$(IMAGE_TAG)