* posix.texi (Pipes): Expand and clarify a bit. Describe port
[bpt/guile.git] / doc / ref / autoconf.texi
CommitLineData
2da09c3f
MV
1@c -*-texinfo-*-
2@c This is part of the GNU Guile Reference Manual.
3@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004
4@c Free Software Foundation, Inc.
5@c See the file guile.texi for copying conditions.
6
d928d47f
TTN
7@page
8@node Autoconf Support
9@chapter Autoconf Support
10
11When Guile is installed, a set of autoconf macros is also installed as
12PREFIX/share/aclocal/guile.m4. This chapter documents the macros provided in
a284e708
TTN
13that file, as well as the high-level guile-tool Autofrisk. @xref{Top,The GNU
14Autoconf Manual,,autoconf}, for more info.
d928d47f
TTN
15
16@menu
17* Autoconf Background:: Why use autoconf?
18* Autoconf Macros:: The GUILE_* macros.
19* Using Autoconf Macros:: How to use them, plus examples.
a284e708
TTN
20* Autofrisk:: AUTOFRISK_CHECKS and AUTOFRISK_SUMMARY.
21* Using Autofrisk:: Example modules.af files.
d928d47f
TTN
22@end menu
23
24
25@node Autoconf Background
26@section Autoconf Background
27
28As explained elsewhere (@pxref{Top,The GNU Autoconf Manual,,autoconf}), any
29package needs configuration at build-time. If your package uses Guile (or
30uses a package that in turn uses Guile), you probably need to know what
31specific Guile features are available and details about them.
32
33The way to do this is to write feature tests and arrange for their execution
34by the @file{configure} script, typically by adding the tests to
35@file{configure.ac}, and running @code{autoconf} to create @file{configure}.
36Users of your package then run @file{configure} in the normal way.
37
38Macros are a way to make common feature tests easy to express. Autoconf
a3f0622d
NJ
39provides a wide range of macros (@pxref{Existing Tests,,,autoconf}), and
40Guile installation provides Guile-specific tests in the areas of:
41program detection, compilation flags reporting, and Scheme module
42checks.
d928d47f
TTN
43
44
45@node Autoconf Macros
46@section Autoconf Macros
47
48The macro names all begin with "GUILE_".
49
50@c see Makefile.am
51@include autoconf-macros.texi
52
53
54@node Using Autoconf Macros
55@section Using Autoconf Macros
56
57Using the autoconf macros is straightforward: Add the macro "calls" (actually
58instantiations) to @file{configure.ac}, run @code{aclocal}, and finally,
59run @code{autoconf}. If your system doesn't have guile.m4 installed, place
60the desired macro definitions (@code{AC_DEFUN} forms) in @file{acinclude.m4},
61and @code{aclocal} will do the right thing.
62
63Some of the macros can be used inside normal shell constructs: @code{if foo ;
64then GUILE_BAZ ; fi}, but this is not guaranteed. It's probably a good idea
65to instantiate macros at top-level.
66
67We now include two examples, one simple and one complicated.
68
69The first example is for a package that uses libguile, and thus needs to know
70how to compile and link against it. So we use @code{GUILE_FLAGS} to set the
71vars @code{GUILE_CFLAGS} and @code{GUILE_LDFLAGS}, which are automatically
72substituted in the Makefile.
73
74@example
75In configure.ac:
76
77 GUILE_FLAGS
78
79In Makefile.in:
80
81 GUILE_CFLAGS = @@GUILE_CFLAGS@@
82 GUILE_LDFLAGS = @@GUILE_LDFLAGS@@
83
84 myprog.o: myprog.c
85 $(CC) -o $@ $(GUILE_CFLAGS) $<
86 myprog: myprog.o
87 $(CC) -o $@ $< $(GUILE_LDFLAGS)
88@end example
89
90The second example is for a package of Guile Scheme modules that uses an
91external program and other Guile Scheme modules (some might call this a "pure
92scheme" package). So we use the @code{GUILE_SITE_DIR} macro, a regular
93@code{AC_PATH_PROG} macro, and the @code{GUILE_MODULE_AVAILABLE} macro.
94
95@example
96In configure.ac:
97
98 GUILE_SITE_DIR
99
100 probably_wont_work=""
101
102 # pgtype pgtable
103 GUILE_MODULE_AVAILABLE(have_guile_pg, (database postgres))
104 test $have_guile_pg = no &&
105 probably_wont_work="(my pgtype) (my pgtable) $probably_wont_work"
106
107 # gpgutils
108 AC_PATH_PROG(GNUPG,gpg)
109 test x"$GNUPG" = x &&
110 probably_wont_work="(my gpgutils) $probably_wont_work"
111
112 if test ! "$probably_wont_work" = "" ; then
113 p=" ***"
114 echo
115 echo "$p"
116 echo "$p NOTE:"
117 echo "$p The following modules probably won't work:"
118 echo "$p $probably_wont_work"
119 echo "$p They can be installed anyway, and will work if their"
120 echo "$p dependencies are installed later. Please see README."
121 echo "$p"
122 echo
123 fi
124
125In Makefile.in:
126
127 instdir = @@GUILE_SITE@@/my
128
129 install:
130 $(INSTALL) my/*.scm $(instdir)
131@end example
132
a284e708
TTN
133
134@node Autofrisk
135@section Autofrisk
136
137The @dfn{guile-tools autofrisk} command looks for the file @file{modules.af}
138in the current directory and writes out @file{modules.af.m4} containing
139autoconf definitions for @code{AUTOFRISK_CHECKS} and @code{AUTOFRISK_SUMMARY}.
140@xref{Autoconf Background}, and @xref{Using Autoconf Macros}, for more info.
141
142The modules.af file consists of a series of configuration forms (Scheme
143lists), which have one of the following formats:
144
145@example
146 (files-glob PATTERN ...) ;; required
147 (non-critical-external MODULE ...) ;; optional
148 (non-critical-internal MODULE ...) ;; optional
149 (programs (MODULE PROG ...) ...) ;; optional
150 (pww-varname VARNAME) ;; optional
151@end example
152
153@var{pattern} is a string that may contain "*" and "?" characters to be
154expanded into filenames. @var{module} is a list of symbols naming a module,
155such as `(srfi srfi-1)'. @var{varname} is a shell-safe name to use instead of
156@code{probably_wont_work}, the default. This var is passed to `AC_SUBST'.
157@var{prog} is a string that names a program, such as "gpg".
158
159Autofrisk expands the @code{files-glob} pattern(s) into a list of files, scans
160each file's module definition form(s), and constructs a module dependency
161graph wherein modules defined by @code{define-module} are considered
162@dfn{internal} and the remaining, @dfn{external}. For each external module
163that has an internal dependency, Autofrisk emits a
164@code{GUILE_MODULE_REQUIRED} check (@pxref{Autoconf Macros}), which altogether
165form the body of @code{AUTOFRISK_CHECKS}.
166
167@code{GUILE_MODULE_REQUIRED} causes the @file{configure} script to exit with
168an error message if the specified module is not available; it enforces a
169strong dependency. You can temper dependency strength by using the
170@code{non-critical-external} and @code{non-critical-internal} configuration
171forms in modules.af. For graph edges that touch such non-critical modules,
172Autofrisk uses @code{GUILE_MODULE_AVAILABLE}, and arranges for
173@code{AUTOFRISK_SUMMARY} to display a warning if they are not found.
174
175The shell code resulting from the expansion of @code{AUTOFRISK_CHECKS} and
176@code{AUTOFRISK_SUMMARY} uses the shell variable @code{probably_wont_work} to
177collect the names of unfound non-critical modules. If this bothers you, use
178configuration form @code{(pww-name foo)} in modules.af.
179
180Although Autofrisk does not detect when a module uses a program (for example,
181in a @code{system} call), it can generate @code{AC_PATH_PROG} forms anyway if
182you use the @code{programs} configuration form in modules.af. These are
183collected into @code{AUTOCONF_CHECKS}.
184
185@xref{Using Autofrisk}, for some modules.af examples.
186
187
188@node Using Autofrisk
189@section Using Autofrisk
190
191Using Autofrisk (@pxref{Autofrisk}) involves writing @file{modules.af} and
192adding two macro calls to @file{configure.in}. Here is an example of the
193latter:
194
195@example
196AUTOFRISK_CHECKS
197AUTOFRISK_SUMMARY
198@end example
199
200Here is an adaptation of the second "GUILE_*" example (@pxref{Using Autoconf
201Macros}) that does basically the same thing.
202
203@example
204(files-glob "my/*.scm")
205(non-critical-external (database postgres))
206(programs ((my gpgutils) "gpg")) ;; (my gpgutils) uses "gpg"
207@end example
208
209If the SRFI modules (@pxref{SRFI Support}) were a separate package, we could
210use @code{guile-tools frisk} to find out its dependencies:
211
212@example
213$ guile-tools frisk srfi/*.scm
21413 files, 18 modules (13 internal, 5 external), 9 edges
215
216x (ice-9 and-let-star)
217 regular (srfi srfi-2)
218x (ice-9 syncase)
219 regular (srfi srfi-11)
220x (ice-9 rdelim)
221 regular (srfi srfi-10)
222x (ice-9 receive)
223 regular (srfi srfi-8)
224 regular (srfi srfi-1)
225x (ice-9 session)
226 regular (srfi srfi-1)
227@end example
228
229Then, we could use the following modules.af to help configure it:
230
231@example
232(files-glob "srfi/*.scm")
233(non-critical-external ;; relatively recent
234 (ice-9 rdelim)
235 (ice-9 receive)
236 (ice-9 and-let-star))
237(pww-varname not_fully_supported)
238@end example
239
d928d47f 240@c autoconf.texi ends here