bug-autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AC_SEARCH_LIBS with OTHER-LIBRARIES


From: Paolo Bonzini
Subject: Re: AC_SEARCH_LIBS with OTHER-LIBRARIES
Date: Thu, 29 Apr 2010 10:20:12 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.8) Gecko/20100301 Fedora/3.0.3-1.fc12 Lightning/1.0b2pre Thunderbird/3.0.3

On 04/26/2010 05:11 AM, NIIBE Yutaka wrote:
Ralf Wildenhues wrote:
The semantics are that OTHER-LIBRARIES are libraries needed by the
library in SEARCH_LIBS.

Thanks for the clarification.

I had thought that it were possible for users of AC_SEARCH_LIBS to
expect FUNCTION to be linked to OTHER-LIBRARIES with no library.

Well, let me give my example.

The code I wrote:
------------------
AC_SEARCH_LIBS(openpty, util,
[AC_DEFINE(HAVE_OPENPTY, 1, [Define if you have openpty])
LIBS=$ac_func_search_save_LIBS
test "$ac_res" = "none required" || TERMIOSLIB="$ac_res"])
AC_SEARCH_LIBS(forkpty, util,
[AC_DEFINE(HAVE_FORKPTY, 1, [Define if you have forkpty])
LIBS=$ac_func_search_save_LIBS
test "$ac_res" = "none required" || TERMIOSLIB="$ac_res"], , $TERMIOSLIB)
AC_SUBST(TERMIOSLIB)
------------------

You do not need to pass $TERMIOSLIB to the second AC_SEARCH_LIBS. You can see it this way: think about what would happen if you invert the two AC_SEARCH_LIBS invocations.

Also, ac_res and ac_func_search_save_LIBS are not documented.

I think it's better if you write a macro that generalizes the idiom. What you'd get would look like this:

AC_DEFUN([ny_SEARCH_LIBS],
[AC_FOREACH([ny_Func], [$1],
[AH_TEMPLATE([HAVE_]m4_quote(AS_TR_CPP(ny_Func)),
             [Define if you have ]m4_quote(ny_Func))])
for func in $1; do
  ny_save_LIBS=$LIBS
  AC_SEARCH_LIBS([$func], [$2])
  LIBS=$ny_save_LIBS
  AS_VAR_PUSHDEF([ny_Res], [ac_cv_search_$func])
  AS_VAR_IF([ny_Res], [no], [], [
    AC_DEFINE_UNQUOTED([HAVE_]m4_quote(AS_TR_CPP([$func])), 1)
    AS_VAR_IF([$3], [],
      [AS_VAR_IF([ny_Res], ["none required"], [],
                 [AS_VAR_COPY([$3], [ny_Res])])])])
  AS_VAR_POPDEF([ny_Res])AC_SUBST([$3])
done])

ny_SEARCH_LIBS([openpty forkpty], [util], [TERMIOSLIB])

Not shorter than the original code you had, but more reusable.

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]