From patchwork Tue Jan 19 11:47:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lo=C3=AFc_Minier?= X-Patchwork-Id: 43187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 701D8B7CD8 for ; Tue, 19 Jan 2010 22:50:45 +1100 (EST) Received: from localhost ([127.0.0.1]:48699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXCaG-00024X-CO for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2010 06:49:20 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXCYv-00023I-P6 for qemu-devel@nongnu.org; Tue, 19 Jan 2010 06:47:57 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXCYr-00022k-9C for qemu-devel@nongnu.org; Tue, 19 Jan 2010 06:47:57 -0500 Received: from [199.232.76.173] (port=34798 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXCYr-00022h-5D for qemu-devel@nongnu.org; Tue, 19 Jan 2010 06:47:53 -0500 Received: from duck.dooz.org ([194.146.227.125]:37041) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXCYq-0006Zw-Lt for qemu-devel@nongnu.org; Tue, 19 Jan 2010 06:47:52 -0500 Received: from bee.dooz.org (serris.dooz.org [88.166.229.232]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by duck.dooz.org (Postfix) with ESMTP id 9E06DC809C for ; Tue, 19 Jan 2010 12:47:51 +0100 (CET) Received: by bee.dooz.org (Postfix, from userid 1000) id 5D2C28A2; Tue, 19 Jan 2010 12:47:50 +0100 (CET) Date: Tue, 19 Jan 2010 12:47:50 +0100 From: =?iso-8859-1?Q?Lo=EFc?= Minier To: qemu-devel@nongnu.org Subject: Re: [Qemu-devel] Stop using "which" in ./configure Message-ID: <20100119114750.GB11613@bee.dooz.org> References: <20100117124528.GA24106@bee.dooz.org> <4B531406.2070904@mail.berlios.de> <20100119101119.GA11358@bee.dooz.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20100119101119.GA11358@bee.dooz.org> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. From 5fc05ec61d87049ea0f29b2dd51c16e260698ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Minier?= 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 +} + +# 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 @@ -969,7 +1006,7 @@ fi # pkgconfig probe pkgconfig="${cross_prefix}pkg-config" -if ! test -x "$(which $pkgconfig 2>/dev/null)"; then +if ! has $pkgconfig; then # likely not cross compiling, or hope for the best pkgconfig=pkg-config fi @@ -977,7 +1014,7 @@ fi ########################################## # Sparse probe if test "$sparse" != "no" ; then - if test -x "$(which cgcc 2>/dev/null)"; then + if has cgcc; then sparse=yes else if test "$sparse" = "yes" ; then @@ -993,7 +1030,7 @@ fi if $pkgconfig sdl --modversion >/dev/null 2>&1; then sdlconfig="$pkgconfig sdl" _sdlversion=`$sdlconfig --modversion 2>/dev/null | sed 's/[^0-9]//g'` -elif which sdl-config >/dev/null 2>&1; then +elif has sdl-config; then sdlconfig='sdl-config' _sdlversion=`$sdlconfig --version | sed 's/[^0-9]//g'` else @@ -1424,8 +1461,7 @@ EOF fi else if test "$kvm" = "yes" ; then - if [ -x "`which awk 2>/dev/null`" ] && \ - [ -x "`which grep 2>/dev/null`" ]; then + if has awk && has 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);}'` @@ -1694,8 +1730,7 @@ 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 has texi2html && has pod2man; then docs=yes else if test "$docs" = "yes" ; then -- 1.6.5