ax_lua.m4 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_lua.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_PROG_LUA[([MINIMUM-VERSION], [TOO-BIG-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
  8. # AX_LUA_HEADERS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
  9. # AX_LUA_LIBS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
  10. # AX_LUA_READLINE[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
  11. #
  12. # DESCRIPTION
  13. #
  14. # Detect a Lua interpreter, optionally specifying a minimum and maximum
  15. # version number. Set up important Lua paths, such as the directories in
  16. # which to install scripts and modules (shared libraries).
  17. #
  18. # Also detect Lua headers and libraries. The Lua version contained in the
  19. # header is checked to match the Lua interpreter version exactly. When
  20. # searching for Lua libraries, the version number is used as a suffix.
  21. # This is done with the goal of supporting multiple Lua installs (5.1 and
  22. # 5.2 side-by-side).
  23. #
  24. # A note on compatibility with previous versions: This file has been
  25. # mostly rewritten for serial 18. Most developers should be able to use
  26. # these macros without needing to modify configure.ac. Care has been taken
  27. # to preserve each macro's behavior, but there are some differences:
  28. #
  29. # 1) AX_WITH_LUA is deprecated; it now expands to the exact same thing as
  30. # AX_PROG_LUA with no arguments.
  31. #
  32. # 2) AX_LUA_HEADERS now checks that the version number defined in lua.h
  33. # matches the interpreter version. AX_LUA_HEADERS_VERSION is therefore
  34. # unnecessary, so it is deprecated and does not expand to anything.
  35. #
  36. # 3) The configure flag --with-lua-suffix no longer exists; the user
  37. # should instead specify the LUA precious variable on the command line.
  38. # See the AX_PROG_LUA description for details.
  39. #
  40. # Please read the macro descriptions below for more information.
  41. #
  42. # This file was inspired by Andrew Dalke's and James Henstridge's
  43. # python.m4 and Tom Payne's, Matthieu Moy's, and Reuben Thomas's ax_lua.m4
  44. # (serial 17). Basically, this file is a mash-up of those two files. I
  45. # like to think it combines the best of the two!
  46. #
  47. # AX_PROG_LUA: Search for the Lua interpreter, and set up important Lua
  48. # paths. Adds precious variable LUA, which may contain the path of the Lua
  49. # interpreter. If LUA is blank, the user's path is searched for an
  50. # suitable interpreter.
  51. #
  52. # If MINIMUM-VERSION is supplied, then only Lua interpreters with a
  53. # version number greater or equal to MINIMUM-VERSION will be accepted. If
  54. # TOO-BIG- VERSION is also supplied, then only Lua interpreters with a
  55. # version number greater or equal to MINIMUM-VERSION and less than
  56. # TOO-BIG-VERSION will be accepted.
  57. #
  58. # Version comparisons require the AX_COMPARE_VERSION macro, which is
  59. # provided by ax_compare_version.m4 from the Autoconf Archive.
  60. #
  61. # The Lua version number, LUA_VERSION, is found from the interpreter, and
  62. # substituted. LUA_PLATFORM is also found, but not currently supported (no
  63. # standard representation).
  64. #
  65. # Finally, the macro finds four paths:
  66. #
  67. # luadir Directory to install Lua scripts.
  68. # pkgluadir $luadir/$PACKAGE
  69. # luaexecdir Directory to install Lua modules.
  70. # pkgluaexecdir $luaexecdir/$PACKAGE
  71. #
  72. # These paths a found based on $prefix, $exec_prefix, Lua's package.path,
  73. # and package.cpath. The first path of package.path beginning with $prefix
  74. # is selected as luadir. The first path of package.cpath beginning with
  75. # $exec_prefix is used as luaexecdir. This should work on all reasonable
  76. # Lua installations. If a path cannot be determined, a default path is
  77. # used. Of course, the user can override these later when invoking make.
  78. #
  79. # luadir Default: $prefix/share/lua/$LUA_VERSION
  80. # luaexecdir Default: $exec_prefix/lib/lua/$LUA_VERSION
  81. #
  82. # These directories can be used by Automake as install destinations. The
  83. # variable name minus 'dir' needs to be used as a prefix to the
  84. # appropriate Automake primary, e.g. lua_SCRIPS or luaexec_LIBRARIES.
  85. #
  86. # If an acceptable Lua interpreter is found, then ACTION-IF-FOUND is
  87. # performed, otherwise ACTION-IF-NOT-FOUND is preformed. If ACTION-IF-NOT-
  88. # FOUND is blank, then it will default to printing an error. To prevent
  89. # the default behavior, give ':' as an action.
  90. #
  91. # AX_LUA_HEADERS: Search for Lua headers. Requires that AX_PROG_LUA be
  92. # expanded before this macro. Adds precious variable LUA_INCLUDE, which
  93. # may contain Lua specific include flags, e.g. -I/usr/include/lua5.1. If
  94. # LUA_INCLUDE is blank, then this macro will attempt to find suitable
  95. # flags.
  96. #
  97. # LUA_INCLUDE can be used by Automake to compile Lua modules or
  98. # executables with embedded interpreters. The *_CPPFLAGS variables should
  99. # be used for this purpose, e.g. myprog_CPPFLAGS = $(LUA_INCLUDE).
  100. #
  101. # This macro searches for the header lua.h (and others). The search is
  102. # performed with a combination of CPPFLAGS, CPATH, etc, and LUA_INCLUDE.
  103. # If the search is unsuccessful, then some common directories are tried.
  104. # If the headers are then found, then LUA_INCLUDE is set accordingly.
  105. #
  106. # The paths automatically searched are:
  107. #
  108. # * /usr/include/luaX.Y
  109. # * /usr/include/lua/X.Y
  110. # * /usr/include/luaXY
  111. # * /usr/local/include/luaX.Y
  112. # * /usr/local/include/lua/X.Y
  113. # * /usr/local/include/luaXY
  114. #
  115. # (Where X.Y is the Lua version number, e.g. 5.1.)
  116. #
  117. # The Lua version number found in the headers is always checked to match
  118. # the Lua interpreter's version number. Lua headers with mismatched
  119. # version numbers are not accepted.
  120. #
  121. # If headers are found, then ACTION-IF-FOUND is performed, otherwise
  122. # ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
  123. # it will default to printing an error. To prevent the default behavior,
  124. # set the action to ':'.
  125. #
  126. # AX_LUA_LIBS: Search for Lua libraries. Requires that AX_PROG_LUA be
  127. # expanded before this macro. Adds precious variable LUA_LIB, which may
  128. # contain Lua specific linker flags, e.g. -llua5.1. If LUA_LIB is blank,
  129. # then this macro will attempt to find suitable flags.
  130. #
  131. # LUA_LIB can be used by Automake to link Lua modules or executables with
  132. # embedded interpreters. The *_LIBADD and *_LDADD variables should be used
  133. # for this purpose, e.g. mymod_LIBADD = $(LUA_LIB).
  134. #
  135. # This macro searches for the Lua library. More technically, it searches
  136. # for a library containing the function lua_load. The search is performed
  137. # with a combination of LIBS, LIBRARY_PATH, and LUA_LIB.
  138. #
  139. # If the search determines that some linker flags are missing, then those
  140. # flags will be added to LUA_LIB.
  141. #
  142. # If libraries are found, then ACTION-IF-FOUND is performed, otherwise
  143. # ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
  144. # it will default to printing an error. To prevent the default behavior,
  145. # set the action to ':'.
  146. #
  147. # AX_LUA_READLINE: Search for readline headers and libraries. Requires the
  148. # AX_LIB_READLINE macro, which is provided by ax_lib_readline.m4 from the
  149. # Autoconf Archive.
  150. #
  151. # If a readline compatible library is found, then ACTION-IF-FOUND is
  152. # performed, otherwise ACTION-IF-NOT-FOUND is performed.
  153. #
  154. # LICENSE
  155. #
  156. # Copyright (c) 2013 Tim Perkins <tprk77@gmail.com>
  157. # Copyright (c) 2013 Reuben Thomas <rrt@sc3d.org>
  158. #
  159. # This program is free software: you can redistribute it and/or modify it
  160. # under the terms of the GNU General Public License as published by the
  161. # Free Software Foundation, either version 3 of the License, or (at your
  162. # option) any later version.
  163. #
  164. # This program is distributed in the hope that it will be useful, but
  165. # WITHOUT ANY WARRANTY; without even the implied warranty of
  166. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  167. # Public License for more details.
  168. #
  169. # You should have received a copy of the GNU General Public License along
  170. # with this program. If not, see <http://www.gnu.org/licenses/>.
  171. #
  172. # As a special exception, the respective Autoconf Macro's copyright owner
  173. # gives unlimited permission to copy, distribute and modify the configure
  174. # scripts that are the output of Autoconf when processing the Macro. You
  175. # need not follow the terms of the GNU General Public License when using
  176. # or distributing such scripts, even though portions of the text of the
  177. # Macro appear in them. The GNU General Public License (GPL) does govern
  178. # all other use of the material that constitutes the Autoconf Macro.
  179. #
  180. # This special exception to the GPL applies to versions of the Autoconf
  181. # Macro released by the Autoconf Archive. When you make and distribute a
  182. # modified version of the Autoconf Macro, you may extend this special
  183. # exception to the GPL to apply to your modified version as well.
  184. #serial 20
  185. dnl =========================================================================
  186. dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
  187. dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  188. dnl =========================================================================
  189. AC_DEFUN([AX_PROG_LUA],
  190. [
  191. dnl Make LUA a precious variable.
  192. AC_ARG_VAR([LUA], [The Lua interpreter, e.g. /usr/bin/lua5.1])
  193. dnl Find a Lua interpreter.
  194. m4_define_default([_AX_LUA_INTERPRETER_LIST],
  195. [lua lua5.2 lua5.1 lua50])
  196. m4_if([$1], [],
  197. [ dnl No version check is needed. Find any Lua interpreter.
  198. AS_IF([test "x$LUA" = 'x'],
  199. [AC_PATH_PROGS([LUA], [_AX_LUA_INTERPRETER_LIST], [:])])
  200. ax_display_LUA='lua'
  201. dnl At least check if this is a Lua interpreter.
  202. AC_MSG_CHECKING([if $LUA is a Lua interpreter])
  203. _AX_LUA_CHK_IS_INTRP([$LUA],
  204. [AC_MSG_RESULT([yes])],
  205. [ AC_MSG_RESULT([no])
  206. AC_MSG_ERROR([not a Lua interpreter])
  207. ])
  208. ],
  209. [ dnl A version check is needed.
  210. AS_IF([test "x$LUA" != 'x'],
  211. [ dnl Check if this is a Lua interpreter.
  212. AC_MSG_CHECKING([if $LUA is a Lua interpreter])
  213. _AX_LUA_CHK_IS_INTRP([$LUA],
  214. [AC_MSG_RESULT([yes])],
  215. [ AC_MSG_RESULT([no])
  216. AC_MSG_ERROR([not a Lua interpreter])
  217. ])
  218. dnl Check the version.
  219. m4_if([$2], [],
  220. [_ax_check_text="whether $LUA version >= $1"],
  221. [_ax_check_text="whether $LUA version >= $1, < $2"])
  222. AC_MSG_CHECKING([$_ax_check_text])
  223. _AX_LUA_CHK_VER([$LUA], [$1], [$2],
  224. [AC_MSG_RESULT([yes])],
  225. [ AC_MSG_RESULT([no])
  226. AC_MSG_ERROR([version is out of range for specified LUA])])
  227. ax_display_LUA=$LUA
  228. ],
  229. [ dnl Try each interpreter until we find one that satisfies VERSION.
  230. m4_if([$2], [],
  231. [_ax_check_text="for a Lua interpreter with version >= $1"],
  232. [_ax_check_text="for a Lua interpreter with version >= $1, < $2"])
  233. AC_CACHE_CHECK([$_ax_check_text],
  234. [ax_cv_pathless_LUA],
  235. [ for ax_cv_pathless_LUA in _AX_LUA_INTERPRETER_LIST none; do
  236. test "x$ax_cv_pathless_LUA" = 'xnone' && break
  237. _AX_LUA_CHK_IS_INTRP([$ax_cv_pathless_LUA], [], [continue])
  238. _AX_LUA_CHK_VER([$ax_cv_pathless_LUA], [$1], [$2], [break])
  239. done
  240. ])
  241. dnl Set $LUA to the absolute path of $ax_cv_pathless_LUA.
  242. AS_IF([test "x$ax_cv_pathless_LUA" = 'xnone'],
  243. [LUA=':'],
  244. [AC_PATH_PROG([LUA], [$ax_cv_pathless_LUA])])
  245. ax_display_LUA=$ax_cv_pathless_LUA
  246. ])
  247. ])
  248. AS_IF([test "x$LUA" = 'x:'],
  249. [ dnl Run any user-specified action, or abort.
  250. m4_default([$4], [AC_MSG_ERROR([cannot find suitable Lua interpreter])])
  251. ],
  252. [ dnl Query Lua for its version number.
  253. AC_CACHE_CHECK([for $ax_display_LUA version], [ax_cv_lua_version],
  254. [ ax_cv_lua_version=`$LUA -e "print(_VERSION)" | \
  255. sed "s|^Lua \(.*\)|\1|" | \
  256. grep -o "^@<:@0-9@:>@\+\\.@<:@0-9@:>@\+"`
  257. ])
  258. AS_IF([test "x$ax_cv_lua_version" = 'x'],
  259. [AC_MSG_ERROR([invalid Lua version number])])
  260. AC_SUBST([LUA_VERSION], [$ax_cv_lua_version])
  261. AC_SUBST([LUA_SHORT_VERSION], [`echo "$LUA_VERSION" | sed 's|\.||'`])
  262. dnl The following check is not supported:
  263. dnl At times (like when building shared libraries) you may want to know
  264. dnl which OS platform Lua thinks this is.
  265. AC_CACHE_CHECK([for $ax_display_LUA platform], [ax_cv_lua_platform],
  266. [ax_cv_lua_platform=`$LUA -e "print('unknown')"`])
  267. AC_SUBST([LUA_PLATFORM], [$ax_cv_lua_platform])
  268. dnl Use the values of $prefix and $exec_prefix for the corresponding
  269. dnl values of LUA_PREFIX and LUA_EXEC_PREFIX. These are made distinct
  270. dnl variables so they can be overridden if need be. However, the general
  271. dnl consensus is that you shouldn't need this ability.
  272. AC_SUBST([LUA_PREFIX], ['${prefix}'])
  273. AC_SUBST([LUA_EXEC_PREFIX], ['${exec_prefix}'])
  274. dnl Lua provides no way to query the script directory, and instead
  275. dnl provides LUA_PATH. However, we should be able to make a safe educated
  276. dnl guess. If the built-in search path contains a directory which is
  277. dnl prefixed by $prefix, then we can store scripts there. The first
  278. dnl matching path will be used.
  279. AC_CACHE_CHECK([for $ax_display_LUA script directory],
  280. [ax_cv_lua_luadir],
  281. [ AS_IF([test "x$prefix" = 'xNONE'],
  282. [ax_lua_prefix=$ac_default_prefix],
  283. [ax_lua_prefix=$prefix])
  284. dnl Initialize to the default path.
  285. ax_cv_lua_luadir="$LUA_PREFIX/share/lua/$LUA_VERSION"
  286. dnl Try to find a path with the prefix.
  287. _AX_LUA_FND_PRFX_PTH([$LUA], [$ax_lua_prefix], [package.path])
  288. AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
  289. [ dnl Fix the prefix.
  290. _ax_strip_prefix=`echo "$ax_lua_prefix" | sed 's|.|.|g'`
  291. ax_cv_lua_luadir=`echo "$ax_lua_prefixed_path" | \
  292. sed "s,^$_ax_strip_prefix,$LUA_PREFIX,"`
  293. ])
  294. ])
  295. AC_SUBST([luadir], [$ax_cv_lua_luadir])
  296. AC_SUBST([pkgluadir], [\${luadir}/$PACKAGE])
  297. dnl Lua provides no way to query the module directory, and instead
  298. dnl provides LUA_PATH. However, we should be able to make a safe educated
  299. dnl guess. If the built-in search path contains a directory which is
  300. dnl prefixed by $exec_prefix, then we can store modules there. The first
  301. dnl matching path will be used.
  302. AC_CACHE_CHECK([for $ax_display_LUA module directory],
  303. [ax_cv_lua_luaexecdir],
  304. [ AS_IF([test "x$exec_prefix" = 'xNONE'],
  305. [ax_lua_exec_prefix=$ax_lua_prefix],
  306. [ax_lua_exec_prefix=$exec_prefix])
  307. dnl Initialize to the default path.
  308. ax_cv_lua_luaexecdir="$LUA_EXEC_PREFIX/lib/lua/$LUA_VERSION"
  309. dnl Try to find a path with the prefix.
  310. _AX_LUA_FND_PRFX_PTH([$LUA],
  311. [$ax_lua_exec_prefix], [package.cpathd])
  312. AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
  313. [ dnl Fix the prefix.
  314. _ax_strip_prefix=`echo "$ax_lua_exec_prefix" | sed 's|.|.|g'`
  315. ax_cv_lua_luaexecdir=`echo "$ax_lua_prefixed_path" | \
  316. sed "s,^$_ax_strip_prefix,$LUA_EXEC_PREFIX,"`
  317. ])
  318. ])
  319. AC_SUBST([luaexecdir], [$ax_cv_lua_luaexecdir])
  320. AC_SUBST([pkgluaexecdir], [\${luaexecdir}/$PACKAGE])
  321. dnl Run any user specified action.
  322. $3
  323. ])
  324. ])
  325. dnl AX_WITH_LUA is now the same thing as AX_PROG_LUA.
  326. AC_DEFUN([AX_WITH_LUA],
  327. [
  328. AC_MSG_WARN([[$0 is deprecated, please use AX_PROG_LUA]])
  329. AX_PROG_LUA
  330. ])
  331. dnl =========================================================================
  332. dnl _AX_LUA_CHK_IS_INTRP(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  333. dnl =========================================================================
  334. AC_DEFUN([_AX_LUA_CHK_IS_INTRP],
  335. [
  336. dnl Just print _VERSION because all Lua interpreters have this global.
  337. AS_IF([$1 -e "print('Hello ' .. _VERSION .. '!')" &>/dev/null],
  338. [$2], [$3])
  339. ])
  340. dnl =========================================================================
  341. dnl _AX_LUA_CHK_VER(PROG, MINIMUM-VERSION, [TOO-BIG-VERSION],
  342. dnl [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  343. dnl =========================================================================
  344. AC_DEFUN([_AX_LUA_CHK_VER],
  345. [
  346. _ax_test_ver=`$1 -e "print(_VERSION)" 2>/dev/null | \
  347. sed "s|^Lua \(.*\)|\1|" | grep -o "^@<:@0-9@:>@\+\\.@<:@0-9@:>@\+"`
  348. AS_IF([test "x$_ax_test_ver" = 'x'],
  349. [_ax_test_ver='0'])
  350. AX_COMPARE_VERSION([$_ax_test_ver], [ge], [$2])
  351. m4_if([$3], [], [],
  352. [ AS_IF([$ax_compare_version],
  353. [AX_COMPARE_VERSION([$_ax_test_ver], [lt], [$3])])
  354. ])
  355. AS_IF([$ax_compare_version], [$4], [$5])
  356. ])
  357. dnl =========================================================================
  358. dnl _AX_LUA_FND_PRFX_PTH(PROG, PREFIX, LUA-PATH-VARIABLE)
  359. dnl =========================================================================
  360. AC_DEFUN([_AX_LUA_FND_PRFX_PTH],
  361. [
  362. dnl Invokes the Lua interpreter PROG to print the path variable
  363. dnl LUA-PATH-VARIABLE, usually package.path or package.cpath. Paths are
  364. dnl then matched against PREFIX. The first path to begin with PREFIX is set
  365. dnl to ax_lua_prefixed_path.
  366. ax_lua_prefixed_path=''
  367. _ax_package_paths=`$1 -e 'print($3)' 2>/dev/null | sed 's|;|\n|g'`
  368. dnl Try the paths in order, looking for the prefix.
  369. for _ax_package_path in $_ax_package_paths; do
  370. dnl Copy the path, up to the use of a Lua wildcard.
  371. _ax_path_parts=`echo "$_ax_package_path" | sed 's|/|\n|g'`
  372. _ax_reassembled=''
  373. for _ax_path_part in $_ax_path_parts; do
  374. echo "$_ax_path_part" | grep '\?' >/dev/null && break
  375. _ax_reassembled="$_ax_reassembled/$_ax_path_part"
  376. done
  377. dnl Check the path against the prefix.
  378. _ax_package_path=$_ax_reassembled
  379. if echo "$_ax_package_path" | grep "^$2" >/dev/null; then
  380. dnl Found it.
  381. ax_lua_prefixed_path=$_ax_package_path
  382. break
  383. fi
  384. done
  385. ])
  386. dnl =========================================================================
  387. dnl AX_LUA_HEADERS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  388. dnl =========================================================================
  389. AC_DEFUN([AX_LUA_HEADERS],
  390. [
  391. dnl Check for LUA_VERSION.
  392. AC_MSG_CHECKING([if LUA_VERSION is defined])
  393. AS_IF([test "x$LUA_VERSION" != 'x'],
  394. [AC_MSG_RESULT([yes])],
  395. [ AC_MSG_RESULT([no])
  396. AC_MSG_ERROR([cannot check Lua headers without knowing LUA_VERSION])
  397. ])
  398. dnl Make LUA_INCLUDE a precious variable.
  399. AC_ARG_VAR([LUA_INCLUDE], [The Lua includes, e.g. -I/usr/include/lua5.1])
  400. dnl Some default directories to search.
  401. LUA_SHORT_VERSION=`echo "$LUA_VERSION" | sed 's|\.||'`
  402. m4_define_default([_AX_LUA_INCLUDE_LIST],
  403. [ /usr/include/lua$LUA_VERSION \
  404. /usr/include/lua/$LUA_VERSION \
  405. /usr/include/lua$LUA_SHORT_VERSION \
  406. /usr/local/include/lua$LUA_VERSION \
  407. /usr/local/include/lua/$LUA_VERSION \
  408. /usr/local/include/lua$LUA_SHORT_VERSION \
  409. ])
  410. dnl Try to find the headers.
  411. _ax_lua_saved_cppflags=$CPPFLAGS
  412. CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
  413. AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
  414. CPPFLAGS=$_ax_lua_saved_cppflags
  415. dnl Try some other directories if LUA_INCLUDE was not set.
  416. AS_IF([test "x$LUA_INCLUDE" = 'x' &&
  417. test "x$ac_cv_header_lua_h" != 'xyes'],
  418. [ dnl Try some common include paths.
  419. for _ax_include_path in _AX_LUA_INCLUDE_LIST; do
  420. test ! -d "$_ax_include_path" && continue
  421. AC_MSG_CHECKING([for Lua headers in])
  422. AC_MSG_RESULT([$_ax_include_path])
  423. AS_UNSET([ac_cv_header_lua_h])
  424. AS_UNSET([ac_cv_header_lualib_h])
  425. AS_UNSET([ac_cv_header_lauxlib_h])
  426. AS_UNSET([ac_cv_header_luaconf_h])
  427. _ax_lua_saved_cppflags=$CPPFLAGS
  428. CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
  429. AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
  430. CPPFLAGS=$_ax_lua_saved_cppflags
  431. AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
  432. [ LUA_INCLUDE="-I$_ax_include_path"
  433. break
  434. ])
  435. done
  436. ])
  437. AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
  438. [ dnl Make a program to print LUA_VERSION defined in the header.
  439. dnl TODO This probably shouldn't be a runtime test.
  440. AC_CACHE_CHECK([for Lua header version],
  441. [ax_cv_lua_header_version],
  442. [ _ax_lua_saved_cppflags=$CPPFLAGS
  443. CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
  444. AC_RUN_IFELSE(
  445. [ AC_LANG_SOURCE([[
  446. #include <lua.h>
  447. #include <stdlib.h>
  448. #include <stdio.h>
  449. int main(int argc, char ** argv)
  450. {
  451. if(argc > 1) printf("%s", LUA_VERSION);
  452. exit(EXIT_SUCCESS);
  453. }
  454. ]])
  455. ],
  456. [ ax_cv_lua_header_version=`./conftest$EXEEXT p | \
  457. sed "s|^Lua \(.*\)|\1|" | \
  458. grep -o "^@<:@0-9@:>@\+\\.@<:@0-9@:>@\+"`
  459. ],
  460. [ax_cv_lua_header_version='unknown'],
  461. [ax_cv_lua_header_version=$LUA_VERSION])
  462. CPPFLAGS=$_ax_lua_saved_cppflags
  463. ])
  464. dnl Compare this to the previously found LUA_VERSION.
  465. AC_MSG_CHECKING([if Lua header version matches $LUA_VERSION])
  466. AS_IF([test "x$ax_cv_lua_header_version" = "x$LUA_VERSION"],
  467. [ AC_MSG_RESULT([yes])
  468. ax_header_version_match='yes'
  469. ],
  470. [ AC_MSG_RESULT([no])
  471. ax_header_version_match='no'
  472. ])
  473. ])
  474. dnl Was LUA_INCLUDE specified?
  475. AS_IF([test "x$ax_header_version_match" != 'xyes' &&
  476. test "x$LUA_INCLUDE" != 'x'],
  477. [AC_MSG_ERROR([cannot find headers for specified LUA_INCLUDE])])
  478. dnl Test the final result and run user code.
  479. AS_IF([test "x$ax_header_version_match" = 'xyes'], [$1],
  480. [m4_default([$2], [AC_MSG_ERROR([cannot find Lua includes])])])
  481. ])
  482. dnl AX_LUA_HEADERS_VERSION no longer exists, use AX_LUA_HEADERS.
  483. AC_DEFUN([AX_LUA_HEADERS_VERSION],
  484. [
  485. AC_MSG_WARN([[$0 is deprecated, please use AX_LUA_HEADERS]])
  486. ])
  487. dnl =========================================================================
  488. dnl AX_LUA_LIBS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  489. dnl =========================================================================
  490. AC_DEFUN([AX_LUA_LIBS],
  491. [
  492. dnl TODO Should this macro also check various -L flags?
  493. dnl Check for LUA_VERSION.
  494. AC_MSG_CHECKING([if LUA_VERSION is defined])
  495. AS_IF([test "x$LUA_VERSION" != 'x'],
  496. [AC_MSG_RESULT([yes])],
  497. [ AC_MSG_RESULT([no])
  498. AC_MSG_ERROR([cannot check Lua libs without knowing LUA_VERSION])
  499. ])
  500. dnl Make LUA_LIB a precious variable.
  501. AC_ARG_VAR([LUA_LIB], [The Lua library, e.g. -llua5.1])
  502. AS_IF([test "x$LUA_LIB" != 'x'],
  503. [ dnl Check that LUA_LIBS works.
  504. _ax_lua_saved_libs=$LIBS
  505. LIBS="$LIBS $LUA_LIB"
  506. AC_SEARCH_LIBS([lua_load], [],
  507. [_ax_found_lua_libs='yes'],
  508. [_ax_found_lua_libs='no'])
  509. LIBS=$_ax_lua_saved_libs
  510. dnl Check the result.
  511. AS_IF([test "x$_ax_found_lua_libs" != 'xyes'],
  512. [AC_MSG_ERROR([cannot find libs for specified LUA_LIB])])
  513. ],
  514. [ dnl First search for extra libs.
  515. _ax_lua_extra_libs=''
  516. _ax_lua_saved_libs=$LIBS
  517. LIBS="$LIBS $LUA_LIB"
  518. AC_SEARCH_LIBS([exp], [m])
  519. AC_SEARCH_LIBS([dlopen], [dl])
  520. LIBS=$_ax_lua_saved_libs
  521. AS_IF([test "x$ac_cv_search_exp" != 'xno' &&
  522. test "x$ac_cv_search_exp" != 'xnone required'],
  523. [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_exp"])
  524. AS_IF([test "x$ac_cv_search_dlopen" != 'xno' &&
  525. test "x$ac_cv_search_dlopen" != 'xnone required'],
  526. [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_dlopen"])
  527. dnl Try to find the Lua libs.
  528. _ax_lua_saved_libs=$LIBS
  529. LIBS="$LIBS $LUA_LIB"
  530. AC_SEARCH_LIBS([lua_load], [lua$LUA_VERSION lua$LUA_SHORT_VERSION lua],
  531. [_ax_found_lua_libs='yes'],
  532. [_ax_found_lua_libs='no'],
  533. [$_ax_lua_extra_libs])
  534. LIBS=$_ax_lua_saved_libs
  535. AS_IF([test "x$ac_cv_search_lua_load" != 'xno' &&
  536. test "x$ac_cv_search_lua_load" != 'xnone required'],
  537. [LUA_LIB="$ac_cv_search_lua_load $_ax_lua_extra_libs"])
  538. ])
  539. dnl Test the result and run user code.
  540. AS_IF([test "x$_ax_found_lua_libs" = 'xyes'], [$1],
  541. [m4_default([$2], [AC_MSG_ERROR([cannot find Lua libs])])])
  542. ])
  543. dnl =========================================================================
  544. dnl AX_LUA_READLINE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  545. dnl =========================================================================
  546. AC_DEFUN([AX_LUA_READLINE],
  547. [
  548. AX_LIB_READLINE
  549. AS_IF([test "x$ac_cv_header_readline_readline_h" != 'x' &&
  550. test "x$ac_cv_header_readline_history_h" != 'x'],
  551. [ LUA_LIBS_CFLAGS="-DLUA_USE_READLINE $LUA_LIBS_CFLAGS"
  552. $1
  553. ],
  554. [$2])
  555. ])