2 dnl virt-lib.m4: Helper macros for checking for libraries
4 dnl Copyright (C) 2012-2014 Red Hat, Inc.
6 dnl This library is free software; you can redistribute it and/or
7 dnl modify it under the terms of the GNU Lesser General Public
8 dnl License as published by the Free Software Foundation; either
9 dnl version 2.1 of the License, or (at your option) any later version.
11 dnl This library is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 dnl Lesser General Public License for more details.
16 dnl You should have received a copy of the GNU Lesser General Public
17 dnl License along with this library. If not, see
18 dnl <http://www.gnu.org/licenses/>.
22 dnl Probe for existence of libXXXX and set WITH_XXX
23 dnl config header var, WITH_XXXX make conditional and
24 dnl with_XXX configure shell var.
26 dnl LIBVIRT_CHECK_LIB([CHECK_NAME], [LIBRARY_NAME],
27 dnl [FUNCTION_NAME], [HEADER_NAME],
30 dnl CHECK_NAME: Suffix/prefix used for variables / flags, in uppercase.
32 dnl config.h: WITH_XXX macro
33 dnl Makefile: WITH_XXX conditional
34 dnl Makefile: XXX_CFLAGS, XXX_LIBS variables
35 dnl configure: --with-xxx argument
36 dnl configure: with_xxx variable
38 dnl LIBRARY_NAME: base name of library to check for eg libXXX.so
39 dnl FUNCTION_NAME: function to check for in libXXX.so
40 dnl HEADER_NAME: header file to check for
41 dnl FAIL_ACTION: overrides the default fail action
46 dnl LIBVIRT_CHECK_LIB([SELINUX], [selinux],
47 dnl [getfilecon], [selinux/selinux.h])
48 dnl LIBVIRT_CHECK_LIB([SANLOCK], [sanlock_client],
49 dnl [sanlock_init], [sanlock.h])
50 dnl LIBVIRT_CHECK_LIB([LIBATTR], [attr],
51 dnl [getxattr], [attr/attr.h])
53 AC_DEFUN([LIBVIRT_CHECK_LIB],[
54 m4_pushdef([check_name], [$1])
55 m4_pushdef([library_name], [$2])
56 m4_pushdef([function_name], [$3])
57 m4_pushdef([header_name], [$4])
58 m4_pushdef([fail_action], [$5])
60 m4_pushdef([check_name_lc], m4_tolower(check_name))
62 m4_pushdef([config_var], [WITH_]check_name)
63 m4_pushdef([make_var], [WITH_]check_name)
64 m4_pushdef([cflags_var], check_name[_CFLAGS])
65 m4_pushdef([libs_var], check_name[_LIBS])
66 m4_pushdef([with_var], [with_]check_name_lc)
74 if test "x$with_var" != "xno" ; then
75 if test "x$with_var" != "xyes" && test "x$with_var" != "xcheck" ; then
76 cflags_var="-I$with_var/include"
77 libs_var="-L$with_var/lib"
79 CFLAGS="$CFLAGS $cflags_var"
80 LIBS="$LIBS $libs_var"
81 AC_CHECK_LIB(library_name, function_name, [],[
82 if test "x$with_var" != "xcheck"; then
87 if test "$fail" = "0" && test "x$with_var" != "xno" ; then
88 AC_CHECK_HEADER(header_name, [
91 if test "x$with_var" != "xcheck"; then
102 if test $fail = 1; then
103 m4_default(fail_action,
104 [AC_MSG_ERROR([You must install the lib]library_name[ library & headers to compile libvirt])])
106 if test "x$with_var" = "xyes" ; then
107 if test "x$libs_var" = 'x' ; then
108 libs_var="-l[]library_name"
110 libs_var="$libs_var -l[]library_name"
112 AC_DEFINE_UNQUOTED(config_var, 1, [whether lib]library_name[ is available])
115 AM_CONDITIONAL(make_var, [test "x$with_var" = "xyes"])
121 m4_popdef([with_var])
122 m4_popdef([libs_var])
123 m4_popdef([cflags_var])
124 m4_popdef([make_var])
125 m4_popdef([config_var])
127 m4_popdef([check_name_lc])
129 m4_popdef([fail_action])
130 m4_popdef([header_name])
131 m4_popdef([function_name])
132 m4_popdef([library_name])
133 m4_popdef([check_name])
136 dnl Probe for existence of libXXXX and set WITH_XXX
137 dnl config header var, WITH_XXXX make conditional and
138 dnl with_XXX configure shell var.
140 dnl LIBVIRT_CHECK_LIB_ALT([CHECK_NAME], [LIBRARY_NAME],
141 dnl [FUNCTION_NAME], [HEADER_NAME],
142 dnl [CHECK_NAME_ALT, [LIBRARY_NAME_ALT],
143 dnl [FUNCTION_NAME_ALT], [HEADER_NAME_ALT],
146 dnl CHECK_NAME: Suffix/prefix used for variables / flags, in uppercase.
148 dnl config.h: WITH_XXX macro
149 dnl Makefile: WITH_XXX conditional
150 dnl Makefile: XXX_CFLAGS, XXX_LIBS variables
151 dnl configure: --with-xxx argument
152 dnl configure: with_xxx variable
154 dnl LIBRARY_NAME: base name of library to check for eg libXXX.so
155 dnl FUNCTION_NAME: function to check for in libXXX.so
156 dnl HEADER_NAME: header file to check for
158 dnl CHECK_NAME_ALT: Suffix/prefix used to set additional
159 dnl variables if alternative check succeeds
160 dnl config.h: WITH_XXX macro
161 dnl Makefile: WITH_XXX conditional
162 dnl NB all vars for CHECK_NAME are also set
163 dnl LIBRARY_NAME_ALT: alternative library name to check for
164 dnl FUNCTION_NAME_ALT: alternative function name to check for
165 dnl HEADER_NAME_ALT: alternative header file to check for
166 dnl FAIL_ACTION: overrides the default fail action
170 dnl LIBVIRT_CHECK_LIB([YAJL], [yajl],
171 dnl [yajl_parse_complete], [yajl/yajl_common.h],
173 dnl [yajl_tree_parse], [yajl/yajl_common.h])
175 AC_DEFUN([LIBVIRT_CHECK_LIB_ALT],[
176 m4_pushdef([check_name], [$1])
177 m4_pushdef([library_name], [$2])
178 m4_pushdef([function_name], [$3])
179 m4_pushdef([header_name], [$4])
180 m4_pushdef([check_name_alt], [$5])
181 m4_pushdef([library_name_alt], [$6])
182 m4_pushdef([function_name_alt], [$7])
183 m4_pushdef([header_name_alt], [$8])
184 m4_pushdef([fail_action], [$9])
186 m4_pushdef([check_name_lc], m4_tolower(check_name))
188 m4_pushdef([config_var], [WITH_]check_name)
189 m4_pushdef([make_var], [WITH_]check_name)
190 m4_pushdef([cflags_var], check_name[_CFLAGS])
191 m4_pushdef([libs_var], check_name[_LIBS])
192 m4_pushdef([with_var], [with_]check_name_lc)
193 m4_pushdef([config_var_alt], [WITH_]check_name_alt)
194 m4_pushdef([make_var_alt], [WITH_]check_name_alt)
203 if test "x$with_var" != "xno" ; then
204 if test "x$with_var" != "xyes" && test "x$with_var" != "xcheck" ; then
205 cflags_var="-I$with_var/include"
206 libs_var="-L$with_var/lib"
208 CFLAGS="$CFLAGS $cflags_var"
209 LIBS="$LIBS $libs_var"
210 AC_CHECK_LIB(library_name, function_name, [],[
211 AC_CHECK_LIB(library_name_alt, function_name_alt, [
214 if test "x$with_var" != "xcheck"; then
220 if test "$fail" = "0" && test "x$with_var" != "xno" ; then
221 AC_CHECK_HEADER(header_name, [
224 AC_CHECK_HEADER(header_name_alt, [
227 if test "x$with_var" != "xcheck"; then
239 if test $fail = 1; then
240 m4_default(fail_action,
241 [AC_MSG_ERROR([You must install the lib]library_name[ library & headers to compile libvirt])])
243 if test "x$with_var" = "xyes" ; then
244 if test "x$libs_var" = 'x' ; then
245 libs_var="-l[]library_name"
247 libs_var="$libs_var -l[]library_name"
250 AC_DEFINE_UNQUOTED(config_var, 1, [whether lib]library_name[ is available])
251 if test "$alt" = "1" ; then
252 AC_DEFINE_UNQUOTED(config_var_alt, 1, [whether lib]library_name[ is available])
256 AM_CONDITIONAL(make_var, [test "x$with_var" = "xyes"])
257 AM_CONDITIONAL(make_var_alt, [test "x$with_var" = "xyes" && test "$alt" = "1"])
263 m4_popdef([make_var_alt])
264 m4_popdef([config_var_alt])
265 m4_popdef([with_var])
266 m4_popdef([libs_var])
267 m4_popdef([cflags_var])
268 m4_popdef([make_var])
269 m4_popdef([config_var])
271 m4_popdef([check_name_lc])
273 m4_popdef([fail_action])
274 m4_popdef([header_name_alt])
275 m4_popdef([function_name_alt])
276 m4_popdef([library_name_alt])
277 m4_popdef([header_name])
278 m4_popdef([function_name])
279 m4_popdef([library_name])
280 m4_popdef([check_name])
284 dnl Probe for existence of libXXXX and set WITH_XXX
285 dnl config header var, WITH_XXXX make conditional and
286 dnl with_XXX configure shell var.
288 dnl LIBVIRT_CHECK_PKG([CHECK_NAME], [PC_NAME], [PC_VERSION],
291 dnl CHECK_NAME: Suffix/prefix used for variables / flags, in uppercase.
293 dnl config.h: WITH_XXX macro
294 dnl Makefile: WITH_XXX conditional
295 dnl Makefile: XXX_CFLAGS, XXX_LIBS variables
296 dnl configure: --with-xxx argument
297 dnl configure: with_xxx variable
298 dnl PC_NAME: Name of the pkg-config module
299 dnl PC_VERSION: Version of the pkg-config module
300 dnl FAIL_ACTION: overrides the default fail action
304 dnl LIBVIRT_CHECK_PKG([NETCF], [netcf], [0.1.4])
306 AC_DEFUN([LIBVIRT_CHECK_PKG],[
307 m4_pushdef([check_name], [$1])
308 m4_pushdef([pc_name], [$2])
309 m4_pushdef([pc_version], [$3])
310 m4_pushdef([fail_action], [$4])
312 m4_pushdef([check_name_lc], m4_tolower(check_name))
314 m4_pushdef([config_var], [WITH_]check_name)
315 m4_pushdef([make_var], [WITH_]check_name)
316 m4_pushdef([cflags_var], check_name[_CFLAGS])
317 m4_pushdef([libs_var], check_name[_LIBS])
318 m4_pushdef([with_var], [with_]check_name_lc)
321 if test "x$with_var" != "xno" ; then
322 PKG_CHECK_MODULES(check_name, pc_name[ >= ]pc_version, [
325 if test "x$with_var" != "xcheck"; then
332 if test $fail = 1; then
333 m4_default(fail_action,
334 [AC_MSG_ERROR([You must install the ]pc_name[ >= ]pc_version[ pkg-config module to compile libvirt])])
337 if test "x$with_var" = "xyes" ; then
338 AC_DEFINE_UNQUOTED(config_var, 1, [whether ]pc_name[ >= ]pc_version[ is available])
341 AM_CONDITIONAL(make_var, [test "x$with_var" = "xyes"])
343 m4_popdef([with_var])
344 m4_popdef([libs_var])
345 m4_popdef([cflags_var])
346 m4_popdef([make_var])
347 m4_popdef([config_var])
349 m4_popdef([check_name_lc])
351 m4_popdef([fail_action])
352 m4_popdef([pc_version])
354 m4_popdef([check_name])
358 dnl To be used after a call to LIBVIRT_CHECK_LIB,
359 dnl LIBVIRT_CHECK_LIB_ALT or LIBVIRT_CHECK_PKG
360 dnl to print the result status
362 dnl LIBVIRT_RESULT_LIB([CHECK_NAME])
364 dnl CHECK_NAME: Suffix/prefix used for variables / flags, in uppercase.
366 dnl LIBVIRT_RESULT_LIB([SELINUX])
368 AC_DEFUN([LIBVIRT_RESULT_LIB],[
369 m4_pushdef([check_name], [$1])
371 m4_pushdef([check_name_lc], m4_tolower(check_name))
373 m4_pushdef([cflags_var], check_name[_CFLAGS])
374 m4_pushdef([libs_var], check_name[_LIBS])
375 m4_pushdef([with_var], [with_]check_name_lc)
377 LIBVIRT_RESULT(check_name_lc, [$with_var], [CFLAGS='$cflags_var' LIBS='$libs_var'])
379 m4_popdef([with_var])
380 m4_popdef([libs_var])
381 m4_popdef([cflags_var])
383 m4_popdef([check_name_lc])
385 m4_popdef([check_name])