guile.m4 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. ## Autoconf macros for working with Guile.
  2. ##
  3. ## Copyright (C) 1998,2001, 2006 Free Software Foundation, Inc.
  4. ##
  5. ## This library is free software; you can redistribute it and/or
  6. ## modify it under the terms of the GNU Lesser General Public License
  7. ## as published by the Free Software Foundation; either version 3 of
  8. ## the License, or (at your option) any later version.
  9. ##
  10. ## This library is distributed in the hope that it will be useful,
  11. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ## Lesser General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU Lesser General Public
  16. ## License along with this library; if not, write to the Free Software
  17. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. ## 02110-1301 USA
  19. # serial 9
  20. ## Index
  21. ## -----
  22. ##
  23. ## GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
  24. ## GUILE_FLAGS -- set flags for compiling and linking with Guile
  25. ## GUILE_SITE_DIR -- find path to Guile "site" directory
  26. ## GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
  27. ## GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
  28. ## GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
  29. ## GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
  30. ## GUILE_MODULE_EXPORTS -- check if a module exports a variable
  31. ## GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
  32. ## Code
  33. ## ----
  34. ## NOTE: Comments preceding an AC_DEFUN (starting from "Usage:") are massaged
  35. ## into doc/ref/autoconf-macros.texi (see Makefile.am in that directory).
  36. # GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
  37. #
  38. # Usage: GUILE_PROGS
  39. #
  40. # This macro looks for programs @code{guile}, @code{guile-config} and
  41. # @code{guile-tools}, and sets variables @var{GUILE}, @var{GUILE_CONFIG} and
  42. # @var{GUILE_TOOLS}, to their paths, respectively. If either of the first two
  43. # is not found, signal error.
  44. #
  45. # The variables are marked for substitution, as by @code{AC_SUBST}.
  46. #
  47. AC_DEFUN([GUILE_PROGS],
  48. [AC_PATH_PROG(GUILE,guile)
  49. if test "$GUILE" = "" ; then
  50. AC_MSG_ERROR([guile required but not found])
  51. fi
  52. AC_SUBST(GUILE)
  53. AC_PATH_PROG(GUILE_CONFIG,guile-config)
  54. if test "$GUILE_CONFIG" = "" ; then
  55. AC_MSG_ERROR([guile-config required but not found])
  56. fi
  57. AC_SUBST(GUILE_CONFIG)
  58. AC_PATH_PROG(GUILE_TOOLS,guile-tools)
  59. AC_SUBST(GUILE_TOOLS)
  60. ])
  61. # GUILE_FLAGS -- set flags for compiling and linking with Guile
  62. #
  63. # Usage: GUILE_FLAGS
  64. #
  65. # This macro runs the @code{guile-config} script, installed with Guile, to
  66. # find out where Guile's header files and libraries are installed. It sets
  67. # two variables, @var{GUILE_CFLAGS} and @var{GUILE_LDFLAGS}.
  68. #
  69. # @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that
  70. # uses Guile header files. This is almost always just a @code{-I} flag.
  71. #
  72. # @var{GUILE_LDFLAGS}: flags to pass to the linker to link a program against
  73. # Guile. This includes @code{-lguile} for the Guile library itself, any
  74. # libraries that Guile itself requires (like -lqthreads), and so on. It may
  75. # also include a @code{-L} flag to tell the compiler where to find the
  76. # libraries.
  77. #
  78. # The variables are marked for substitution, as by @code{AC_SUBST}.
  79. #
  80. AC_DEFUN([GUILE_FLAGS],
  81. [AC_REQUIRE([GUILE_PROGS])dnl
  82. AC_MSG_CHECKING([libguile compile flags])
  83. GUILE_CFLAGS="`$GUILE_CONFIG compile`"
  84. AC_MSG_RESULT([$GUILE_CFLAGS])
  85. AC_MSG_CHECKING([libguile link flags])
  86. GUILE_LDFLAGS="`$GUILE_CONFIG link`"
  87. AC_MSG_RESULT([$GUILE_LDFLAGS])
  88. AC_SUBST(GUILE_CFLAGS)
  89. AC_SUBST(GUILE_LDFLAGS)
  90. ])
  91. # GUILE_SITE_DIR -- find path to Guile "site" directory
  92. #
  93. # Usage: GUILE_SITE_DIR
  94. #
  95. # This looks for Guile's "site" directory, usually something like
  96. # PREFIX/share/guile/site, and sets var @var{GUILE_SITE} to the path.
  97. # Note that the var name is different from the macro name.
  98. #
  99. # The variable is marked for substitution, as by @code{AC_SUBST}.
  100. #
  101. AC_DEFUN([GUILE_SITE_DIR],
  102. [AC_REQUIRE([GUILE_PROGS])dnl
  103. AC_MSG_CHECKING(for Guile site directory)
  104. GUILE_SITE=`[$GUILE_CONFIG] info sitedir`
  105. AC_MSG_RESULT($GUILE_SITE)
  106. AC_SUBST(GUILE_SITE)
  107. ])
  108. # GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
  109. #
  110. # Usage: GUILE_CHECK_RETVAL(var,check)
  111. #
  112. # @var{var} is a shell variable name to be set to the return value.
  113. # @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and
  114. # returning either 0 or non-#f to indicate the check passed.
  115. # Non-0 number or #f indicates failure.
  116. # Avoid using the character "#" since that confuses autoconf.
  117. #
  118. AC_DEFUN([GUILE_CHECK],
  119. [AC_REQUIRE([GUILE_PROGS])
  120. $GUILE -c "$2" > /dev/null 2>&1
  121. $1=$?
  122. ])
  123. # GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
  124. #
  125. # Usage: GUILE_MODULE_CHECK(var,module,featuretest,description)
  126. #
  127. # @var{var} is a shell variable name to be set to "yes" or "no".
  128. # @var{module} is a list of symbols, like: (ice-9 common-list).
  129. # @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v.
  130. # @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING).
  131. #
  132. AC_DEFUN([GUILE_MODULE_CHECK],
  133. [AC_MSG_CHECKING([if $2 $4])
  134. GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3))))
  135. if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi
  136. AC_MSG_RESULT($$1)
  137. ])
  138. # GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
  139. #
  140. # Usage: GUILE_MODULE_AVAILABLE(var,module)
  141. #
  142. # @var{var} is a shell variable name to be set to "yes" or "no".
  143. # @var{module} is a list of symbols, like: (ice-9 common-list).
  144. #
  145. AC_DEFUN([GUILE_MODULE_AVAILABLE],
  146. [GUILE_MODULE_CHECK($1,$2,0,is available)
  147. ])
  148. # GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
  149. #
  150. # Usage: GUILE_MODULE_REQUIRED(symlist)
  151. #
  152. # @var{symlist} is a list of symbols, WITHOUT surrounding parens,
  153. # like: ice-9 common-list.
  154. #
  155. AC_DEFUN([GUILE_MODULE_REQUIRED],
  156. [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1))
  157. if test "$ac_guile_module_required" = "no" ; then
  158. AC_MSG_ERROR([required guile module not found: ($1)])
  159. fi
  160. ])
  161. # GUILE_MODULE_EXPORTS -- check if a module exports a variable
  162. #
  163. # Usage: GUILE_MODULE_EXPORTS(var,module,modvar)
  164. #
  165. # @var{var} is a shell variable to be set to "yes" or "no".
  166. # @var{module} is a list of symbols, like: (ice-9 common-list).
  167. # @var{modvar} is the Guile Scheme variable to check.
  168. #
  169. AC_DEFUN([GUILE_MODULE_EXPORTS],
  170. [GUILE_MODULE_CHECK($1,$2,$3,exports `$3')
  171. ])
  172. # GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
  173. #
  174. # Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar)
  175. #
  176. # @var{module} is a list of symbols, like: (ice-9 common-list).
  177. # @var{modvar} is the Guile Scheme variable to check.
  178. #
  179. AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT],
  180. [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2)
  181. if test "$guile_module_required_export" = "no" ; then
  182. AC_MSG_ERROR([module $1 does not export $2; required])
  183. fi
  184. ])
  185. ## guile.m4 ends here