merge from 1.8 branch
[bpt/guile.git] / guile-config / guile.m4
CommitLineData
b6aaeeac
TTN
1## Autoconf macros for working with Guile.
2##
6e7d5622 3## Copyright (C) 1998,2001, 2006 Free Software Foundation, Inc.
b6aaeeac 4##
73be1d9e
MV
5## This library is free software; you can redistribute it and/or
6## modify it under the terms of the GNU Lesser General Public
7## License as published by the Free Software Foundation; either
8## version 2.1 of the License, or (at your option) any later version.
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
92205699 17## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
b6aaeeac
TTN
18
19## Index
20## -----
21##
22## GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
23## GUILE_FLAGS -- set flags for compiling and linking with Guile
24## GUILE_SITE_DIR -- find path to Guile "site" directory
25## GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
26## GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
27## GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
28## GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
29## GUILE_MODULE_EXPORTS -- check if a module exports a variable
30## GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
31
32## Code
33## ----
34
8c4b7ca3
TTN
35## NOTE: Comments preceding an AC_DEFUN (starting from "Usage:") are massaged
36## into doc/ref/autoconf-macros.texi (see Makefile.am in that directory).
37
b6aaeeac
TTN
38# GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
39#
40# Usage: GUILE_PROGS
41#
8c4b7ca3
TTN
42# This macro looks for programs @code{guile}, @code{guile-config} and
43# @code{guile-tools}, and sets variables @var{GUILE}, @var{GUILE_CONFIG} and
44# @var{GUILE_TOOLS}, to their paths, respectively. If either of the first two
e12ed7aa 45# is not found, signal error.
b6aaeeac 46#
8c4b7ca3 47# The variables are marked for substitution, as by @code{AC_SUBST}.
b6aaeeac
TTN
48#
49AC_DEFUN([GUILE_PROGS],
50 [AC_PATH_PROG(GUILE,guile)
51 if test "$GUILE" = "" ; then
52 AC_MSG_ERROR([guile required but not found])
53 fi
54 AC_SUBST(GUILE)
55 AC_PATH_PROG(GUILE_CONFIG,guile-config)
56 if test "$GUILE_CONFIG" = "" ; then
57 AC_MSG_ERROR([guile-config required but not found])
58 fi
59 AC_SUBST(GUILE_CONFIG)
60 AC_PATH_PROG(GUILE_TOOLS,guile-tools)
61 AC_SUBST(GUILE_TOOLS)
62 ])
63
64# GUILE_FLAGS -- set flags for compiling and linking with Guile
65#
66# Usage: GUILE_FLAGS
67#
8c4b7ca3
TTN
68# This macro runs the @code{guile-config} script, installed with Guile, to
69# find out where Guile's header files and libraries are installed. It sets
70# two variables, @var{GUILE_CFLAGS} and @var{GUILE_LDFLAGS}.
b6aaeeac 71#
8c4b7ca3
TTN
72# @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that
73# uses Guile header files. This is almost always just a @code{-I} flag.
b6aaeeac 74#
8c4b7ca3
TTN
75# @var{GUILE_LDFLAGS}: flags to pass to the linker to link a program against
76# Guile. This includes @code{-lguile} for the Guile library itself, any
77# libraries that Guile itself requires (like -lqthreads), and so on. It may
78# also include a @code{-L} flag to tell the compiler where to find the
b6aaeeac
TTN
79# libraries.
80#
8c4b7ca3
TTN
81# The variables are marked for substitution, as by @code{AC_SUBST}.
82#
83AC_DEFUN([GUILE_FLAGS],
84 [AC_REQUIRE([GUILE_PROGS])dnl
85 AC_MSG_CHECKING([libguile compile flags])
86 GUILE_CFLAGS="`$GUILE_CONFIG compile`"
87 AC_MSG_RESULT([$GUILE_CFLAGS])
88 AC_MSG_CHECKING([libguile link flags])
89 GUILE_LDFLAGS="`$GUILE_CONFIG link`"
90 AC_MSG_RESULT([$GUILE_LDFLAGS])
2b9fe19f
JB
91 AC_SUBST(GUILE_CFLAGS)
92 AC_SUBST(GUILE_LDFLAGS)
8c4b7ca3 93 ])
d0001215 94
b6aaeeac
TTN
95# GUILE_SITE_DIR -- find path to Guile "site" directory
96#
97# Usage: GUILE_SITE_DIR
98#
99# This looks for Guile's "site" directory, usually something like
8c4b7ca3 100# PREFIX/share/guile/site, and sets var @var{GUILE_SITE} to the path.
b6aaeeac
TTN
101# Note that the var name is different from the macro name.
102#
8c4b7ca3 103# The variable is marked for substitution, as by @code{AC_SUBST}.
b6aaeeac
TTN
104#
105AC_DEFUN([GUILE_SITE_DIR],
106 [AC_REQUIRE([GUILE_PROGS])dnl
107 AC_MSG_CHECKING(for Guile site directory)
108 GUILE_SITE=`[$GUILE_CONFIG] info pkgdatadir`/site
109 AC_MSG_RESULT($GUILE_SITE)
110 AC_SUBST(GUILE_SITE)
111 ])
112
113# GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
114#
115# Usage: GUILE_CHECK_RETVAL(var,check)
116#
8c4b7ca3
TTN
117# @var{var} is a shell variable name to be set to the return value.
118# @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and
b6aaeeac
TTN
119# returning either 0 or non-#f to indicate the check passed.
120# Non-0 number or #f indicates failure.
121# Avoid using the character "#" since that confuses autoconf.
122#
123AC_DEFUN([GUILE_CHECK],
124 [AC_REQUIRE([GUILE_PROGS])
125 $GUILE -c "$2" > /dev/null 2>&1
126 $1=$?
127 ])
128
129# GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
130#
131# Usage: GUILE_MODULE_CHECK(var,module,featuretest,description)
132#
8c4b7ca3
TTN
133# @var{var} is a shell variable name to be set to "yes" or "no".
134# @var{module} is a list of symbols, like: (ice-9 common-list).
135# @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v.
136# @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING).
b6aaeeac
TTN
137#
138AC_DEFUN([GUILE_MODULE_CHECK],
139 [AC_MSG_CHECKING([if $2 $4])
140 GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3))))
141 if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi
142 AC_MSG_RESULT($$1)
d0001215
TTN
143 ])
144
b6aaeeac
TTN
145# GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
146#
147# Usage: GUILE_MODULE_AVAILABLE(var,module)
148#
8c4b7ca3
TTN
149# @var{var} is a shell variable name to be set to "yes" or "no".
150# @var{module} is a list of symbols, like: (ice-9 common-list).
b6aaeeac
TTN
151#
152AC_DEFUN([GUILE_MODULE_AVAILABLE],
153 [GUILE_MODULE_CHECK($1,$2,0,is available)
d0001215
TTN
154 ])
155
b6aaeeac
TTN
156# GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
157#
158# Usage: GUILE_MODULE_REQUIRED(symlist)
159#
8c4b7ca3
TTN
160# @var{symlist} is a list of symbols, WITHOUT surrounding parens,
161# like: ice-9 common-list.
b6aaeeac
TTN
162#
163AC_DEFUN([GUILE_MODULE_REQUIRED],
164 [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1))
d0001215
TTN
165 if test "$ac_guile_module_required" = "no" ; then
166 AC_MSG_ERROR([required guile module not found: ($1)])
167 fi
168 ])
169
b6aaeeac
TTN
170# GUILE_MODULE_EXPORTS -- check if a module exports a variable
171#
172# Usage: GUILE_MODULE_EXPORTS(var,module,modvar)
173#
8c4b7ca3
TTN
174# @var{var} is a shell variable to be set to "yes" or "no".
175# @var{module} is a list of symbols, like: (ice-9 common-list).
176# @var{modvar} is the Guile Scheme variable to check.
b6aaeeac
TTN
177#
178AC_DEFUN([GUILE_MODULE_EXPORTS],
179 [GUILE_MODULE_CHECK($1,$2,$3,exports `$3')
180 ])
181
182# GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
183#
184# Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar)
185#
8c4b7ca3
TTN
186# @var{module} is a list of symbols, like: (ice-9 common-list).
187# @var{modvar} is the Guile Scheme variable to check.
b6aaeeac
TTN
188#
189AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT],
190 [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2)
191 if test "$guile_module_required_export" = "no" ; then
192 AC_MSG_ERROR([module $1 does not export $2; required])
193 fi
194 ])
195
196## guile.m4 ends here