Debian Codegraph @

build-aux/m4/guile.m4

raw
1 ## Autoconf macros for working with Guile.
2 ##
3 ## Copyright (C) 1998,2001, 2006, 2010, 2012, 2013, 2014, 2020 Free Software Foundation, Inc.
4 ##
5 ## This library is free software; you can redistribute it and/or
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.
9 ##
10 ## This library is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## Lesser General Public License for more details.
14 ##
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
17 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301 USA
19
20 # serial 11
21
22 ## Index
23 ## -----
24 ##
25 ## GUILE_PKG -- find Guile development files
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" directories
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
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
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. 3.0), falling back to the previous stable version
51 # (e.g. 2.2) 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 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])
64 if test "x$PKG_CONFIG" = x; then
65 AC_MSG_ERROR([pkg-config is missing, please install it])
66 fi
67 _guile_versions_to_search="m4_default([$1], [3.0 2.2 2.0])"
68 if test -n "$GUILE_EFFECTIVE_VERSION"; then
69 _guile_tmp=""
70 for v in $_guile_versions_to_search; do
71 if test "$v" = "$GUILE_EFFECTIVE_VERSION"; then
72 _guile_tmp=$v
73 fi
74 done
75 if test -z "$_guile_tmp"; then
76 AC_MSG_FAILURE([searching for guile development files for versions $_guile_versions_to_search, but previously found $GUILE version $GUILE_EFFECTIVE_VERSION])
77 fi
78 _guile_versions_to_search=$GUILE_EFFECTIVE_VERSION
79 fi
80 GUILE_EFFECTIVE_VERSION=""
81 _guile_errors=""
82 for v in $_guile_versions_to_search; do
83 if test -z "$GUILE_EFFECTIVE_VERSION"; then
84 AC_MSG_NOTICE([checking for guile $v])
85 PKG_CHECK_EXISTS([guile-$v], [GUILE_EFFECTIVE_VERSION=$v], [])
86 fi
87 done
88
89 if test -z "$GUILE_EFFECTIVE_VERSION"; then
90 AC_MSG_ERROR([
91 No Guile development packages were found.
92
93 Please verify that you have Guile installed. If you installed Guile
94 from a binary distribution, please verify that you have also installed
95 the development packages. If you installed it yourself, you might need
96 to adjust your PKG_CONFIG_PATH; see the pkg-config man page for more.
97 ])
98 fi
99 AC_MSG_NOTICE([found guile $GUILE_EFFECTIVE_VERSION])
100 AC_SUBST([GUILE_EFFECTIVE_VERSION])
101 ])
102
103 # GUILE_FLAGS -- set flags for compiling and linking with Guile
104 #
105 # Usage: GUILE_FLAGS
106 #
107 # This macro runs the @code{pkg-config} tool to find out how to compile
108 # and link programs against Guile. It sets four variables:
109 # @var{GUILE_CFLAGS}, @var{GUILE_LDFLAGS}, @var{GUILE_LIBS}, and
110 # @var{GUILE_LTLIBS}.
111 #
112 # @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that
113 # uses Guile header files. This is almost always just one or more @code{-I}
114 # flags.
115 #
116 # @var{GUILE_LDFLAGS}: flags to pass to the compiler to link a program
117 # against Guile. This includes @code{-lguile-@var{VERSION}} for the
118 # Guile library itself, and may also include one or more @code{-L} flag
119 # to tell the compiler where to find the libraries. But it does not
120 # include flags that influence the program's runtime search path for
121 # libraries, and will therefore lead to a program that fails to start,
122 # unless all necessary libraries are installed in a standard location
123 # such as @file{/usr/lib}.
124 #
125 # @var{GUILE_LIBS} and @var{GUILE_LTLIBS}: flags to pass to the compiler or to
126 # libtool, respectively, to link a program against Guile. It includes flags
127 # that augment the program's runtime search path for libraries, so that shared
128 # libraries will be found at the location where they were during linking, even
129 # in non-standard locations. @var{GUILE_LIBS} is to be used when linking the
130 # program directly with the compiler, whereas @var{GUILE_LTLIBS} is to be used
131 # when linking the program is done through libtool.
132 #
133 # The variables are marked for substitution, as by @code{AC_SUBST}.
134 #
135 AC_DEFUN([GUILE_FLAGS],
136 [AC_REQUIRE([GUILE_PKG])
137 PKG_CHECK_MODULES(GUILE, [guile-$GUILE_EFFECTIVE_VERSION])
138
139 dnl GUILE_CFLAGS and GUILE_LIBS are already defined and AC_SUBST'd by
140 dnl PKG_CHECK_MODULES. But GUILE_LIBS to pkg-config is GUILE_LDFLAGS
141 dnl to us.
142
143 GUILE_LDFLAGS=$GUILE_LIBS
144
145 dnl Determine the platform dependent parameters needed to use rpath.
146 dnl AC_LIB_LINKFLAGS_FROM_LIBS is defined in gnulib/m4/lib-link.m4 and needs
147 dnl the file gnulib/build-aux/config.rpath.
148 AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LIBS], [$GUILE_LDFLAGS], [])
149 GUILE_LIBS="$GUILE_LDFLAGS $GUILE_LIBS"
150 AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LTLIBS], [$GUILE_LDFLAGS], [yes])
151 GUILE_LTLIBS="$GUILE_LDFLAGS $GUILE_LTLIBS"
152
153 AC_SUBST([GUILE_EFFECTIVE_VERSION])
154 AC_SUBST([GUILE_CFLAGS])
155 AC_SUBST([GUILE_LDFLAGS])
156 AC_SUBST([GUILE_LIBS])
157 AC_SUBST([GUILE_LTLIBS])
158 ])
159
160 # GUILE_SITE_DIR -- find path to Guile site directories
161 #
162 # Usage: GUILE_SITE_DIR
163 #
164 # This looks for Guile's "site" directories. The variable @var{GUILE_SITE} will
165 # be set to Guile's "site" directory for Scheme source files (usually something
166 # like PREFIX/share/guile/site). @var{GUILE_SITE_CCACHE} will be set to the
167 # directory for compiled Scheme files also known as @code{.go} files
168 # (usually something like
169 # PREFIX/lib/guile/@var{GUILE_EFFECTIVE_VERSION}/site-ccache).
170 # @var{GUILE_EXTENSION} will be set to the directory for compiled C extensions
171 # (usually something like
172 # PREFIX/lib/guile/@var{GUILE_EFFECTIVE_VERSION}/extensions). The latter two
173 # are set to blank if the particular version of Guile does not support
174 # them. Note that this macro will run the macros @code{GUILE_PKG} and
175 # @code{GUILE_PROGS} if they have not already been run.
176 #
177 # The variables are marked for substitution, as by @code{AC_SUBST}.
178 #
179 AC_DEFUN([GUILE_SITE_DIR],
180 [AC_REQUIRE([GUILE_PKG])
181 AC_REQUIRE([GUILE_PROGS])
182 AC_MSG_CHECKING(for Guile site directory)
183 GUILE_SITE=`$PKG_CONFIG --print-errors --variable=sitedir guile-$GUILE_EFFECTIVE_VERSION`
184 AC_MSG_RESULT($GUILE_SITE)
185 if test "$GUILE_SITE" = ""; then
186 AC_MSG_FAILURE(sitedir not found)
187 fi
188 AC_SUBST(GUILE_SITE)
189 AC_MSG_CHECKING([for Guile site-ccache directory using pkgconfig])
190 GUILE_SITE_CCACHE=`$PKG_CONFIG --variable=siteccachedir guile-$GUILE_EFFECTIVE_VERSION`
191 if test "$GUILE_SITE_CCACHE" = ""; then
192 AC_MSG_RESULT(no)
193 AC_MSG_CHECKING([for Guile site-ccache directory using interpreter])
194 GUILE_SITE_CCACHE=`$GUILE -c "(display (if (defined? '%site-ccache-dir) (%site-ccache-dir) \"\"))"`
195 if test $? != "0" -o "$GUILE_SITE_CCACHE" = ""; then
196 AC_MSG_RESULT(no)
197 GUILE_SITE_CCACHE=""
198 AC_MSG_WARN([siteccachedir not found])
199 fi
200 fi
201 AC_MSG_RESULT($GUILE_SITE_CCACHE)
202 AC_SUBST([GUILE_SITE_CCACHE])
203 AC_MSG_CHECKING(for Guile extensions directory)
204 GUILE_EXTENSION=`$PKG_CONFIG --print-errors --variable=extensiondir guile-$GUILE_EFFECTIVE_VERSION`
205 AC_MSG_RESULT($GUILE_EXTENSION)
206 if test "$GUILE_EXTENSION" = ""; then
207 GUILE_EXTENSION=""
208 AC_MSG_WARN(extensiondir not found)
209 fi
210 AC_SUBST(GUILE_EXTENSION)
211 ])
212
213 # GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
214 #
215 # Usage: GUILE_PROGS([VERSION])
216 #
217 # This macro looks for programs @code{guile} and @code{guild}, setting
218 # variables @var{GUILE} and @var{GUILD} to their paths, respectively.
219 # The macro will attempt to find @code{guile} with the suffix of
220 # @code{-X.Y}, followed by looking for it with the suffix @code{X.Y}, and
221 # then fall back to looking for @code{guile} with no suffix. If
222 # @code{guile} is still not found, signal an error. The suffix, if any,
223 # that was required to find @code{guile} will be used for @code{guild}
224 # as well.
225 #
226 # By default, this macro will search for the latest stable version of
227 # Guile (e.g. 3.0). x.y or x.y.z versions can be specified. If an older
228 # version is found, the macro will signal an error.
229 #
230 # The effective version of the found @code{guile} is set to
231 # @var{GUILE_EFFECTIVE_VERSION}. This macro ensures that the effective
232 # version is compatible with the result of a previous invocation of
233 # @code{GUILE_FLAGS}, if any.
234 #
235 # As a legacy interface, it also looks for @code{guile-config} and
236 # @code{guile-tools}, setting @var{GUILE_CONFIG} and @var{GUILE_TOOLS}.
237 #
238 # The variables are marked for substitution, as by @code{AC_SUBST}.
239 #
240 AC_DEFUN([GUILE_PROGS],
241 [_guile_required_version="m4_default([$1], [$GUILE_EFFECTIVE_VERSION])"
242 if test -z "$_guile_required_version"; then
243 _guile_required_version=3.0
244 fi
245
246 _guile_candidates=guile
247 _tmp=
248 for v in `echo "$_guile_required_version" | tr . ' '`; do
249 if test -n "$_tmp"; then _tmp=$_tmp.; fi
250 _tmp=$_tmp$v
251 _guile_candidates="guile-$_tmp guile$_tmp $_guile_candidates"
252 done
253
254 AC_PATH_PROGS(GUILE,[$_guile_candidates])
255 if test -z "$GUILE"; then
256 AC_MSG_ERROR([guile required but not found])
257 fi
258
259 _guile_suffix=`echo "$GUILE" | sed -e 's,^.*/guile\(.*\)$,\1,'`
260 _guile_effective_version=`$GUILE -c "(display (effective-version))"`
261 if test -z "$GUILE_EFFECTIVE_VERSION"; then
262 GUILE_EFFECTIVE_VERSION=$_guile_effective_version
263 elif test "$GUILE_EFFECTIVE_VERSION" != "$_guile_effective_version"; then
264 AC_MSG_ERROR([found development files for Guile $GUILE_EFFECTIVE_VERSION, but $GUILE has effective version $_guile_effective_version])
265 fi
266
267 _guile_major_version=`$GUILE -c "(display (major-version))"`
268 _guile_minor_version=`$GUILE -c "(display (minor-version))"`
269 _guile_micro_version=`$GUILE -c "(display (micro-version))"`
270 _guile_prog_version="$_guile_major_version.$_guile_minor_version.$_guile_micro_version"
271
272 AC_MSG_CHECKING([for Guile version >= $_guile_required_version])
273 _major_version=`echo $_guile_required_version | cut -d . -f 1`
274 _minor_version=`echo $_guile_required_version | cut -d . -f 2`
275 _micro_version=`echo $_guile_required_version | cut -d . -f 3`
276 if test "$_guile_major_version" -gt "$_major_version"; then
277 true
278 elif test "$_guile_major_version" -eq "$_major_version"; then
279 if test "$_guile_minor_version" -gt "$_minor_version"; then
280 true
281 elif test "$_guile_minor_version" -eq "$_minor_version"; then
282 if test -n "$_micro_version"; then
283 if test "$_guile_micro_version" -lt "$_micro_version"; then
284 AC_MSG_ERROR([Guile $_guile_required_version required, but $_guile_prog_version found])
285 fi
286 fi
287 elif test "$GUILE_EFFECTIVE_VERSION" = "$_major_version.$_minor_version" -a -z "$_micro_version"; then
288 # Allow prereleases that have the right effective version.
289 true
290 else
291 as_fn_error $? "Guile $_guile_required_version required, but $_guile_prog_version found" "$LINENO" 5
292 fi
293 elif test "$GUILE_EFFECTIVE_VERSION" = "$_major_version.$_minor_version" -a -z "$_micro_version"; then
294 # Allow prereleases that have the right effective version.
295 true
296 else
297 AC_MSG_ERROR([Guile $_guile_required_version required, but $_guile_prog_version found])
298 fi
299 AC_MSG_RESULT([$_guile_prog_version])
300
301 AC_PATH_PROG(GUILD,[guild$_guile_suffix])
302 AC_SUBST(GUILD)
303
304 AC_PATH_PROG(GUILE_CONFIG,[guile-config$_guile_suffix])
305 AC_SUBST(GUILE_CONFIG)
306 if test -n "$GUILD"; then
307 GUILE_TOOLS=$GUILD
308 else
309 AC_PATH_PROG(GUILE_TOOLS,[guile-tools$_guile_suffix])
310 fi
311 AC_SUBST(GUILE_TOOLS)
312 ])
313
314 # GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
315 #
316 # Usage: GUILE_CHECK_RETVAL(var,check)
317 #
318 # @var{var} is a shell variable name to be set to the return value.
319 # @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and
320 # returning either 0 or non-#f to indicate the check passed.
321 # Non-0 number or #f indicates failure.
322 # Avoid using the character "#" since that confuses autoconf.
323 #
324 AC_DEFUN([GUILE_CHECK],
325 [AC_REQUIRE([GUILE_PROGS])
326 $GUILE -c "$2" > /dev/null 2>&1
327 $1=$?
328 ])
329
330 # GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
331 #
332 # Usage: GUILE_MODULE_CHECK(var,module,featuretest,description)
333 #
334 # @var{var} is a shell variable name to be set to "yes" or "no".
335 # @var{module} is a list of symbols, like: (ice-9 common-list).
336 # @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v.
337 # @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING).
338 #
339 AC_DEFUN([GUILE_MODULE_CHECK],
340 [AC_MSG_CHECKING([if $2 $4])
341 GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3))))
342 if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi
343 AC_MSG_RESULT($$1)
344 ])
345
346 # GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
347 #
348 # Usage: GUILE_MODULE_AVAILABLE(var,module)
349 #
350 # @var{var} is a shell variable name to be set to "yes" or "no".
351 # @var{module} is a list of symbols, like: (ice-9 common-list).
352 #
353 AC_DEFUN([GUILE_MODULE_AVAILABLE],
354 [GUILE_MODULE_CHECK($1,$2,0,is available)
355 ])
356
357 # GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
358 #
359 # Usage: GUILE_MODULE_REQUIRED(symlist)
360 #
361 # @var{symlist} is a list of symbols, WITHOUT surrounding parens,
362 # like: ice-9 common-list.
363 #
364 AC_DEFUN([GUILE_MODULE_REQUIRED],
365 [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1))
366 if test "$ac_guile_module_required" = "no" ; then
367 AC_MSG_ERROR([required guile module not found: ($1)])
368 fi
369 ])
370
371 # GUILE_MODULE_EXPORTS -- check if a module exports a variable
372 #
373 # Usage: GUILE_MODULE_EXPORTS(var,module,modvar)
374 #
375 # @var{var} is a shell variable to be set to "yes" or "no".
376 # @var{module} is a list of symbols, like: (ice-9 common-list).
377 # @var{modvar} is the Guile Scheme variable to check.
378 #
379 AC_DEFUN([GUILE_MODULE_EXPORTS],
380 [GUILE_MODULE_CHECK($1,$2,$3,exports `$3')
381 ])
382
383 # GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
384 #
385 # Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar)
386 #
387 # @var{module} is a list of symbols, like: (ice-9 common-list).
388 # @var{modvar} is the Guile Scheme variable to check.
389 #
390 AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT],
391 [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2)
392 if test "$guile_module_required_export" = "no" ; then
393 AC_MSG_ERROR([module $1 does not export $2; required])
394 fi
395 ])
396
397 ## guile.m4 ends here