Patchwork [1/5] substitute all uses of which by type

login
register
mail settings
Submitter Juan Quintela
Date Jan. 20, 2010, 5:27 p.m.
Message ID <f95b339dffed5629c1cbd0baf8afc134f7f9124b.1264008180.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/43325/
State New
Headers show

Comments

Juan Quintela - Jan. 20, 2010, 5:27 p.m.
Except in one case, we are only interested in knowing if a command
exist, not is path.  Just create prog_exists() function that does this
check.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 configure |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)
Stefan Weil - Jan. 20, 2010, 6:40 p.m.
Juan Quintela schrieb:
> Except in one case, we are only interested in knowing if a command
> exist, not is path. Just create prog_exists() function that does this
> check.
>
> Signed-off-by: Juan Quintela <quintela@redhat.com>

See comments below. The changes proposed are a suggestion, no real need.

Regards,
Stefan

> ---
> configure | 25 ++++++++++++++-----------
> 1 files changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/configure b/configure
> index 5631bbb..71edaf5 100755
> --- a/configure
> +++ b/configure
> @@ -27,6 +27,11 @@ compile_prog() {
> $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
> > /dev/null 2> /dev/null
> }
>
> +prog_exist() {
> + prog="$1"
> + type $prog > /dev/null 2> /dev/null

I personally prefer
+ type $prog >/dev/null 2>&1
because it is shorter (no whitespace after >, no duplicate /dev/null).
Currently, all variants to write this pattern are used.
Maybe we can reduce this.

> +}
> +
> # default parameters
> cpu=""
> prefix=""
> @@ -763,21 +768,19 @@ 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"`
2>/dev/null
> - if test -z "$solinst" ; then
> + if ! prog_exist "$install" ; 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"
> echo "to get ginstall which is used by default (which lives in
> /opt/csw/bin)"
> exit 1
> fi
> - if test "$solinst" = "/usr/sbin/install" ; then
> + if type "$install" 2> /dev/null | grep /usr/bin/install >/dev/null ;
> then
2>/dev/null
> echo "Error: Solaris /usr/sbin/install is not an appropriate install
> program."
> echo "try ginstall from the GNU fileutils available from
> www.blastwave.org"
> 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"`
> - if test -z "$sol_ar" ; then
> + if ! prog_exist "ar" ; then
> echo "Error: No path includes ar"
> if test -f /usr/ccs/bin/ar ; then
> echo "Add /usr/ccs/bin to your path and rerun configure"
> @@ -969,7 +972,7 @@ fi
> # pkgconfig probe
>
> pkgconfig="${cross_prefix}pkg-config"
> -if ! test -x "$(which $pkgconfig 2>/dev/null)"; then
> +if ! prog_exist "$pkgconfig" ; then
> # likely not cross compiling, or hope for the best
> pkgconfig=pkg-config
> fi
> @@ -977,7 +980,7 @@ fi
> ##########################################
> # Sparse probe
> if test "$sparse" != "no" ; then
> - if test -x "$(which cgcc 2>/dev/null)"; then
> + if prog_exist "cgcc" ; then
> sparse=yes
> else
> if test "$sparse" = "yes" ; then
> @@ -1419,8 +1422,8 @@ EOF
> fi
> else
> if test "$kvm" = "yes" ; then
> - if [ -x "`which awk 2>/dev/null`" ] && \
> - [ -x "`which grep 2>/dev/null`" ]; then
> + if prog_exist "awk" && \
> + prog_exist "grep"; then
> kvmerr=`LANG=C $cc $QEMU_CFLAGS -o $TMPE $kvm_cflags $TMPC 2>&1 \
> | grep "error: " \
> | awk -F "error: " '{if (NR>1) printf(", "); printf("%s",$2);}'`
> @@ -1689,8 +1692,8 @@ fi
>
> # Check if tools are available to build documentation.
> if test "$docs" != "no" ; then
> - if test -x "`which texi2html 2>/dev/null`" -a \
> - -x "`which pod2man 2>/dev/null`" ; then
> + if prog_exist "texi2html" && \
> + prog_exist "pod2man" ; then
> docs=yes
> else
> if test "$docs" = "yes" ; then
Juan Quintela - Jan. 20, 2010, 6:52 p.m.
Stefan Weil <weil@mail.berlios.de> wrote:
> Juan Quintela schrieb:
>> Except in one case, we are only interested in knowing if a command
>> exist, not is path. Just create prog_exists() function that does this
>> check.
>>
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>
> See comments below. The changes proposed are a suggestion, no real need.
>
> Regards,
> Stefan
>
>> ---
>> configure | 25 ++++++++++++++-----------
>> 1 files changed, 14 insertions(+), 11 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 5631bbb..71edaf5 100755
>> --- a/configure
>> +++ b/configure
>> @@ -27,6 +27,11 @@ compile_prog() {
>> $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
>> > /dev/null 2> /dev/null
>> }
>>
>> +prog_exist() {
>> + prog="$1"
>> + type $prog > /dev/null 2> /dev/null
>
> I personally prefer
> + type $prog >/dev/null 2>&1
> because it is shorter (no whitespace after >, no duplicate /dev/null).
> Currently, all variants to write this pattern are used.
> Maybe we can reduce this.

Agreed.  For next series if there is not needed a rebase.

Later, Juan.

Patch

diff --git a/configure b/configure
index 5631bbb..71edaf5 100755
--- a/configure
+++ b/configure
@@ -27,6 +27,11 @@  compile_prog() {
   $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags > /dev/null 2> /dev/null
 }

+prog_exist() {
+    prog="$1"
+    type $prog > /dev/null 2> /dev/null
+}
+
 # default parameters
 cpu=""
 prefix=""
@@ -763,21 +768,19 @@  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"`
-  if test -z "$solinst" ; then
+  if ! prog_exist "$install" ; 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"
     echo "to get ginstall which is used by default (which lives in /opt/csw/bin)"
     exit 1
   fi
-  if test "$solinst" = "/usr/sbin/install" ; then
+  if type "$install" 2> /dev/null | grep /usr/bin/install >/dev/null ; then
     echo "Error: Solaris /usr/sbin/install is not an appropriate install program."
     echo "try ginstall from the GNU fileutils available from www.blastwave.org"
     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"`
-  if test -z "$sol_ar" ; then
+  if ! prog_exist "ar" ; then
     echo "Error: No path includes ar"
     if test -f /usr/ccs/bin/ar ; then
       echo "Add /usr/ccs/bin to your path and rerun configure"
@@ -969,7 +972,7 @@  fi
 # pkgconfig probe

 pkgconfig="${cross_prefix}pkg-config"
-if ! test -x "$(which $pkgconfig 2>/dev/null)"; then
+if ! prog_exist "$pkgconfig" ; then
   # likely not cross compiling, or hope for the best
   pkgconfig=pkg-config
 fi
@@ -977,7 +980,7 @@  fi
 ##########################################
 # Sparse probe
 if test "$sparse" != "no" ; then
-  if test -x "$(which cgcc 2>/dev/null)"; then
+  if prog_exist "cgcc" ; then
     sparse=yes
   else
     if test "$sparse" = "yes" ; then
@@ -1419,8 +1422,8 @@  EOF
     fi
   else
     if test "$kvm" = "yes" ; then
-      if [ -x "`which awk 2>/dev/null`" ] && \
-         [ -x "`which grep 2>/dev/null`" ]; then
+      if prog_exist "awk" && \
+         prog_exist "grep"; then
         kvmerr=`LANG=C $cc $QEMU_CFLAGS -o $TMPE $kvm_cflags $TMPC 2>&1 \
 	| grep "error: " \
 	| awk -F "error: " '{if (NR>1) printf(", "); printf("%s",$2);}'`
@@ -1689,8 +1692,8 @@  fi

 # Check if tools are available to build documentation.
 if test "$docs" != "no" ; then
-  if test -x "`which texi2html 2>/dev/null`" -a \
-          -x "`which pod2man 2>/dev/null`" ; then
+  if prog_exist "texi2html" && \
+     prog_exist "pod2man" ; then
     docs=yes
   else
     if test "$docs" = "yes" ; then