Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some more debug output to understand the gras/empty_main bug
[simgrid.git] / acmacro / ax_cxx_check_lib.m4
1 dnl @synopsis AX_CXX_CHECK_LIB(libname, functioname, action-if, action-if-not)
2 dnl
3 dnl The standard AC_CHECK_LIB can not test functions in namespaces.
4 dnl Therefore AC_CHECK_LIB(cgicc, cgicc::Cgicc::getVersion) will always
5 dnl fail. We need to decompose the functionname into a series of namespaces
6 dnl where it gets declared so that it can be used for a link test.
7 dnl
8 dnl In the first version I did allow namespace::functionname to be a
9 dnl reference to a void-argument global functionname (just wrapped in a
10 dnl namespace) like its C counterparts would be - but in reality such
11 dnl thing does not exist. The only global / static functions are always
12 dnl made const-functions which is an attribute mangled along into the
13 dnl library function export name. 
14 dnl
15 dnl The normal usage will ask for a test of a class-member function which
16 dnl should be presented with a full function spec with arguments given in 
17 dnl parentheses following the function name - if the function to test for 
18 dnl does expect arguments then you should add default initial values in the 
19 dnl prototype (even if they do not exist originally, these are used only 
20 dnl locally to build a correct function call in the configure test script).
21 dnl
22 dnl In the current version if you do omit the parenthesis from the macro
23 dnl argument then the macro will assume that you want to check for the
24 dnl class name - which is really to check for default constructor being
25 dnl exported from the given library name. 
26 dnl
27 dnl   EXAMPLE:
28 dnl AX_CXX_CHECK_LIB(cgicc, [cgicc::HTTPCookie])
29 dnl AX_CXX_CHECK_LIB(cgicc, [cgicc::Cgicc::getVersion () const],
30 dnl AX_CXX_CHECK_LIB(boost_regex, [boost::RegEx::Position (int i = 0) const])
31 dnl
32 dnl Result:
33 dnl Just as the usual AX_CXX_CHECK_LIB - defines HAVE_LIBCGICC 
34 dnl and adds the libraries to the default library path (and
35 dnl uses internally the normal ac_check_lib cache symbol
36 dnl like ac_cv_lib_cgicc_cgicc__Cgicc)
37 dnl
38 dnl Footnote: The C++ language is not good at creating stable library
39 dnl interfaces at the binary level - a lot of functionality is usually being 
40 dnl given as inline functions plus there is hardly a chance to create opaque 
41 dnl types. Therefore most C++ library tests will only do compile tests using
42 dnl the header files. Doing a check_lib is however good to check the link
43 dnl dependency before hitting it as an error in the build later.
44 dnl
45 dnl @category C++
46 dnl @author Guido U. Draheim
47 dnl @vesion 2006-12-18
48
49 AC_DEFUN([AX_CXX_CHECK_LIB],
50 [m4_ifval([$3], , [AH_CHECK_LIB([$1])])dnl
51 AS_LITERAL_IF([$1],
52               [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])],
53               [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1''_$2])])dnl
54 AC_CACHE_CHECK([for $2 in -l$1], ac_Lib,
55 [ac_check_lib_save_LIBS=$LIBS
56 LIBS="-l$1 $5 $LIBS"
57 case "$2" 
58 in *::*::*\(*)
59 AC_LINK_IFELSE([AC_LANG_PROGRAM([
60  namespace `echo "$2" | sed -e "s/::.*//"` 
61  { class `echo "$2" | sed -e "s/.*::\\(.*\\)::.*/\\1/" -e "s/(.*//"` 
62    { public: int `echo "$2" | sed -e "s/.*:://" -e "/(/!s/..*/&()/"`;
63    };
64  }
65 ],[`echo "$2" | sed  -e "s/(.*//" -e "s/\\(.*\\)::\\(.*\\)/((\\1*)(0))->\\2/g"`()])],
66                [AS_VAR_SET(ac_Lib, yes)],
67                [AS_VAR_SET(ac_Lib, no)])
68 ;; *::*::*)
69 AC_LINK_IFELSE([AC_LANG_PROGRAM([
70  namespace `echo "$2" | sed -e "s/::.*//"` 
71  { namespace `echo "$2" | sed -e "s/.*::\\(.*\\)::.*/\\1/"` 
72    { class `echo "$2" | sed -e "s/.*:://"` 
73       { public: `echo "$2" | sed -e "s/.*:://"` ();
74       };
75    }
76  }
77 ],[new $2()])],
78                [AS_VAR_SET(ac_Lib, yes)],
79                [AS_VAR_SET(ac_Lib, no)])
80 ;; *::*\(*)
81 AC_LINK_IFELSE([AC_LANG_PROGRAM([
82  class `echo "$2" | sed -e "s/\\(.*\\)::.*/\\1/" -e "s/(.*//"` 
83    { public: int `echo "$2" | sed -e "s/.*:://" -e "/(/!s/..*/&()/"`;
84    };
85 ],[`echo "$2" | sed  -e "s/(.*//" -e "s/\\(.*\\)::\\(.*\\)/((\\1*)(0))->\\2/g"`()])],
86                [AS_VAR_SET(ac_Lib, yes)],
87                [AS_VAR_SET(ac_Lib, no)])
88 ;; *::*)
89 AC_LINK_IFELSE([AC_LANG_PROGRAM([
90  namespace `echo "$2" | sed -e "s/::.*//"` 
91  { class `echo "$2" | sed -e "s/.*:://"`
92    { public: `echo "$2" | sed -e "s/.*:://"` ();
93    };
94  }
95 ],[new $2()])],
96                [AS_VAR_SET(ac_Lib, yes)],
97                [AS_VAR_SET(ac_Lib, no)])
98 ;; *)
99 AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
100                [AS_VAR_SET(ac_Lib, yes)],
101                [AS_VAR_SET(ac_Lib, no)])
102 ;; esac
103 LIBS=$ac_check_lib_save_LIBS])
104 AS_IF([test AS_VAR_GET(ac_Lib) = yes],
105       [m4_default([$3], [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
106   LIBS="-l$1 $LIBS"
107 ])],
108       [$4])dnl
109 AS_VAR_POPDEF([ac_Lib])dnl
110 ])# AC_CHECK_LIB