Merge commit 'cc8afa2b361635953dfba7f10e4193b1f243a50f'
[bpt/guile.git] / meta / guile.m4
CommitLineData
b6aaeeac
TTN
1## Autoconf macros for working with Guile.
2##
5ad38816 3## Copyright (C) 1998,2001, 2006, 2010 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.
73be1d9e
MV
9##
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.
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
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##
25## GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
26## GUILE_FLAGS -- set flags for compiling and linking with Guile
27## GUILE_SITE_DIR -- find path to Guile "site" directory
28## GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
29## GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
30## GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
31## GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
32## GUILE_MODULE_EXPORTS -- check if a module exports a variable
33## GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
34
35## Code
36## ----
37
8c4b7ca3
TTN
38## NOTE: Comments preceding an AC_DEFUN (starting from "Usage:") are massaged
39## into doc/ref/autoconf-macros.texi (see Makefile.am in that directory).
40
b6aaeeac
TTN
41# GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
42#
43# Usage: GUILE_PROGS
44#
8c4b7ca3
TTN
45# This macro looks for programs @code{guile}, @code{guile-config} and
46# @code{guile-tools}, and sets variables @var{GUILE}, @var{GUILE_CONFIG} and
47# @var{GUILE_TOOLS}, to their paths, respectively. If either of the first two
e12ed7aa 48# is not found, signal error.
b6aaeeac 49#
8c4b7ca3 50# The variables are marked for substitution, as by @code{AC_SUBST}.
b6aaeeac
TTN
51#
52AC_DEFUN([GUILE_PROGS],
53 [AC_PATH_PROG(GUILE,guile)
54 if test "$GUILE" = "" ; then
55 AC_MSG_ERROR([guile required but not found])
56 fi
57 AC_SUBST(GUILE)
58 AC_PATH_PROG(GUILE_CONFIG,guile-config)
59 if test "$GUILE_CONFIG" = "" ; then
60 AC_MSG_ERROR([guile-config required but not found])
61 fi
62 AC_SUBST(GUILE_CONFIG)
63 AC_PATH_PROG(GUILE_TOOLS,guile-tools)
64 AC_SUBST(GUILE_TOOLS)
65 ])
66
67# GUILE_FLAGS -- set flags for compiling and linking with Guile
68#
69# Usage: GUILE_FLAGS
70#
8c4b7ca3
TTN
71# This macro runs the @code{guile-config} script, installed with Guile, to
72# find out where Guile's header files and libraries are installed. It sets
1867d3e0
BH
73# four variables, @var{GUILE_CFLAGS}, @var{GUILE_LDFLAGS}, @var{GUILE_LIBS},
74# and @var{GUILE_LTLIBS}.
b6aaeeac 75#
8c4b7ca3 76# @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that
1867d3e0
BH
77# uses Guile header files. This is almost always just one or more @code{-I}
78# flags.
b6aaeeac 79#
1867d3e0 80# @var{GUILE_LDFLAGS}: flags to pass to the compiler to link a program against
8c4b7ca3
TTN
81# Guile. This includes @code{-lguile} for the Guile library itself, any
82# libraries that Guile itself requires (like -lqthreads), and so on. It may
1867d3e0
BH
83# also include one or more @code{-L} flag to tell the compiler where to find
84# the libraries. But it does not include flags that influence the program's
85# runtime search path for libraries, and will therefore lead to a program
86# that fails to start, unless all necessary libraries are installed in a
87# standard location such as @file{/usr/lib}.
88#
89# @var{GUILE_LIBS} and @var{GUILE_LTLIBS}: flags to pass to the compiler or to
90# libtool, respectively, to link a program against Guile. It includes flags
91# that augment the program's runtime search path for libraries, so that shared
92# libraries will be found at the location where they were during linking, even
93# in non-standard locations. @var{GUILE_LIBS} is to be used when linking the
94# program directly with the compiler, whereas @var{GUILE_LTLIBS} is to be used
95# when linking the program is done through libtool.
b6aaeeac 96#
8c4b7ca3
TTN
97# The variables are marked for substitution, as by @code{AC_SUBST}.
98#
99AC_DEFUN([GUILE_FLAGS],
1867d3e0
BH
100 [dnl Find guile-config.
101 AC_REQUIRE([GUILE_PROGS])dnl
102
8c4b7ca3
TTN
103 AC_MSG_CHECKING([libguile compile flags])
104 GUILE_CFLAGS="`$GUILE_CONFIG compile`"
105 AC_MSG_RESULT([$GUILE_CFLAGS])
1867d3e0 106
8c4b7ca3
TTN
107 AC_MSG_CHECKING([libguile link flags])
108 GUILE_LDFLAGS="`$GUILE_CONFIG link`"
109 AC_MSG_RESULT([$GUILE_LDFLAGS])
1867d3e0
BH
110
111 dnl Determine the platform dependent parameters needed to use rpath.
112 dnl AC_LIB_LINKFLAGS_FROM_LIBS is defined in gnulib/m4/lib-link.m4 and needs
113 dnl the file gnulib/build-aux/config.rpath.
114 AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LIBS], [$GUILE_LDFLAGS], [])
115 GUILE_LIBS="$GUILE_LDFLAGS $GUILE_LIBS"
116 AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LTLIBS], [$GUILE_LDFLAGS], [yes])
117 GUILE_LTLIBS="$GUILE_LDFLAGS $GUILE_LTLIBS"
118
119 AC_SUBST([GUILE_CFLAGS])
120 AC_SUBST([GUILE_LDFLAGS])
121 AC_SUBST([GUILE_LIBS])
122 AC_SUBST([GUILE_LTLIBS])
8c4b7ca3 123 ])
d0001215 124
b6aaeeac
TTN
125# GUILE_SITE_DIR -- find path to Guile "site" directory
126#
127# Usage: GUILE_SITE_DIR
128#
129# This looks for Guile's "site" directory, usually something like
8c4b7ca3 130# PREFIX/share/guile/site, and sets var @var{GUILE_SITE} to the path.
b6aaeeac
TTN
131# Note that the var name is different from the macro name.
132#
8c4b7ca3 133# The variable is marked for substitution, as by @code{AC_SUBST}.
b6aaeeac
TTN
134#
135AC_DEFUN([GUILE_SITE_DIR],
136 [AC_REQUIRE([GUILE_PROGS])dnl
137 AC_MSG_CHECKING(for Guile site directory)
922d3695 138 GUILE_SITE=`[$GUILE_CONFIG] info sitedir`
5ad38816
MG
139 if test "$GUILE_SITE" = ""; then
140 GUILE_SITE=`[$GUILE_CONFIG] info pkgdatadir`/site
141 fi
b6aaeeac
TTN
142 AC_MSG_RESULT($GUILE_SITE)
143 AC_SUBST(GUILE_SITE)
144 ])
145
146# GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
147#
148# Usage: GUILE_CHECK_RETVAL(var,check)
149#
8c4b7ca3
TTN
150# @var{var} is a shell variable name to be set to the return value.
151# @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and
b6aaeeac
TTN
152# returning either 0 or non-#f to indicate the check passed.
153# Non-0 number or #f indicates failure.
154# Avoid using the character "#" since that confuses autoconf.
155#
156AC_DEFUN([GUILE_CHECK],
157 [AC_REQUIRE([GUILE_PROGS])
158 $GUILE -c "$2" > /dev/null 2>&1
159 $1=$?
160 ])
161
162# GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
163#
164# Usage: GUILE_MODULE_CHECK(var,module,featuretest,description)
165#
8c4b7ca3
TTN
166# @var{var} is a shell variable name to be set to "yes" or "no".
167# @var{module} is a list of symbols, like: (ice-9 common-list).
168# @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v.
169# @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING).
b6aaeeac
TTN
170#
171AC_DEFUN([GUILE_MODULE_CHECK],
172 [AC_MSG_CHECKING([if $2 $4])
173 GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3))))
174 if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi
175 AC_MSG_RESULT($$1)
d0001215
TTN
176 ])
177
b6aaeeac
TTN
178# GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
179#
180# Usage: GUILE_MODULE_AVAILABLE(var,module)
181#
8c4b7ca3
TTN
182# @var{var} is a shell variable name to be set to "yes" or "no".
183# @var{module} is a list of symbols, like: (ice-9 common-list).
b6aaeeac
TTN
184#
185AC_DEFUN([GUILE_MODULE_AVAILABLE],
186 [GUILE_MODULE_CHECK($1,$2,0,is available)
d0001215
TTN
187 ])
188
b6aaeeac
TTN
189# GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
190#
191# Usage: GUILE_MODULE_REQUIRED(symlist)
192#
8c4b7ca3
TTN
193# @var{symlist} is a list of symbols, WITHOUT surrounding parens,
194# like: ice-9 common-list.
b6aaeeac
TTN
195#
196AC_DEFUN([GUILE_MODULE_REQUIRED],
197 [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1))
d0001215
TTN
198 if test "$ac_guile_module_required" = "no" ; then
199 AC_MSG_ERROR([required guile module not found: ($1)])
200 fi
201 ])
202
b6aaeeac
TTN
203# GUILE_MODULE_EXPORTS -- check if a module exports a variable
204#
205# Usage: GUILE_MODULE_EXPORTS(var,module,modvar)
206#
8c4b7ca3
TTN
207# @var{var} is a shell variable to be set to "yes" or "no".
208# @var{module} is a list of symbols, like: (ice-9 common-list).
209# @var{modvar} is the Guile Scheme variable to check.
b6aaeeac
TTN
210#
211AC_DEFUN([GUILE_MODULE_EXPORTS],
212 [GUILE_MODULE_CHECK($1,$2,$3,exports `$3')
213 ])
214
215# GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
216#
217# Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar)
218#
8c4b7ca3
TTN
219# @var{module} is a list of symbols, like: (ice-9 common-list).
220# @var{modvar} is the Guile Scheme variable to check.
b6aaeeac
TTN
221#
222AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT],
223 [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2)
224 if test "$guile_module_required_export" = "no" ; then
225 AC_MSG_ERROR([module $1 does not export $2; required])
226 fi
227 ])
228
229## guile.m4 ends here