Newer
Older
monitord / m4 / .svn / text-base / lua.m4.svn-base
  1. # ===========================================================================
  2. # http://www.nongnu.org/autoconf-archive/lua.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_WITH_LUA
  8. # AX_LUA_VERSION (MIN-VERSION, [TOO-BIG-VERSION])
  9. # AX_LUA_HEADERS
  10. # AX_LUA_LIBS
  11. # AX_LUA_LIB_VERSION (MIN-VERSION, [TOO-BIG-VERSION])
  12. #
  13. # DESCRIPTION
  14. #
  15. # Detect Lua interpreter, headers and libraries, optionally enforcing a
  16. # particular range of versions.
  17. #
  18. # AX_WITH_LUA searches for Lua interpreter and defines LUA if found.
  19. #
  20. # AX_LUA_VERSION checks that the version of Lua is at least MIN-VERSION
  21. # and less than TOO-BIG-VERSION, if given.
  22. #
  23. # AX_LUA_HEADERS searches for Lua headers and defines HAVE_LUA_H and
  24. # HAVE_LUALIB_H if found, and defines LUA_INCLUDE to the preprocessor
  25. # flags needed, if any.
  26. #
  27. # AX_LUA_LIBS searches for Lua libraries and defines LUA_LIB if found.
  28. #
  29. # AX_LUA_LIB_VERSION checks that the Lua libraries' version is at least
  30. # MIN-VERSION, and less than TOO-BIG-VERSION, if given.
  31. #
  32. # Versions are specified as three-digit integers whose first digit is the
  33. # major version and last two are the minor version (the same format as
  34. # LUA_VERSION_NUM in lua.h); e.g. 501 for Lua 5.1. The revision (e.g. the
  35. # "3" in "5.1.3") is ignored.
  36. #
  37. # The following options are added by these macros:
  38. #
  39. # --with-lua-prefix=DIR Lua files are in DIR.
  40. # --with-lua-suffix=ARG Lua binaries and library files are
  41. # suffixed with ARG.
  42. # --with-lua-includes=DIR Lua include files are in DIR.
  43. # --with-lua-libraries=DIR Lua library files are in DIR.
  44. #
  45. # LICENSE
  46. #
  47. # Copyright (c) 2009 Reuben Thomas <rrt@sc3d.org>
  48. # Copyright (c) 2009 Matthieu Moy <Matthieu.Moy@imag.fr>
  49. # Copyright (c) 2009 Tom Payne <twpayne@gmail.com>
  50. #
  51. # This program is free software: you can redistribute it and/or modify it
  52. # under the terms of the GNU General Public License as published by the
  53. # Free Software Foundation, either version 3 of the License, or (at your
  54. # option) any later version.
  55. #
  56. # This program is distributed in the hope that it will be useful, but
  57. # WITHOUT ANY WARRANTY; without even the implied warranty of
  58. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  59. # Public License for more details.
  60. #
  61. # You should have received a copy of the GNU General Public License along
  62. # with this program. If not, see <http://www.gnu.org/licenses/>.
  63. #
  64. # As a special exception, the respective Autoconf Macro's copyright owner
  65. # gives unlimited permission to copy, distribute and modify the configure
  66. # scripts that are the output of Autoconf when processing the Macro. You
  67. # need not follow the terms of the GNU General Public License when using
  68. # or distributing such scripts, even though portions of the text of the
  69. # Macro appear in them. The GNU General Public License (GPL) does govern
  70. # all other use of the material that constitutes the Autoconf Macro.
  71. #
  72. # This special exception to the GPL applies to versions of the Autoconf
  73. # Macro released by the Autoconf Archive. When you make and distribute a
  74. # modified version of the Autoconf Macro, you may extend this special
  75. # exception to the GPL to apply to your modified version as well.
  76.  
  77. dnl Helper function to declare extra options
  78. AC_DEFUN([_AX_LUA_OPTS],
  79. [AC_ARG_WITH([lua-prefix],
  80. [AS_HELP_STRING([--with-lua-prefix=DIR],
  81. [Lua files are in DIR])])
  82. AC_ARG_WITH([lua-suffix],
  83. [AS_HELP_STRING([--with-lua-suffix=ARG],
  84. [Lua binary and library files are suffixed with ARG])])
  85. AC_ARG_WITH([lua-includes],
  86. [AS_HELP_STRING([--with-lua-includes=DIR],
  87. [Lua include files are in DIR])])
  88. AC_ARG_WITH([lua-libraries],
  89. [AS_HELP_STRING([--with-lua-libraries=DIR],
  90. [Lua library files are in DIR])])])dnl
  91.  
  92. AC_DEFUN([AX_WITH_LUA],
  93. [_AX_LUA_OPTS
  94. if test "x$with_lua_prefix" = x; then
  95. lua_search_path="$PATH"
  96. else
  97. lua_search_path="$with_lua_prefix/bin"
  98. fi
  99. if test "x$LUA" = x; then
  100. AC_PATH_PROG([LUA], [lua$with_lua_suffix], [], [$lua_search_path])
  101. fi])dnl
  102.  
  103. dnl Helper function to parse minimum & maximum versions
  104. AC_DEFUN([_AX_LUA_VERSIONS],
  105. [lua_min_version=$1
  106. lua_max_version=$2
  107. if test "x$lua_min_version" = x; then
  108. lua_min_version=0
  109. fi
  110. if test "x$lua_max_version" = x; then
  111. lua_max_version=1000
  112. fi])
  113.  
  114. AC_DEFUN([AX_LUA_VERSION],
  115. [_AX_LUA_OPTS
  116. AC_MSG_CHECKING([Lua version is in range $1 <= v < $2])
  117. _AX_LUA_VERSIONS($1, $2)
  118. if test "x$LUA" != x; then
  119. lua_text_version=$($LUA -v 2>&1 | head -n 1 | cut -d' ' -f2)
  120. case $lua_text_version in
  121. 5.1*)
  122. lua_version=501
  123. ;;
  124. 5.0*)
  125. lua_version=500
  126. ;;
  127. 4.0*)
  128. lua_version=400
  129. ;;
  130. *)
  131. lua_version=-1
  132. ;;
  133. esac
  134. if test $lua_version -ge "$lua_min_version" -a $lua_version -lt "$lua_max_version"; then
  135. AC_MSG_RESULT([yes])
  136. else
  137. AC_MSG_RESULT([no])
  138. AC_MSG_FAILURE([Lua version not in desired range.])
  139. fi
  140. else
  141. AC_MSG_RESULT([no])
  142. AC_MSG_FAILURE([Lua version not in desired range.])
  143. fi])dnl
  144.  
  145. AC_DEFUN([AX_LUA_HEADERS],
  146. [_AX_LUA_OPTS
  147. if test "x$with_lua_includes" != x; then
  148. LUA_INCLUDE="-I$with_lua_includes"
  149. elif test "x$with_lua_prefix" != x; then
  150. LUA_INCLUDE="-I$with_lua_prefix/include"
  151. fi
  152. LUA_OLD_CPPFLAGS="$CPPFLAGS"
  153. CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
  154. AC_CHECK_HEADERS([lua.h lualib.h])
  155. CPPFLAGS="$LUA_OLD_CPPFLAGS"])dnl
  156.  
  157. AC_DEFUN([AX_LUA_LIBS],
  158. [_AX_LUA_OPTS
  159. if test "x$with_lua_libraries" != x; then
  160. LUA_LIB="-L$with_lua_libraries"
  161. elif test "x$with_lua_prefix" != x; then
  162. LUA_LIB="-L$with_lua_prefix/lib"
  163. fi
  164. AC_CHECK_LIB([m], [exp], [lua_extra_libs="$lua_extra_libs -lm"], [])
  165. AC_CHECK_LIB([dl], [dlopen], [lua_extra_libs="$lua_extra_libs -ldl"], [])
  166. AC_CHECK_LIB([lua$with_lua_suffix],
  167. [lua_call],
  168. [LUA_LIB="$LUA_LIB -llua$with_lua_suffix $lua_extra_libs"],
  169. [],
  170. [$LUA_LIB $lua_extra_libs])])dnl
  171.  
  172. AC_DEFUN([AX_LUA_LIB_VERSION],
  173. [_AX_LUA_OPTS
  174. AC_MSG_CHECKING([liblua version is in range $1 <= v < $2])
  175. _AX_LUA_VERSIONS($1, $2)
  176. LUA_OLD_LIBS="$LIBS"
  177. LIBS="$LIBS $LUA_LIB"
  178. LUA_OLD_CPPFLAGS="$CPPFLAGS"
  179. CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
  180. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  181. #include <lua.h>
  182. #include <stdlib.h>
  183. #include <stdio.h>
  184. int main()
  185. {
  186. printf("(found %s, %d)... ", LUA_VERSION, LUA_VERSION_NUM);
  187. if (LUA_VERSION_NUM >= $lua_min_version && LUA_VERSION_NUM < $lua_max_version)
  188. exit(EXIT_SUCCESS);
  189. exit(EXIT_FAILURE);
  190. }
  191. ]])],
  192. [AC_MSG_RESULT([yes])],
  193. [AC_MSG_RESULT([no])
  194. AC_MSG_FAILURE([Lua libraries version not in desired range])])
  195. LIBS="$LUA_OLD_LIBS"
  196. CPPFLAGS="$LUA_OLD_CPPFLAGS"])dnl