autoconf
[Top][All Lists]
Advanced

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

AC_SUBST for variables with AS_SET_VAR


From: Jason Curl
Subject: AC_SUBST for variables with AS_SET_VAR
Date: Thu, 19 Aug 2010 21:50:18 +0200

Hello,

I'm trying to write a macro that will iterate through a list of
libraries looking for a function. If it is found, I wish to do a
AC_SUBST on a variable dependent on the name of the library.

e.g. LX_SEARCH_LIBS([nsl socket], [gethostbyname], [])

The output would either:
AC_SUBST(LIBNSL, "-lnsl")
or
AC_SUBST(LIBSOCKET, "-lsocket")
depending on where the function was found

I've got it to set the variable LIBNSL or LIBSOCKET appropriately. But
because I'm using AC_VAR_*, I don't know how to do an AC_SUBST on this
dynamically named variable.

All workarounds, hacks and the like are very welcome.

What I have now is:


# LX_SEARCH_LIBS(LIBRARIES, FUNCTION, [OTHER-LIBRARIES]) 
#
--------------------------------------------------------------------------
# We search through a list of libraries (separated by spaces) looking
for
# the function FUNCTION. You can specify other libraries that we need to
# link with.
#
# If the function is found, we produce the define
#  #define HAVE_FUNCTION 1
#
# The variable "lx_cv_func_FUNCTION" is set with the name of the library
# that is required. If no library is required, "none" is set. If we
can't
# find the library, "no" is set.
AC_DEFUN([LX_SEARCH_LIBS],
  [AC_MSG_CHECKING([for $2])
   ac_check_lib_save_LIBS=$LIBS
   LIBS="$3 $LIBS"
   AS_VAR_PUSHDEF([ac_Lib], [lx_cv_func_$2])
   AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
     [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$2]), [1], [Function $2
defined])
      AS_VAR_SET([ac_Lib], [none])
      AC_MSG_RESULT([yes])],
     [AS_VAR_SET([ac_Lib], [no])])

   for lxlib in $1; do
      if test AS_VAR_GET([ac_Lib]) = no; then
         LIBS="-l$lxlib $3 $ac_check_lib_save_LIBS"
         AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
           [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$2]), [1], [Function $2
defined])
            AS_VAR_SET([ac_Lib], [$lxlib])
            AS_VAR_PUSHDEF([lx_liblib], [AS_TR_CPP([LIB$lxlib])])
            AS_VAR_SET([lx_liblib], [-l$lxlib])

>>> PROBLEM IS HERE
            AC_SUBST(lx_liblib)
>>> ---------------

            AS_VAR_POPDEF([lx_liblib])
            AC_MSG_RESULT([yes in $lxlib])],
           [AS_VAR_SET([ac_Lib], [no])])
      fi
   done

   if test AS_VAR_GET([ac_Lib]) = no; then
      AC_MSG_RESULT([no])
   fi
   AS_VAR_POPDEF([ac_Lib])
   LIBS=$ac_check_lib_save_LIBS
])





reply via email to

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