How can I check if a program is callable from a Makefile?
(That is, the program should exist in the path or otherwise be callable.)
It could be used to chec
The solutions checking for STDERR
output of --version
does not work for programs which print their version to STDOUT
instead of STDERR
. Instead of checking their output to STDERR
or STDOUT
, check for the program return code. If the program does not exist, its exit code will always be non zero.
#!/usr/bin/make -f
# https://stackoverflow.com/questions/7123241/makefile-as-an-executable-script-with-shebang
ECHOCMD:=/bin/echo -e
SHELL := /bin/bash
RESULT := $(shell python --version >/dev/null 2>&1 || (echo "Your command failed with $$?"))
ifeq (,${RESULT})
EXISTS := true
else
EXISTS := false
endif
all:
echo EXISTS: ${EXISTS}
echo RESULT: ${RESULT}