* RE: [Qemu-devel] Stop using "which" in ./configure
@ 2010-01-19 10:35 Laurent Vivier
2010-01-19 11:40 ` Loïc Minier
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Laurent Vivier @ 2010-01-19 10:35 UTC (permalink / raw)
To: lool; +Cc: qemu-devel
> Hi
>
> 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.)
>
> Thanks,
Why don't you use "type -P" for "path_of" ?"
Regards,
Laurent
--
--------------------- Laurent@vivier.eu ---------------------
"Tout ce qui est impossible reste à accomplir" Jules Verne
"Things are only impossible until they're not" Jean-Luc Picard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Stop using "which" in ./configure
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
2010-01-19 18:01 ` [Qemu-devel] " Måns Rullgård
2 siblings, 0 replies; 8+ messages in thread
From: Loïc Minier @ 2010-01-19 11:40 UTC (permalink / raw)
To: qemu-devel
On Tue, Jan 19, 2010, Laurent Vivier wrote:
> Why don't you use "type -P" for "path_of" ?"
I don't think that's portable enough:
$ sh -c 'type -P ls'
-P: not found
ls is /bin/ls
--
Loïc Minier
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [Qemu-devel] Stop using "which" in ./configure
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
2010-01-19 18:01 ` [Qemu-devel] " Måns Rullgård
2 siblings, 0 replies; 8+ messages in thread
From: Krumme, Chris @ 2010-01-19 13:58 UTC (permalink / raw)
To: Laurent Vivier, lool; +Cc: qemu-devel
Hello Laurent,
Good or bad "type -P" skips the aliases.
Thanks
Chris
> -----Original Message-----
> From:
> qemu-devel-bounces+chris.krumme=windriver.com@nongnu.org
> [mailto:qemu-devel-bounces+chris.krumme=windriver.com@nongnu.o
> rg] On Behalf Of Laurent Vivier
> Sent: Tuesday, January 19, 2010 4:36 AM
> To: lool@dooz.org
> Cc: qemu-devel@nongnu.org
> Subject: RE: [Qemu-devel] Stop using "which" in ./configure
>
> > Hi
> >
> > 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.)
> >
> > Thanks,
>
> Why don't you use "type -P" for "path_of" ?"
>
> Regards,
> Laurent
> --
> --------------------- Laurent@vivier.eu ---------------------
> "Tout ce qui est impossible reste à accomplir" Jules Verne
> "Things are only impossible until they're not" Jean-Luc Picard
>
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] Re: Stop using "which" in ./configure
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
@ 2010-01-19 18:01 ` Måns Rullgård
2 siblings, 0 replies; 8+ messages in thread
From: Måns Rullgård @ 2010-01-19 18:01 UTC (permalink / raw)
To: qemu-devel
Laurent Vivier <Laurent@Vivier.EU> writes:
>> Hi
>>
>> 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.)
>>
>> Thanks,
>
> Why don't you use "type -P" for "path_of" ?"
The standard "type" has no options.
--
Måns Rullgård
mans@mansr.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH] Check for sdl-config before calling it
@ 2010-01-17 12:45 Loïc Minier
2010-01-17 13:17 ` [Qemu-devel] " Måns Rullgård
0 siblings, 1 reply; 8+ messages in thread
From: Loïc Minier @ 2010-01-17 12:45 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 223 bytes --]
Hi
On systems were sdl-config isn't installed, ./configure triggers this
warning:
./configure: 957: sdl-config: not found
The attached patch fixes the warning for me.
Thanks,
--
Loïc Minier
[-- Attachment #2: 0001-Check-for-sdl-config-before-calling-it.patch --]
[-- Type: text/x-diff, Size: 1150 bytes --]
>From 94876939db7f46cf8d920e289d0d4f929d3b7df1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Minier?= <lool@dooz.org>
Date: Sun, 17 Jan 2010 13:42:04 +0100
Subject: [PATCH] Check for sdl-config before calling it
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Check whether sdl-config is available before calling it, otherwise
./configure triggers a warning:
./configure: 957: sdl-config: not found
If neither the .pc file not sdl-config are present, disable SDL support.
Signed-off-by: Loïc Minier <lool@dooz.org>
---
configure | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/configure b/configure
index 5631bbb..450e1a2 100755
--- a/configure
+++ b/configure
@@ -993,9 +993,11 @@ fi
if $pkgconfig sdl --modversion >/dev/null 2>&1; then
sdlconfig="$pkgconfig sdl"
_sdlversion=`$sdlconfig --modversion 2>/dev/null | sed 's/[^0-9]//g'`
-else
+elif which sdl-config >/dev/null 2>&1; then
sdlconfig='sdl-config'
_sdlversion=`$sdlconfig --version | sed 's/[^0-9]//g'`
+else
+ sdl=no
fi
sdl_too_old=no
--
1.6.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] Re: [PATCH] Check for sdl-config before calling it
2010-01-17 12:45 [Qemu-devel] [PATCH] Check for sdl-config before calling it Loïc Minier
@ 2010-01-17 13:17 ` Måns Rullgård
2010-01-17 13:43 ` Stefan Weil
0 siblings, 1 reply; 8+ messages in thread
From: Måns Rullgård @ 2010-01-17 13:17 UTC (permalink / raw)
To: qemu-devel
Loïc Minier <lool@dooz.org> writes:
> Hi
>
> On systems were sdl-config isn't installed, ./configure triggers this
> warning:
> ./configure: 957: sdl-config: not found
>
> The attached patch fixes the warning for me.
>
> Thanks,
> --
> Loïc Minier
>
> From 94876939db7f46cf8d920e289d0d4f929d3b7df1 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Lo=C3=AFc=20Minier?= <lool@dooz.org>
> Date: Sun, 17 Jan 2010 13:42:04 +0100
> Subject: [PATCH] Check for sdl-config before calling it
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> Check whether sdl-config is available before calling it, otherwise
> ./configure triggers a warning:
> ./configure: 957: sdl-config: not found
>
> If neither the .pc file not sdl-config are present, disable SDL support.
>
> Signed-off-by: Loïc Minier <lool@dooz.org>
> ---
> configure | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/configure b/configure
> index 5631bbb..450e1a2 100755
> --- a/configure
> +++ b/configure
> @@ -993,9 +993,11 @@ fi
> if $pkgconfig sdl --modversion >/dev/null 2>&1; then
> sdlconfig="$pkgconfig sdl"
> _sdlversion=`$sdlconfig --modversion 2>/dev/null | sed 's/[^0-9]//g'`
> -else
> +elif which sdl-config >/dev/null 2>&1; then
> sdlconfig='sdl-config'
> _sdlversion=`$sdlconfig --version | sed 's/[^0-9]//g'`
> +else
> + sdl=no
> fi
"which" isn't a standard command. Would simply 2>/dev/null do the
trick just as well? If you really need to test for the existence of
something, use "type".
--
Måns Rullgård
mans@mansr.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Re: [PATCH] Check for sdl-config before calling it
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
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Weil @ 2010-01-17 13:43 UTC (permalink / raw)
To: Måns Rullgård; +Cc: qemu-devel
Måns Rullgård schrieb:
> Loïc Minier <lool@dooz.org> writes:
>
>
>> Hi
>>
>> On systems were sdl-config isn't installed, ./configure triggers this
>> warning:
>> ./configure: 957: sdl-config: not found
>>
>> The attached patch fixes the warning for me.
>>
>> Thanks,
>> --
>> Loïc Minier
>>
>> From 94876939db7f46cf8d920e289d0d4f929d3b7df1 Mon Sep 17 00:00:00 2001
>> From: =?UTF-8?q?Lo=C3=AFc=20Minier?= <lool@dooz.org>
>> Date: Sun, 17 Jan 2010 13:42:04 +0100
>> Subject: [PATCH] Check for sdl-config before calling it
>> MIME-Version: 1.0
>> Content-Type: text/plain; charset=UTF-8
>> Content-Transfer-Encoding: 8bit
>>
>> Check whether sdl-config is available before calling it, otherwise
>> ./configure triggers a warning:
>> ./configure: 957: sdl-config: not found
>>
>> If neither the .pc file not sdl-config are present, disable SDL support.
>>
>> Signed-off-by: Loïc Minier <lool@dooz.org>
>> ---
>> configure | 4 +++-
>> 1 files changed, 3 insertions(+), 1 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 5631bbb..450e1a2 100755
>> --- a/configure
>> +++ b/configure
>> @@ -993,9 +993,11 @@ fi
>> if $pkgconfig sdl --modversion >/dev/null 2>&1; then
>> sdlconfig="$pkgconfig sdl"
>> _sdlversion=`$sdlconfig --modversion 2>/dev/null | sed 's/[^0-9]//g'`
>> -else
>> +elif which sdl-config >/dev/null 2>&1; then
>> sdlconfig='sdl-config'
>> _sdlversion=`$sdlconfig --version | sed 's/[^0-9]//g'`
>> +else
>> + sdl=no
>> fi
>>
>
> "which" isn't a standard command. Would simply 2>/dev/null do the
> trick just as well? If you really need to test for the existence of
> something, use "type".
>
"which" is already used several times in configure,
so this would not make things worse.
A macro for all these tests might be a better solution.
And that macro should use "type" or "type -t".
Regards,
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] Re: [PATCH] Check for sdl-config before calling it
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
0 siblings, 1 reply; 8+ messages in thread
From: Måns Rullgård @ 2010-01-17 14:39 UTC (permalink / raw)
To: qemu-devel
Stefan Weil <weil@mail.berlios.de> writes:
> Måns Rullgård schrieb:
>> Loïc Minier <lool@dooz.org> writes:
>>
>>
>>> Hi
>>>
>>> On systems were sdl-config isn't installed, ./configure triggers this
>>> warning:
>>> ./configure: 957: sdl-config: not found
>>>
>>> The attached patch fixes the warning for me.
>>>
>>> Thanks,
>>> --
>>> Loïc Minier
>>>
>>> From 94876939db7f46cf8d920e289d0d4f929d3b7df1 Mon Sep 17 00:00:00 2001
>>> From: =?UTF-8?q?Lo=C3=AFc=20Minier?= <lool@dooz.org>
>>> Date: Sun, 17 Jan 2010 13:42:04 +0100
>>> Subject: [PATCH] Check for sdl-config before calling it
>>> MIME-Version: 1.0
>>> Content-Type: text/plain; charset=UTF-8
>>> Content-Transfer-Encoding: 8bit
>>>
>>> Check whether sdl-config is available before calling it, otherwise
>>> ./configure triggers a warning:
>>> ./configure: 957: sdl-config: not found
>>>
>>> If neither the .pc file not sdl-config are present, disable SDL support.
>>>
>>> Signed-off-by: Loïc Minier <lool@dooz.org>
>>> ---
>>> configure | 4 +++-
>>> 1 files changed, 3 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/configure b/configure
>>> index 5631bbb..450e1a2 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -993,9 +993,11 @@ fi
>>> if $pkgconfig sdl --modversion >/dev/null 2>&1; then
>>> sdlconfig="$pkgconfig sdl"
>>> _sdlversion=`$sdlconfig --modversion 2>/dev/null | sed 's/[^0-9]//g'`
>>> -else
>>> +elif which sdl-config >/dev/null 2>&1; then
>>> sdlconfig='sdl-config'
>>> _sdlversion=`$sdlconfig --version | sed 's/[^0-9]//g'`
>>> +else
>>> + sdl=no
>>> fi
>>>
>>
>> "which" isn't a standard command. Would simply 2>/dev/null do the
>> trick just as well? If you really need to test for the existence of
>> something, use "type".
>>
>
> "which" is already used several times in configure,
Then those should be fixed.
> so this would not make things worse.
One error does not justify another.
> A macro for all these tests might be a better solution.
> And that macro should use "type" or "type -t".
"type -t" is also not standard. The standard "type" has no options.
In most cases the simpler solution is still probably to try the
command and let it fail.
--
Måns Rullgård
mans@mansr.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] Stop using "which" in ./configure
2010-01-17 14:39 ` Måns Rullgård
@ 2010-01-19 10:11 ` Loïc Minier
2010-01-19 11:47 ` Loïc Minier
0 siblings, 1 reply; 8+ messages in thread
From: Loïc Minier @ 2010-01-19 10:11 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 408 bytes --]
Hi
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.)
Thanks,
--
Loïc Minier
[-- Attachment #2: 0001-Add-and-use-has-and-path_of-funcs.patch --]
[-- Type: text/x-diff, Size: 4257 bytes --]
>From 815ca36e9b3e2c56040d7fc7709c95d600ed6496 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 | 57 ++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 48 insertions(+), 9 deletions(-)
diff --git a/configure b/configure
index baa2800..8d67b9c 100755
--- a/configure
+++ b/configure
@@ -27,6 +27,47 @@ 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_path="$PATH"
+ local_dir=""
+ # absolute path?
+ if [ "${local_command#*/}" != "$local_command" ]; then
+ if [ -x "$local_command" ] && [ ! -d "$local_command" ]; then
+ echo "$local_command"
+ return 0
+ fi
+ fi
+ if [ -z "$local_path" ] || [ -z "$local_command" ]; then
+ return 1
+ fi
+ while :; do
+ local_dir="${local_path%%:*}"
+ if [ "${local_path#*:}" = "$local_path" ]; then
+ # last loop
+ local_path=""
+ else
+ local_path="${local_path#*:}"
+ fi
+ if [ -x "$local_dir/$local_command" ] && [ ! -d "$local_dir/$local_command" ]; then
+ echo "$local_dir/$local_command"
+ return 0
+ fi
+ if [ -z "$local_path" ]; then
+ # not found
+ return 1
+ fi
+ done
+}
+
# default parameters
cpu=""
prefix=""
@@ -763,7 +804,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 +817,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 +1010,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 +1018,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 +1034,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 +1465,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 +1734,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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Stop using "which" in ./configure
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
0 siblings, 1 reply; 8+ messages in thread
From: Loïc Minier @ 2010-01-19 11:47 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 649 bytes --]
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
[-- Attachment #2: 0001-Add-and-use-has-and-path_of-funcs.patch --]
[-- Type: text/x-diff, Size: 4040 bytes --]
>From 5fc05ec61d87049ea0f29b2dd51c16e260698ef8 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..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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Stop using "which" in ./configure
2010-01-19 11:47 ` Loïc Minier
@ 2010-01-19 17:42 ` Stefan Weil
2010-01-20 9:02 ` Loïc Minier
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Weil @ 2010-01-19 17:42 UTC (permalink / raw)
To: Loïc Minier; +Cc: qemu-devel
Loïc Minier schrieb:
> 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.
I did not test the whole patch, but I think this would be better:
+ type "$local_command" >/dev/null 2>&1
(type sends error messages to stderr, we don't want to see them)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Stop using "which" in ./configure
2010-01-19 17:42 ` Stefan Weil
@ 2010-01-20 9:02 ` Loïc Minier
0 siblings, 0 replies; 8+ messages in thread
From: Loïc Minier @ 2010-01-20 9:02 UTC (permalink / raw)
To: qemu-devel
[-- 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
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-01-20 9:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2010-01-19 18:01 ` [Qemu-devel] " Måns Rullgård
-- strict thread matches above, loose matches on Subject: below --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).