From 75de8ac385ad2b56a6f56da746eb5c70b733d16c 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 f600179..e26c60c 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 keyd.service src/vkbd/usb-gadget.service test: From 50cd69fdd98640f11e7eb4e793a7b816adf00962 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 e26c60c..bcf390e 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 c85acd9eca30203da7ad8af14caef8051bae6d76 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 bcf390e..ef3debf 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 keyd.service src/vkbd/usb-gadget.service test: From fd81395b6cb9e4771b3f17bda1b177ef4da0ec4b 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 ef3debf..35b0c69 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 \