From: "Loïc Minier" <lool@dooz.org>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Stop using "which" in ./configure
Date: Wed, 20 Jan 2010 10:02:44 +0100 [thread overview]
Message-ID: <20100120090244.GA22351@bee.dooz.org> (raw)
In-Reply-To: <4B55EF10.7080502@mail.berlios.de>
[-- Attachment #1: Type: text/plain, Size: 220 bytes --]
On Tue, Jan 19, 2010, Stefan Weil wrote:
> I did not test the whole patch, but I think this would be better:
> + type "$local_command" >/dev/null 2>&1
Attaching an updated patch
Thanks
--
Loïc Minier
[-- Attachment #2: 0001-Add-and-use-has-and-path_of-funcs.patch --]
[-- Type: text/x-diff, Size: 4045 bytes --]
>From 1c0b63fb9fc735a6d367a65a6ed1b998942fb6a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Minier?= <lool@dooz.org>
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..db97a2c 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 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"
+ 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
next prev parent reply other threads:[~2010-01-20 9:03 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-17 12:45 [Qemu-devel] [PATCH] Check for sdl-config before calling it Loïc Minier
2010-01-17 13:17 ` [Qemu-devel] " Måns Rullgård
2010-01-17 13:43 ` Stefan Weil
2010-01-17 14:39 ` Måns Rullgård
2010-01-19 10:11 ` [Qemu-devel] Stop using "which" in ./configure Loïc Minier
2010-01-19 11:47 ` Loïc Minier
2010-01-19 17:42 ` Stefan Weil
2010-01-20 9:02 ` Loïc Minier [this message]
2010-01-19 18:09 ` [Qemu-devel] " Måns Rullgård
2010-01-20 11:37 ` Loïc Minier
2010-01-20 12:19 ` Paolo Bonzini
2010-01-20 13:49 ` Loïc Minier
2010-01-20 14:18 ` Paolo Bonzini
2010-01-20 16:51 ` Loïc Minier
2010-01-20 18:11 ` Måns Rullgård
2010-01-21 8:44 ` Loïc Minier
2010-01-21 9:48 ` Juan Quintela
2010-01-21 12:14 ` Måns Rullgård
2010-01-26 16:47 ` Loïc Minier
2010-01-26 19:16 ` Blue Swirl
2010-01-27 12:10 ` [Qemu-devel] [PATCH 1/3] Check for sdl-config before calling it Loïc Minier
2010-01-27 12:10 ` [Qemu-devel] [PATCH 2/3] Add and use has() and path_of() funcs Loïc Minier
2010-01-27 12:10 ` [Qemu-devel] [PATCH 3/3] Solaris: test for presence of commands with has() Loïc Minier
2010-01-27 12:47 ` [Qemu-devel] [PATCH 1/3] Check for sdl-config before calling it Ben Taylor
2010-01-27 13:02 ` [Qemu-devel] " Paolo Bonzini
2010-01-27 12:41 ` [Qemu-devel] Re: Stop using "which" in ./configure Loïc Minier
2010-01-27 17:54 ` Blue Swirl
2010-01-28 20:33 ` Loïc Minier
2010-01-28 21:30 ` Blue Swirl
2010-01-21 16:53 ` Jamie Lokier
2010-01-21 20:12 ` Paolo Bonzini
2010-01-20 12:49 ` Juan Quintela
2010-01-20 13:16 ` Paolo Bonzini
2010-01-20 13:54 ` Loïc Minier
2010-01-20 14:06 ` Loïc Minier
2010-01-17 13:36 ` [Qemu-devel] [PATCH] Check for sdl-config before calling it Stefan Weil
2010-01-17 16:06 ` Loïc Minier
2010-01-18 11:35 ` [Qemu-devel] " Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2010-01-19 10:35 [Qemu-devel] Stop using "which" in ./configure Laurent Vivier
2010-01-19 11:40 ` Loïc Minier
2010-01-19 13:58 ` Krumme, Chris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100120090244.GA22351@bee.dooz.org \
--to=lool@dooz.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.