]> git.ipfire.org Git - thirdparty/squid.git/blob - acinclude/pkg.m4
SourceFormat Enforcement
[thirdparty/squid.git] / acinclude / pkg.m4
1 ## Copyright (C) 1996-2017 The Squid Software Foundation and contributors
2 ##
3 ## Squid software is distributed under GPLv2+ license and includes
4 ## contributions from numerous individuals and organizations.
5 ## Please see the COPYING and CONTRIBUTORS files for details.
6 ##
7
8 # pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
9 # serial 1 (pkg-config-0.24)
10 #
11 # Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
12 #
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #
27 # As a special exception to the GNU General Public License, if you
28 # distribute this file as part of a program that contains a
29 # configuration script generated by Autoconf, you may include it under
30 # the same distribution terms that you use for the rest of that program.
31
32 # PKG_PROG_PKG_CONFIG([MIN-VERSION])
33 # ----------------------------------
34 AC_DEFUN([PKG_PROG_PKG_CONFIG],
35 [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
36 m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
37 AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
38 AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
39 AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
40
41 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
42 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
43 fi
44 if test -n "$PKG_CONFIG"; then
45 _pkg_min_version=m4_default([$1], [0.9.0])
46 AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
47 if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
48 AC_MSG_RESULT([yes])
49 else
50 AC_MSG_RESULT([no])
51 PKG_CONFIG=""
52 fi
53 fi[]dnl
54 ])# PKG_PROG_PKG_CONFIG
55
56 # PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
57 #
58 # Check to see whether a particular set of modules exists. Similar
59 # to PKG_CHECK_MODULES(), but does not set variables or print errors.
60 #
61 # Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
62 # only at the first occurence in configure.ac, so if the first place
63 # it's called might be skipped (such as if it is within an "if", you
64 # have to call PKG_CHECK_EXISTS manually
65 # --------------------------------------------------------------
66 AC_DEFUN([PKG_CHECK_EXISTS],
67 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
68 if test -n "$PKG_CONFIG" && \
69 AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
70 m4_default([$2], [:])
71 m4_ifvaln([$3], [else
72 $3])dnl
73 fi])
74
75 # _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
76 # ---------------------------------------------
77 m4_define([_PKG_CONFIG],
78 [if test -n "$$1"; then
79 pkg_cv_[]$1="$$1"
80 elif test -n "$PKG_CONFIG"; then
81 PKG_CHECK_EXISTS([$3],
82 [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
83 [pkg_failed=yes])
84 else
85 pkg_failed=untried
86 fi[]dnl
87 ])# _PKG_CONFIG
88
89 # _PKG_SHORT_ERRORS_SUPPORTED
90 # -----------------------------
91 AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
92 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])
93 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
94 _pkg_short_errors_supported=yes
95 else
96 _pkg_short_errors_supported=no
97 fi[]dnl
98 ])# _PKG_SHORT_ERRORS_SUPPORTED
99
100
101 # PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
102 # [ACTION-IF-NOT-FOUND])
103 #
104 #
105 # Note that if there is a possibility the first call to
106 # PKG_CHECK_MODULES might not happen, you should be sure to include an
107 # explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
108 #
109 #
110 # --------------------------------------------------------------
111 AC_DEFUN([PKG_CHECK_MODULES],
112 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
113 AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
114 AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
115
116 pkg_failed=no
117 AC_MSG_CHECKING([for $1])
118
119 _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
120 _PKG_CONFIG([$1][_LIBS], [libs], [$2])
121
122 m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
123 and $1[]_LIBS to avoid the need to call pkg-config.
124 See the pkg-config man page for more details.])
125
126 if test $pkg_failed = yes; then
127 AC_MSG_RESULT([no])
128 _PKG_SHORT_ERRORS_SUPPORTED
129 if test $_pkg_short_errors_supported = yes; then
130 $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
131 else
132 $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
133 fi
134 # Put the nasty error message in config.log where it belongs
135 echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
136
137 m4_default([$4], [AC_MSG_ERROR(
138 [Package requirements ($2) were not met:
139
140 $$1_PKG_ERRORS
141
142 Consider adjusting the PKG_CONFIG_PATH environment variable if you
143 installed software in a non-standard prefix.
144
145 _PKG_TEXT])dnl
146 ])
147 elif test $pkg_failed = untried; then
148 AC_MSG_RESULT([no])
149 m4_default([$4], [AC_MSG_FAILURE(
150 [The pkg-config script could not be found or is too old. Make sure it
151 is in your PATH or set the PKG_CONFIG environment variable to the full
152 path to pkg-config.
153
154 _PKG_TEXT
155
156 To get pkg-config, see <http://pkg-config.freedesktop.org/>.])dnl
157 ])
158 else
159 $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
160 $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
161 AC_MSG_RESULT([yes])
162 $3
163 fi[]dnl
164 ])# PKG_CHECK_MODULES