From 712467f4339557d48e574a4d9d86b4d7492e38fd Mon Sep 17 00:00:00 2001 From: "Brian J. Tarricone" Date: Wed, 11 May 2022 22:37:04 -0700 Subject: [PATCH] Improve makefile, add autogenerated manpages --- Makefile | 69 +++++++++++++++---- ...sktop => bscreensaver-settings.desktop.in} | 2 +- 2 files changed, 56 insertions(+), 15 deletions(-) rename settings/{bscreensaver-settings.desktop => bscreensaver-settings.desktop.in} (84%) diff --git a/Makefile b/Makefile index 74860f8..c76b2da 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all release dev install clean uninstall run run-dialog +.PHONY: all release dev manpages install clean uninstall run run-dialog DESTDIR ?= = PREFIX ?= /usr/local @@ -6,17 +6,44 @@ BINDIR ?= $(PREFIX)/bin LIBEXECDIR ?= $(PREFIX)/libexec SYSCONFDIR ?= $(PREFIX)/etc DATADIR ?= $(PREFIX)/share +MANDIR ?= $(DATADIR)/man APPLICATIONS_DIR = $(DATADIR)/applications CONFIG_DIR = $(SYSCONFDIR)/xdg/bscreensaver HELPER_DIR = $(LIBEXECDIR)/bscreensaver -HELPERS = \ + +HELPERS := \ bscreensaver-dbus-service \ bscreensaver-systemd \ bscreensaver-dialog-gtk3 \ $(NULL) +BINARIES := \ + bscreensaver \ + bscreensaver-command \ + bscreensaver-settings \ + $(NULL) + +TARGETS := \ + $(BINARIES) \ + $(HELPERS) \ + $(NULL) + +DEV_OUT = target/debug +RELEASE_OUT = target/release + +SOURCES := $(find . -name '*.rs') $(find . -name Cargo.toml) Cargo.lock +DEV_TARGETS := $(addprefix $(DEV_OUT),$(TARGETS)) +RELEASE_TARGETS := $(addprefix $(RELEASE_OUT),$(TARGETS)) + +MANPAGES := \ + bscreensaver.1.gz \ + bscreensaver-command.1.gz \ + $(NULL) +RELEASE_MANPAGES := $(addprefix $(RELEASE_OUT)/,$(MANPAGES)) + INSTALL ?= install +HELP2MAN ?= help2man RUST_RELEASE_CHANNEL = nightly ifeq ($(RUST_RELEASE_CHANNEL),nightly) @@ -27,29 +54,43 @@ endif DEV_LOG_LEVEL = debug -all: release +all: release manpages -release: - HELPER_DIR=$(HELPER_DIR) cargo $(RUST_RELEASE_CHANNEL_ARG) build $(FEATURES_ARGS) --release +release: $(RELEASE_TARGETS) -dev: - HELPER_DIR=target/debug cargo $(RUST_RELEASE_CHANNEL_ARG) build $(FEATURES_ARGS) +dev: $(DEV_TARGETS) -install: release - $(INSTALL) -m 0755 -d $(addprefix $(DESTDIR),$(BINDIR) $(HELPER_DIR) $(CONFIG_DIR) $(APPLICATIONS_DIR)) - $(INSTALL) -m 0755 target/release/bscreensaver target/release/bscreensaver-command target/release/bscreensaver-settings $(DESTDIR)$(BINDIR) - $(INSTALL) -m 0755 $(addprefix target/release/,$(HELPERS)) $(DESTDIR)$(HELPER_DIR) +manpages: $(RELEASE_MANPAGES) + +install: release manpages + $(INSTALL) -m 0755 -d $(addprefix $(DESTDIR),$(BINDIR) $(HELPER_DIR) $(CONFIG_DIR) $(APPLICATIONS_DIR) $(MANDIR)/man1) + $(INSTALL) -m 0755 $(addprefix $(RELEASE_OUT)/,$(BINARIES)) $(DESTDIR)$(BINDIR) + $(INSTALL) -m 0755 $(addprefix $(RELEASE_OUT)/,$(HELPERS)) $(DESTDIR)$(HELPER_DIR) $(INSTALL) -m 0644 bscreensaver.toml.example $(DESTDIR)$(CONFIG_DIR) $(INSTALL) -m 0644 settings/bscreensaver-settings.desktop $(DESTDIR)$(APPLICATIONS_DIR) + $(INSTALL) -m 0644 $(RELEASE_MANPAGES) $(DESTDIR)$(MANDIR)/man1 + +$(DEV_TARGETS): $(SOURCES) + HELPER_DIR=target/debug cargo $(RUST_RELEASE_CHANNEL_ARG) build $(FEATURES_ARGS) + +$(RELEASE_TARGETS): $(SOURCES) + HELPER_DIR=$(HELPER_DIR) cargo $(RUST_RELEASE_CHANNEL_ARG) build $(FEATURES_ARGS) --release + +$(RELEASE_OUT)/%.1.gz: $(RELEASE_OUT)/%.1 + gzip -c -k $< > $@ + +$(RELEASE_OUT)/%.1: $(RELEASE_TARGETS) + $(HELP2MAN) --no-info $(subst .1,,$@) > $@ clean: cargo $(RUST_RELEASE_CHANNEL_ARG) clean uninstall: - rm -f $(addprefix $(DESTDIR),$(BINDIR)/bscreensaver $(BINDIR)/bscreensaver-command $(BINDIR)/bscreensaver-settings $(addprefix $(HELPER_DIR)/,$(HELPERS))) || true - rmdir -p $(addprefix $(DESTDIR),$(BINDIR) $(HELPER_DIR) $(APPLICATIONS_DIR)) || true + rm -f $(addprefix $(DESTDIR)$(BINDIR),$(BINARIES)) $(addprefix $(HELPER_DIR)/,$(HELPERS))) || true + rm -f $(addprefix $(DESTDIR)$(MANDIR)/man1/,$(MANPAGES)) + rmdir -p $(addprefix $(DESTDIR),$(BINDIR) $(HELPER_DIR) $(APPLICATIONS_DIR) $(MANDIR)/man1) || true -run: dev +run: $(DEV_TARGETS) BSCREENSAVER_LOCAL_DEV=1 \ RUST_BACKTRACE=1 \ BSCREENSAVER_LOG=$(DEV_LOG_LEVEL) \ diff --git a/settings/bscreensaver-settings.desktop b/settings/bscreensaver-settings.desktop.in similarity index 84% rename from settings/bscreensaver-settings.desktop rename to settings/bscreensaver-settings.desktop.in index b0f336b..9b4483d 100644 --- a/settings/bscreensaver-settings.desktop +++ b/settings/bscreensaver-settings.desktop.in @@ -2,7 +2,7 @@ Version=1.0 Name=Screensaver Settings Comment=Customize screensaver settings -Exec=bscreensaver-settings +Exec=@BINDIR@/bscreensaver-settings Icon=screensaver Terminal=false StartupNotify=true