diff --git a/Makefile b/Makefile index de310a1..1236ff2 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ # # `make` builds as you, so `make && sudo make install PREFIX=/usr/local` # builds nothing as root. +# +# Each step prints one line such as ` INSTALL ~/.local/bin/fsfork`. +# `make V=1` prints the commands instead. PREFIX ?= $(HOME)/.local BINDIR ?= $(PREFIX)/bin @@ -15,28 +18,55 @@ COMMANDS = fsfork confine fsdiff BINARIES = $(COMMANDS:%=target/release/%) SOURCES = Cargo.toml Cargo.lock $(wildcard fsfork/Cargo.toml fsfork/*.rs cmd/*/Cargo.toml cmd/*/*.rs) +# $(Q) hides a command, and $(call msg,VERB,what) announces it. With V=1 +# the command is shown instead; with `make -s` nothing is. +ifeq ($(V),1) + Q = + msg = +else + Q = @ + msg = @printf ' %-7s %s\n' '$(1)' '$(2)' +endif +ifneq ($(findstring s,$(firstword -$(MAKEFLAGS))),) + msg = +endif + +# The recipe lines that install, or remove, one command and its man page. +define install_command + $(call msg,INSTALL,$(DESTDIR)$(BINDIR)/$(1)) + $(Q)install -m 755 target/release/$(1) $(DESTDIR)$(BINDIR)/$(1) + $(call msg,INSTALL,$(DESTDIR)$(MANDIR)/man1/$(1).1) + $(Q)install -m 644 cmd/$(1)/$(1).1 $(DESTDIR)$(MANDIR)/man1/$(1).1 + +endef +define uninstall_command + $(call msg,RM,$(DESTDIR)$(BINDIR)/$(1)) + $(Q)rm -f $(DESTDIR)$(BINDIR)/$(1) + $(call msg,RM,$(DESTDIR)$(MANDIR)/man1/$(1).1) + $(Q)rm -f $(DESTDIR)$(MANDIR)/man1/$(1).1 + +endef + all: $(BINARIES) $(BINARIES): $(SOURCES) - cargo build --release - @touch $(BINARIES) + $(call msg,CARGO,target/release) + $(Q)cargo build --release + $(Q)touch $(BINARIES) install: all - install -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1 - for command in $(COMMANDS); do \ - install -m 755 target/release/$$command $(DESTDIR)$(BINDIR)/$$command && \ - install -m 644 cmd/$$command/$$command.1 $(DESTDIR)$(MANDIR)/man1/$$command.1 || exit 1; \ - done + $(Q)install -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1 + $(foreach command,$(COMMANDS),$(call install_command,$(command))) uninstall: - for command in $(COMMANDS); do \ - rm -f $(DESTDIR)$(BINDIR)/$$command $(DESTDIR)$(MANDIR)/man1/$$command.1; \ - done + $(foreach command,$(COMMANDS),$(call uninstall_command,$(command))) test: - cargo test + $(call msg,TEST,workspace) + $(Q)cargo test clean: - cargo clean + $(call msg,CLEAN,target) + $(Q)cargo clean .PHONY: all install uninstall test clean