From 620faec9ee77cf5197c138431b08fafc5ed82946 Mon Sep 17 00:00:00 2001 From: Jorrit Fahlke <joe@dune-project.org> Date: Mon, 18 Jan 2010 16:04:53 +0000 Subject: [PATCH] This should actually have been checked in in revision 5830: Rewrite the DUNE_CHECK_LIB_EXT macro: * Essentially copy and adapt the definition of AC_CHECK_LIB. This should make sure the two macros behave the same even in corner cases (except for the added functionality, of course). * Properly document what exactly is allowed in the arguments. [[Imported from SVN: r5833]] --- m4/dune_check_lib.m4 | 59 +++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/m4/dune_check_lib.m4 b/m4/dune_check_lib.m4 index 2f4ef3a54..d8e7012f4 100644 --- a/m4/dune_check_lib.m4 +++ b/m4/dune_check_lib.m4 @@ -1,20 +1,49 @@ dnl -*- autoconf -*- +# DUNE_CHECK_LIB_EXT(PATH, LIBRARY, FUNCTION, [ACTION-IF-FOUND], +# [ACTION-IF-NOT-FOUND], [OTHER-LIBRARIES]) +# # Just like AC_CHECK_LIB, but in allow a library path to be specified. The # default ACTION-IF-FOUND is extended to also add that library path to LIBS. # -# DUNE_CHECK_LIB_EXT(PATH, LIBRARY, FUNCTION, [ACTION-IF-FOUND], -# [ACTION-IF-NOT-FOUND], [OTHER-LIBRARIES]) +# PATH Path to search for the library. This should be something suitable +# to be used inside a double quoted shell string. +# +# LIBRARY Name of the library. This should be something suitable to be used +# inside a double quoted shell string. If this containes shell +# subtitutions, no config.h template will be generated by the default +# action. +# +# FUNCTION Function to check for. This should be something suitable to be +# used inside a double quoted shell string. +# +# ACTION-IF-FOUND Action to perform when the library was found. If empty, set +# prepend "-L{PATH} -l{LIBRARY}" and create a preprocessor define +# HAVE_LIB{LIBRARY} (the preprocessor define's name is passed through +# AS_TR_CPP to make it suitable first). +# +# ACTION-IF-NOT-FOUND Action to perform when the library was not found. +# +# OTHER-LIBRARIES If linking agains LIBRARY will only succeed in the presence +# of other libraries not already in LIBS, specify them here. These +# libraries will not be added to LIBS in the default ACTION-IF-FOUND. AC_DEFUN([DUNE_CHECK_LIB_EXT], -[ - dune_cle_save_LDFLAGS="$LDFLAGS" - LDFLAGS="$LDFLAGS -L$1" - m4_if(m4_eval([$# <= 3]), [1], - [AC_CHECK_LIB([$2], [$3], - [ - LIBS="-L$1 -l$2 $LIBS" - AC_DEFINE([HAVE_LIB]m4_translit([[$2]], [-a-z], [_A-Z]), [1], - [Define to 1 if you have the `$2' library (-l$2).]) - ])], - [AC_CHECK_LIB(m4_shift($@))]) - LDFLAGS="$dune_cle_save_LDFLAGS" -]) +[m4_ifval([$4], , [AH_TEMPLATE(AS_TR_CPP([HAVE_LIB$2]), + [Define to 1 if you have the `$2' library (-L$1 -l$2).])])dnl +AS_VAR_PUSHDEF([dune_Lib], + [dune_cv_lib_$1]AS_LITERAL_IF([$1], , [['']])dnl +[_$2]AS_LITERAL_IF([$2], , [['']])dnl +[_$3])dnl +AC_CACHE_CHECK([for $3 in -L$1 -l$2], [dune_Lib], +[dune_check_lib_ext_save_LIBS=$LIBS +LIBS="-L$1 -l$2 $6 $LIBS" +AC_LINK_IFELSE([AC_LANG_CALL([], [$3])], + [AS_VAR_SET([dune_Lib], [yes])], + [AS_VAR_SET([dune_Lib], [no])]) +LIBS=$dune_check_lib_ext_save_LIBS]) +AS_VAR_IF([dune_Lib], [yes], + [m4_default([$4], [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_LIB$2])) + LIBS="-L$1 -l$2 $LIBS" +])], + [$5]) +AS_VAR_POPDEF([dune_Lib])dnl +])# DUNE_CHECK_LIB_EXT -- GitLab