Patchwork [v2] Remove the extra -lrt switch

login
register
mail settings
Submitter Peter Portante
Date April 27, 2012, 8:16 p.m.
Message ID <1335557783-13575-1-git-send-email-peter.portante@redhat.com>
Download mbox | patch
Permalink /patch/155585/
State New
Headers show

Comments

Peter Portante - April 27, 2012, 8:16 p.m.
The package config check for gthreads might have already placed
a -lrt switch in LIBS earlier.

Refactored the code from the pthread switch removal, from commit
e3c56761b465a4253871c32b06ebbc2d8b3fc3e1, to make it work for the
more general case.

Signed-off-by: Peter Portante <peter.portante@redhat.com>
---
 configure |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)
Eric Blake - April 27, 2012, 9:55 p.m.
On 04/27/2012 02:16 PM, Peter Portante wrote:
> The package config check for gthreads might have already placed
> a -lrt switch in LIBS earlier.
> 
> Refactored the code from the pthread switch removal, from commit
> e3c56761b465a4253871c32b06ebbc2d8b3fc3e1, to make it work for the
> more general case.
> 

> +add_to_libs() {
> +  found=no
> +  for lib_entry in $LIBS; do
> +    if test "$lib_entry" = "$1"; then
> +      found=yes
> +      break
> +    fi
> +  done
> +  if test "$found" = "no"; then
> +    LIBS="$1 $LIBS"
> +  fi
> +}

Shorter (and probably faster) to write this as:

add_to_libs() {
  case " $LIBS " in
    " $1 ") ;;
    *) LIBS="$1 $LIBS" ;;
  esac
}
Peter Maydell - April 27, 2012, 10:16 p.m.
On 27 April 2012 22:55, Eric Blake <eblake@redhat.com> wrote:
> Shorter (and probably faster) to write this as:
>
> add_to_libs() {
>  case " $LIBS " in
>    " $1 ") ;;
>    *) LIBS="$1 $LIBS" ;;
>  esac
> }

...doesn't that need to be
     *" $1 "*) ;;

?

-- PMM
Andreas Färber - April 27, 2012, 10:20 p.m.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 27.04.2012 23:55, schrieb Eric Blake:
> On 04/27/2012 02:16 PM, Peter Portante wrote:
>> The package config check for gthreads might have already placed a
>> -lrt switch in LIBS earlier.
>> 
>> Refactored the code from the pthread switch removal, from commit 
>> e3c56761b465a4253871c32b06ebbc2d8b3fc3e1, to make it work for
>> the more general case.
>> 
> 
>> +add_to_libs() { +  found=no +  for lib_entry in $LIBS; do +
>> if test "$lib_entry" = "$1"; then +      found=yes +      break +
>> fi +  done +  if test "$found" = "no"; then +    LIBS="$1 $LIBS" 
>> +  fi +}
> 
> Shorter (and probably faster) to write this as:
> 
> add_to_libs() { case " $LIBS " in " $1 ") ;; *) LIBS="$1 $LIBS" ;; 
> esac }

Er, no. That would only catch the initial duplication case -lrt -lrt
but not -lbla -lrt -lrt or -lrt -lbla -lrt, wouldn't it?

But then again Peter's function wouldn't find duplicates when $1
contains a space either... tricky.

Andreas

- -- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)

iQIcBAEBAgAGBQJPmxuZAAoJEPou0S0+fgE/ycMP/iW+aPgv810H/RUAzc90pQf0
pjRh+R1dFKyukIcwGlYT7WiuAjLdNTM7HcUbOL1Gfads6ZvxEHonYBpNxTOi424U
kHpfhWU0hfZxv78Rv8gvD4VpSlIo6x4nwrmFvRKqskiOjPCf/yQ/Qde1MVJMmRAR
x1Mjmy1Wnm71smA8sbdSCqPM3VTWzqZKcXIkSw1kymz3g43OIM98QFNPz/EkwmQb
+q7pos8GwjanwQDBt4OQW5sYQDLpWMKA2na4tRYU/nxL6jXBi2BLXqm+8lbu1bhE
MHOulQZ90CELSiYyKgZeLNQCNrH4F/B4XoIwBgWhqV/ND1zWQndSDlWxWYVZ2DHY
awqs5KPOFybVWFfwFLaZ4cWefOPRJPNSHNufVdgVrjbn7UgXYZ/n97TAaHbqNX5/
HqtR/N4XSn4SYblsRXbkzNg6EcTdolLUuE/RSey46+NlfiCjWnr047SzJjoHmfyq
YRFf3VK7N8Aa46y8szQOvVCOBOv117U8uqzfzVEGn4zfmkYi6No+1O640SmsYGyY
Iii8EpBDCwyGzWw8o96R/BeJBufpNHg3vyUcWXAK5MEftHf/5aLhEmOAhGBz+TGU
jHKmhiXUSLFH0xVGOkwq0wNXKkMsHuk9hIYb6k687P/AV6Iu8SkEtG7/4HFV6RV/
btycq/KaQ75a7TJj/XFW
=+qrm
-----END PGP SIGNATURE-----
Eric Blake - April 27, 2012, 10:27 p.m.
On 04/27/2012 04:16 PM, Peter Maydell wrote:
> On 27 April 2012 22:55, Eric Blake <eblake@redhat.com> wrote:
>> Shorter (and probably faster) to write this as:
>>
>> add_to_libs() {
>>  case " $LIBS " in
>>    " $1 ") ;;
>>    *) LIBS="$1 $LIBS" ;;
>>  esac
>> }
> 
> ...doesn't that need to be
>      *" $1 "*) ;;

Yep; that's what I get for typing without testing.
Eric Blake - April 27, 2012, 10:30 p.m.
On 04/27/2012 04:20 PM, Andreas Färber wrote:
> Am 27.04.2012 23:55, schrieb Eric Blake:
>> On 04/27/2012 02:16 PM, Peter Portante wrote:
>>> The package config check for gthreads might have already placed a
>>> -lrt switch in LIBS earlier.
>>>
>>> Refactored the code from the pthread switch removal, from commit 
>>> e3c56761b465a4253871c32b06ebbc2d8b3fc3e1, to make it work for
>>> the more general case.
>>>
> 
>>> +add_to_libs() { +  found=no +  for lib_entry in $LIBS; do +
>>> if test "$lib_entry" = "$1"; then +      found=yes +      break +
>>> fi +  done +  if test "$found" = "no"; then +    LIBS="$1 $LIBS" 
>>> +  fi +}
> 
>> Shorter (and probably faster) to write this as:
> 
>> add_to_libs() { case " $LIBS " in " $1 ") ;; *) LIBS="$1 $LIBS" ;; 
>> esac }
> 
> Er, no. That would only catch the initial duplication case -lrt -lrt
> but not -lbla -lrt -lrt or -lrt -lbla -lrt, wouldn't it?
> 
> But then again Peter's function wouldn't find duplicates when $1
> contains a space either... tricky.

If you want to filter duplicates out of $1, then:

add_to_libs() {
  for lib in $1; do
    case " $LIBS " in
      *" $lib "*) ;;
      *) LIBS="$lib $LIBS" ;;
    esac
  done
}

Hopefully, we don't encounter any libs with circular dependencies, where
a lib must be listed twice to be effective.

Patch

diff --git a/configure b/configure
index 15bbc73..4c4ecfb 100755
--- a/configure
+++ b/configure
@@ -81,6 +81,19 @@  path_of() {
     return 1
 }
 
+add_to_libs() {
+  found=no
+  for lib_entry in $LIBS; do
+    if test "$lib_entry" = "$1"; then
+      found=yes
+      break
+    fi
+  done
+  if test "$found" = "no"; then
+    LIBS="$1 $LIBS"
+  fi
+}
+
 # default parameters
 source_path=`dirname "$0"`
 cpu=""
@@ -2083,16 +2096,7 @@  else
   for pthread_lib in $PTHREADLIBS_LIST; do
     if compile_prog "" "$pthread_lib" ; then
       pthread=yes
-      found=no
-      for lib_entry in $LIBS; do
-        if test "$lib_entry" = "$pthread_lib"; then
-          found=yes
-          break
-        fi
-      done
-      if test "$found" = "no"; then
-        LIBS="$pthread_lib $LIBS"
-      fi
+      add_to_libs "$pthread_lib"
       break
     fi
   done
@@ -2581,7 +2585,7 @@  EOF
 if compile_prog "" "" ; then
   :
 elif compile_prog "" "-lrt" ; then
-  LIBS="-lrt $LIBS"
+  add_to_libs "-lrt"
 fi
 
 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \