1 dnl @synopsis GP_CHECK_LIBRARY([VARNAMEPART],[libname],[VERSION-REQUIREMENT],
2 dnl [headername],[functionname],
3 dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
4 dnl [OPTIONAL-REQUIRED-ETC],[WHERE-TO-GET-IT])
6 dnl Checks for the presence of a certain library.
10 dnl VARNAMEPART partial variable name for variable definitions
11 dnl libname name of library
12 dnl VERSION-REQUIREMENT check for the version using pkg-config
14 dnl headername name of header file
16 dnl functionname name of function name in library
18 dnl ACTION-IF-FOUND shell action to execute if found
20 dnl ACTION-IF-NOT-FOUND shell action to execute if not found
22 dnl OPTIONAL-REQUIRED-ETC one of "mandatory", "default-on", "default-off"
23 dnl default: [mandatory]
24 dnl WHERE-TO-GET-IT place where to find the library
27 dnl What the ACTION-IFs can do:
29 dnl * change the variable have_[$1] to "yes" or "now" and thus change
30 dnl the outcome of the test
31 dnl * execute additional checks to define more specific variables, e.g.
32 dnl for different API versions
34 dnl Results after calling it:
36 dnl AM_CONDITIONAL([HAVE_VARPREFIX],[ if found ])
37 dnl AM_SUBST([have_VARPREFIX], [ "yes" if found, "no" if not found ])
38 dnl AM_SUBST([VARPREFIX_CFLAGS],[ -I, -D and stuff ])
39 dnl AM_SUBST([VARPREFIX_LIBS], [ /path/to/libname.la ])
41 dnl Parameters to ./configure which influence the results:
43 dnl * VARNAMEPART_LIBS=/foobar/arm-palmos/lib/libname.la
44 dnl VARNAMEPART_CFLAGS=-I/foobar/include
45 dnl * --without-libfoo
46 dnl * --with-libfoo=/usr/local
47 dnl * --with-libfoo-include-dir=/foobar/include
48 dnl * --with-libfoo-lib=/foobar/arm-palmos/lib
49 dnl * --with-libfoo=autodetect
52 dnl GP_CHECK_LIBRARY([LIBEXIF], [libexif])dnl
53 dnl GP_CHECK_LIBRARY([LIBEXIF], [libexif-gtk], [>= 0.3.3])dnl
55 dnl Possible enhancements:
57 dnl * Derive VAR_PREFIX directly from libname
58 dnl This will change the calling conventions, so be aware of that.
59 dnl * Give names of a header file and function name and to a test
62 AC_DEFUN([_GP_CHECK_LIBRARY_SOEXT],[dnl
63 AC_MSG_CHECKING([for dynamic library extension])
66 *linux*) soext=".so" ;;
67 *sunos*) soext=".so" ;;
69 *darwin*) soext=".dylib" ;;
70 *w32*) soext=".dll" ;;
72 if test "x$soext" = "x"; then
74 AC_MSG_RESULT([${soext}])
76 Host system "${host}" not recognized, defaulting to "${soext}".
79 AC_MSG_RESULT([${soext}])
83 AC_DEFUN([_GP_CHECK_LIBRARY],[
84 # ----------------------------------------------------------------------
85 # [GP_CHECK_LIBRARY]([$1],[$2],[$3],
91 # ----------------------------------------------------------------------
93 AC_REQUIRE([GP_CONFIG_MSG])dnl
94 AC_REQUIRE([GP_PKG_CONFIG])dnl
95 AC_REQUIRE([_GP_CHECK_LIBRARY_SOEXT])dnl
96 dnl Use _CFLAGS and _LIBS given to configure.
97 dnl This makes it possible to set these vars in a configure script
98 dnl and AC_CONFIG_SUBDIRS this configure.
99 AC_ARG_VAR([$1][_CFLAGS], [CFLAGS for compiling with ][$2])dnl
100 AC_ARG_VAR([$1][_LIBS], [LIBS to add for linking against ][$2])dnl
102 AC_MSG_CHECKING([for ][$2][ to use])
105 if test "x${[$1][_LIBS]}" = "x" && test "x${[$1][_CFLAGS]}" = "x"; then
106 m4_if([$8], [default-off],
107 [m4_pushdef([gp_lib_arg],[--without-][$2])dnl
110 [m4_pushdef([gp_lib_arg],[--with-][$2])dnl
113 AC_ARG_WITH([$2],[AS_HELP_STRING([gp_lib_arg][=PREFIX],[where to find ][$2][, "no" or "auto"])],[try_][$1][="$withval"])
114 if test "x${[try_][$1]}" = "xauto"; then [try_][$1]=autodetect; fi
115 AC_MSG_RESULT([${try_][$1][}])
116 m4_popdef([gp_lib_arg])dnl
117 if test "x${[try_][$1]}" = "xautodetect"; then
118 dnl we need that line break after the PKG_CHECK_MODULES
120 [PKG_CHECK_MODULES([$1],[$2][ $3],[have_][$1][=yes])],
121 [PKG_CHECK_MODULES([$1],[$2], [have_][$1][=yes])]
123 if test "x${[have_][$1]}" = "xno"; then
125 IFS=":" # FIXME: for W32 and OS/2 we need ";" here
129 "${prefix}/lib64" "${prefix}/lib" \
130 /usr/lib64 /usr/lib \
131 /usr/local/lib64 /usr/local/lib \
135 for _soext_ in .la ${soext} .a; do
136 if test -f "${_libdir_}/[$2]${_soext_}"
138 if test "x${_soext_}" = "x.la" ||
139 test "x${_soext_}" = "x.a"; then
140 [$1]_LIBS="${_libdir_}/[$2]${_soext_}"
142 [$1]_LIBS="-L${_libdir_} -l$(echo "$2" | sed 's/^lib//')"
147 if test "x${[$1][_LIBS]}" != "x"; then
152 if test "x${[$1][_LIBS]}" != "x"; then
156 elif test "x${[try_][$1]}" = "xno"; then
159 [$1][_LIBS]="-L${[try_][$1]}/lib -l$(echo "$2" | sed 's/^lib//')"
160 [$1][_CFLAGS]="-I${[try_][$1]}/include"
162 elif test "x${[$1][_LIBS]}" != "x" && test "x${[$1][_CFLAGS]}" != "x"; then
163 AC_MSG_RESULT([user-defined])
169 * When calling configure for ${PACKAGE_TARNAME}
171 * either set both [$1][_LIBS] *and* [$1][_CFLAGS]
179 if test "x${[have_][$1]}" = "xyes"; then
185 dnl ACTION-IF-NOT-FOUND
188 if test "x${[have_][$1]}" = "xno"; then
189 # ACTION-IF-NOT-FOUND
194 dnl Run our own test compilation
197 if test "x${[have_][$1]}" = "xyes"; then
198 dnl AC_MSG_CHECKING([whether ][$2][ test compile succeeds])
199 dnl AC_MSG_RESULT([${[have_][$1]}])
200 CPPFLAGS_save="$CPPFLAGS"
201 CPPFLAGS="${[$1]_CFLAGS}"
202 AC_CHECK_HEADER([$4],[have_][$1][=yes],[have_][$1][=no])
203 CPPFLAGS="$CPPFLAGS_save"
207 dnl Run our own test link
208 dnl Does not work for libraries which be built after configure time,
209 dnl so we deactivate it for them (userdef_).
212 if test "x${[userdef_][$1]}" = "xno" && test "x${[have_][$1]}" = "xyes"; then
215 AC_TRY_LINK_FUNC([$5],[],[have_][$1][=no])
220 dnl Abort configure script if mandatory, but not found
222 m4_if([$8],[mandatory],[
223 if test "x${[have_][$1]}" = "xno"; then
225 PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
226 [$1][_LIBS]=${[$1][_LIBS]}
227 [$1][_CFLAGS]=${[$1][_CFLAGS]}
229 * Fatal: ${PACKAGE_NAME} requires $2 to build.
231 * Possible solutions:
232 * - set PKG_CONFIG_PATH to adequate value
233 * - call configure with [$1][_LIBS]=.. and [$1][_CFLAGS]=..
234 * - call configure with one of the --with-$2 parameters
236 * - get $2 and install it
238 * - get $2 and install it:
242 AM_CONDITIONAL([HAVE_][$1], [test "x$have_[$1]" = "xyes"])
243 if test "x$have_[$1]" = "xyes"; then
244 AC_DEFINE([HAVE_][$1], 1, [whether we compile with ][$2][ support])
245 GP_CONFIG_MSG([$2],[yes])dnl
246 AC_MSG_CHECKING([$2][ library flags])
247 AC_MSG_RESULT([${[$1][_LIBS]}])
248 AC_MSG_CHECKING([$2][ cpp flags])
249 AC_MSG_RESULT([${[$1][_CFLAGS]}])
251 GP_CONFIG_MSG([$2],[no])dnl
253 dnl AC_SUBST is done implicitly by AC_ARG_VAR above.
254 dnl AC_SUBST([$1][_LIBS])
255 dnl AC_SUBST([$1][_CFLAGS])
258 dnl ####################################################################
260 AC_DEFUN([_GP_CHECK_LIBRARY_SYNTAX_ERROR],[dnl
261 m4_errprint(__file__:__line__:[ Error:
262 *** Calling $0 macro with old syntax
268 dnl ####################################################################
270 AC_DEFUN([GP_CHECK_LIBRARY],[dnl
271 m4_if([$4], [mandatory], [_GP_CHECK_LIBRARY_SYNTAX_ERROR($0)],
272 [$4], [default-enabled], [_GP_CHECK_LIBRARY_SYNTAX_ERROR($0)],
273 [$4], [default-disabled], [_GP_CHECK_LIBRARY_SYNTAX_ERROR($0)])dnl
275 _GP_CHECK_LIBRARY([$1],[$2],[$3],[$4],[$5],[$6],[$7],[mandatory],[$9])],
276 [$8], [default-on], [dnl
277 _GP_CHECK_LIBRARY([$1],[$2],[$3],[$4],[$5],[$6],[$7],[$8],[$9])],
278 [$8], [default-off], [dnl
279 _GP_CHECK_LIBRARY([$1],[$2],[$3],[$4],[$5],[$6],[$7],[$8],[$9])],
280 [$8], [mandatory], [dnl
281 _GP_CHECK_LIBRARY([$1],[$2],[$3],[$4],[$5],[$6],[$7],[$8],[$9])],
282 [m4_errprint(__file__:__line__:[ Error:
283 Illegal argument 6 to $0: `$6'
284 It must be one of "default-on", "default-off", "mandatory".
288 m4_pattern_disallow([GP_CHECK_LIBRARY])
289 m4_pattern_disallow([_GP_CHECK_LIBRARY])
290 m4_pattern_disallow([_GP_CHECK_LIBRARY_SYNTAX_ERROR])
291 m4_pattern_disallow([_GP_CHECK_LIBRARY_SOEXT])
293 dnl ####################################################################
295 dnl Please do not remove this:
296 dnl filetype: 6e60b4f0-acb2-4cd5-8258-42014f92bd2c
297 dnl I use this to find all the different instances of this file which
298 dnl are supposed to be synchronized.