Robert A. Knop Jr. writes:
> I'm fairly new to autoconf, so this may be a clueless question.
>
> What I'm trying to do is check a few standard places for a library
> and then set a variable (*not* LIBS, but my own) based on where this
> library was found. To this end, I have the following code in
> configure.in:
>
> for i in '' -L$prefix/lib -L$prefix/pgsql/lib; do
> found=''
> AC_MSG_RESULT("Looking for Postgres library in $i")
> AC_CHECK_LIB(pq, PQconnectdb, found=1, found='', $i)
> if test $found; then
> pgsql_lib=$i
> break
> fi
> done
> if test $found; then
> AC_MSG_RESULT("Postgres library found: $pgsql_lib")
> else
> AC_MSG_ERROR("Postgres library not found!")
> fi
>
> The problem I'm having is that after the first test fails, the generated
> configure script never really tests the other places I'm looking for the
> library-- because the failure of the first test is cached, so it thinks it
> doesn't need to do the test again!
>
> Is there some way I can tell configure to throw out the previous cached
> value of this test before tryiing the AC_CHECK_LIB test again? I haven't
> found anything in the documentation which would indicate how one does
> this.
>
> I don't want to include the result of the test in LIBS, I want to set a
> different value; this is why I don't just use AC_SEARCH_LIBS. (In any
> event, AC_SEARCH_LIBS says it sets -lsomething, not -Lsomething.)
I have been doing something very similar for gnuplot: two macros, one
for headers, one for libs, with a for loop around non-caching and silent
versions of the resp. autoconf macros. See attached. I think I wrote
this stuff before AC_SEARCH_LIBS became part of autoconf.
## --------------------------------------------- ##
## Search several directories for header file. ##
## Built around a non-caching and silent version ##
## of AC_CHECK_HEADER. ##
## From Lars Hecking ##
## --------------------------------------------- ##
# serial 2
dnl GP_PATH_HEADER(HEADER-FILE, SEARCH-DIRS [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])
AC_DEFUN(GP_PATH_HEADER,
[ac_safe=`echo "$1" | sed 'y%./+-%__p_%'`
changequote(, )dnl
ac_tr_hdr=HAVE_`echo $1 | sed
'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
changequote([, ])dnl
AC_MSG_CHECKING([for $1])
gp_save_CPPFLAGS="$CPPFLAGS"
if test "$2" != yes && test "$2" != no; then
gp_h_path=`echo "$2" | sed -e 's%/lib$1\.a$%%'`
gp_h_prfx=`echo "$gp_h_path" | sed -e 's%/lib$%%' -e 's%/include$%%'`
gp_h_list="$gp_h_prfx $gp_h_prfx/include $gp_h_path"
else
gp_h_list=''
fi
for ac_dir in $gp_h_list '' /usr/local/include ; do
test x${ac_dir} != x && CPPFLAGS="$gp_save_CPPFLAGS -I${ac_dir}"
AC_TRY_CPP([#include <$1>], eval "ac_cv_header_$ac_safe=yes",
eval "ac_cv_header_$ac_safe=no")
if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
break
fi
done
if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
AC_DEFINE_UNQUOTED($ac_tr_hdr)
AC_MSG_RESULT(yes)
ifelse([$3], , :, [$3])
else
AC_MSG_RESULT(no)
CPPFLAGS="$gp_save_CPPFLAGS"
ifelse([$4], , , [$4
])dnl
fi
])
## ------------------------------ ##
## Like AC_CHECK_LIB, but quiet, ##
## and no caching. ##
## From Lars Hecking ##
## ------------------------------ ##
# serial 2
dnl AC_CHECK_LIB(LIBRARY, FUNCTION [, OTHER-LIBRARIES])
AC_DEFUN(GP_CHECK_LIB_QUIET,
[ac_lib_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
ac_save_LIBS="$LIBS"
LIBS="$TERMLIBS $TERMXLIBS -l$1 $3 $LIBS"
AC_TRY_LINK(dnl
ifelse([$2], [main], , dnl Avoid conflicting decl of main.
[/* Override any gcc2 internal prototype to avoid an error. */
]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
extern "C"
#endif
])dnl
[/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char $2();
]),
[$2()],
eval "ac_cv_lib_$ac_lib_var=yes",
eval "ac_cv_lib_$ac_lib_var=no")
LIBS="$ac_save_LIBS"
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
changequote(, )dnl
ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
changequote([, ])dnl
dnl LIBS="$LIBS -l$1"
fi
])
## ------------------------------------------- ##
## Search several directories for library. ##
## NOTE: OTHER_LIBRARIES are NOT automatically ##
## added to TERMLIBS. This must be done in ##
## configure.in! ##
## From Lars Hecking ##
## ------------------------------------------- ##
# serial 2
dnl GP_PATH_LIB(LIBRARY, FUNCTION, SEARCH-DIRS [, OTHER-LIBRARIES])
AC_DEFUN(GP_PATH_LIB,
[ac_lib_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
changequote(, )dnl
gp_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
changequote([, ])dnl
AC_MSG_CHECKING([for $2 in -l$1])
gp_save_TERMLIBS="$TERMLIBS"
if test "$3" != yes && test "$3" != no; then
gp_l_path=`echo "$3" | sed -e 's%/lib$1\.a$%%'`
gp_l_prfx=`echo $gp_l_path | sed -e 's%/lib$%%' -e 's%/include$%%'`
gp_l_list="$gp_l_prfx $gp_l_prfx/lib $gp_l_path"
else
gp_l_list=''
fi
for ac_dir in $gp_l_list '' /usr/local/lib ; do
test x${ac_dir} != x && TERMLIBS="-L${ac_dir} $gp_save_TERMLIBS"
GP_CHECK_LIB_QUIET($1,$2,$4)
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
break
fi
done
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
TERMLIBS="$TERMLIBS -l$1"
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
TERMLIBS="$gp_save_TERMLIBS"
fi
])