Statistics
| Branch: | Tag: | Revision:

root / config / pkg.m4 @ 0a9b999b

History | View | Annotate | Download (6.4 kB)

1 bf89a844 eb
# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
2 bf89a844 eb
# 
3 bf89a844 eb
# Copyright © 2004 Scott James Remnant <[email protected]>.
4 5c02ea03 eb
# Copyright © 2008 Free Software Foundation, Inc.
5 bf89a844 eb
#
6 bf89a844 eb
# This program is free software; you can redistribute it and/or modify
7 bf89a844 eb
# it under the terms of the GNU General Public License as published by
8 bf89a844 eb
# the Free Software Foundation; either version 2 of the License, or
9 bf89a844 eb
# (at your option) any later version.
10 bf89a844 eb
#
11 bf89a844 eb
# This program is distributed in the hope that it will be useful, but
12 bf89a844 eb
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 bf89a844 eb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 bf89a844 eb
# General Public License for more details.
15 bf89a844 eb
#
16 bf89a844 eb
# You should have received a copy of the GNU General Public License
17 bf89a844 eb
# along with this program; if not, write to the Free Software
18 bf89a844 eb
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 bf89a844 eb
#
20 bf89a844 eb
# As a special exception to the GNU General Public License, if you
21 bf89a844 eb
# distribute this file as part of a program that contains a
22 bf89a844 eb
# configuration script generated by Autoconf, you may include it under
23 bf89a844 eb
# the same distribution terms that you use for the rest of that program.
24 bf89a844 eb
25 bf89a844 eb
# PKG_PROG_PKG_CONFIG([MIN-VERSION])
26 bf89a844 eb
# ----------------------------------
27 bf89a844 eb
AC_DEFUN([PKG_PROG_PKG_CONFIG],
28 bf89a844 eb
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
29 bf89a844 eb
m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
30 bf89a844 eb
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl
31 bf89a844 eb
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
32 bf89a844 eb
	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
33 bf89a844 eb
fi
34 bf89a844 eb
if test -n "$PKG_CONFIG"; then
35 bf89a844 eb
	_pkg_min_version=m4_default([$1], [0.18])
36 bf89a844 eb
	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
37 bf89a844 eb
	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
38 bf89a844 eb
		AC_MSG_RESULT([yes])
39 bf89a844 eb
	else
40 bf89a844 eb
		AC_MSG_RESULT([no])
41 bf89a844 eb
		PKG_CONFIG=""
42 bf89a844 eb
	fi
43 bf89a844 eb
		
44 bf89a844 eb
fi[]dnl
45 bf89a844 eb
])# PKG_PROG_PKG_CONFIG
46 bf89a844 eb
47 bf89a844 eb
# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
48 bf89a844 eb
#
49 bf89a844 eb
# Check to see whether a particular set of modules exists.  Similar
50 bf89a844 eb
# to PKG_CHECK_MODULES(), but does not set variables or print errors.
51 bf89a844 eb
#
52 bf89a844 eb
#
53 bf89a844 eb
# Similar to PKG_CHECK_MODULES, make sure that the first instance of
54 bf89a844 eb
# this or PKG_CHECK_MODULES is called, or make sure to call
55 bf89a844 eb
# PKG_CHECK_EXISTS manually
56 bf89a844 eb
# --------------------------------------------------------------
57 bf89a844 eb
AC_DEFUN([PKG_CHECK_EXISTS],
58 bf89a844 eb
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
59 bf89a844 eb
if test -n "$PKG_CONFIG" && \
60 bf89a844 eb
    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
61 bf89a844 eb
  m4_ifval([$2], [$2], [:])
62 bf89a844 eb
m4_ifvaln([$3], [else
63 bf89a844 eb
  $3])dnl
64 bf89a844 eb
fi])
65 bf89a844 eb
66 bf89a844 eb
67 bf89a844 eb
# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
68 bf89a844 eb
# ---------------------------------------------
69 bf89a844 eb
m4_define([_PKG_CONFIG],
70 bf89a844 eb
[if test -n "$PKG_CONFIG"; then
71 bf89a844 eb
    if test -n "$$1"; then
72 bf89a844 eb
        pkg_cv_[]$1="$$1"
73 bf89a844 eb
    else
74 bf89a844 eb
        PKG_CHECK_EXISTS([$3],
75 bf89a844 eb
                         [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
76 bf89a844 eb
			 [pkg_failed=yes])
77 bf89a844 eb
    fi
78 bf89a844 eb
else
79 bf89a844 eb
	pkg_failed=untried
80 bf89a844 eb
fi[]dnl
81 bf89a844 eb
])# _PKG_CONFIG
82 bf89a844 eb
83 bf89a844 eb
# _PKG_SHORT_ERRORS_SUPPORTED
84 bf89a844 eb
# -----------------------------
85 bf89a844 eb
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
86 bf89a844 eb
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
87 bf89a844 eb
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
88 bf89a844 eb
        _pkg_short_errors_supported=yes
89 bf89a844 eb
else
90 bf89a844 eb
        _pkg_short_errors_supported=no
91 bf89a844 eb
fi[]dnl
92 bf89a844 eb
])# _PKG_SHORT_ERRORS_SUPPORTED
93 bf89a844 eb
94 bf89a844 eb
95 bf89a844 eb
# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
96 bf89a844 eb
# [ACTION-IF-NOT-FOUND])
97 bf89a844 eb
#
98 bf89a844 eb
# E.g.,
99 bf89a844 eb
#   PKG_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4, action-if, action-not)
100 5c02ea03 eb
#   defines:
101 5c02ea03 eb
#
102 5c02ea03 eb
#     GSTUFF_LIBS
103 5c02ea03 eb
#     GSTUFF_CFLAGS
104 5c02ea03 eb
#     GSTUFF_INCLUDEDIR
105 5c02ea03 eb
#     GSTUFF_CPPFLAGS    # the -I, -D and -U's out of CFLAGS
106 5c02ea03 eb
#
107 5c02ea03 eb
# see pkg-config man page also defines GSTUFF_PKG_ERRORS on error
108 bf89a844 eb
#
109 bf89a844 eb
# Note that if there is a possibility the first call to
110 bf89a844 eb
# PKG_CHECK_MODULES might not happen, you should be sure to include an
111 bf89a844 eb
# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
112 bf89a844 eb
#
113 bf89a844 eb
# --------------------------------------------------------------
114 06e7a031 eb
AC_DEFUN([PKG_CHECK_MODULES],[
115 06e7a031 eb
AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
116 06e7a031 eb
AC_REQUIRE([AC_CANONICAL_HOST])dnl
117 06e7a031 eb
AC_REQUIRE([AC_CANONICAL_BUILD])dnl
118 06e7a031 eb
119 bf89a844 eb
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
120 bf89a844 eb
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
121 5c02ea03 eb
AC_ARG_VAR([$1][_INCLUDEDIR], [includedir for $1, overriding pkg-config])dnl
122 bf89a844 eb
123 bf89a844 eb
pkg_failed=no
124 bf89a844 eb
AC_MSG_CHECKING([for $1])
125 bf89a844 eb
126 bf89a844 eb
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
127 bf89a844 eb
128 bf89a844 eb
if test x$cross_compiling = xyes
129 bf89a844 eb
then
130 06e7a031 eb
  dnl _PKG_CONFIG([$1][_LIBS], [libs-only-l --static], [$2])
131 06e7a031 eb
  _PKG_CONFIG([$1][_LIBS], [libs --static], [$2])
132 06e7a031 eb
  dnl prune out any -L/lib or -L/usr/lib since they're pointing to the wrong filesystem root
133 06e7a031 eb
  _pkg_tmp=
134 06e7a031 eb
  for flag in [$]pkg_cv_[$1][_LIBS]; do
135 06e7a031 eb
    case $flag in
136 06e7a031 eb
    (-L/lib* | -L/usr/lib* )	   ;; # ignore
137 06e7a031 eb
    (*) _pkg_tmp="$_pkg_tmp $flag" ;;
138 06e7a031 eb
    esac
139 06e7a031 eb
  done
140 06e7a031 eb
  pkg_cv_[$1][_LIBS]="$_pkg_tmp"
141 bf89a844 eb
else
142 bf89a844 eb
  _PKG_CONFIG([$1][_LIBS], [libs --static], [$2])
143 bf89a844 eb
fi
144 bf89a844 eb
145 5c02ea03 eb
_PKG_CONFIG([$1][_INCLUDEDIR], [variable=includedir], [$2])
146 5c02ea03 eb
147 5c02ea03 eb
148 bf89a844 eb
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
149 bf89a844 eb
and $1[]_LIBS to avoid the need to call pkg-config.
150 bf89a844 eb
See the pkg-config man page for more details.])
151 bf89a844 eb
152 bf89a844 eb
if test $pkg_failed = yes; then
153 bf89a844 eb
        _PKG_SHORT_ERRORS_SUPPORTED
154 bf89a844 eb
        if test $_pkg_short_errors_supported = yes; then
155 bf89a844 eb
	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"`
156 bf89a844 eb
        else 
157 bf89a844 eb
	        $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
158 5d69a524 jcorgan
        fi
159 bf89a844 eb
	# Put the nasty error message in config.log where it belongs
160 bf89a844 eb
	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
161 bf89a844 eb
162 bf89a844 eb
	ifelse([$4], , [AC_MSG_ERROR(dnl
163 bf89a844 eb
[Package requirements ($2) were not met:
164 bf89a844 eb
165 bf89a844 eb
$$1_PKG_ERRORS
166 5d69a524 jcorgan
167 bf89a844 eb
Consider adjusting the PKG_CONFIG_PATH environment variable if you
168 bf89a844 eb
installed software in a non-standard prefix.
169 5d69a524 jcorgan
170 bf89a844 eb
_PKG_TEXT
171 bf89a844 eb
])],
172 bf89a844 eb
		[AC_MSG_RESULT([no])
173 bf89a844 eb
                $4])
174 bf89a844 eb
elif test $pkg_failed = untried; then
175 bf89a844 eb
	ifelse([$4], , [AC_MSG_FAILURE(dnl
176 bf89a844 eb
[The pkg-config script could not be found or is too old.  Make sure it
177 bf89a844 eb
is in your PATH or set the PKG_CONFIG environment variable to the full
178 bf89a844 eb
path to pkg-config.
179 5d69a524 jcorgan
180 bf89a844 eb
_PKG_TEXT
181 5d69a524 jcorgan
182 bf89a844 eb
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])],
183 bf89a844 eb
		[$4])
184 bf89a844 eb
else
185 bf89a844 eb
	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
186 bf89a844 eb
	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
187 5c02ea03 eb
	$1[]_INCLUDEDIR=$pkg_cv_[]$1[]_INCLUDEDIR
188 5c02ea03 eb
189 5c02ea03 eb
	$1[]_CPPFLAGS=""
190 5c02ea03 eb
	for flag in $$1[]_CFLAGS; do
191 5c02ea03 eb
	  case $flag in
192 5c02ea03 eb
          -I* | -D* | -U*) $1[]_CPPFLAGS="$$1[]_CPPFLAGS $flag" ;;
193 5c02ea03 eb
          esac
194 5c02ea03 eb
        done
195 5c02ea03 eb
	pkg_cv_[]$1[]_CPPFLAGS=$$1[]_CPPFLAGS
196 5c02ea03 eb
	AC_SUBST($1[]_CPPFLAGS)
197 5c02ea03 eb
198 bf89a844 eb
        AC_MSG_RESULT([yes])
199 bf89a844 eb
	ifelse([$3], , :, [$3])
200 bf89a844 eb
fi[]dnl
201 bf89a844 eb
])# PKG_CHECK_MODULES