elisp @@ macro
[bpt/guile.git] / doc / ref / libguile-autoconf.texi
CommitLineData
2da09c3f
MV
1@c -*-texinfo-*-
2@c This is part of the GNU Guile Reference Manual.
0e8a11c4 3@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2009, 2011
2da09c3f
MV
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
d32df132 9@section Autoconf Support
d928d47f 10
d32df132
AW
11Autoconf, a part of the GNU build system, makes it easy for users to
12build your package. This section documents Guile's Autoconf support.
d928d47f
TTN
13
14@menu
15* Autoconf Background:: Why use autoconf?
16* Autoconf Macros:: The GUILE_* macros.
17* Using Autoconf Macros:: How to use them, plus examples.
18@end menu
19
20
21@node Autoconf Background
d32df132 22@subsection Autoconf Background
d928d47f 23
2c18ac5f
BG
24As explained in the @cite{GNU Autoconf Manual}, any package needs
25configuration at build-time (@pxref{Top, ,Introduction,autoconf,The GNU
26Autoconf Manual}). If your package uses Guile (or uses a package that
27in turn uses Guile), you probably need to know what specific Guile
28features are available and details about them.
d928d47f
TTN
29
30The way to do this is to write feature tests and arrange for their execution
31by the @file{configure} script, typically by adding the tests to
32@file{configure.ac}, and running @code{autoconf} to create @file{configure}.
33Users of your package then run @file{configure} in the normal way.
34
2c18ac5f
BG
35Macros are a way to make common feature tests easy to express.
36Autoconf provides a wide range of macros
37(@pxref{Existing Tests,,,autoconf,The GNU Autoconf Manual}),
38and Guile installation provides Guile-specific tests in the areas of:
a3f0622d
NJ
39program detection, compilation flags reporting, and Scheme module
40checks.
d928d47f
TTN
41
42
43@node Autoconf Macros
d32df132 44@subsection Autoconf Macros
d928d47f 45
d32df132
AW
46As mentioned earlier in this chapter, Guile supports parallel
47installation, and uses @code{pkg-config} to let the user choose which
48version of Guile they are interested in. @code{pkg-config} has its own
49set of Autoconf macros that are probably installed on most every
50development system. The most useful of these macros is
51@code{PKG_CHECK_MODULES}.
92826dd0
LC
52
53@findex PKG_CHECK_MODULES
54
55@example
22b5f518 56PKG_CHECK_MODULES([GUILE], [guile-@value{EFFECTIVE-VERSION}])
92826dd0
LC
57@end example
58
d32df132
AW
59This example looks for Guile and sets the @code{GUILE_CFLAGS} and
60@code{GUILE_LIBS} variables accordingly, or prints an error and exits if
61Guile was not found.
62
92826dd0
LC
63Guile comes with additional Autoconf macros providing more information,
64installed as @file{@var{prefix}/share/aclocal/guile.m4}. Their names
65all begin with @code{GUILE_}.
d928d47f
TTN
66
67@c see Makefile.am
68@include autoconf-macros.texi
69
70
71@node Using Autoconf Macros
d32df132 72@subsection Using Autoconf Macros
d928d47f
TTN
73
74Using the autoconf macros is straightforward: Add the macro "calls" (actually
75instantiations) to @file{configure.ac}, run @code{aclocal}, and finally,
76run @code{autoconf}. If your system doesn't have guile.m4 installed, place
77the desired macro definitions (@code{AC_DEFUN} forms) in @file{acinclude.m4},
78and @code{aclocal} will do the right thing.
79
80Some of the macros can be used inside normal shell constructs: @code{if foo ;
81then GUILE_BAZ ; fi}, but this is not guaranteed. It's probably a good idea
82to instantiate macros at top-level.
83
84We now include two examples, one simple and one complicated.
85
0e8a11c4
AW
86The first example is for a package that uses libguile, and thus needs to
87know how to compile and link against it. So we use
88@code{PKG_CHECK_MODULES} to set the vars @code{GUILE_CFLAGS} and
89@code{GUILE_LIBS}, which are automatically substituted in the Makefile.
d928d47f
TTN
90
91@example
92In configure.ac:
93
0e8a11c4 94 PKG_CHECK_MODULES([GUILE], [guile-@value{EFFECTIVE-VERSION}])
d928d47f
TTN
95
96In Makefile.in:
97
98 GUILE_CFLAGS = @@GUILE_CFLAGS@@
0e8a11c4 99 GUILE_LIBS = @@GUILE_LIBS@@
d928d47f
TTN
100
101 myprog.o: myprog.c
102 $(CC) -o $@ $(GUILE_CFLAGS) $<
103 myprog: myprog.o
0e8a11c4 104 $(CC) -o $@ $< $(GUILE_LIBS)
d928d47f
TTN
105@end example
106
107The second example is for a package of Guile Scheme modules that uses an
108external program and other Guile Scheme modules (some might call this a "pure
109scheme" package). So we use the @code{GUILE_SITE_DIR} macro, a regular
110@code{AC_PATH_PROG} macro, and the @code{GUILE_MODULE_AVAILABLE} macro.
111
112@example
113In configure.ac:
114
115 GUILE_SITE_DIR
116
117 probably_wont_work=""
118
119 # pgtype pgtable
120 GUILE_MODULE_AVAILABLE(have_guile_pg, (database postgres))
121 test $have_guile_pg = no &&
122 probably_wont_work="(my pgtype) (my pgtable) $probably_wont_work"
123
124 # gpgutils
125 AC_PATH_PROG(GNUPG,gpg)
126 test x"$GNUPG" = x &&
127 probably_wont_work="(my gpgutils) $probably_wont_work"
128
129 if test ! "$probably_wont_work" = "" ; then
130 p=" ***"
131 echo
132 echo "$p"
133 echo "$p NOTE:"
134 echo "$p The following modules probably won't work:"
135 echo "$p $probably_wont_work"
136 echo "$p They can be installed anyway, and will work if their"
137 echo "$p dependencies are installed later. Please see README."
138 echo "$p"
139 echo
140 fi
141
142In Makefile.in:
143
144 instdir = @@GUILE_SITE@@/my
145
146 install:
147 $(INSTALL) my/*.scm $(instdir)
148@end example
149
a284e708 150
d928d47f 151@c autoconf.texi ends here