The "which" utility is not guaranteed to be installed either, and if it is, its behavior is not portable either. This means that when various programs are installed, the which check will report a fatal error because the which tool did not exist and the shell returned a nonzero status when attempting to fork+exec. If it did exist, it might not be an implementation of which that returns nonzero when commands do not exist.
The general scripting suggestion is to use the "command -v" shell builtin; this is required to exist in all POSIX 2008 compliant shells, and is thus guaranteed to work everywhere.
For some in-depth discussions on the topic, see:
- https://mywiki.wooledge.org/BashFAQ/081 - https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use...
Examples of open-source shells likely to be installed as /bin/sh on Linux, which implement the 15-year-old standard: ash, bash, busybox, dash, ksh, mksh and zsh.
Several Linux distros which do currently ship a (decent quality) which utility in their default install are looking to get rid of it:
- Gentoo: https://bugs.gentoo.org/646588 - Debian: https://lwn.net/Articles/874049/
In this case, we know that "install" exists. If it doesn't, the Makefile abnormally aborts, since $(INSTALL) expands empty and `make install` fails. Anyways, it is installed by coreutils.
There's no point in converting it to an absolute path inside a Makefile invocation. The only reason it is a variable at all is so that users can override it. The only thing setting it to the value of running (on every single make) a subprocess for $(shell which install) *does*, is potentially mess up when this arbitrary dependency isn't available.
Just default to calling it without a path.
Signed-off-by: Eli Schwartz eschwartz93@gmail.com --- fence_sanlock/Makefile | 2 +- reset/Makefile | 2 +- src/Makefile | 2 +- wdmd/Makefile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/fence_sanlock/Makefile b/fence_sanlock/Makefile index 6e2aa9b..14bbe13 100644 --- a/fence_sanlock/Makefile +++ b/fence_sanlock/Makefile @@ -51,7 +51,7 @@ $(TARGET2): $(SOURCE2) clean: rm -f *.o *.so *.so.* $(TARGET1) $(TARGET2)
-INSTALL=$(shell which install) +INSTALL=install
DESTDIR= BINDIR=/usr/sbin diff --git a/reset/Makefile b/reset/Makefile index 004dbb6..1bc370c 100644 --- a/reset/Makefile +++ b/reset/Makefile @@ -26,7 +26,7 @@ $(TARGET2): $(SOURCE2) clean: rm -f *.o *.so *.so.* $(TARGET1) $(TARGET2)
-INSTALL=$(shell which install) +INSTALL=install
DESTDIR= BINDIR=/usr/sbin diff --git a/src/Makefile b/src/Makefile index 533dd79..c0ef517 100644 --- a/src/Makefile +++ b/src/Makefile @@ -107,7 +107,7 @@ $(LIBPC_CLIENT_TARGET): $(LIBPC_CLIENT_SOURCE) clean: rm -f *.o *.so *.so.* $(CMD_TARGET) $(LIBSO_ENTIRE_TARGET) $(LIBSO_CLIENT_TARGET) $(LIBPC_ENTIRE_TARGET) $(LIBPC_CLIENT_TARGET)
-INSTALL=$(shell which install) +INSTALL=install
DESTDIR= BINDIR=/usr/sbin diff --git a/wdmd/Makefile b/wdmd/Makefile index 5849efc..bf5b698 100644 --- a/wdmd/Makefile +++ b/wdmd/Makefile @@ -52,7 +52,7 @@ clean: rm -f *.o *.so *.so.* $(CMD_TARGET) $(TEST_TARGET)
-INSTALL=$(shell which install) +INSTALL=install
DESTDIR= BINDIR=/usr/sbin
sanlock-devel@lists.fedorahosted.org