Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXseH-0004C4-OX for qemu-devel@nongnu.org; Thu, 21 Jan 2010 03:44:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXseA-00049p-Rt for qemu-devel@nongnu.org; Thu, 21 Jan 2010 03:44:15 -0500 Received: from [199.232.76.173] (port=37354 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXse9-00049f-SE for qemu-devel@nongnu.org; Thu, 21 Jan 2010 03:44:09 -0500 Received: from duck.dooz.org ([194.146.227.125]:33547) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXse9-0001dm-6n for qemu-devel@nongnu.org; Thu, 21 Jan 2010 03:44:09 -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 54B84C809C for ; Thu, 21 Jan 2010 09:44:07 +0100 (CET) Date: Thu, 21 Jan 2010 09:44:06 +0100 From: =?iso-8859-1?Q?Lo=EFc?= Minier Subject: Re: [Qemu-devel] Re: Stop using "which" in ./configure Message-ID: <20100121084406.GA3644@bee.dooz.org> References: <20100119101119.GA11358@bee.dooz.org> <20100119114750.GB11613@bee.dooz.org> <20100120113741.GA31679@pig.zood.org> <20100120134940.GA547@pig.zood.org> <20100120165103.GA3303@pig.zood.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Nq2Wo0NMKNjxTN9z" Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jan 20, 2010, M=E5ns Rullg=E5rd wrote: > If you make that IFS=3D${local_ifs:-$(printf ' \t\n')} it should be saf= e. > Likewise if you set the value first. Ok; see attached patches --=20 Lo=EFc Minier --Nq2Wo0NMKNjxTN9z Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Add-and-use-has-and-path_of-funcs.patch" >From cccdcaeacc2214390c0c6c198ed875ac59d10669 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 1/2] 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 | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 43 insertions(+), 9 deletions(-) diff --git a/configure b/configure index baa2800..eb02de3 100755 --- a/configure +++ b/configure @@ -27,6 +27,42 @@ 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() { + type "$1" >/dev/null 2>&1 +} + +# 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:-$(printf ' \t\n')}" + return 0 + fi + done + # not found + IFS="${local_ifs:-$(printf ' \t\n')}" + return 1 +} + # default parameters cpu="" prefix="" @@ -763,7 +799,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 +812,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 +1005,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 +1013,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 +1029,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 +1460,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 +1729,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 --Nq2Wo0NMKNjxTN9z Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0002-Solaris-test-for-presence-of-commands-with-has.patch" >From 430b06dcc84e82987d0146ef92dddbe838d6a117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Minier?= Date: Wed, 20 Jan 2010 12:35:54 +0100 Subject: [PATCH 2/2] Solaris: test for presence of commands with has() --- configure | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-) diff --git a/configure b/configure index eb02de3..f59f3e2 100755 --- a/configure +++ b/configure @@ -799,21 +799,19 @@ fi # Solaris specific configure tool chain decisions # if test "$solaris" = "yes" ; then - solinst=`path_of $install` - if test -z "$solinst" ; then + if ! has $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 "`path_of $install`" = "/usr/sbin/install" ; 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=`path_of ar` - if test -z "$sol_ar" ; then + if ! has 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" -- 1.6.5 --Nq2Wo0NMKNjxTN9z--