Commit | Line | Data |
---|---|---|
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 | ||
11 | When Guile is installed, a set of autoconf macros is also installed as | |
12 | PREFIX/share/aclocal/guile.m4. This chapter documents the macros provided in | |
a284e708 TTN |
13 | that file, as well as the high-level guile-tool Autofrisk. @xref{Top,The GNU |
14 | Autoconf 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 | ||
28 | As explained elsewhere (@pxref{Top,The GNU Autoconf Manual,,autoconf}), any | |
29 | package needs configuration at build-time. If your package uses Guile (or | |
30 | uses a package that in turn uses Guile), you probably need to know what | |
31 | specific Guile features are available and details about them. | |
32 | ||
33 | The way to do this is to write feature tests and arrange for their execution | |
34 | by the @file{configure} script, typically by adding the tests to | |
35 | @file{configure.ac}, and running @code{autoconf} to create @file{configure}. | |
36 | Users of your package then run @file{configure} in the normal way. | |
37 | ||
38 | Macros are a way to make common feature tests easy to express. Autoconf | |
a3f0622d NJ |
39 | provides a wide range of macros (@pxref{Existing Tests,,,autoconf}), and |
40 | Guile installation provides Guile-specific tests in the areas of: | |
41 | program detection, compilation flags reporting, and Scheme module | |
42 | checks. | |
d928d47f TTN |
43 | |
44 | ||
45 | @node Autoconf Macros | |
46 | @section Autoconf Macros | |
47 | ||
48 | The 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 | ||
57 | Using the autoconf macros is straightforward: Add the macro "calls" (actually | |
58 | instantiations) to @file{configure.ac}, run @code{aclocal}, and finally, | |
59 | run @code{autoconf}. If your system doesn't have guile.m4 installed, place | |
60 | the desired macro definitions (@code{AC_DEFUN} forms) in @file{acinclude.m4}, | |
61 | and @code{aclocal} will do the right thing. | |
62 | ||
63 | Some of the macros can be used inside normal shell constructs: @code{if foo ; | |
64 | then GUILE_BAZ ; fi}, but this is not guaranteed. It's probably a good idea | |
65 | to instantiate macros at top-level. | |
66 | ||
67 | We now include two examples, one simple and one complicated. | |
68 | ||
69 | The first example is for a package that uses libguile, and thus needs to know | |
70 | how to compile and link against it. So we use @code{GUILE_FLAGS} to set the | |
71 | vars @code{GUILE_CFLAGS} and @code{GUILE_LDFLAGS}, which are automatically | |
72 | substituted in the Makefile. | |
73 | ||
74 | @example | |
75 | In configure.ac: | |
76 | ||
77 | GUILE_FLAGS | |
78 | ||
79 | In 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 | ||
90 | The second example is for a package of Guile Scheme modules that uses an | |
91 | external program and other Guile Scheme modules (some might call this a "pure | |
92 | scheme" 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 | |
96 | In 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 | ||
125 | In 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 | ||
137 | The @dfn{guile-tools autofrisk} command looks for the file @file{modules.af} | |
138 | in the current directory and writes out @file{modules.af.m4} containing | |
139 | autoconf definitions for @code{AUTOFRISK_CHECKS} and @code{AUTOFRISK_SUMMARY}. | |
140 | @xref{Autoconf Background}, and @xref{Using Autoconf Macros}, for more info. | |
141 | ||
142 | The modules.af file consists of a series of configuration forms (Scheme | |
143 | lists), 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 | |
154 | expanded into filenames. @var{module} is a list of symbols naming a module, | |
155 | such 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 | ||
159 | Autofrisk expands the @code{files-glob} pattern(s) into a list of files, scans | |
160 | each file's module definition form(s), and constructs a module dependency | |
161 | graph wherein modules defined by @code{define-module} are considered | |
162 | @dfn{internal} and the remaining, @dfn{external}. For each external module | |
163 | that has an internal dependency, Autofrisk emits a | |
164 | @code{GUILE_MODULE_REQUIRED} check (@pxref{Autoconf Macros}), which altogether | |
165 | form the body of @code{AUTOFRISK_CHECKS}. | |
166 | ||
167 | @code{GUILE_MODULE_REQUIRED} causes the @file{configure} script to exit with | |
168 | an error message if the specified module is not available; it enforces a | |
169 | strong dependency. You can temper dependency strength by using the | |
170 | @code{non-critical-external} and @code{non-critical-internal} configuration | |
171 | forms in modules.af. For graph edges that touch such non-critical modules, | |
172 | Autofrisk uses @code{GUILE_MODULE_AVAILABLE}, and arranges for | |
173 | @code{AUTOFRISK_SUMMARY} to display a warning if they are not found. | |
174 | ||
175 | The shell code resulting from the expansion of @code{AUTOFRISK_CHECKS} and | |
176 | @code{AUTOFRISK_SUMMARY} uses the shell variable @code{probably_wont_work} to | |
177 | collect the names of unfound non-critical modules. If this bothers you, use | |
178 | configuration form @code{(pww-name foo)} in modules.af. | |
179 | ||
180 | Although Autofrisk does not detect when a module uses a program (for example, | |
181 | in a @code{system} call), it can generate @code{AC_PATH_PROG} forms anyway if | |
182 | you use the @code{programs} configuration form in modules.af. These are | |
183 | collected 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 | ||
191 | Using Autofrisk (@pxref{Autofrisk}) involves writing @file{modules.af} and | |
192 | adding two macro calls to @file{configure.in}. Here is an example of the | |
193 | latter: | |
194 | ||
195 | @example | |
196 | AUTOFRISK_CHECKS | |
197 | AUTOFRISK_SUMMARY | |
198 | @end example | |
199 | ||
200 | Here is an adaptation of the second "GUILE_*" example (@pxref{Using Autoconf | |
201 | Macros}) 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 | ||
209 | If the SRFI modules (@pxref{SRFI Support}) were a separate package, we could | |
210 | use @code{guile-tools frisk} to find out its dependencies: | |
211 | ||
212 | @example | |
213 | $ guile-tools frisk srfi/*.scm | |
214 | 13 files, 18 modules (13 internal, 5 external), 9 edges | |
215 | ||
216 | x (ice-9 and-let-star) | |
217 | regular (srfi srfi-2) | |
218 | x (ice-9 syncase) | |
219 | regular (srfi srfi-11) | |
220 | x (ice-9 rdelim) | |
221 | regular (srfi srfi-10) | |
222 | x (ice-9 receive) | |
223 | regular (srfi srfi-8) | |
224 | regular (srfi srfi-1) | |
225 | x (ice-9 session) | |
226 | regular (srfi srfi-1) | |
227 | @end example | |
228 | ||
229 | Then, 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 |