guile.m4 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. ## Autoconf macros for working with Guile.
  2. ##
  3. ## Copyright (C) 1998,2001, 2006, 2010 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 10
  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. # four variables, @var{GUILE_CFLAGS}, @var{GUILE_LDFLAGS}, @var{GUILE_LIBS},
  68. # and @var{GUILE_LTLIBS}.
  69. #
  70. # @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that
  71. # uses Guile header files. This is almost always just one or more @code{-I}
  72. # flags.
  73. #
  74. # @var{GUILE_LDFLAGS}: flags to pass to the compiler to link a program against
  75. # Guile. This includes @code{-lguile} for the Guile library itself, any
  76. # libraries that Guile itself requires (like -lqthreads), and so on. It may
  77. # also include one or more @code{-L} flag to tell the compiler where to find
  78. # the libraries. But it does not include flags that influence the program's
  79. # runtime search path for libraries, and will therefore lead to a program
  80. # that fails to start, unless all necessary libraries are installed in a
  81. # standard location such as @file{/usr/lib}.
  82. #
  83. # @var{GUILE_LIBS} and @var{GUILE_LTLIBS}: flags to pass to the compiler or to
  84. # libtool, respectively, to link a program against Guile. It includes flags
  85. # that augment the program's runtime search path for libraries, so that shared
  86. # libraries will be found at the location where they were during linking, even
  87. # in non-standard locations. @var{GUILE_LIBS} is to be used when linking the
  88. # program directly with the compiler, whereas @var{GUILE_LTLIBS} is to be used
  89. # when linking the program is done through libtool.
  90. #
  91. # The variables are marked for substitution, as by @code{AC_SUBST}.
  92. #
  93. AC_DEFUN([GUILE_FLAGS],
  94. [dnl Find guile-config.
  95. AC_REQUIRE([GUILE_PROGS])dnl
  96. AC_MSG_CHECKING([libguile compile flags])
  97. GUILE_CFLAGS="`$GUILE_CONFIG compile`"
  98. AC_MSG_RESULT([$GUILE_CFLAGS])
  99. AC_MSG_CHECKING([libguile link flags])
  100. GUILE_LDFLAGS="`$GUILE_CONFIG link`"
  101. AC_MSG_RESULT([$GUILE_LDFLAGS])
  102. dnl Determine the platform dependent parameters needed to use rpath.
  103. dnl AC_LIB_LINKFLAGS_FROM_LIBS is defined in gnulib/m4/lib-link.m4 and needs
  104. dnl the file gnulib/build-aux/config.rpath.
  105. AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LIBS], [$GUILE_LDFLAGS], [])
  106. GUILE_LIBS="$GUILE_LDFLAGS $GUILE_LIBS"
  107. AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LTLIBS], [$GUILE_LDFLAGS], [yes])
  108. GUILE_LTLIBS="$GUILE_LDFLAGS $GUILE_LTLIBS"
  109. AC_SUBST([GUILE_CFLAGS])
  110. AC_SUBST([GUILE_LDFLAGS])
  111. AC_SUBST([GUILE_LIBS])
  112. AC_SUBST([GUILE_LTLIBS])
  113. ])
  114. # GUILE_SITE_DIR -- find path to Guile "site" directory
  115. #
  116. # Usage: GUILE_SITE_DIR
  117. #
  118. # This looks for Guile's "site" directory, usually something like
  119. # PREFIX/share/guile/site, and sets var @var{GUILE_SITE} to the path.
  120. # Note that the var name is different from the macro name.
  121. #
  122. # The variable is marked for substitution, as by @code{AC_SUBST}.
  123. #
  124. AC_DEFUN([GUILE_SITE_DIR],
  125. [AC_REQUIRE([GUILE_PROGS])dnl
  126. AC_MSG_CHECKING(for Guile site directory)
  127. GUILE_SITE=`[$GUILE_CONFIG] info sitedir`
  128. if test "$GUILE_SITE" = ""; then
  129. GUILE_SITE=`[$GUILE_CONFIG] info pkgdatadir`/site
  130. fi
  131. AC_MSG_RESULT($GUILE_SITE)
  132. AC_SUBST(GUILE_SITE)
  133. ])
  134. # GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
  135. #
  136. # Usage: GUILE_CHECK_RETVAL(var,check)
  137. #
  138. # @var{var} is a shell variable name to be set to the return value.
  139. # @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and
  140. # returning either 0 or non-#f to indicate the check passed.
  141. # Non-0 number or #f indicates failure.
  142. # Avoid using the character "#" since that confuses autoconf.
  143. #
  144. AC_DEFUN([GUILE_CHECK],
  145. [AC_REQUIRE([GUILE_PROGS])
  146. $GUILE -c "$2" > /dev/null 2>&1
  147. $1=$?
  148. ])
  149. # GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
  150. #
  151. # Usage: GUILE_MODULE_CHECK(var,module,featuretest,description)
  152. #
  153. # @var{var} is a shell variable name to be set to "yes" or "no".
  154. # @var{module} is a list of symbols, like: (ice-9 common-list).
  155. # @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v.
  156. # @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING).
  157. #
  158. AC_DEFUN([GUILE_MODULE_CHECK],
  159. [AC_MSG_CHECKING([if $2 $4])
  160. GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3))))
  161. if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi
  162. AC_MSG_RESULT($$1)
  163. ])
  164. # GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
  165. #
  166. # Usage: GUILE_MODULE_AVAILABLE(var,module)
  167. #
  168. # @var{var} is a shell variable name to be set to "yes" or "no".
  169. # @var{module} is a list of symbols, like: (ice-9 common-list).
  170. #
  171. AC_DEFUN([GUILE_MODULE_AVAILABLE],
  172. [GUILE_MODULE_CHECK($1,$2,0,is available)
  173. ])
  174. # GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
  175. #
  176. # Usage: GUILE_MODULE_REQUIRED(symlist)
  177. #
  178. # @var{symlist} is a list of symbols, WITHOUT surrounding parens,
  179. # like: ice-9 common-list.
  180. #
  181. AC_DEFUN([GUILE_MODULE_REQUIRED],
  182. [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1))
  183. if test "$ac_guile_module_required" = "no" ; then
  184. AC_MSG_ERROR([required guile module not found: ($1)])
  185. fi
  186. ])
  187. # GUILE_MODULE_EXPORTS -- check if a module exports a variable
  188. #
  189. # Usage: GUILE_MODULE_EXPORTS(var,module,modvar)
  190. #
  191. # @var{var} is a shell variable to be set to "yes" or "no".
  192. # @var{module} is a list of symbols, like: (ice-9 common-list).
  193. # @var{modvar} is the Guile Scheme variable to check.
  194. #
  195. AC_DEFUN([GUILE_MODULE_EXPORTS],
  196. [GUILE_MODULE_CHECK($1,$2,$3,exports `$3')
  197. ])
  198. # GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
  199. #
  200. # Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar)
  201. #
  202. # @var{module} is a list of symbols, like: (ice-9 common-list).
  203. # @var{modvar} is the Guile Scheme variable to check.
  204. #
  205. AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT],
  206. [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2)
  207. if test "$guile_module_required_export" = "no" ; then
  208. AC_MSG_ERROR([module $1 does not export $2; required])
  209. fi
  210. ])
  211. ## guile.m4 ends here