libguile-autoconf.texi 4.8 KB

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