prettier config msg output
[platform/upstream/libexif.git] / m4m / gp-check-library.m4
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])
5 dnl
6 dnl Checks for the presence of a certain library.
7 dnl
8 dnl Parameters:
9 dnl
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
13 dnl                           default: []
14 dnl    headername             name of header file
15 dnl                           default: []
16 dnl    functionname           name of function name in library
17 dnl                           default: []
18 dnl    ACTION-IF-FOUND        shell action to execute if found
19 dnl                           default: []
20 dnl    ACTION-IF-NOT-FOUND    shell action to execute if not found
21 dnl                           default: []
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
25 dnl                           default: []
26 dnl
27 dnl What the ACTION-IFs can do:
28 dnl
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
33 dnl
34 dnl Results after calling it:
35 dnl
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 ])
40 dnl
41 dnl Parameters to ./configure which influence the results:
42 dnl
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
50 dnl
51 dnl Examples:
52 dnl    GP_CHECK_LIBRARY([LIBEXIF], [libexif])dnl
53 dnl    GP_CHECK_LIBRARY([LIBEXIF], [libexif-gtk], [>= 0.3.3])dnl
54 dnl
55 dnl Possible enhancements:
56 dnl
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
60 dnl     compilation.
61 dnl
62 AC_DEFUN([_GP_CHECK_LIBRARY_SOEXT],[dnl
63 AC_MSG_CHECKING([for dynamic library extension])
64 soext=""
65 case "$host" in
66         *linux*)        soext=".so" ;;
67         *sunos*)        soext=".so" ;;
68         *bsd*)          soext=".so" ;;
69         *darwin*)       soext=".dylib" ;;
70         *w32*)          soext=".dll" ;;
71 esac
72 if test "x$soext" = "x"; then
73         soext=".so"
74         AC_MSG_RESULT([${soext}])
75         AC_MSG_WARN([
76 Host system "${host}" not recognized, defaulting to "${soext}".
77 ])
78 else
79         AC_MSG_RESULT([${soext}])
80 fi
81 ])dnl
82 dnl
83 AC_DEFUN([_GP_CHECK_LIBRARY],[
84 # ----------------------------------------------------------------------
85 # [GP_CHECK_LIBRARY]([$1],[$2],[$3],
86 #                    [$4],[$5],
87 #                    [...],[...],[$8])
88 m4_ifval([$9],[dnl
89 # $9
90 ])dnl
91 # ----------------------------------------------------------------------
92 dnl
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
101 dnl
102 AC_MSG_CHECKING([for ][$2][ to use])
103 userdef_[$1]=no
104 have_[$1]=no
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
108                         try_[$1]=no
109                 ],
110                 [m4_pushdef([gp_lib_arg],[--with-][$2])dnl
111                         try_[$1]=auto
112                 ])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
119                 m4_ifval([$3],
120                         [PKG_CHECK_MODULES([$1],[$2][ $3],[have_][$1][=yes])],
121                         [PKG_CHECK_MODULES([$1],[$2],     [have_][$1][=yes])]
122                 )
123                 if test "x${[have_][$1]}" = "xno"; then
124                         ifs="$IFS"
125                         IFS=":" # FIXME: for W32 and OS/2 we need ";" here
126                         for _libdir_ in \
127                                 ${LD_LIBRARY_PATH} \
128                                 "${libdir}" \
129                                 "${prefix}/lib64" "${prefix}/lib" \
130                                 /usr/lib64 /usr/lib \
131                                 /usr/local/lib64 /usr/local/lib \
132                                 /opt/lib64 /opt/lib
133                         do
134                                 IFS="$ifs"
135                                 for _soext_ in .la ${soext} .a; do
136                                         if test -f "${_libdir_}/[$2]${_soext_}"
137                                         then
138                                                 if test "x${_soext_}" = "x.la" ||
139                                                    test "x${_soext_}" = "x.a"; then
140                                                         [$1]_LIBS="${_libdir_}/[$2]${_soext_}"
141                                                 else
142                                                         [$1]_LIBS="-L${_libdir_} -l$(echo "$2" | sed 's/^lib//')"
143                                                 fi
144                                                 break
145                                         fi
146                                 done
147                                 if test "x${[$1][_LIBS]}" != "x"; then
148                                         break
149                                 fi
150                         done
151                         IFS="$ifs"
152                         if test "x${[$1][_LIBS]}" != "x"; then
153                                 have_[$1]=yes
154                         fi
155                 fi
156         elif test "x${[try_][$1]}" = "xno"; then
157                 :
158         else
159                 [$1][_LIBS]="-L${[try_][$1]}/lib -l$(echo "$2" | sed 's/^lib//')"
160                 [$1][_CFLAGS]="-I${[try_][$1]}/include"
161         fi
162 elif test "x${[$1][_LIBS]}" != "x" && test "x${[$1][_CFLAGS]}" != "x"; then
163         AC_MSG_RESULT([user-defined])
164         userdef_[$1]=yes
165         have_[$1]=yes
166 else
167         AC_MSG_ERROR([
168 * Fatal:
169 * When calling configure for ${PACKAGE_TARNAME}
170 *     ${PACKAGE_NAME}
171 * either set both [$1][_LIBS] *and* [$1][_CFLAGS]
172 * or neither.
173 ])
174 fi
175 dnl
176 dnl ACTION-IF-FOUND
177 dnl
178 m4_ifval([$6],[dnl
179 if test "x${[have_][$1]}" = "xyes"; then
180 # ACTION-IF-FOUND
181 $6
182 fi
183 ])dnl
184 dnl
185 dnl ACTION-IF-NOT-FOUND
186 dnl
187 m4_ifval([$7],[dnl
188 if test "x${[have_][$1]}" = "xno"; then
189 # ACTION-IF-NOT-FOUND
190 $7
191 fi
192 ])dnl
193 dnl
194 dnl Run our own test compilation
195 dnl
196 m4_ifval([$4],[dnl
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"
204 fi
205 ])dnl
206 dnl
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_).
210 dnl
211 m4_ifval([$5],[dnl
212 if test "x${[userdef_][$1]}" = "xno" && test "x${[have_][$1]}" = "xyes"; then
213         LIBS_save="$LIBSS"
214         LIBS="${[$1]_LIBS}"
215         AC_TRY_LINK_FUNC([$5],[],[have_][$1][=no])
216         LIBS="$LIBS_save"
217 fi
218 ])dnl
219 dnl
220 dnl Abort configure script if mandatory, but not found
221 dnl
222 m4_if([$8],[mandatory],[
223 if test "x${[have_][$1]}" = "xno"; then
224         AC_MSG_ERROR([
225 PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
226 [$1][_LIBS]=${[$1][_LIBS]}
227 [$1][_CFLAGS]=${[$1][_CFLAGS]}
228
229 * Fatal: ${PACKAGE_NAME} requires $2 to build.
230
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
235 ]m4_ifval([$9],[dnl
236 *   - get $2 and install it
237 ],[dnl
238 *   - get $2 and install it:
239       $9]))
240 fi
241 ])dnl
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]}])
250 else
251         GP_CONFIG_MSG([$2],[no])dnl
252 fi
253 dnl AC_SUBST is done implicitly by AC_ARG_VAR above.
254 dnl AC_SUBST([$1][_LIBS])
255 dnl AC_SUBST([$1][_CFLAGS])
256 ])dnl
257 dnl
258 dnl ####################################################################
259 dnl
260 AC_DEFUN([_GP_CHECK_LIBRARY_SYNTAX_ERROR],[dnl
261 m4_errprint(__file__:__line__:[ Error:
262 *** Calling $0 macro with old syntax
263 *** Aborting.
264 ])dnl
265 m4_exit(1)dnl
266 ])dnl
267 dnl
268 dnl ####################################################################
269 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
274 m4_if([$8], [], [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".
285 ])m4_exit(1)])dnl
286 ])dnl
287 dnl
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])
292 dnl
293 dnl ####################################################################
294 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.
299 dnl
300 dnl Local Variables:
301 dnl mode: autoconf
302 dnl End: