Revert "make: support: use command -v' instead of which'"

This reverts commit ca6a2907c2.

Switching to using 'command -v' instead of 'which', opened a can of
worms that is hard to fix in a timely manner:

  - recursive call to 'make' from a post-build, post-iamge script, fails
    because of a redefinition of HOSTCC_NOCCACHE (a bug on its own that
    needs a separate fix anyway) [0];

  - 'make' believeing it can call "simple" commands with execve() et al.
    instead of passing them through a shell via system(), and thus
    failing to find 'command' in the PATH [1].

[0] https://lore.kernel.org/buildroot/20211001175329.GA1973888@lbrmn-mmayer.ric.broadcom.net/T/#m95c17eb8374e4e3dd6eee700d397aa12cca0739e
[1] https://lore.kernel.org/buildroot/20211001180304.GV1504958@scaer/T/#m3a8f36bd76ec7d8e5038a6c8932bb6ffe23ea268

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
Yann E. MORIN
2021-10-01 20:08:32 +02:00
parent 6cddc00399
commit 556a0a1104
11 changed files with 35 additions and 35 deletions

View File

@@ -284,12 +284,12 @@ HOSTAS := as
endif endif
ifndef HOSTCC ifndef HOSTCC
HOSTCC := gcc HOSTCC := gcc
HOSTCC := $(shell command -v $(HOSTCC) || type -p $(HOSTCC) || echo gcc) HOSTCC := $(shell which $(HOSTCC) || type -p $(HOSTCC) || echo gcc)
endif endif
HOSTCC_NOCCACHE := $(HOSTCC) HOSTCC_NOCCACHE := $(HOSTCC)
ifndef HOSTCXX ifndef HOSTCXX
HOSTCXX := g++ HOSTCXX := g++
HOSTCXX := $(shell command -v $(HOSTCXX) || type -p $(HOSTCXX) || echo g++) HOSTCXX := $(shell which $(HOSTCXX) || type -p $(HOSTCXX) || echo g++)
endif endif
HOSTCXX_NOCCACHE := $(HOSTCXX) HOSTCXX_NOCCACHE := $(HOSTCXX)
ifndef HOSTCPP ifndef HOSTCPP
@@ -310,15 +310,15 @@ endif
ifndef HOSTRANLIB ifndef HOSTRANLIB
HOSTRANLIB := ranlib HOSTRANLIB := ranlib
endif endif
HOSTAR := $(shell command -v $(HOSTAR) || type -p $(HOSTAR) || echo ar) HOSTAR := $(shell which $(HOSTAR) || type -p $(HOSTAR) || echo ar)
HOSTAS := $(shell command -v $(HOSTAS) || type -p $(HOSTAS) || echo as) HOSTAS := $(shell which $(HOSTAS) || type -p $(HOSTAS) || echo as)
HOSTCPP := $(shell command -v $(HOSTCPP) || type -p $(HOSTCPP) || echo cpp) HOSTCPP := $(shell which $(HOSTCPP) || type -p $(HOSTCPP) || echo cpp)
HOSTLD := $(shell command -v $(HOSTLD) || type -p $(HOSTLD) || echo ld) HOSTLD := $(shell which $(HOSTLD) || type -p $(HOSTLD) || echo ld)
HOSTLN := $(shell command -v $(HOSTLN) || type -p $(HOSTLN) || echo ln) HOSTLN := $(shell which $(HOSTLN) || type -p $(HOSTLN) || echo ln)
HOSTNM := $(shell command -v $(HOSTNM) || type -p $(HOSTNM) || echo nm) HOSTNM := $(shell which $(HOSTNM) || type -p $(HOSTNM) || echo nm)
HOSTOBJCOPY := $(shell command -v $(HOSTOBJCOPY) || type -p $(HOSTOBJCOPY) || echo objcopy) HOSTOBJCOPY := $(shell which $(HOSTOBJCOPY) || type -p $(HOSTOBJCOPY) || echo objcopy)
HOSTRANLIB := $(shell command -v $(HOSTRANLIB) || type -p $(HOSTRANLIB) || echo ranlib) HOSTRANLIB := $(shell which $(HOSTRANLIB) || type -p $(HOSTRANLIB) || echo ranlib)
SED := $(shell command -v sed || type -p sed) -i -e SED := $(shell which sed || type -p sed) -i -e
export HOSTAR HOSTAS HOSTCC HOSTCXX HOSTLD export HOSTAR HOSTAS HOSTCC HOSTCXX HOSTLD
export HOSTCC_NOCCACHE HOSTCXX_NOCCACHE export HOSTCC_NOCCACHE HOSTCXX_NOCCACHE

View File

@@ -4,7 +4,7 @@ endif
ifndef HOSTMAKE ifndef HOSTMAKE
HOSTMAKE = $(MAKE) HOSTMAKE = $(MAKE)
endif endif
HOSTMAKE := $(shell command -v $(HOSTMAKE) || type -p $(HOSTMAKE) || echo make) HOSTMAKE := $(shell which $(HOSTMAKE) || type -p $(HOSTMAKE) || echo make)
# If BR2_JLEVEL is 0, scale the maximum concurrency with the number of # If BR2_JLEVEL is 0, scale the maximum concurrency with the number of
# CPUs. An additional job is used in order to keep processors busy # CPUs. An additional job is used in order to keep processors busy
@@ -222,8 +222,8 @@ else
TARGET_STRIP = /bin/true TARGET_STRIP = /bin/true
STRIPCMD = $(TARGET_STRIP) STRIPCMD = $(TARGET_STRIP)
endif endif
INSTALL := $(shell command -v install || type -p install) INSTALL := $(shell which install || type -p install)
UNZIP := $(shell command -v unzip || type -p unzip) -q UNZIP := $(shell which unzip || type -p unzip) -q
APPLY_PATCHES = PATH=$(HOST_DIR)/bin:$$PATH support/scripts/apply-patches.sh $(if $(QUIET),-s) APPLY_PATCHES = PATH=$(HOST_DIR)/bin:$$PATH support/scripts/apply-patches.sh $(if $(QUIET),-s)
@@ -237,7 +237,7 @@ HOST_LDFLAGS += -L$(HOST_DIR)/lib -Wl,-rpath,$(HOST_DIR)/lib
# the path to the system perl, before a host-perl built by Buildroot # the path to the system perl, before a host-perl built by Buildroot
# might get installed into $(HOST_DIR)/bin and therefore appears # might get installed into $(HOST_DIR)/bin and therefore appears
# in our PATH. This system perl will be used as INTLTOOL_PERL. # in our PATH. This system perl will be used as INTLTOOL_PERL.
export PERL=$(shell command -v perl) export PERL=$(shell which perl)
# host-intltool needs libxml-parser-perl, which Buildroot installs in # host-intltool needs libxml-parser-perl, which Buildroot installs in
# $(HOST_DIR)/lib/perl, so we must make sure that the system perl # $(HOST_DIR)/lib/perl, so we must make sure that the system perl

View File

@@ -5,10 +5,10 @@
# that runs on host, e.g. Kconfig. To build code for target use plain # that runs on host, e.g. Kconfig. To build code for target use plain
# host-{bison,flex}. # host-{bison,flex}.
ifeq ($(shell command -v bison 2>/dev/null),) ifeq ($(shell which bison 2>/dev/null),)
BR2_BISON_HOST_DEPENDENCY = host-bison BR2_BISON_HOST_DEPENDENCY = host-bison
endif endif
ifeq ($(shell command -v flex 2>/dev/null),) ifeq ($(shell which flex 2>/dev/null),)
BR2_FLEX_HOST_DEPENDENCY = host-flex BR2_FLEX_HOST_DEPENDENCY = host-flex
endif endif

View File

@@ -11,7 +11,7 @@ shift
for candidate; do for candidate; do
# Try to locate the candidate. Discard it if not located. # Try to locate the candidate. Discard it if not located.
cmake=`command -v "${candidate}" 2>/dev/null` cmake=`which "${candidate}" 2>/dev/null`
[ -n "${cmake}" ] || continue [ -n "${cmake}" ] || continue
# Extract version X.Y from versions in the form X.Y or X.Y.Z # Extract version X.Y from versions in the form X.Y or X.Y.Z

View File

@@ -2,7 +2,7 @@
candidate="$1" # ignored candidate="$1" # ignored
gzip="$(command -v gzip)" gzip="$(which gzip)"
if [ ! -x "${gzip}" ]; then if [ ! -x "${gzip}" ]; then
# echo nothing: no suitable gzip found # echo nothing: no suitable gzip found
exit 1 exit 1

View File

@@ -2,9 +2,9 @@
candidate="$1" candidate="$1"
lzip=`command -v $candidate 2>/dev/null` lzip=`which $candidate 2>/dev/null`
if [ ! -x "$lzip" ]; then if [ ! -x "$lzip" ]; then
lzip=`command -v lzip 2>/dev/null` lzip=`which lzip 2>/dev/null`
if [ ! -x "$lzip" ]; then if [ ! -x "$lzip" ]; then
# echo nothing: no suitable lzip found # echo nothing: no suitable lzip found
exit 1 exit 1

View File

@@ -14,7 +14,7 @@ shift
# a more recent version. # a more recent version.
for candidate in "${@}" ; do for candidate in "${@}" ; do
python3=`command -v $candidate 2>/dev/null` python3=`which $candidate 2>/dev/null`
if [ ! -x "$python3" ]; then if [ ! -x "$python3" ]; then
continue continue
fi fi

View File

@@ -2,9 +2,9 @@
candidate="$1" candidate="$1"
tar=`command -v $candidate` tar=`which $candidate`
if [ ! -x "$tar" ]; then if [ ! -x "$tar" ]; then
tar=`command -v tar` tar=`which tar`
if [ ! -x "$tar" ]; then if [ ! -x "$tar" ]; then
# echo nothing: no suitable tar found # echo nothing: no suitable tar found
exit 1 exit 1

View File

@@ -2,9 +2,9 @@
candidate="$1" candidate="$1"
xzcat=`command -v $candidate 2>/dev/null` xzcat=`which $candidate 2>/dev/null`
if [ ! -x "$xzcat" ]; then if [ ! -x "$xzcat" ]; then
xzcat=`command -v xzcat 2>/dev/null` xzcat=`which xzcat 2>/dev/null`
if [ ! -x "$xzcat" ]; then if [ ! -x "$xzcat" ]; then
# echo nothing: no suitable xzcat found # echo nothing: no suitable xzcat found
exit 1 exit 1

View File

@@ -58,7 +58,7 @@ fi
check_prog_host() check_prog_host()
{ {
prog="$1" prog="$1"
if ! command -v $prog > /dev/null ; then if ! which $prog > /dev/null ; then
echo >&2 echo >&2
echo "You must install '$prog' on your build machine" >&2 echo "You must install '$prog' on your build machine" >&2
exit 1 exit 1
@@ -75,7 +75,7 @@ check_prog_host "sed"
check_prog_host "/usr/bin/file" check_prog_host "/usr/bin/file"
# Check make # Check make
MAKE=$(command -v make 2> /dev/null) MAKE=$(which make 2> /dev/null)
if [ -z "$MAKE" ] ; then if [ -z "$MAKE" ] ; then
echo echo
echo "You must install 'make' on your build machine"; echo "You must install 'make' on your build machine";
@@ -96,9 +96,9 @@ if [ $MAKE_MAJOR -lt 3 ] || [ $MAKE_MAJOR -eq 3 -a $MAKE_MINOR -lt 81 ] ; then
fi; fi;
# Check host gcc # Check host gcc
COMPILER=$(command -v $HOSTCC_NOCCACHE 2> /dev/null) COMPILER=$(which $HOSTCC_NOCCACHE 2> /dev/null)
if [ -z "$COMPILER" ] ; then if [ -z "$COMPILER" ] ; then
COMPILER=$(command -v cc 2> /dev/null) COMPILER=$(which cc 2> /dev/null)
fi; fi;
if [ -z "$COMPILER" ] ; then if [ -z "$COMPILER" ] ; then
echo echo
@@ -122,9 +122,9 @@ if [ $COMPILER_MAJOR -lt 4 -o $COMPILER_MAJOR -eq 4 -a $COMPILER_MINOR -lt 8 ] ;
fi; fi;
# check for host CXX # check for host CXX
CXXCOMPILER=$(command -v $HOSTCXX_NOCCACHE 2> /dev/null) CXXCOMPILER=$(which $HOSTCXX_NOCCACHE 2> /dev/null)
if [ -z "$CXXCOMPILER" ] ; then if [ -z "$CXXCOMPILER" ] ; then
CXXCOMPILER=$(command -v c++ 2> /dev/null) CXXCOMPILER=$(which c++ 2> /dev/null)
fi fi
if [ -z "$CXXCOMPILER" ] ; then if [ -z "$CXXCOMPILER" ] ; then
@@ -164,7 +164,7 @@ fi
# Check that a few mandatory programs are installed # Check that a few mandatory programs are installed
missing_progs="no" missing_progs="no"
for prog in perl tar wget cpio unzip rsync bc ${DL_TOOLS} ; do for prog in perl tar wget cpio unzip rsync bc ${DL_TOOLS} ; do
if ! command -v $prog > /dev/null ; then if ! which $prog > /dev/null ; then
echo "You must install '$prog' on your build machine"; echo "You must install '$prog' on your build machine";
missing_progs="yes" missing_progs="yes"
if test $prog = "svn" ; then if test $prog = "svn" ; then
@@ -198,7 +198,7 @@ if [ "${PATCH_MAJOR}" -lt 2 ] || [ "${PATCH_MAJOR}" -eq 2 -a "${PATCH_MINOR}" -l
fi fi
if grep ^BR2_NEEDS_HOST_UTF8_LOCALE=y $BR2_CONFIG > /dev/null; then if grep ^BR2_NEEDS_HOST_UTF8_LOCALE=y $BR2_CONFIG > /dev/null; then
if ! command -v locale > /dev/null ; then if ! which locale > /dev/null ; then
echo echo
echo "You need locale support on your build machine to build a toolchain supporting locales" echo "You need locale support on your build machine to build a toolchain supporting locales"
exit 1 ; exit 1 ;

View File

@@ -74,7 +74,7 @@ endif
ifeq ($(TOOLCHAIN_EXTERNAL_INSTALL_DIR),) ifeq ($(TOOLCHAIN_EXTERNAL_INSTALL_DIR),)
ifneq ($(TOOLCHAIN_EXTERNAL_PREFIX),) ifneq ($(TOOLCHAIN_EXTERNAL_PREFIX),)
# if no path set, figure it out from path # if no path set, figure it out from path
TOOLCHAIN_EXTERNAL_BIN := $(dir $(shell command -v $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc)) TOOLCHAIN_EXTERNAL_BIN := $(dir $(shell which $(TOOLCHAIN_EXTERNAL_PREFIX)-gcc))
endif endif
else else
TOOLCHAIN_EXTERNAL_REL_BIN_PATH = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_REL_BIN_PATH)) TOOLCHAIN_EXTERNAL_REL_BIN_PATH = $(call qstrip,$(BR2_TOOLCHAIN_EXTERNAL_REL_BIN_PATH))