guile.m4 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. ## Autoconf macros for working with Guile.
  2. ##
  3. ## Copyright (C) 1998,2001, 2006, 2010, 2012, 2013 - 2016 Free
  4. ## Software Foundation, Inc.
  5. ##
  6. ## This library is free software; you can redistribute it and/or
  7. ## modify it under the terms of the GNU Lesser General Public License
  8. ## as published by the Free Software Foundation; either version 3 of
  9. ## the License, or (at your option) any later version.
  10. ##
  11. ## This library is distributed in the hope that it will be useful,
  12. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ## Lesser General Public License for more details.
  15. ##
  16. ## You should have received a copy of the GNU Lesser General Public
  17. ## License along with this library; if not, write to the Free Software
  18. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. ## 02110-1301 USA
  20. # serial 10
  21. ## Index
  22. ## -----
  23. ##
  24. ## GUILE_PKG -- find Guile development files
  25. ## GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
  26. ## GUILE_FLAGS -- set flags for compiling and linking with Guile
  27. ## GUILE_SITE_DIR -- find path to Guile "site" directory
  28. ## GUILE_GLOBAL_SITE_DIR -- find path to Guile "global site" directory
  29. ## GUILE_SITE_CCACHE_DIR -- find path to Guile "site-ccache" directory
  30. ## GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
  31. ## GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
  32. ## GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
  33. ## GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
  34. ## GUILE_MODULE_EXPORTS -- check if a module exports a variable
  35. ## GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
  36. ## Code
  37. ## ----
  38. ## NOTE: Comments preceding an AC_DEFUN (starting from "Usage:") are massaged
  39. ## into doc/ref/autoconf-macros.texi (see Makefile.am in that directory).
  40. # GUILE_PKG -- find Guile development files
  41. #
  42. # Usage: GUILE_PKG([VERSIONS])
  43. #
  44. # This macro runs the @code{pkg-config} tool to find development files
  45. # for an available version of Guile.
  46. #
  47. # By default, this macro will search for the latest stable version of
  48. # Guile (e.g. 2.0), falling back to the previous stable version
  49. # (e.g. 1.8) if it is available. If no guile-@var{VERSION}.pc file is
  50. # found, an error is signalled. The found version is stored in
  51. # @var{GUILE_EFFECTIVE_VERSION}.
  52. #
  53. # If @code{GUILE_PROGS} was already invoked, this macro ensures that the
  54. # development files have the same effective version as the Guile
  55. # program.
  56. #
  57. # @var{GUILE_EFFECTIVE_VERSION} is marked for substitution, as by
  58. # @code{AC_SUBST}.
  59. #
  60. AC_DEFUN([GUILE_PKG],
  61. [PKG_PROG_PKG_CONFIG
  62. _guile_versions_to_search="m4_default([$1], [2.2 2.0])"
  63. if test -n "$GUILE_EFFECTIVE_VERSION"; then
  64. _guile_tmp=""
  65. for v in $_guile_versions_to_search; do
  66. if test "$v" = "$GUILE_EFFECTIVE_VERSION"; then
  67. _guile_tmp=$v
  68. fi
  69. done
  70. if test -z "$_guile_tmp"; then
  71. AC_MSG_FAILURE([searching for guile development files for versions $_guile_versions_to_search, but previously found $GUILE version $GUILE_EFFECTIVE_VERSION])
  72. fi
  73. _guile_versions_to_search=$GUILE_EFFECTIVE_VERSION
  74. fi
  75. GUILE_EFFECTIVE_VERSION=""
  76. _guile_errors=""
  77. for v in $_guile_versions_to_search; do
  78. if test -z "$GUILE_EFFECTIVE_VERSION"; then
  79. AC_MSG_NOTICE([checking for guile $v])
  80. PKG_CHECK_EXISTS([guile-$v], [GUILE_EFFECTIVE_VERSION=$v], [])
  81. fi
  82. done
  83. if test -z "$GUILE_EFFECTIVE_VERSION"; then
  84. AC_MSG_ERROR([
  85. No Guile development packages were found.
  86. Please verify that you have Guile installed. If you installed Guile
  87. from a binary distribution, please verify that you have also installed
  88. the development packages. If you installed it yourself, you might need
  89. to adjust your PKG_CONFIG_PATH; see the pkg-config man page for more.
  90. ])
  91. fi
  92. AC_MSG_NOTICE([found guile $GUILE_EFFECTIVE_VERSION])
  93. AC_SUBST([GUILE_EFFECTIVE_VERSION])
  94. ])
  95. # GUILE_FLAGS -- set flags for compiling and linking with Guile
  96. #
  97. # Usage: GUILE_FLAGS
  98. #
  99. # This macro runs the @code{pkg-config} tool to find out how to compile
  100. # and link programs against Guile. It sets four variables:
  101. # @var{GUILE_CFLAGS}, @var{GUILE_LDFLAGS}, @var{GUILE_LIBS}, and
  102. # @var{GUILE_LTLIBS}.
  103. #
  104. # @var{GUILE_CFLAGS}: flags to pass to a C or C++ compiler to build code that
  105. # uses Guile header files. This is almost always just one or more @code{-I}
  106. # flags.
  107. #
  108. # @var{GUILE_LDFLAGS}: flags to pass to the compiler to link a program
  109. # against Guile. This includes @code{-lguile-@var{VERSION}} for the
  110. # Guile library itself, and may also include one or more @code{-L} flag
  111. # to tell the compiler where to find the libraries. But it does not
  112. # include flags that influence the program's runtime search path for
  113. # libraries, and will therefore lead to a program that fails to start,
  114. # unless all necessary libraries are installed in a standard location
  115. # such as @file{/usr/lib}.
  116. #
  117. # @var{GUILE_LIBS} and @var{GUILE_LTLIBS}: flags to pass to the compiler or to
  118. # libtool, respectively, to link a program against Guile. It includes flags
  119. # that augment the program's runtime search path for libraries, so that shared
  120. # libraries will be found at the location where they were during linking, even
  121. # in non-standard locations. @var{GUILE_LIBS} is to be used when linking the
  122. # program directly with the compiler, whereas @var{GUILE_LTLIBS} is to be used
  123. # when linking the program is done through libtool.
  124. #
  125. # The variables are marked for substitution, as by @code{AC_SUBST}.
  126. #
  127. AC_DEFUN([GUILE_FLAGS],
  128. [AC_REQUIRE([GUILE_PKG])
  129. PKG_CHECK_MODULES(GUILE, [guile-$GUILE_EFFECTIVE_VERSION])
  130. dnl GUILE_CFLAGS and GUILE_LIBS are already defined and AC_SUBST'd by
  131. dnl PKG_CHECK_MODULES. But GUILE_LIBS to pkg-config is GUILE_LDFLAGS
  132. dnl to us.
  133. GUILE_LDFLAGS=$GUILE_LIBS
  134. dnl Determine the platform dependent parameters needed to use rpath.
  135. dnl AC_LIB_LINKFLAGS_FROM_LIBS is defined in gnulib/m4/lib-link.m4 and needs
  136. dnl the file gnulib/build-aux/config.rpath.
  137. AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LIBS], [$GUILE_LDFLAGS], [])
  138. GUILE_LIBS="$GUILE_LDFLAGS $GUILE_LIBS"
  139. AC_LIB_LINKFLAGS_FROM_LIBS([GUILE_LTLIBS], [$GUILE_LDFLAGS], [yes])
  140. GUILE_LTLIBS="$GUILE_LDFLAGS $GUILE_LTLIBS"
  141. AC_SUBST([GUILE_EFFECTIVE_VERSION])
  142. AC_SUBST([GUILE_CFLAGS])
  143. AC_SUBST([GUILE_LDFLAGS])
  144. AC_SUBST([GUILE_LIBS])
  145. AC_SUBST([GUILE_LTLIBS])
  146. ])
  147. # GUILE_PREFIX_DIR -- find path to Guile "prefix" directory
  148. #
  149. # Usage: GUILE_PREFIX_DIR
  150. #
  151. # This looks for Guile's "prefix" directory and sets var
  152. # @var{GUILE_PREFIX} to the path. Note that the var name is different
  153. # from the macro name.
  154. #
  155. # The variable is marked for substitution, as by @code{AC_SUBST}.
  156. #
  157. AC_DEFUN([GUILE_PREFIX_DIR],
  158. [AC_REQUIRE([GUILE_PKG])
  159. AC_MSG_CHECKING(for Guile prefix directory)
  160. GUILE_PREFIX=`$PKG_CONFIG --print-errors --variable=prefix guile-$GUILE_EFFECTIVE_VERSION`
  161. AC_MSG_RESULT($GUILE_PREFIX)
  162. if test "$GUILE_PREFIX" = ""; then
  163. AC_MSG_FAILURE(prefix not found)
  164. fi
  165. AC_SUBST(GUILE_PREFIX)
  166. ])
  167. # GUILE_SITE_DIR -- find path to Guile "site" directory
  168. #
  169. # Usage: GUILE_SITE_DIR
  170. #
  171. # This looks for Guile's "site" directory, usually something like
  172. # PREFIX/share/guile/site/2.x, and sets var @var{GUILE_SITE} to the
  173. # path. Note that the var name is different from the macro name.
  174. #
  175. # The variable is marked for substitution, as by @code{AC_SUBST}.
  176. #
  177. AC_DEFUN([GUILE_SITE_DIR],
  178. [AC_REQUIRE([GUILE_PKG])
  179. AC_MSG_CHECKING(for Guile site directory)
  180. GUILE_SITE=`$PKG_CONFIG --print-errors --variable=sitedir guile-$GUILE_EFFECTIVE_VERSION`
  181. AC_MSG_RESULT($GUILE_SITE)
  182. if test "$GUILE_SITE" = ""; then
  183. AC_MSG_FAILURE(sitedir not found)
  184. fi
  185. AC_SUBST(GUILE_SITE)
  186. ])
  187. # GUILE_GLOBAL_SITE_DIR -- find path to Guile global site directory
  188. #
  189. # Usage: GUILE_GLOBAL_SITE_DIR
  190. #
  191. # This looks for Guile's global site directory, usually something like
  192. # PREFIX/share/guile/site, and sets var @var{GUILE_GLOBAL_SITE} to the
  193. # path. Note that the var name is different from the macro name.
  194. #
  195. # The variable is marked for substitution, as by @code{AC_SUBST}.
  196. #
  197. AC_DEFUN([GUILE_GLOBAL_SITE_DIR],
  198. [AC_REQUIRE([GUILE_PROGS])
  199. AC_MSG_CHECKING(for Guile global site directory)
  200. GUILE_GLOBAL_SITE=`$GUILE -c "(display (%global-site-dir))"`
  201. AC_MSG_RESULT($GUILE_GLOBAL_SITE)
  202. if test "$GUILE_GLOBAL_SITE" = ""; then
  203. AC_MSG_FAILURE(global site dir not found)
  204. fi
  205. AC_SUBST(GUILE_GLOBAL_SITE)
  206. ])
  207. # GUILE_SITE_CCACHE_DIR -- find path to Guile "site-ccache" directory
  208. #
  209. # Usage: GUILE_SITE_CCACHE_DIR
  210. #
  211. # This looks for Guile's "site-ccache" directory, usually something
  212. # like PREFIX/lib/guile/GUILE_EFFECTIVE_VERSION/site-ccache, and sets
  213. # var @var{GUILE_SITE_CCACHE} to the path. Note that the var name is
  214. # different from the macro name.
  215. #
  216. # The variable is marked for substitution, as by @code{AC_SUBST}.
  217. #
  218. AC_DEFUN([GUILE_SITE_CCACHE_DIR],
  219. [AC_REQUIRE([GUILE_PKG])
  220. AC_MSG_CHECKING(for Guile site-ccache directory)
  221. _guile_lib=`$PKG_CONFIG --print-errors --variable=libdir guile-$GUILE_EFFECTIVE_VERSION`
  222. if test "$_guile_lib" = ""; then
  223. AC_MSG_FAILURE(libdir not found)
  224. fi
  225. GUILE_SITE_CCACHE=$_guile_lib/guile/$GUILE_EFFECTIVE_VERSION/site-ccache
  226. AC_MSG_RESULT($GUILE_SITE_CCACHE)
  227. AC_SUBST(GUILE_SITE_CCACHE)
  228. ])
  229. # GUILE_PROGS -- set paths to Guile interpreter, config and tool programs
  230. #
  231. # Usage: GUILE_PROGS([VERSION])
  232. #
  233. # This macro looks for programs @code{guile} and @code{guild}, setting
  234. # variables @var{GUILE} and @var{GUILD} to their paths, respectively.
  235. # If @code{guile} is not found, signal an error.
  236. #
  237. # By default, this macro will search for the latest stable version of
  238. # Guile (e.g. 2.0). x.y or x.y.z versions can be specified. If an older
  239. # version is found, the macro will signal an error.
  240. #
  241. # The effective version of the found @code{guile} is set to
  242. # @var{GUILE_EFFECTIVE_VERSION}. This macro ensures that the effective
  243. # version is compatible with the result of a previous invocation of
  244. # @code{GUILE_FLAGS}, if any.
  245. #
  246. # As a legacy interface, it also looks for @code{guile-config} and
  247. # @code{guile-tools}, setting @var{GUILE_CONFIG} and @var{GUILE_TOOLS}.
  248. #
  249. # The variables are marked for substitution, as by @code{AC_SUBST}.
  250. #
  251. AC_DEFUN([GUILE_PROGS],
  252. [AC_PATH_PROG(GUILE,guile)
  253. _guile_required_version="m4_default([$1], [$GUILE_EFFECTIVE_VERSION])"
  254. if test -z "$_guile_required_version"; then
  255. _guile_required_version=2.0
  256. fi
  257. if test "$GUILE" = "" ; then
  258. AC_MSG_ERROR([guile required but not found])
  259. fi
  260. AC_SUBST(GUILE)
  261. _guile_effective_version=`$GUILE -c "(display (effective-version))"`
  262. if test -z "$GUILE_EFFECTIVE_VERSION"; then
  263. GUILE_EFFECTIVE_VERSION=$_guile_effective_version
  264. elif test "$GUILE_EFFECTIVE_VERSION" != "$_guile_effective_version"; then
  265. AC_MSG_ERROR([found development files for Guile $GUILE_EFFECTIVE_VERSION, but $GUILE has effective version $_guile_effective_version])
  266. fi
  267. _guile_major_version=`$GUILE -c "(display (major-version))"`
  268. _guile_minor_version=`$GUILE -c "(display (minor-version))"`
  269. _guile_micro_version=`$GUILE -c "(display (micro-version))"`
  270. _guile_prog_version="$_guile_major_version.$_guile_minor_version.$_guile_micro_version"
  271. AC_MSG_CHECKING([for Guile version >= $_guile_required_version])
  272. _major_version=`echo $_guile_required_version | cut -d . -f 1`
  273. _minor_version=`echo $_guile_required_version | cut -d . -f 2`
  274. _micro_version=`echo $_guile_required_version | cut -d . -f 3`
  275. if test "$_guile_major_version" -gt "$_major_version"; then
  276. true
  277. elif test "$_guile_major_version" -eq "$_major_version"; then
  278. if test "$_guile_minor_version" -gt "$_minor_version"; then
  279. true
  280. elif test "$_guile_minor_version" -eq "$_minor_version"; then
  281. if test -n "$_micro_version"; then
  282. if test "$_guile_micro_version" -lt "$_micro_version"; then
  283. AC_MSG_ERROR([Guile $_guile_required_version required, but $_guile_prog_version found])
  284. fi
  285. fi
  286. elif test "$GUILE_EFFECTIVE_VERSION" = "$_major_version.$_minor_version" -a -z "$_micro_version"; then
  287. # Allow prereleases that have the right effective version.
  288. true
  289. else
  290. as_fn_error $? "Guile $_guile_required_version required, but $_guile_prog_version found" "$LINENO" 5
  291. fi
  292. else
  293. AC_MSG_ERROR([Guile $_guile_required_version required, but $_guile_prog_version found])
  294. fi
  295. AC_MSG_RESULT([$_guile_prog_version])
  296. AC_PATH_PROG(GUILD,guild)
  297. AC_SUBST(GUILD)
  298. AC_PATH_PROG(GUILE_CONFIG,guile-config)
  299. AC_SUBST(GUILE_CONFIG)
  300. if test -n "$GUILD"; then
  301. GUILE_TOOLS=$GUILD
  302. else
  303. AC_PATH_PROG(GUILE_TOOLS,guile-tools)
  304. fi
  305. AC_SUBST(GUILE_TOOLS)
  306. ])
  307. # GUILE_CHECK -- evaluate Guile Scheme code and capture the return value
  308. #
  309. # Usage: GUILE_CHECK_RETVAL(var,check)
  310. #
  311. # @var{var} is a shell variable name to be set to the return value.
  312. # @var{check} is a Guile Scheme expression, evaluated with "$GUILE -c", and
  313. # returning either 0 or non-#f to indicate the check passed.
  314. # Non-0 number or #f indicates failure.
  315. # Avoid using the character "#" since that confuses autoconf.
  316. #
  317. AC_DEFUN([GUILE_CHECK],
  318. [AC_REQUIRE([GUILE_PROGS])
  319. $GUILE -c "$2" > /dev/null 2>&1
  320. $1=$?
  321. ])
  322. # GUILE_MODULE_CHECK -- check feature of a Guile Scheme module
  323. #
  324. # Usage: GUILE_MODULE_CHECK(var,module,featuretest,description)
  325. #
  326. # @var{var} is a shell variable name to be set to "yes" or "no".
  327. # @var{module} is a list of symbols, like: (ice-9 common-list).
  328. # @var{featuretest} is an expression acceptable to GUILE_CHECK, q.v.
  329. # @var{description} is a present-tense verb phrase (passed to AC_MSG_CHECKING).
  330. #
  331. AC_DEFUN([GUILE_MODULE_CHECK],
  332. [AC_MSG_CHECKING([if $2 $4])
  333. GUILE_CHECK($1,(use-modules $2) (exit ((lambda () $3))))
  334. if test "$$1" = "0" ; then $1=yes ; else $1=no ; fi
  335. AC_MSG_RESULT($$1)
  336. ])
  337. # GUILE_MODULE_AVAILABLE -- check availability of a Guile Scheme module
  338. #
  339. # Usage: GUILE_MODULE_AVAILABLE(var,module)
  340. #
  341. # @var{var} is a shell variable name to be set to "yes" or "no".
  342. # @var{module} is a list of symbols, like: (ice-9 common-list).
  343. #
  344. AC_DEFUN([GUILE_MODULE_AVAILABLE],
  345. [GUILE_MODULE_CHECK($1,$2,0,is available)
  346. ])
  347. # GUILE_MODULE_REQUIRED -- fail if a Guile Scheme module is unavailable
  348. #
  349. # Usage: GUILE_MODULE_REQUIRED(symlist)
  350. #
  351. # @var{symlist} is a list of symbols, WITHOUT surrounding parens,
  352. # like: ice-9 common-list.
  353. #
  354. AC_DEFUN([GUILE_MODULE_REQUIRED],
  355. [GUILE_MODULE_AVAILABLE(ac_guile_module_required, ($1))
  356. if test "$ac_guile_module_required" = "no" ; then
  357. AC_MSG_ERROR([required guile module not found: ($1)])
  358. fi
  359. ])
  360. # GUILE_MODULE_EXPORTS -- check if a module exports a variable
  361. #
  362. # Usage: GUILE_MODULE_EXPORTS(var,module,modvar)
  363. #
  364. # @var{var} is a shell variable to be set to "yes" or "no".
  365. # @var{module} is a list of symbols, like: (ice-9 common-list).
  366. # @var{modvar} is the Guile Scheme variable to check.
  367. #
  368. AC_DEFUN([GUILE_MODULE_EXPORTS],
  369. [GUILE_MODULE_CHECK($1,$2,$3,exports `$3')
  370. ])
  371. # GUILE_MODULE_REQUIRED_EXPORT -- fail if a module doesn't export a variable
  372. #
  373. # Usage: GUILE_MODULE_REQUIRED_EXPORT(module,modvar)
  374. #
  375. # @var{module} is a list of symbols, like: (ice-9 common-list).
  376. # @var{modvar} is the Guile Scheme variable to check.
  377. #
  378. AC_DEFUN([GUILE_MODULE_REQUIRED_EXPORT],
  379. [GUILE_MODULE_EXPORTS(guile_module_required_export,$1,$2)
  380. if test "$guile_module_required_export" = "no" ; then
  381. AC_MSG_ERROR([module $1 does not export $2; required])
  382. fi
  383. ])
  384. ## guile.m4 ends here