autoconf.texi 9.2 KB

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