]> jfr.im git - solanum.git/blame - m4/pkg.m4
Merge pull request #260 from FauxFaux/yesno-1
[solanum.git] / m4 / pkg.m4
CommitLineData
83c9439a
LS
1# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
2# serial 1 (pkg-config-0.24)
3#
4# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19#
20# As a special exception to the GNU General Public License, if you
21# distribute this file as part of a program that contains a
22# configuration script generated by Autoconf, you may include it under
23# the same distribution terms that you use for the rest of that program.
24
25# PKG_PROG_PKG_CONFIG([MIN-VERSION])
26# ----------------------------------
27AC_DEFUN([PKG_PROG_PKG_CONFIG],
28[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
29m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
30m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
31AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
32AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
33AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
34
35if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
36 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
37fi
38if test -n "$PKG_CONFIG"; then
39 _pkg_min_version=m4_default([$1], [0.9.0])
40 AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
41 if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
42 AC_MSG_RESULT([yes])
43 else
44 AC_MSG_RESULT([no])
45 PKG_CONFIG=""
46 fi
47fi[]dnl
48])# PKG_PROG_PKG_CONFIG
49
50# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
51#
52# Check to see whether a particular set of modules exists. Similar
53# to PKG_CHECK_MODULES(), but does not set variables or print errors.
54#
55# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
56# only at the first occurence in configure.ac, so if the first place
57# it's called might be skipped (such as if it is within an "if", you
58# have to call PKG_CHECK_EXISTS manually
59# --------------------------------------------------------------
60AC_DEFUN([PKG_CHECK_EXISTS],
61[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
62if test -n "$PKG_CONFIG" && \
63 AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
64 m4_default([$2], [:])
65m4_ifvaln([$3], [else
66 $3])dnl
67fi])
68
69# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
70# ---------------------------------------------
71m4_define([_PKG_CONFIG],
72[if test -n "$$1"; then
73 pkg_cv_[]$1="$$1"
74 elif test -n "$PKG_CONFIG"; then
75 PKG_CHECK_EXISTS([$3],
76 [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
77 test "x$?" != "x0" && pkg_failed=yes ],
78 [pkg_failed=yes])
79 else
80 pkg_failed=untried
81fi[]dnl
82])# _PKG_CONFIG
83
84# _PKG_SHORT_ERRORS_SUPPORTED
85# -----------------------------
86AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
87[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
88if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
89 _pkg_short_errors_supported=yes
90else
91 _pkg_short_errors_supported=no
92fi[]dnl
93])# _PKG_SHORT_ERRORS_SUPPORTED
94
95
96# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
97# [ACTION-IF-NOT-FOUND])
98#
99#
100# Note that if there is a possibility the first call to
101# PKG_CHECK_MODULES might not happen, you should be sure to include an
102# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
103#
104#
105# --------------------------------------------------------------
106AC_DEFUN([PKG_CHECK_MODULES],
107[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
108AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
109AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
110
111pkg_failed=no
112AC_MSG_CHECKING([for $1])
113
114_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
115_PKG_CONFIG([$1][_LIBS], [libs], [$2])
116
117m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
118and $1[]_LIBS to avoid the need to call pkg-config.
119See the pkg-config man page for more details.])
120
121if test $pkg_failed = yes; then
122 AC_MSG_RESULT([no])
123 _PKG_SHORT_ERRORS_SUPPORTED
124 if test $_pkg_short_errors_supported = yes; then
125 $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
126 else
127 $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
128 fi
129 # Put the nasty error message in config.log where it belongs
130 echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
131
132 m4_default([$4], [AC_MSG_ERROR(
133[Package requirements ($2) were not met:
134
135$$1_PKG_ERRORS
136
137Consider adjusting the PKG_CONFIG_PATH environment variable if you
138installed software in a non-standard prefix.
139
140_PKG_TEXT])[]dnl
141 ])
142elif test $pkg_failed = untried; then
143 AC_MSG_RESULT([no])
144 m4_default([$4], [AC_MSG_FAILURE(
145[The pkg-config script could not be found or is too old. Make sure it
146is in your PATH or set the PKG_CONFIG environment variable to the full
147path to pkg-config.
148
149_PKG_TEXT
150
151To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
152 ])
153else
154 $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
155 $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
156 AC_MSG_RESULT([yes])
157 $3
158fi[]dnl
159])# PKG_CHECK_MODULES
160
161# PKG_INSTALLDIR(DIRECTORY)
162# -------------------------
163# Substitutes the variable pkgconfigdir as the location where a module
164# should install pkg-config .pc files. By default the directory is
165# $libdir/pkgconfig, but the default can be changed by passing
166# DIRECTORY. The user can override through the --with-pkgconfigdir
167# parameter.
168AC_DEFUN([PKG_INSTALLDIR],
169[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
170m4_pushdef([pkg_description],
171 [pkg-config installation directory @<:@]pkg_default[@:>@])
172AC_ARG_WITH([pkgconfigdir],
173 [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
174 [with_pkgconfigdir=]pkg_default)
175AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
176m4_popdef([pkg_default])
177m4_popdef([pkg_description])
178]) dnl PKG_INSTALLDIR
179
180
181# PKG_NOARCH_INSTALLDIR(DIRECTORY)
182# -------------------------
183# Substitutes the variable noarch_pkgconfigdir as the location where a
184# module should install arch-independent pkg-config .pc files. By
185# default the directory is $datadir/pkgconfig, but the default can be
186# changed by passing DIRECTORY. The user can override through the
187# --with-noarch-pkgconfigdir parameter.
188AC_DEFUN([PKG_NOARCH_INSTALLDIR],
189[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
190m4_pushdef([pkg_description],
191 [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
192AC_ARG_WITH([noarch-pkgconfigdir],
193 [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
194 [with_noarch_pkgconfigdir=]pkg_default)
195AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
196m4_popdef([pkg_default])
197m4_popdef([pkg_description])
198]) dnl PKG_NOARCH_INSTALLDIR
199
200
201# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
202# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
203# -------------------------------------------
204# Retrieves the value of the pkg-config variable for the given module.
205AC_DEFUN([PKG_CHECK_VAR],
206[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
207AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
208
209_PKG_CONFIG([$1], [variable="][$3]["], [$2])
210AS_VAR_COPY([$1], [pkg_cv_][$1])
211
212AS_VAR_IF([$1], [""], [$5], [$4])dnl
213])# PKG_CHECK_VAR
214
215# PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
216# [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
217# [DESCRIPTION], [DEFAULT])
218#
219# Prepare a "--with-" configure option using the lowercase [VARIABLE-PREFIX]
220# name, merging the behaviour of AC_ARG_WITH and PKG_CHECK_MODULES in a single
221# macro
222#
223# --------------------------------------------------------------
224AC_DEFUN([PKG_WITH_MODULES],
225[
226m4_pushdef([with_arg], m4_tolower([$1]))
227
228m4_pushdef([description],
229 [m4_default([$5], [build with ]with_arg[ support])])
230
231m4_pushdef([def_arg], [m4_default([$6], [auto])])
232m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
233m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])
234
235m4_case(def_arg,
236 [yes],[m4_pushdef([with_without], [--without-]with_arg)],
237 [m4_pushdef([with_without],[--with-]with_arg)])
238
239AC_ARG_WITH(with_arg,
240 AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
241 [AS_TR_SH([with_]with_arg)=def_arg])
242
243AS_CASE([$AS_TR_SH([with_]with_arg)],
244 [yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
245 [auto],[PKG_CHECK_MODULES([$1],[$2],
246 [m4_n([def_action_if_found]) $3],
247 [m4_n([def_action_if_not_found]) $4])])
248
249m4_popdef([with_arg])
250m4_popdef([description])
251m4_popdef([def_arg])
252
253]) dnl PKG_WITH_MODULES
254
255# PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
256# [DESCRIPTION], [DEFAULT])
257#
258# Convenience macro to trigger AM_CONDITIONAL after
259# PKG_WITH_MODULES check.
260#
261# HAVE_[VARIABLE-PREFIX] is exported as make variable.
262#
263# --------------------------------------------------------------
264AC_DEFUN([PKG_HAVE_WITH_MODULES],
265[
266PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])
267
268AM_CONDITIONAL([HAVE_][$1],
269 [test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
270])
271
272# PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
273# [DESCRIPTION], [DEFAULT])
274#
275# Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
276# PKG_WITH_MODULES check.
277#
278# HAVE_[VARIABLE-PREFIX] is exported as make and preprocessor variable.
279#
280# --------------------------------------------------------------
281AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],
282[
283PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])
284
285AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
286 [AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
287])