From 353ba33b61af62c321300981e0318f19f1bdcf49 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 27 Feb 2024 23:41:40 -0800 Subject: [PATCH 1/4] Make the systemd system directory configurable --- Makefile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 8c315ca..0e98a6b 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,8 @@ PREFIX?=/usr/local CONFIG_DIR?=/etc/keyd SOCKET_PATH=/var/run/keyd.socket +SYSTEMD_SYSTEM_DIR = $(PREFIX)/lib/systemd/system + CFLAGS:=-DVERSION=\"v$(VERSION)\ \($(COMMIT)\)\" \ -I/usr/local/include \ -L/usr/local/lib \ @@ -50,15 +52,15 @@ install: @if [ -e /run/systemd/system ]; then \ sed -e 's#@PREFIX@#$(PREFIX)#' keyd.service.in > keyd.service; \ - mkdir -p $(DESTDIR)$(PREFIX)/lib/systemd/system/; \ - install -Dm644 keyd.service $(DESTDIR)$(PREFIX)/lib/systemd/system/keyd.service; \ + mkdir -p '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)'; \ + install -Dm644 keyd.service '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd.service'; \ else \ echo "NOTE: systemd not found, you will need to manually add keyd to your system's init process."; \ fi @if [ "$(VKBD)" = "usb-gadget" ]; then \ sed -e 's#@PREFIX@#$(PREFIX)#' src/vkbd/usb-gadget.service.in > src/vkbd/usb-gadget.service; \ - install -Dm644 src/vkbd/usb-gadget.service $(DESTDIR)$(PREFIX)/lib/systemd/system/keyd-usb-gadget.service; \ + install -Dm644 src/vkbd/usb-gadget.service '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd-usb-gadget.service'; \ install -Dm755 src/vkbd/usb-gadget.sh $(DESTDIR)$(PREFIX)/bin/keyd-usb-gadget.sh; \ fi @@ -81,15 +83,14 @@ install: uninstall: -groupdel keyd - rm -rf $(DESTDIR)$(PREFIX)/lib/systemd/system/keyd.service \ - $(DESTDIR)$(PREFIX)/bin/keyd \ + rm -rf $(DESTDIR)$(PREFIX)/bin/keyd \ $(DESTDIR)$(PREFIX)/bin/keyd-application-mapper \ $(DESTDIR)$(PREFIX)/share/doc/keyd/ \ $(DESTDIR)$(PREFIX)/share/man/man1/keyd*.gz \ $(DESTDIR)$(PREFIX)/share/keyd/ \ - $(DESTDIR)$(PREFIX)/lib/systemd/system/keyd-usb-gadget.service \ + '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd-usb-gadget.service' \ $(DESTDIR)$(PREFIX)/bin/keyd-usb-gadget.sh \ - $(DESTDIR)$(PREFIX)/lib/systemd/system/keyd.service + '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd.service' clean: rm -rf bin data/*.1.gz data/keyd.compose keyd.service src/unicode.c src/vkbd/usb-gadget.service test: From 9bd72f60e9c5a7363c8026a7558fbf2a3e547272 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 27 Feb 2024 23:43:33 -0800 Subject: [PATCH 2/4] Use `/usr` instead of `$(PREFIX)` for systemd system directory This is more likely to match user systems. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0e98a6b..808b8cd 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ PREFIX?=/usr/local CONFIG_DIR?=/etc/keyd SOCKET_PATH=/var/run/keyd.socket -SYSTEMD_SYSTEM_DIR = $(PREFIX)/lib/systemd/system +SYSTEMD_SYSTEM_DIR = /usr/lib/systemd/system CFLAGS:=-DVERSION=\"v$(VERSION)\ \($(COMMIT)\)\" \ -I/usr/local/include \ From 4b2da6076e4c0409197436d7df9aa5e0cae9fa1c Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 27 Feb 2024 23:53:00 -0800 Subject: [PATCH 3/4] Skip systemd service install if `SYSTEMD_SYSTEM_DIR` is empty --- Makefile | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 808b8cd..1bd4bb1 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,8 @@ PREFIX?=/usr/local CONFIG_DIR?=/etc/keyd SOCKET_PATH=/var/run/keyd.socket +# If this variable is set to the empty string, no systemd unit files will be +# installed. SYSTEMD_SYSTEM_DIR = /usr/lib/systemd/system CFLAGS:=-DVERSION=\"v$(VERSION)\ \($(COMMIT)\)\" \ @@ -50,17 +52,19 @@ man: done install: - @if [ -e /run/systemd/system ]; then \ + @if [ -e /run/systemd/system ] && [ -n '$(SYSTEMD_SYSTEM_DIR)' ]; then \ sed -e 's#@PREFIX@#$(PREFIX)#' keyd.service.in > keyd.service; \ mkdir -p '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)'; \ install -Dm644 keyd.service '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd.service'; \ - else \ + elif [ -n '$(SYSTEMD_SYSTEM_DIR)' ]; then \ echo "NOTE: systemd not found, you will need to manually add keyd to your system's init process."; \ fi @if [ "$(VKBD)" = "usb-gadget" ]; then \ - sed -e 's#@PREFIX@#$(PREFIX)#' src/vkbd/usb-gadget.service.in > src/vkbd/usb-gadget.service; \ - install -Dm644 src/vkbd/usb-gadget.service '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd-usb-gadget.service'; \ + if [ -n '$(SYSTEMD_SYSTEM_DIR)' ]; then \ + sed -e 's#@PREFIX@#$(PREFIX)#' src/vkbd/usb-gadget.service.in > src/vkbd/usb-gadget.service; \ + install -Dm644 src/vkbd/usb-gadget.service '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd-usb-gadget.service'; \ + fi; \ install -Dm755 src/vkbd/usb-gadget.sh $(DESTDIR)$(PREFIX)/bin/keyd-usb-gadget.sh; \ fi @@ -83,14 +87,15 @@ install: uninstall: -groupdel keyd + [ -z '$(SYSTEMD_SYSTEM_DIR)' ] || rm -f \ + '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd.service' \ + '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd-usb-gadget.service' rm -rf $(DESTDIR)$(PREFIX)/bin/keyd \ $(DESTDIR)$(PREFIX)/bin/keyd-application-mapper \ $(DESTDIR)$(PREFIX)/share/doc/keyd/ \ $(DESTDIR)$(PREFIX)/share/man/man1/keyd*.gz \ $(DESTDIR)$(PREFIX)/share/keyd/ \ - '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd-usb-gadget.service' \ - $(DESTDIR)$(PREFIX)/bin/keyd-usb-gadget.sh \ - '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd.service' + $(DESTDIR)$(PREFIX)/bin/keyd-usb-gadget.sh clean: rm -rf bin data/*.1.gz data/keyd.compose keyd.service src/unicode.c src/vkbd/usb-gadget.service test: From 31191d062ff45f39adc49962678204267795b515 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 27 Feb 2024 23:55:34 -0800 Subject: [PATCH 4/4] Always install systemd service if `SYSTEMD_SYSTEM_DIR` is set This makes it easier to build inside a chroot jail, for example. --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1bd4bb1..3ae1276 100644 --- a/Makefile +++ b/Makefile @@ -52,12 +52,10 @@ man: done install: - @if [ -e /run/systemd/system ] && [ -n '$(SYSTEMD_SYSTEM_DIR)' ]; then \ + @if [ -n '$(SYSTEMD_SYSTEM_DIR)' ]; then \ sed -e 's#@PREFIX@#$(PREFIX)#' keyd.service.in > keyd.service; \ mkdir -p '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)'; \ install -Dm644 keyd.service '$(DESTDIR)$(SYSTEMD_SYSTEM_DIR)/keyd.service'; \ - elif [ -n '$(SYSTEMD_SYSTEM_DIR)' ]; then \ - echo "NOTE: systemd not found, you will need to manually add keyd to your system's init process."; \ fi @if [ "$(VKBD)" = "usb-gadget" ]; then \