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, e.g. a URL
27 dnl What the ACTION-IFs can do:
29 dnl * change the variable have_[$1] to "yes" or "no" 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 These results have happened after calling GP_CHECK_LIBRARY:
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 -L/path -lfoo ])
41 dnl Parameters to ./configure which influence the GP_CHECK_LIBRARY 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
56 dnl Possible enhancements:
58 dnl * Derive VAR_PREFIX directly from libname
59 dnl This will change the calling conventions, so be aware of that.
60 dnl * Give names of a header file and function name and to a test
63 AC_DEFUN([_GP_CHECK_LIBRARY_SOEXT],[dnl
64 AC_MSG_CHECKING([for dynamic library extension])
67 *linux*) soext=".so" ;;
68 *sunos*) soext=".so" ;;
69 *solaris*) soext=".so" ;;
71 *darwin*) soext=".dylib" ;;
72 *w32*) soext=".dll" ;;
74 if test "x$soext" = "x"; then
76 AC_MSG_RESULT([${soext}])
78 Host system "${host}" not recognized, defaulting to "${soext}".
81 AC_MSG_RESULT([${soext}])
85 AC_DEFUN([_GP_CHECK_LIBRARY],[
86 # ----------------------------------------------------------------------
87 # [GP_CHECK_LIBRARY]([$1],[$2],[$3],
93 # ----------------------------------------------------------------------
95 AC_REQUIRE([GP_CONFIG_MSG])dnl
96 AC_REQUIRE([GP_PKG_CONFIG])dnl
97 AC_REQUIRE([_GP_CHECK_LIBRARY_SOEXT])dnl
98 dnl Use _CFLAGS and _LIBS given to configure.
99 dnl This makes it possible to set these vars in a configure script
100 dnl and AC_CONFIG_SUBDIRS this configure.
101 AC_ARG_VAR([$1][_CFLAGS], [CFLAGS for compiling with ][$2])dnl
102 AC_ARG_VAR([$1][_LIBS], [LIBS to add for linking against ][$2])dnl
104 AC_MSG_CHECKING([for ][$2][ to use])
107 if test "x${[$1][_LIBS]}" = "x" && test "x${[$1][_CFLAGS]}" = "x"; then
108 dnl define --with/--without argument
109 m4_if([$8], [default-off],
110 [m4_pushdef([gp_lib_arg],[--without-][$2])dnl
113 [m4_pushdef([gp_lib_arg],[--with-][$2])dnl
116 AC_ARG_WITH([$2],[AS_HELP_STRING([gp_lib_arg][=PREFIX],[where to find ][$2][, "no" or "auto"])],[try_][$1][="$withval"])
117 if test "x${[try_][$1]}" = "xauto"; then [try_][$1]=autodetect; fi
118 AC_MSG_RESULT([${try_][$1][}])
119 m4_popdef([gp_lib_arg])dnl
120 if test "x${[try_][$1]}" = "xautodetect"; then
121 dnl OK, we have to autodetect.
122 dnl We start autodetection with the cleanest known method: pkg-config
123 if test "x${[have_][$1]}" = "xno"; then
124 dnl we need that line break after the PKG_CHECK_MODULES
126 [PKG_CHECK_MODULES([$1],[$2][ $3],[have_][$1][=yes],[:])],
127 [PKG_CHECK_MODULES([$1],[$2], [have_][$1][=yes],[:])]
130 dnl If pkg-config didn't find anything, try the libfoo-config program
131 dnl certain known libraries ship with.
132 if test "x${[have_][$1]}" = "xno"; then
133 AC_MSG_WARN([The `$2' library could not be found using pkg-config.
134 No version checks will be performed if it is found using any other method.])
135 AC_MSG_CHECKING([$2][ config program])
136 m4_pushdef([gp_lib_config],[m4_if([$2],[libusb],[libusb-config],
137 [$2],[libgphoto2],[gphoto2-config],
138 [$2],[libgphoto2_port],[gphoto2-port-config],
140 AC_MSG_RESULT([gp_lib_config])
141 AC_PATH_PROG([$1][_CONFIG_PROG],[gp_lib_config])
142 if test -n "${[$1][_CONFIG_PROG]}" &&
143 test "${[$1][_CONFIG_PROG]}" != "none"; then
144 AC_MSG_CHECKING([for ][$2][ parameters from ][gp_lib_config])
145 [$1]_LIBS="$(${[$1][_CONFIG_PROG]} --libs || echo "*error*")"
146 [$1]_CFLAGSS="$(${[$1][_CONFIG_PROG]} --cflags || echo "*error*")"
147 if test "x${[$1]_LIBS}" = "*error*" ||
148 test "x${[$1]_CFLAGS}" = "*error*"; then
149 AC_MSG_RESULT([error])
155 m4_popdef([gp_lib_config])dnl
157 dnl Neither pkg-config, nor the libfoo-config program have found anything.
158 dnl So let's just probe the system.
159 if test "x${[have_][$1]}" = "xno"; then
161 IFS=":" # FIXME: for W32 and OS/2 we may need ";" here
165 "${prefix}/lib64" "${prefix}/lib" \
166 /usr/lib64 /usr/lib \
167 /usr/local/lib64 /usr/local/lib \
171 for _soext_ in .la ${soext} .a; do
172 if test -f "${_libdir_}/[$2]${_soext_}"
174 if test "x${_soext_}" = "x.la" ||
175 test "x${_soext_}" = "x.a"; then
176 [$1]_LIBS="${_libdir_}/[$2]${_soext_}"
178 [$1]_LIBS="-L${_libdir_} -l$(echo "$2" | sed 's/^lib//')"
183 if test "x${[$1][_LIBS]}" != "x"; then
188 if test "x${[$1][_LIBS]}" != "x"; then
192 elif test "x${[try_][$1]}" = "xno"; then
195 [$1][_LIBS]="-L${[try_][$1]}/lib -l$(echo "$2" | sed 's/^lib//')"
196 [$1][_CFLAGS]="-I${[try_][$1]}/include"
198 elif test "x${[$1][_LIBS]}" != "x" && test "x${[$1][_CFLAGS]}" != "x"; then
199 AC_MSG_RESULT([user-defined])
203 AC_MSG_RESULT([broken call])
206 * When calling configure for ${PACKAGE_TARNAME}
208 * either set both [$1][_LIBS] *and* [$1][_CFLAGS]
216 if test "x${[have_][$1]}" = "xyes"; then
222 dnl ACTION-IF-NOT-FOUND
225 if test "x${[have_][$1]}" = "xno"; then
226 # ACTION-IF-NOT-FOUND
231 dnl Run our own test compilation
234 if test "x${[have_][$1]}" = "xyes"; then
235 dnl AC_MSG_CHECKING([whether ][$2][ test compile succeeds])
236 dnl AC_MSG_RESULT([${[have_][$1]}])
237 CPPFLAGS_save="$CPPFLAGS"
238 CPPFLAGS="${[$1]_CFLAGS}"
239 AC_CHECK_HEADER([$4],[have_][$1][=yes],[have_][$1][=no])
240 CPPFLAGS="$CPPFLAGS_save"
244 dnl Run our own test link
245 dnl Does not work for libraries which be built after configure time,
246 dnl so we deactivate it for them (userdef_).
249 if test "x${[userdef_][$1]}" = "xno" && test "x${[have_][$1]}" = "xyes"; then
250 AC_MSG_CHECKING([for function ][$5][ in ][$2])
253 AC_TRY_LINK_FUNC([$5],[],[have_][$1][=no])
255 AC_MSG_RESULT([${[have_][$1]}])
259 dnl Abort configure script if mandatory, but not found
261 m4_if([$8],[mandatory],[
262 if test "x${[have_][$1]}" = "xno"; then
264 PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
265 [$1][_LIBS]=${[$1][_LIBS]}
266 [$1][_CFLAGS]=${[$1][_CFLAGS]}
268 * Fatal: ${PACKAGE_NAME} requires $2 to build.
270 * Possible solutions:
271 * - set PKG_CONFIG_PATH to adequate value
272 * - call configure with [$1][_LIBS]=.. and [$1][_CFLAGS]=..
273 * - call configure with one of the --with-$2 parameters
275 * - get $2 and install it
277 * - get $2 and install it:
281 AM_CONDITIONAL([HAVE_][$1], [test "x$have_[$1]" = "xyes"])
282 if test "x$have_[$1]" = "xyes"; then
283 AC_DEFINE([HAVE_][$1], 1, [whether we compile with ][$2][ support])
284 GP_CONFIG_MSG([$2],[yes])dnl
285 AC_MSG_CHECKING([$2][ library flags])
286 AC_MSG_RESULT([${[$1][_LIBS]}])
287 AC_MSG_CHECKING([$2][ cpp flags])
288 AC_MSG_RESULT([${[$1][_CFLAGS]}])
290 GP_CONFIG_MSG([$2],[no])dnl
292 dnl AC_SUBST is done implicitly by AC_ARG_VAR above.
293 dnl AC_SUBST([$1][_LIBS])
294 dnl AC_SUBST([$1][_CFLAGS])
297 dnl ####################################################################
299 AC_DEFUN([_GP_CHECK_LIBRARY_SYNTAX_ERROR],[dnl
300 m4_errprint(__file__:__line__:[ Error:
301 *** Calling $0 macro with old syntax
307 dnl ####################################################################
309 AC_DEFUN([GP_CHECK_LIBRARY],[dnl
310 m4_if([$4], [mandatory], [_GP_CHECK_LIBRARY_SYNTAX_ERROR($0)],
311 [$4], [default-enabled], [_GP_CHECK_LIBRARY_SYNTAX_ERROR($0)],
312 [$4], [default-disabled], [_GP_CHECK_LIBRARY_SYNTAX_ERROR($0)])dnl
314 _GP_CHECK_LIBRARY([$1],[$2],[$3],[$4],[$5],[$6],[$7],[mandatory],[$9])],
315 [$8], [default-on], [dnl
316 _GP_CHECK_LIBRARY([$1],[$2],[$3],[$4],[$5],[$6],[$7],[$8],[$9])],
317 [$8], [default-off], [dnl
318 _GP_CHECK_LIBRARY([$1],[$2],[$3],[$4],[$5],[$6],[$7],[$8],[$9])],
319 [$8], [mandatory], [dnl
320 _GP_CHECK_LIBRARY([$1],[$2],[$3],[$4],[$5],[$6],[$7],[$8],[$9])],
321 [m4_errprint(__file__:__line__:[ Error:
322 Illegal argument 6 to $0: `$6'
323 It must be one of "default-on", "default-off", "mandatory".
327 m4_pattern_disallow([GP_CHECK_LIBRARY])
328 m4_pattern_disallow([_GP_CHECK_LIBRARY])
329 m4_pattern_disallow([_GP_CHECK_LIBRARY_SYNTAX_ERROR])
330 m4_pattern_disallow([_GP_CHECK_LIBRARY_SOEXT])
332 dnl ####################################################################
334 dnl Please do not remove this:
335 dnl filetype: 6e60b4f0-acb2-4cd5-8258-42014f92bd2c
336 dnl I use this to find all the different instances of this file which
337 dnl are supposed to be synchronized.