guile.m4 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. ## Autoconf macros for working with Guile.
  2. ##
  3. ## Copyright (C) 1998,2001, 2006, 2010, 2012 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_PKG -- find Guile development files
  24. ## GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
  25. ## GUILE_FLAGS -- set flags for compiling and linking with Guile
  26. ## GUILE_SITE_DIR -- find path to Guile "site" directory
  27. ## GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
  28. ## GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
  29. ## GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
  30. ## GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
  31. ## GUILE_MODULE_EXPORTS -- check if a module exports a variable
  32. ## GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
  33. ## Code
  34. ## ----
  35. ## NOTE: Comments preceding an AC_DEFUN (starting from "Usage:") are massaged
  36. ## into doc/ref/autoconf-macros.texi (see Makefile.am in that directory).
  37. # GUILE_PKG -- find Guile development files
  38. #
  39. # Usage: GUILE_PKG([VERSIONS])
  40. #
  41. # This macro runs the @code{pkg-config} tool to find development files
  42. # for an available version of Guile.
  43. #
  44. # By default, this macro will search for the latest stable version of
  45. # Guile (e.g. 2.0), falling back to the previous stable version
  46. # (e.g. 1.8) if it is available. If no guile-@var{VERSION}.pc file is
  47. # found, an error is signalled. The found version is stored in
  48. # @var{GUILE_EFFECTIVE_VERSION}.
  49. #
  50. # If @code{GUILE_PROGS} was already invoked, this macro ensures that the
  51. # development files have the same effective version as the Guile
  52. # program.
  53. #
  54. # @var{GUILE_EFFECTIVE_VERSION} is marked for substitution, as by
  55. # @code{AC_SUBST}.
  56. #
  57. AC_DEFUN([GUILE_PKG],
  58. [PKG_PROG_PKG_CONFIG
  59. _guile_versions_to_search="m4_default([$1], [2.0 1.8])"
  60. if test -n "$GUILE_EFFECTIVE_VERSION"; then
  61. _guile_tmp=""
  62. for v in $_guile_versions_to_search; do
  63. if test "$v" = "$GUILE_EFFECTIVE_VERSION"; then
  64. _guile_tmp=$v
  65. fi
  66. done
  67. if test -z "$_guile_tmp"; then
  68. AC_MSG_FAILURE([searching for guile development files for versions $_guile_versions_to_search, but previously found $GUILE version $GUILE_EFFECTIVE_VERSION])
  69. fi
  70. _guile_versions_to_search=$GUILE_EFFECTIVE_VERSION
  71. fi
  72. GUILE_EFFECTIVE_VERSION=""
  73. _guile_errors=""
  74. for v in $_guile_versions_to_search; do
  75. AC_MSG_NOTICE([checking for guile $v])
  76. if test -z "$GUILE_EFFECTIVE_VERSION"; then
  77. PKG_CHECK_EXISTS([guile-$v], [GUILE_EFFECTIVE_VERSION=$v], [])
  78. fi
  79. done
  80. if test -z "$GUILE_EFFECTIVE_VERSION"; then
  81. AC_MSG_ERROR([
  82. No Guile development packages were found.
  83. Please verify that you have Guile installed. If you installed Guile
  84. from a binary distribution, please verify that you have also installed
  85. the development packages. If you installed it yourself, you might need
  86. to adjust your PKG_CONFIG_PATH; see the pkg-config man page for more.
  87. ])
  88. fi
  89. AC_MSG_NOTICE([found guile $v])
  90. AC_SUBST([GUILE_EFFECTIVE_VERSION])
  91. ])
  92. # GUILE_FLAGS -- set flags for compiling and linking with Guile
  93. #
  94. # Usage: GUILE_FLAGS
  95. #
  96. # This macro runs the @code{pkg-config} tool to find out how to compile
  97. # and link programs against Guile. It sets four variables:
  98. # @var{GUILE_CFLAGS}, @var{GUILE_LDFLAGS}, @var{GUILE_LIBS}, and
  99. # @var{GUILE_LTLIBS}.
  100. #
  101. # @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that
  102. # uses Guile header files. This is almost always just one or more @code{-I}
  103. # flags.
  104. #
  105. # @var{GUILE_LDFLAGS}: flags to pass to the compiler to link a program
  106. # against Guile. This includes @code{-lguile-@var{VERSION}} for the
  107. # Guile library itself, and may also include one or more @code{-L} flag
  108. # to tell the compiler where to find the libraries. But it does not
  109. # include flags that influence the program's runtime search path for
  110. # libraries, and will therefore lead to a program that fails to start,
  111. # unless all necessary libraries are installed in a standard location
  112. # such as @file{/usr/lib}.
  113. #
  114. # @var{GUILE_LIBS} and @var{GUILE_LTLIBS}: flags to pass to the compiler or to
  115. # libtool, respectively, to link a program against Guile. It includes flags
  116. # that augment the program's runtime search path for libraries, so that shared
  117. # libraries will be found at the location where they were during linking, even
  118. # in non-standard locations. @var{GUILE_LIBS} is to be used when linking the
  119. # program directly with the compiler, whereas @var{GUILE_LTLIBS} is to be used
  120. # when linking the program is done through libtool.
  121. #
  122. # The variables are marked for substitution, as by @code{AC_SUBST}.
  123. #
  124. AC_DEFUN([GUILE_FLAGS],
  125. [AC_REQUIRE([GUILE_PKG])
  126. PKG_CHECK_MODULES(GUILE, [guile-$GUILE_EFFECTIVE_VERSION])
  127. dnl GUILE_CFLAGS and GUILE_LIBS are already defined and AC_SUBST'd by
  128. dnl PKG_CHECK_MODULES. But GUILE_LIBS to pkg-config is GUILE_LDFLAGS
  129. dnl to us.
  130. GUILE_LDFLAGS=$GUILE_LIBS
  131. dnl Determine the platform dependent parameters needed to use rpath.
  132. dnl AC_LIB_LINKFLAGS_FROM_LIBS is defined in gnulib/m4/lib-link.m4 and needs
  133. dnl the file gnulib/build-aux/config.rpath.
  134. AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LIBS], [$GUILE_LDFLAGS], [])
  135. GUILE_LIBS="$GUILE_LDFLAGS $GUILE_LIBS"
  136. AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LTLIBS], [$GUILE_LDFLAGS], [yes])
  137. GUILE_LTLIBS="$GUILE_LDFLAGS $GUILE_LTLIBS"
  138. AC_SUBST([GUILE_EFFECTIVE_VERSION])
  139. AC_SUBST([GUILE_CFLAGS])
  140. AC_SUBST([GUILE_LDFLAGS])
  141. AC_SUBST([GUILE_LIBS])
  142. AC_SUBST([GUILE_LTLIBS])
  143. ])
  144. # GUILE_SITE_DIR -- find path to Guile "site" directory
  145. #
  146. # Usage: GUILE_SITE_DIR
  147. #
  148. # This looks for Guile's "site" directory, usually something like
  149. # PREFIX/share/guile/site, and sets var @var{GUILE_SITE} to the path.
  150. # Note that the var name is different from the macro name.
  151. #
  152. # The variable is marked for substitution, as by @code{AC_SUBST}.
  153. #
  154. AC_DEFUN([GUILE_SITE_DIR],
  155. [AC_REQUIRE([GUILE_PKG])
  156. AC_MSG_CHECKING(for Guile site directory)
  157. GUILE_SITE=`$PKG_CONFIG --print-errors --variable=sitedir guile-$GUILE_EFFECTIVE_VERSION`
  158. AC_MSG_RESULT($GUILE_SITE)
  159. if test "$GUILE_SITE" = ""; then
  160. AC_MSG_FAILURE(sitedir not found)
  161. fi
  162. AC_SUBST(GUILE_SITE)
  163. ])
  164. # GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
  165. #
  166. # Usage: GUILE_PROGS
  167. #
  168. # This macro looks for programs @code{guile} and @code{guild}, setting
  169. # variables @var{GUILE} and @var{GUILD} to their paths, respectively.
  170. # If @code{guile} is not found, signal an error.
  171. #
  172. # The effective version of the found @code{guile} is set to
  173. # @var{GUILE_EFFECTIVE_VERSION}. This macro ensures that the effective
  174. # version is compatible with the result of a previous invocation of
  175. # @code{GUILE_FLAGS}, if any.
  176. #
  177. # As a legacy interface, it also looks for @code{guile-config} and
  178. # @code{guile-tools}, setting @var{GUILE_CONFIG} and @var{GUILE_TOOLS}.
  179. #
  180. # The variables are marked for substitution, as by @code{AC_SUBST}.
  181. #
  182. AC_DEFUN([GUILE_PROGS],
  183. [AC_PATH_PROG(GUILE,guile)
  184. if test "$GUILE" = "" ; then
  185. AC_MSG_ERROR([guile required but not found])
  186. fi
  187. AC_SUBST(GUILE)
  188. _guile_prog_version=`$GUILE -c "(display (effective-version))"`
  189. if test -z "$GUILE_EFFECTIVE_VERSION"; then
  190. GUILE_EFFECTIVE_VERSION=$_guile_prog_version
  191. elif test "$GUILE_EFFECTIVE_VERSION" != "$_guile_prog_version"; then
  192. AC_MSG_ERROR([found development files for Guile $GUILE_EFFECTIVE_VERSION, but $GUILE has effective version $_guile_prog_version])
  193. fi
  194. AC_PATH_PROG(GUILD,guild)
  195. AC_SUBST(GUILD)
  196. AC_PATH_PROG(GUILE_CONFIG,guile-config)
  197. AC_SUBST(GUILE_CONFIG)
  198. if test -n "$GUILD"; then
  199. GUILE_TOOLS=$GUILD
  200. else
  201. AC_PATH_PROG(GUILE_TOOLS,guile-tools)
  202. fi
  203. AC_SUBST(GUILE_TOOLS)
  204. ])
  205. # GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
  206. #
  207. # Usage: GUILE_CHECK_RETVAL(var,check)
  208. #
  209. # @var{var} is a shell variable name to be set to the return value.
  210. # @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and
  211. # returning either 0 or non-#f to indicate the check passed.
  212. # Non-0 number or #f indicates failure.
  213. # Avoid using the character "#" since that confuses autoconf.
  214. #
  215. AC_DEFUN([GUILE_CHECK],
  216. [AC_REQUIRE([GUILE_PROGS])
  217. $GUILE -c "$2" > /dev/null 2>&1
  218. $1=$?
  219. ])
  220. # GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
  221. #
  222. # Usage: GUILE_MODULE_CHECK(var,module,featuretest,description)
  223. #
  224. # @var{var} is a shell variable name to be set to "yes" or "no".
  225. # @var{module} is a list of symbols, like: (ice-9 common-list).
  226. # @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v.
  227. # @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING).
  228. #
  229. AC_DEFUN([GUILE_MODULE_CHECK],
  230. [AC_MSG_CHECKING([if $2 $4])
  231. GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3))))
  232. if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi
  233. AC_MSG_RESULT($$1)
  234. ])
  235. # GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
  236. #
  237. # Usage: GUILE_MODULE_AVAILABLE(var,module)
  238. #
  239. # @var{var} is a shell variable name to be set to "yes" or "no".
  240. # @var{module} is a list of symbols, like: (ice-9 common-list).
  241. #
  242. AC_DEFUN([GUILE_MODULE_AVAILABLE],
  243. [GUILE_MODULE_CHECK($1,$2,0,is available)
  244. ])
  245. # GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
  246. #
  247. # Usage: GUILE_MODULE_REQUIRED(symlist)
  248. #
  249. # @var{symlist} is a list of symbols, WITHOUT surrounding parens,
  250. # like: ice-9 common-list.
  251. #
  252. AC_DEFUN([GUILE_MODULE_REQUIRED],
  253. [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1))
  254. if test "$ac_guile_module_required" = "no" ; then
  255. AC_MSG_ERROR([required guile module not found: ($1)])
  256. fi
  257. ])
  258. # GUILE_MODULE_EXPORTS -- check if a module exports a variable
  259. #
  260. # Usage: GUILE_MODULE_EXPORTS(var,module,modvar)
  261. #
  262. # @var{var} is a shell variable to be set to "yes" or "no".
  263. # @var{module} is a list of symbols, like: (ice-9 common-list).
  264. # @var{modvar} is the Guile Scheme variable to check.
  265. #
  266. AC_DEFUN([GUILE_MODULE_EXPORTS],
  267. [GUILE_MODULE_CHECK($1,$2,$3,exports `$3')
  268. ])
  269. # GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
  270. #
  271. # Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar)
  272. #
  273. # @var{module} is a list of symbols, like: (ice-9 common-list).
  274. # @var{modvar} is the Guile Scheme variable to check.
  275. #
  276. AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT],
  277. [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2)
  278. if test "$guile_module_required_export" = "no" ; then
  279. AC_MSG_ERROR([module $1 does not export $2; required])
  280. fi
  281. ])
  282. ## guile.m4 ends here