Commit | Line | Data |
---|---|---|
b6aaeeac TTN |
1 | ## Autoconf macros for working with Guile. |
2 | ## | |
fc3192dc | 3 | ## Copyright (C) 1998,2001, 2006, 2010, 2012, 2013, 2014 Free Software Foundation, Inc. |
b6aaeeac | 4 | ## |
73be1d9e | 5 | ## This library is free software; you can redistribute it and/or |
53befeb7 NJ |
6 | ## modify it under the terms of the GNU Lesser General Public License |
7 | ## as published by the Free Software Foundation; either version 3 of | |
8 | ## the License, or (at your option) any later version. | |
ecf0498d | 9 | ## |
73be1d9e | 10 | ## This library is distributed in the hope that it will be useful, |
b6aaeeac | 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | ## Lesser General Public License for more details. | |
ecf0498d | 14 | ## |
73be1d9e MV |
15 | ## You should have received a copy of the GNU Lesser General Public |
16 | ## License along with this library; if not, write to the Free Software | |
53befeb7 NJ |
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | ## 02110-1301 USA | |
b6aaeeac | 19 | |
5ad38816 | 20 | # serial 10 |
84eebc64 | 21 | |
b6aaeeac TTN |
22 | ## Index |
23 | ## ----- | |
24 | ## | |
ccd0ae1f | 25 | ## GUILE_PKG -- find Guile development files |
b6aaeeac TTN |
26 | ## GUILE_PROGS -- set paths to Guile interpreter, config and tool programs |
27 | ## GUILE_FLAGS -- set flags for compiling and linking with Guile | |
28 | ## GUILE_SITE_DIR -- find path to Guile "site" directory | |
29 | ## GUILE_CHECK -- evaluate Guile Scheme code and capture the return value | |
30 | ## GUILE_MODULE_CHECK -- check feature of a Guile Scheme module | |
31 | ## GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module | |
32 | ## GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable | |
33 | ## GUILE_MODULE_EXPORTS -- check if a module exports a variable | |
34 | ## GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable | |
35 | ||
36 | ## Code | |
37 | ## ---- | |
38 | ||
8c4b7ca3 TTN |
39 | ## NOTE: Comments preceding an AC_DEFUN (starting from "Usage:") are massaged |
40 | ## into doc/ref/autoconf-macros.texi (see Makefile.am in that directory). | |
41 | ||
ccd0ae1f AW |
42 | # GUILE_PKG -- find Guile development files |
43 | # | |
44 | # Usage: GUILE_PKG([VERSIONS]) | |
45 | # | |
46 | # This macro runs the @code{pkg-config} tool to find development files | |
47 | # for an available version of Guile. | |
48 | # | |
49 | # By default, this macro will search for the latest stable version of | |
50 | # Guile (e.g. 2.0), falling back to the previous stable version | |
51 | # (e.g. 1.8) if it is available. If no guile-@var{VERSION}.pc file is | |
52 | # found, an error is signalled. The found version is stored in | |
53 | # @var{GUILE_EFFECTIVE_VERSION}. | |
54 | # | |
55 | # If @code{GUILE_PROGS} was already invoked, this macro ensures that the | |
56 | # development files have the same effective version as the Guile | |
57 | # program. | |
58 | # | |
59 | # @var{GUILE_EFFECTIVE_VERSION} is marked for substitution, as by | |
60 | # @code{AC_SUBST}. | |
61 | # | |
62 | AC_DEFUN([GUILE_PKG], | |
63 | [PKG_PROG_PKG_CONFIG | |
64 | _guile_versions_to_search="m4_default([$1], [2.0 1.8])" | |
65 | if test -n "$GUILE_EFFECTIVE_VERSION"; then | |
66 | _guile_tmp="" | |
67 | for v in $_guile_versions_to_search; do | |
68 | if test "$v" = "$GUILE_EFFECTIVE_VERSION"; then | |
69 | _guile_tmp=$v | |
70 | fi | |
71 | done | |
72 | if test -z "$_guile_tmp"; then | |
73 | AC_MSG_FAILURE([searching for guile development files for versions $_guile_versions_to_search, but previously found $GUILE version $GUILE_EFFECTIVE_VERSION]) | |
74 | fi | |
75 | _guile_versions_to_search=$GUILE_EFFECTIVE_VERSION | |
b6aaeeac | 76 | fi |
ccd0ae1f AW |
77 | GUILE_EFFECTIVE_VERSION="" |
78 | _guile_errors="" | |
79 | for v in $_guile_versions_to_search; do | |
ccd0ae1f | 80 | if test -z "$GUILE_EFFECTIVE_VERSION"; then |
fc3192dc | 81 | AC_MSG_NOTICE([checking for guile $v]) |
ccd0ae1f AW |
82 | PKG_CHECK_EXISTS([guile-$v], [GUILE_EFFECTIVE_VERSION=$v], []) |
83 | fi | |
84 | done | |
85 | ||
86 | if test -z "$GUILE_EFFECTIVE_VERSION"; then | |
87 | AC_MSG_ERROR([ | |
88 | No Guile development packages were found. | |
89 | ||
90 | Please verify that you have Guile installed. If you installed Guile | |
91 | from a binary distribution, please verify that you have also installed | |
92 | the development packages. If you installed it yourself, you might need | |
93 | to adjust your PKG_CONFIG_PATH; see the pkg-config man page for more. | |
94 | ]) | |
b6aaeeac | 95 | fi |
fc3192dc | 96 | AC_MSG_NOTICE([found guile $GUILE_EFFECTIVE_VERSION]) |
ccd0ae1f | 97 | AC_SUBST([GUILE_EFFECTIVE_VERSION]) |
b6aaeeac TTN |
98 | ]) |
99 | ||
100 | # GUILE_FLAGS -- set flags for compiling and linking with Guile | |
101 | # | |
102 | # Usage: GUILE_FLAGS | |
103 | # | |
ccd0ae1f AW |
104 | # This macro runs the @code{pkg-config} tool to find out how to compile |
105 | # and link programs against Guile. It sets four variables: | |
106 | # @var{GUILE_CFLAGS}, @var{GUILE_LDFLAGS}, @var{GUILE_LIBS}, and | |
107 | # @var{GUILE_LTLIBS}. | |
b6aaeeac | 108 | # |
8c4b7ca3 | 109 | # @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that |
1867d3e0 BH |
110 | # uses Guile header files. This is almost always just one or more @code{-I} |
111 | # flags. | |
b6aaeeac | 112 | # |
ccd0ae1f AW |
113 | # @var{GUILE_LDFLAGS}: flags to pass to the compiler to link a program |
114 | # against Guile. This includes @code{-lguile-@var{VERSION}} for the | |
115 | # Guile library itself, and may also include one or more @code{-L} flag | |
116 | # to tell the compiler where to find the libraries. But it does not | |
117 | # include flags that influence the program's runtime search path for | |
118 | # libraries, and will therefore lead to a program that fails to start, | |
119 | # unless all necessary libraries are installed in a standard location | |
120 | # such as @file{/usr/lib}. | |
1867d3e0 BH |
121 | # |
122 | # @var{GUILE_LIBS} and @var{GUILE_LTLIBS}: flags to pass to the compiler or to | |
123 | # libtool, respectively, to link a program against Guile. It includes flags | |
124 | # that augment the program's runtime search path for libraries, so that shared | |
125 | # libraries will be found at the location where they were during linking, even | |
126 | # in non-standard locations. @var{GUILE_LIBS} is to be used when linking the | |
127 | # program directly with the compiler, whereas @var{GUILE_LTLIBS} is to be used | |
128 | # when linking the program is done through libtool. | |
b6aaeeac | 129 | # |
8c4b7ca3 TTN |
130 | # The variables are marked for substitution, as by @code{AC_SUBST}. |
131 | # | |
132 | AC_DEFUN([GUILE_FLAGS], | |
ccd0ae1f AW |
133 | [AC_REQUIRE([GUILE_PKG]) |
134 | PKG_CHECK_MODULES(GUILE, [guile-$GUILE_EFFECTIVE_VERSION]) | |
1867d3e0 | 135 | |
ccd0ae1f AW |
136 | dnl GUILE_CFLAGS and GUILE_LIBS are already defined and AC_SUBST'd by |
137 | dnl PKG_CHECK_MODULES. But GUILE_LIBS to pkg-config is GUILE_LDFLAGS | |
138 | dnl to us. | |
1867d3e0 | 139 | |
ccd0ae1f | 140 | GUILE_LDFLAGS=$GUILE_LIBS |
1867d3e0 BH |
141 | |
142 | dnl Determine the platform dependent parameters needed to use rpath. | |
143 | dnl AC_LIB_LINKFLAGS_FROM_LIBS is defined in gnulib/m4/lib-link.m4 and needs | |
144 | dnl the file gnulib/build-aux/config.rpath. | |
145 | AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LIBS], [$GUILE_LDFLAGS], []) | |
146 | GUILE_LIBS="$GUILE_LDFLAGS $GUILE_LIBS" | |
147 | AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LTLIBS], [$GUILE_LDFLAGS], [yes]) | |
148 | GUILE_LTLIBS="$GUILE_LDFLAGS $GUILE_LTLIBS" | |
149 | ||
ccd0ae1f | 150 | AC_SUBST([GUILE_EFFECTIVE_VERSION]) |
1867d3e0 BH |
151 | AC_SUBST([GUILE_CFLAGS]) |
152 | AC_SUBST([GUILE_LDFLAGS]) | |
153 | AC_SUBST([GUILE_LIBS]) | |
154 | AC_SUBST([GUILE_LTLIBS]) | |
8c4b7ca3 | 155 | ]) |
d0001215 | 156 | |
b6aaeeac TTN |
157 | # GUILE_SITE_DIR -- find path to Guile "site" directory |
158 | # | |
159 | # Usage: GUILE_SITE_DIR | |
160 | # | |
161 | # This looks for Guile's "site" directory, usually something like | |
8c4b7ca3 | 162 | # PREFIX/share/guile/site, and sets var @var{GUILE_SITE} to the path. |
b6aaeeac TTN |
163 | # Note that the var name is different from the macro name. |
164 | # | |
8c4b7ca3 | 165 | # The variable is marked for substitution, as by @code{AC_SUBST}. |
b6aaeeac TTN |
166 | # |
167 | AC_DEFUN([GUILE_SITE_DIR], | |
ccd0ae1f | 168 | [AC_REQUIRE([GUILE_PKG]) |
b6aaeeac | 169 | AC_MSG_CHECKING(for Guile site directory) |
ccd0ae1f AW |
170 | GUILE_SITE=`$PKG_CONFIG --print-errors --variable=sitedir guile-$GUILE_EFFECTIVE_VERSION` |
171 | AC_MSG_RESULT($GUILE_SITE) | |
5ad38816 | 172 | if test "$GUILE_SITE" = ""; then |
ccd0ae1f | 173 | AC_MSG_FAILURE(sitedir not found) |
5ad38816 | 174 | fi |
b6aaeeac TTN |
175 | AC_SUBST(GUILE_SITE) |
176 | ]) | |
177 | ||
ccd0ae1f AW |
178 | # GUILE_PROGS -- set paths to Guile interpreter, config and tool programs |
179 | # | |
ecf0498d | 180 | # Usage: GUILE_PROGS([VERSION]) |
ccd0ae1f AW |
181 | # |
182 | # This macro looks for programs @code{guile} and @code{guild}, setting | |
183 | # variables @var{GUILE} and @var{GUILD} to their paths, respectively. | |
184 | # If @code{guile} is not found, signal an error. | |
185 | # | |
ecf0498d ACF |
186 | # By default, this macro will search for the latest stable version of |
187 | # Guile (e.g. 2.0). x.y or x.y.z versions can be specified. If an older | |
188 | # version is found, the macro will signal an error. | |
189 | # | |
ccd0ae1f AW |
190 | # The effective version of the found @code{guile} is set to |
191 | # @var{GUILE_EFFECTIVE_VERSION}. This macro ensures that the effective | |
192 | # version is compatible with the result of a previous invocation of | |
193 | # @code{GUILE_FLAGS}, if any. | |
194 | # | |
195 | # As a legacy interface, it also looks for @code{guile-config} and | |
196 | # @code{guile-tools}, setting @var{GUILE_CONFIG} and @var{GUILE_TOOLS}. | |
197 | # | |
198 | # The variables are marked for substitution, as by @code{AC_SUBST}. | |
199 | # | |
200 | AC_DEFUN([GUILE_PROGS], | |
201 | [AC_PATH_PROG(GUILE,guile) | |
fc3192dc AW |
202 | _guile_required_version="m4_default([$1], [$GUILE_EFFECTIVE_VERSION])" |
203 | if test -z "$_guile_required_version"; then | |
204 | _guile_required_version=2.0 | |
205 | fi | |
ccd0ae1f AW |
206 | if test "$GUILE" = "" ; then |
207 | AC_MSG_ERROR([guile required but not found]) | |
208 | fi | |
209 | AC_SUBST(GUILE) | |
210 | ||
ecf0498d | 211 | _guile_effective_version=`$GUILE -c "(display (effective-version))"` |
ccd0ae1f | 212 | if test -z "$GUILE_EFFECTIVE_VERSION"; then |
ecf0498d ACF |
213 | GUILE_EFFECTIVE_VERSION=$_guile_effective_version |
214 | elif test "$GUILE_EFFECTIVE_VERSION" != "$_guile_effective_version"; then | |
215 | AC_MSG_ERROR([found development files for Guile $GUILE_EFFECTIVE_VERSION, but $GUILE has effective version $_guile_effective_version]) | |
216 | fi | |
217 | ||
218 | _guile_major_version=`$GUILE -c "(display (major-version))"` | |
219 | _guile_minor_version=`$GUILE -c "(display (minor-version))"` | |
220 | _guile_micro_version=`$GUILE -c "(display (micro-version))"` | |
221 | _guile_prog_version="$_guile_major_version.$_guile_minor_version.$_guile_micro_version" | |
222 | ||
223 | AC_MSG_CHECKING([for Guile version >= $_guile_required_version]) | |
224 | _major_version=`echo $_guile_required_version | cut -d . -f 1` | |
225 | _minor_version=`echo $_guile_required_version | cut -d . -f 2` | |
226 | _micro_version=`echo $_guile_required_version | cut -d . -f 3` | |
227 | if test "$_guile_major_version" -ge "$_major_version"; then | |
228 | if test "$_guile_minor_version" -ge "$_minor_version"; then | |
229 | if test -n "$_micro_version"; then | |
230 | if test "$_guile_micro_version" -lt "$_micro_version"; then | |
231 | AC_MSG_ERROR([Guile $_guile_required_version required, but $_guile_prog_version found]) | |
232 | fi | |
233 | fi | |
fc3192dc AW |
234 | elif test "$GUILE_EFFECTIVE_VERSION" == "$_major_version.$_minor_version" -a -z "$_micro_version"; then |
235 | # Allow prereleases that have the right effective version. | |
236 | true | |
ecf0498d | 237 | else |
fc3192dc | 238 | as_fn_error $? "Guile $_guile_required_version required, but $_guile_prog_version found" "$LINENO" 5 |
ecf0498d ACF |
239 | fi |
240 | else | |
241 | AC_MSG_ERROR([Guile $_guile_required_version required, but $_guile_prog_version found]) | |
ccd0ae1f | 242 | fi |
ecf0498d | 243 | AC_MSG_RESULT([$_guile_prog_version]) |
ccd0ae1f AW |
244 | |
245 | AC_PATH_PROG(GUILD,guild) | |
246 | AC_SUBST(GUILD) | |
247 | ||
248 | AC_PATH_PROG(GUILE_CONFIG,guile-config) | |
249 | AC_SUBST(GUILE_CONFIG) | |
250 | if test -n "$GUILD"; then | |
251 | GUILE_TOOLS=$GUILD | |
252 | else | |
253 | AC_PATH_PROG(GUILE_TOOLS,guile-tools) | |
254 | fi | |
255 | AC_SUBST(GUILE_TOOLS) | |
256 | ]) | |
257 | ||
b6aaeeac TTN |
258 | # GUILE_CHECK -- evaluate Guile Scheme code and capture the return value |
259 | # | |
260 | # Usage: GUILE_CHECK_RETVAL(var,check) | |
261 | # | |
8c4b7ca3 TTN |
262 | # @var{var} is a shell variable name to be set to the return value. |
263 | # @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and | |
b6aaeeac TTN |
264 | # returning either 0 or non-#f to indicate the check passed. |
265 | # Non-0 number or #f indicates failure. | |
266 | # Avoid using the character "#" since that confuses autoconf. | |
267 | # | |
268 | AC_DEFUN([GUILE_CHECK], | |
269 | [AC_REQUIRE([GUILE_PROGS]) | |
270 | $GUILE -c "$2" > /dev/null 2>&1 | |
271 | $1=$? | |
272 | ]) | |
273 | ||
274 | # GUILE_MODULE_CHECK -- check feature of a Guile Scheme module | |
275 | # | |
276 | # Usage: GUILE_MODULE_CHECK(var,module,featuretest,description) | |
277 | # | |
8c4b7ca3 TTN |
278 | # @var{var} is a shell variable name to be set to "yes" or "no". |
279 | # @var{module} is a list of symbols, like: (ice-9 common-list). | |
280 | # @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v. | |
281 | # @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING). | |
b6aaeeac TTN |
282 | # |
283 | AC_DEFUN([GUILE_MODULE_CHECK], | |
284 | [AC_MSG_CHECKING([if $2 $4]) | |
285 | GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3)))) | |
286 | if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi | |
287 | AC_MSG_RESULT($$1) | |
d0001215 TTN |
288 | ]) |
289 | ||
b6aaeeac TTN |
290 | # GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module |
291 | # | |
292 | # Usage: GUILE_MODULE_AVAILABLE(var,module) | |
293 | # | |
8c4b7ca3 TTN |
294 | # @var{var} is a shell variable name to be set to "yes" or "no". |
295 | # @var{module} is a list of symbols, like: (ice-9 common-list). | |
b6aaeeac TTN |
296 | # |
297 | AC_DEFUN([GUILE_MODULE_AVAILABLE], | |
298 | [GUILE_MODULE_CHECK($1,$2,0,is available) | |
d0001215 TTN |
299 | ]) |
300 | ||
b6aaeeac TTN |
301 | # GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable |
302 | # | |
303 | # Usage: GUILE_MODULE_REQUIRED(symlist) | |
304 | # | |
8c4b7ca3 TTN |
305 | # @var{symlist} is a list of symbols, WITHOUT surrounding parens, |
306 | # like: ice-9 common-list. | |
b6aaeeac TTN |
307 | # |
308 | AC_DEFUN([GUILE_MODULE_REQUIRED], | |
309 | [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1)) | |
d0001215 TTN |
310 | if test "$ac_guile_module_required" = "no" ; then |
311 | AC_MSG_ERROR([required guile module not found: ($1)]) | |
312 | fi | |
313 | ]) | |
314 | ||
b6aaeeac TTN |
315 | # GUILE_MODULE_EXPORTS -- check if a module exports a variable |
316 | # | |
317 | # Usage: GUILE_MODULE_EXPORTS(var,module,modvar) | |
318 | # | |
8c4b7ca3 TTN |
319 | # @var{var} is a shell variable to be set to "yes" or "no". |
320 | # @var{module} is a list of symbols, like: (ice-9 common-list). | |
321 | # @var{modvar} is the Guile Scheme variable to check. | |
b6aaeeac TTN |
322 | # |
323 | AC_DEFUN([GUILE_MODULE_EXPORTS], | |
324 | [GUILE_MODULE_CHECK($1,$2,$3,exports `$3') | |
325 | ]) | |
326 | ||
327 | # GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable | |
328 | # | |
329 | # Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar) | |
330 | # | |
8c4b7ca3 TTN |
331 | # @var{module} is a list of symbols, like: (ice-9 common-list). |
332 | # @var{modvar} is the Guile Scheme variable to check. | |
b6aaeeac TTN |
333 | # |
334 | AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT], | |
335 | [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2) | |
336 | if test "$guile_module_required_export" = "no" ; then | |
337 | AC_MSG_ERROR([module $1 does not export $2; required]) | |
338 | fi | |
339 | ]) | |
340 | ||
341 | ## guile.m4 ends here |