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