Makefile: single cargo build + atomic install -Dm mode

Address review comments on #139:

- build: replace 14-call loop with a single
  `cargo build --workspace --bins --exclude shadow-rs` invocation,
  eliminating per-tool Cargo startup/metadata overhead. Matches the
  uutils/coreutils GNUmakefile pattern.

- install: use `install -Dm4755` / `install -Dm0755` to set mode atomically
  during install instead of post-install chmod. Errors no longer swallowed:
  if install can't set the setuid bit, `make install` now fails loudly.

- install-multicall: same — `install -Dm4755` sets the shadow-rs binary
  setuid in one step.
This commit is contained in:
Pierre Warnier
2026-04-15 14:40:52 +02:00
parent 698eaf7cf3
commit de1e96c605
+6 -11
View File
@@ -17,9 +17,7 @@ ALL_TOOLS = $(SETUID_TOOLS) $(ROOT_TOOLS)
all: build
build:
@for tool in $(ALL_TOOLS); do \
cargo build --profile $(PROFILE) -p uu_$$tool --bin $$tool || exit 1; \
done
cargo build --profile $(PROFILE) --workspace --bins --exclude shadow-rs
build-multicall:
cargo build --profile $(PROFILE) --bin shadow-rs
@@ -30,11 +28,11 @@ test:
# Default install: 14 standalone per-tool binaries with least-privilege setuid
# layout matching GNU shadow-utils. Only passwd/chfn/chsh/newgrp are setuid.
install: build
@for tool in $(ALL_TOOLS); do \
install -Dm755 target/$(PROFILE)/$$tool $(DESTDIR)$(BINDIR)/$$tool; \
done
@for tool in $(SETUID_TOOLS); do \
chmod 4755 $(DESTDIR)$(BINDIR)/$$tool 2>/dev/null || true; \
install -Dm4755 target/$(PROFILE)/$$tool $(DESTDIR)$(BINDIR)/$$tool || exit 1; \
done
@for tool in $(ROOT_TOOLS); do \
install -Dm0755 target/$(PROFILE)/$$tool $(DESTDIR)$(BINDIR)/$$tool || exit 1; \
done
@echo "Installed $(words $(ALL_TOOLS)) standalone binaries to $(DESTDIR)$(BINDIR)/"
@echo " setuid (4755): $(SETUID_TOOLS)"
@@ -45,13 +43,10 @@ install: build
# the ELF, so all tools end up running with euid=root. Intended for
# container/embedded use where disk savings matter and attack surface does not.
install-multicall: build-multicall
install -Dm755 target/$(PROFILE)/shadow-rs $(DESTDIR)$(BINDIR)/shadow-rs
install -Dm4755 target/$(PROFILE)/shadow-rs $(DESTDIR)$(BINDIR)/shadow-rs
@for tool in $(ALL_TOOLS); do \
ln -sf shadow-rs $(DESTDIR)$(BINDIR)/$$tool; \
done
@for tool in $(SETUID_TOOLS); do \
chmod 4755 $(DESTDIR)$(BINDIR)/$$tool 2>/dev/null || true; \
done
@echo "Installed multicall shadow-rs + $(words $(ALL_TOOLS)) symlinks to $(DESTDIR)$(BINDIR)/"
uninstall: