Add install and uninstall targets

install copies the binary to $(BINDIR), defaulting to /usr/local/bin.
PREFIX, BINDIR and INSTALL are overridable, and DESTDIR is honoured so a
packager can stage into a temporary root; it is deliberately left
undefaulted rather than set to empty.

uninstall removes what install placed, and is idempotent.

Both use install(1) rather than cp, so the mode is set explicitly and the
target directory is created in the same step. The flags used, -d and -m,
are common to GNU and BSD install, which SPEC.md section 19 asks for.

Verified: staged install under DESTDIR, PREFIX and BINDIR overrides,
uninstall in both plain and staged form, uninstall with nothing to
remove, and install from a clean tree rebuilding first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
This commit is contained in:
Fabio Scotto di Santolo
2026-08-26 15:46:05 +02:00
parent 4e56e3e37c
commit 25b328ba79
2 changed files with 30 additions and 4 deletions

View File

@@ -40,6 +40,18 @@ make # produces build/fsnap
make clean
```
`make install` copies the binary to `$(BINDIR)`, which defaults to
`/usr/local/bin`; `make uninstall` removes it again. Both honour `DESTDIR` for
staged installs:
```sh
make install PREFIX=~/.local # ~/.local/bin/fsnap
make install DESTDIR=/tmp/stage # /tmp/stage/usr/local/bin/fsnap
sudo make install # /usr/local/bin/fsnap
```
`PREFIX`, `BINDIR` and `INSTALL` can all be overridden.
The sources declare no feature test macros of their own; the `Makefile` sets
`-D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE` for the whole build. Everything
used behind them — `getline`, `realpath(path, NULL)`, `mkstemp`, `readlink`,
@@ -48,7 +60,7 @@ used behind them — `getline`, `realpath(path, NULL)`, `mkstemp`, `readlink`,
`dirent.d_type`, used as a fast path only, with an `lstat` fallback for
`DT_UNKNOWN` as the spec requires.
Only Linux/glibc has been tested. There is no `install` target.
Only Linux/glibc has been tested.
## Usage
@@ -206,7 +218,6 @@ Rough order of intent, no timeline:
rather than collapsing them ([SPEC.md](SPEC.md) §18).
- [ ] Honour `TMPDIR` instead of hardcoding `/tmp`.
- [ ] Add a test suite and wire it into the `Makefile`.
- [ ] Add an `install` target.
## License