Skip to content

Commit b5f530a

Browse files
committed
Makefile: fix DESTDIR environment variable behaviour
The DESTDIR environment variable is used in the wrong way: since 30+ years it's common practise using it for specifying *temporary* target *root* (where eg. packaging infrastructure picks up the install image), instead of the installation *prefix* on the final target. Fixing this by introducing PREFIX variable (with default /usr/local) and using both variables according to the 30 years matured common practise. That way, distro packagers and other standardized build/installation systems can easily do correct deployments w/o individual hacks. changes v2: removed variables not used yet added documentation Signed-off-by: Enrico Weigelt, metux IT consult <[email protected]>
1 parent c8b33ba commit b5f530a

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

BUILDING.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ You can move them in your global path, `/usr/local/bin` with:
9090
sudo make install
9191
```
9292

93+
The install prefix can be changed by passing the `PREFIX` variable (defaults
94+
to `/usr/local`).
95+
96+
Note: if you set one of these vars, set them to the same values on all make stages
97+
(build as well as install).
98+
99+
If you want to prepend an additional prefix on actual installation (eg. packaging or chroot install),
100+
you can pass it via `DESTDIR` variable:
101+
102+
```sudo
103+
sudo make install DESTDIR=/tmp/install-x973234/
104+
```
105+
106+
The above command installs the `containerd` binary to `/tmp/install-x973234/usr/local/bin/containerd`
107+
108+
The current `DESTDIR` convention is supported since containerd v1.6.
109+
Older releases was using `DESTDIR` for a different purpose that is similar to `PREFIX`.
110+
111+
93112
When making any changes to the gRPC API, you can use the installed `protoc`
94113
compiler to regenerate the API generated code packages with:
95114

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ INSTALL ?= install
2121
ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
2222

2323
# Base path used to install.
24-
DESTDIR ?= /usr/local
24+
# The files will be installed under `$(DESTDIR)/$(PREFIX)`.
25+
# The convention of `DESTDIR` was changed in containerd v1.6.
26+
PREFIX ?= /usr/local
27+
2528
TEST_IMAGE_LIST ?=
2629

2730
# Used to populate variables in version package.
@@ -250,8 +253,8 @@ man/%: docs/man/%.md FORCE
250253
go-md2man -in "$<" -out "$@"
251254

252255
define installmanpage
253-
$(INSTALL) -d $(DESTDIR)/man/man$(2);
254-
gzip -c $(1) >$(DESTDIR)/man/man$(2)/$(3).gz;
256+
$(INSTALL) -d $(DESTDIR)/$(PREFIX)/man/man$(2);
257+
gzip -c $(1) >$(DESTDIR)/$(PREFIX)/man/man$(2)/$(3).gz;
255258
endef
256259

257260
install-man: man
@@ -346,12 +349,12 @@ clean-test: ## clean up debris from previously failed tests
346349

347350
install: ## install binaries
348351
@echo "$(WHALE) $@ $(BINARIES)"
349-
@$(INSTALL) -d $(DESTDIR)/bin
350-
@$(INSTALL) $(BINARIES) $(DESTDIR)/bin
352+
@$(INSTALL) -d $(DESTDIR)/$(PREFIX)/bin
353+
@$(INSTALL) $(BINARIES) $(DESTDIR)/$(PREFIX)/bin
351354

352355
uninstall:
353356
@echo "$(WHALE) $@"
354-
@rm -f $(addprefix $(DESTDIR)/bin/,$(notdir $(BINARIES)))
357+
@rm -f $(addprefix $(DESTDIR)/$(PREFIX)/bin/,$(notdir $(BINARIES)))
355358

356359
ifeq ($(GOOS),windows)
357360
install-deps:

0 commit comments

Comments
 (0)