Skip to content

Commit 09c4d4c

Browse files
committed
proper use of $(DESTDIR)
@rofl0r @ [1] "...still it's unusual/unexpected to embed DESTDIR in LIBPATH etc. where this could hickup is when for example hardcoded paths need to be embedded into the resulting binary. for example, in the netbsd-curses makefile i linked earlier, such a case would be reference to the terminfo DB location, which is derived from PREFIX. other possible cases might be stuff that dlopen()s its own libs using an absolute path, or uses other data files. for such a case a contributor would typically re-use DATAPATH oslt and put it into CPPFLAGS or write it into a header, to find the required files. when now these paths have DESTDIR in them too, this will not work. thus it is good practice to use $(DESTDIR) only in install targets, and keep it out of other vars." [1] 8e29a60#commitcomment-22678488 This closes #232
1 parent e3937a2 commit 09c4d4c

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

makefile.shared

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ $(LIBNAME): $(OBJECTS)
4747

4848
install: .common_install
4949
sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > libtomcrypt.pc
50-
install -d $(LIBPATH)/pkgconfig
51-
install -m 644 libtomcrypt.pc $(LIBPATH)/pkgconfig/
50+
install -d $(DESTDIR)/$(LIBPATH)/pkgconfig
51+
install -m 644 libtomcrypt.pc $(DESTDIR)/$(LIBPATH)/pkgconfig/
5252

5353
install_bins: .common_install_bins
5454

makefile.unix

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#The following can be overridden from command line e.g. "make -f makefile.unix CC=gcc ARFLAGS=rcs"
2626
DESTDIR =
2727
PREFIX = /usr/local
28-
LIBPATH = $(DESTDIR)$(PREFIX)/lib
29-
INCPATH = $(DESTDIR)$(PREFIX)/include
30-
DATAPATH = $(DESTDIR)$(PREFIX)/share/doc/libtomcrypt/pdf
31-
BINPATH = $(DESTDIR)$(PREFIX)/bin
28+
LIBPATH = $(PREFIX)/lib
29+
INCPATH = $(PREFIX)/include
30+
DATAPATH = $(PREFIX)/share/doc/libtomcrypt/pdf
31+
BINPATH = $(PREFIX)/bin
3232
CC = cc
3333
AR = ar
3434
ARFLAGS = r
@@ -272,17 +272,17 @@ clean:
272272

273273
#Install the library + headers
274274
install: $(LIBMAIN_S) $(HEADERS)
275-
@mkdir -p $(INCPATH) $(LIBPATH)/pkgconfig
276-
@cp $(LIBMAIN_S) $(LIBPATH)/
277-
@cp $(HEADERS) $(INCPATH)/
278-
@sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > $(LIBPATH)/pkgconfig/libtomcrypt.pc
275+
@mkdir -p $(DESTDIR)/$(INCPATH) $(DESTDIR)/$(LIBPATH)/pkgconfig
276+
@cp $(LIBMAIN_S) $(DESTDIR)/$(LIBPATH)/
277+
@cp $(HEADERS) $(DESTDIR)/$(INCPATH)/
278+
@sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > $(DESTDIR)/$(LIBPATH)/pkgconfig/libtomcrypt.pc
279279

280280
#Install useful tools
281281
install_bins: hashsum
282-
@mkdir -p $(BINPATH)
283-
@cp hashsum $(BINPATH)/
282+
@mkdir -p $(DESTDIR)/$(BINPATH)
283+
@cp hashsum $(DESTDIR)/$(BINPATH)/
284284

285285
#Install documentation
286286
install_docs: doc/crypt.pdf
287-
@mkdir -p $(DATAPATH)
288-
@cp doc/crypt.pdf $(DATAPATH)/
287+
@mkdir -p $(DESTDIR)/$(DATAPATH)
288+
@cp doc/crypt.pdf $(DESTDIR)/$(DATAPATH)/

makefile_include.mk

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ TIMINGS=demos/timing.o
132132
#BINPATH The directory to install the binaries provided.
133133
DESTDIR ?=
134134
PREFIX ?= /usr/local
135-
LIBPATH ?= $(DESTDIR)$(PREFIX)/lib
136-
INCPATH ?= $(DESTDIR)$(PREFIX)/include
137-
DATAPATH ?= $(DESTDIR)$(PREFIX)/share/doc/libtomcrypt/pdf
138-
BINPATH ?= $(DESTDIR)$(PREFIX)/bin
135+
LIBPATH ?= $(PREFIX)/lib
136+
INCPATH ?= $(PREFIX)/include
137+
DATAPATH ?= $(PREFIX)/share/doc/libtomcrypt/pdf
138+
BINPATH ?= $(PREFIX)/bin
139139

140140
#Who do we install as?
141141
ifdef INSTALL_USER
@@ -362,18 +362,18 @@ install_all: install install_bins install_docs install_test
362362
INSTALL_OPTS ?= -m 644
363363

364364
.common_install: $(LIBNAME)
365-
install -d $(INCPATH)
366-
install -d $(LIBPATH)
367-
$(INSTALL_CMD) $(INSTALL_OPTS) $(LIBNAME) $(LIBPATH)/$(LIBNAME)
368-
install -m 644 $(HEADERS) $(INCPATH)
365+
install -d $(DESTDIR)/$(INCPATH)
366+
install -d $(DESTDIR)/$(LIBPATH)
367+
$(INSTALL_CMD) $(INSTALL_OPTS) $(LIBNAME) $(DESTDIR)/$(LIBPATH)/$(LIBNAME)
368+
install -m 644 $(HEADERS) $(DESTDIR)/$(INCPATH)
369369

370370
.common_install_bins: $(USEFUL_DEMOS)
371371
install -d $(BINPATH)
372-
$(INSTALL_CMD) -m 775 $(USEFUL_DEMOS) $(BINPATH)
372+
$(INSTALL_CMD) -m 775 $(USEFUL_DEMOS) $(DESTDIR)/$(BINPATH)
373373

374374
install_docs: doc/crypt.pdf
375375
install -d $(DATAPATH)
376-
install -m 644 doc/crypt.pdf $(DATAPATH)
376+
install -m 644 doc/crypt.pdf $(DESTDIR)/$(DATAPATH)
377377

378378
install_hooks:
379379
for s in `ls hooks/`; do ln -s ../../hooks/$$s .git/hooks/$$s; done

0 commit comments

Comments
 (0)