qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Re: Stop using "which" in ./configure


From: Måns Rullgård
Subject: [Qemu-devel] Re: Stop using "which" in ./configure
Date: Tue, 19 Jan 2010 18:09:45 +0000
User-agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (Instant Classic, linux)

Loïc Minier <address@hidden> writes:

> On Tue, Jan 19, 2010, Loïc Minier wrote:
>>  Following the thread on the sdl-config patch, please find attached a
>>  patch to add a couple of portable shell functions which allow testing
>>  whehter a command/builtin is available and to find the full pathname of
>>  an executable in the PATH.  This also replaces all uses of "which" in
>>  ./configure.  (This should be applied on top of the sdl-config patch.)
>
>  Please find attached a new version of the patch with a simpler version
>  of path_of() which uses IFS instead of the ${foo#bar} and ${foo%%bar}
>  constructs.  It also removes the special casing of an empty PATH.
>
> -- 
> Loïc Minier
>
> From 5fc05ec61d87049ea0f29b2dd51c16e260698ef8 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Lo=C3=AFc=20Minier?= <address@hidden>
> Date: Tue, 19 Jan 2010 11:05:00 +0100
> Subject: [PATCH] Add and use has() and path_of() funcs
>
> Add has() and path_of() funcs and use them across configure; has()
> will test whether a command or builtin is available; path_of() will
> search the PATH for executables and return the full pathname if found.
> ---
>  configure |   53 ++++++++++++++++++++++++++++++++++++++++++++---------
>  1 files changed, 44 insertions(+), 9 deletions(-)
>
> diff --git a/configure b/configure
> index baa2800..711e335 100755
> --- a/configure
> +++ b/configure
> @@ -27,6 +27,43 @@ compile_prog() {
>    $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags > 
> /dev/null 2> /dev/null
>  }
>  
> +# check whether a command is available to this shell (may be either an
> +# executable or a builtin)
> +has() {
> +    local_command="$1"
> +    type "$local_command" >/dev/null
> +}

Why the extra variable?  Using $1 directly seems just as obvious to me.

> +# search for an executable in PATH
> +path_of() {
> +    local_command="$1"
> +    local_ifs="$IFS"
> +    local_dir=""
> +
> +    # pathname has a dir component?
> +    if [ "${local_command#*/}" != "$local_command" ]; then
> +        if [ -x "$local_command" ] && [ ! -d "$local_command" ]; then
> +            echo "$local_command"
> +            return 0
> +        fi
> +    fi
> +    if [ -z "$local_command" ]; then
> +        return 1
> +    fi
> +
> +    IFS=:
> +    for local_dir in $PATH; do
> +        if [ -x "$local_dir/$local_command" ] && [ ! -d 
> "$local_dir/$local_command" ]; then
> +            echo "$local_dir/$local_command"
> +            IFS="$local_ifs"
> +            return 0
> +        fi
> +    done
> +    # not found
> +    IFS="$local_ifs"
> +    return 1
> +}
> +
>  # default parameters
>  cpu=""
>  prefix=""
> @@ -763,7 +800,7 @@ fi
>  # Solaris specific configure tool chain decisions
>  #
>  if test "$solaris" = "yes" ; then
> -  solinst=`which $install 2> /dev/null | /usr/bin/grep -v "no $install in"`
> +  solinst=`path_of $install`
>    if test -z "$solinst" ; then
>      echo "Solaris install program not found. Use --install=/usr/ucb/install 
> or"
>      echo "install fileutils from www.blastwave.org using pkg-get -i 
> fileutils"
> @@ -776,7 +813,7 @@ if test "$solaris" = "yes" ; then
>      echo "using pkg-get -i fileutils, or use --install=/usr/ucb/install"
>      exit 1
>    fi
> -  sol_ar=`which ar 2> /dev/null | /usr/bin/grep -v "no ar in"`
> +  sol_ar=`path_of ar`
>    if test -z "$sol_ar" ; then
>      echo "Error: No path includes ar"
>      if test -f /usr/ccs/bin/ar ; then

Is the full path of these tools really important?  Doesn't look like
it to me.

-- 
Måns Rullgård
address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]