fix guile-tools --help and --version
[bpt/guile.git] / meta / 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 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
84eebc64
NJ
20# serial 9
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
73# two variables, @var{GUILE_CFLAGS} and @var{GUILE_LDFLAGS}.
b6aaeeac 74#
8c4b7ca3
TTN
75# @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that
76# uses Guile header files. This is almost always just a @code{-I} flag.
b6aaeeac 77#
8c4b7ca3
TTN
78# @var{GUILE_LDFLAGS}: flags to pass to the linker to link a program against
79# Guile. This includes @code{-lguile} for the Guile library itself, any
80# libraries that Guile itself requires (like -lqthreads), and so on. It may
81# also include a @code{-L} flag to tell the compiler where to find the
b6aaeeac
TTN
82# libraries.
83#
8c4b7ca3
TTN
84# The variables are marked for substitution, as by @code{AC_SUBST}.
85#
86AC_DEFUN([GUILE_FLAGS],
87 [AC_REQUIRE([GUILE_PROGS])dnl
88 AC_MSG_CHECKING([libguile compile flags])
89 GUILE_CFLAGS="`$GUILE_CONFIG compile`"
90 AC_MSG_RESULT([$GUILE_CFLAGS])
91 AC_MSG_CHECKING([libguile link flags])
92 GUILE_LDFLAGS="`$GUILE_CONFIG link`"
93 AC_MSG_RESULT([$GUILE_LDFLAGS])
2b9fe19f
JB
94 AC_SUBST(GUILE_CFLAGS)
95 AC_SUBST(GUILE_LDFLAGS)
8c4b7ca3 96 ])
d0001215 97
b6aaeeac
TTN
98# GUILE_SITE_DIR -- find path to Guile "site" directory
99#
100# Usage: GUILE_SITE_DIR
101#
102# This looks for Guile's "site" directory, usually something like
8c4b7ca3 103# PREFIX/share/guile/site, and sets var @var{GUILE_SITE} to the path.
b6aaeeac
TTN
104# Note that the var name is different from the macro name.
105#
8c4b7ca3 106# The variable is marked for substitution, as by @code{AC_SUBST}.
b6aaeeac
TTN
107#
108AC_DEFUN([GUILE_SITE_DIR],
109 [AC_REQUIRE([GUILE_PROGS])dnl
110 AC_MSG_CHECKING(for Guile site directory)
922d3695 111 GUILE_SITE=`[$GUILE_CONFIG] info sitedir`
b6aaeeac
TTN
112 AC_MSG_RESULT($GUILE_SITE)
113 AC_SUBST(GUILE_SITE)
114 ])
115
116# GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
117#
118# Usage: GUILE_CHECK_RETVAL(var,check)
119#
8c4b7ca3
TTN
120# @var{var} is a shell variable name to be set to the return value.
121# @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and
b6aaeeac
TTN
122# returning either 0 or non-#f to indicate the check passed.
123# Non-0 number or #f indicates failure.
124# Avoid using the character "#" since that confuses autoconf.
125#
126AC_DEFUN([GUILE_CHECK],
127 [AC_REQUIRE([GUILE_PROGS])
128 $GUILE -c "$2" > /dev/null 2>&1
129 $1=$?
130 ])
131
132# GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
133#
134# Usage: GUILE_MODULE_CHECK(var,module,featuretest,description)
135#
8c4b7ca3
TTN
136# @var{var} is a shell variable name to be set to "yes" or "no".
137# @var{module} is a list of symbols, like: (ice-9 common-list).
138# @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v.
139# @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING).
b6aaeeac
TTN
140#
141AC_DEFUN([GUILE_MODULE_CHECK],
142 [AC_MSG_CHECKING([if $2 $4])
143 GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3))))
144 if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi
145 AC_MSG_RESULT($$1)
d0001215
TTN
146 ])
147
b6aaeeac
TTN
148# GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
149#
150# Usage: GUILE_MODULE_AVAILABLE(var,module)
151#
8c4b7ca3
TTN
152# @var{var} is a shell variable name to be set to "yes" or "no".
153# @var{module} is a list of symbols, like: (ice-9 common-list).
b6aaeeac
TTN
154#
155AC_DEFUN([GUILE_MODULE_AVAILABLE],
156 [GUILE_MODULE_CHECK($1,$2,0,is available)
d0001215
TTN
157 ])
158
b6aaeeac
TTN
159# GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
160#
161# Usage: GUILE_MODULE_REQUIRED(symlist)
162#
8c4b7ca3
TTN
163# @var{symlist} is a list of symbols, WITHOUT surrounding parens,
164# like: ice-9 common-list.
b6aaeeac
TTN
165#
166AC_DEFUN([GUILE_MODULE_REQUIRED],
167 [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1))
d0001215
TTN
168 if test "$ac_guile_module_required" = "no" ; then
169 AC_MSG_ERROR([required guile module not found: ($1)])
170 fi
171 ])
172
b6aaeeac
TTN
173# GUILE_MODULE_EXPORTS -- check if a module exports a variable
174#
175# Usage: GUILE_MODULE_EXPORTS(var,module,modvar)
176#
8c4b7ca3
TTN
177# @var{var} is a shell variable to be set to "yes" or "no".
178# @var{module} is a list of symbols, like: (ice-9 common-list).
179# @var{modvar} is the Guile Scheme variable to check.
b6aaeeac
TTN
180#
181AC_DEFUN([GUILE_MODULE_EXPORTS],
182 [GUILE_MODULE_CHECK($1,$2,$3,exports `$3')
183 ])
184
185# GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
186#
187# Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar)
188#
8c4b7ca3
TTN
189# @var{module} is a list of symbols, like: (ice-9 common-list).
190# @var{modvar} is the Guile Scheme variable to check.
b6aaeeac
TTN
191#
192AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT],
193 [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2)
194 if test "$guile_module_required_export" = "no" ; then
195 AC_MSG_ERROR([module $1 does not export $2; required])
196 fi
197 ])
198
199## guile.m4 ends here