ax_lua.m4 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. # ===========================================================================
  2. # https://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,
  22. # 5.2, and 5.3 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. # The Lua version number, LUA_VERSION, is found from the interpreter, and
  59. # substituted. LUA_PLATFORM is also found, but not currently supported (no
  60. # standard representation).
  61. #
  62. # Finally, the macro finds four paths:
  63. #
  64. # luadir Directory to install Lua scripts.
  65. # pkgluadir $luadir/$PACKAGE
  66. # luaexecdir Directory to install Lua modules.
  67. # pkgluaexecdir $luaexecdir/$PACKAGE
  68. #
  69. # These paths are found based on $prefix, $exec_prefix, Lua's
  70. # package.path, and package.cpath. The first path of package.path
  71. # beginning with $prefix is selected as luadir. The first path of
  72. # package.cpath beginning with $exec_prefix is used as luaexecdir. This
  73. # should work on all reasonable Lua installations. If a path cannot be
  74. # determined, a default path is used. Of course, the user can override
  75. # these later when invoking make.
  76. #
  77. # luadir Default: $prefix/share/lua/$LUA_VERSION
  78. # luaexecdir Default: $exec_prefix/lib/lua/$LUA_VERSION
  79. #
  80. # These directories can be used by Automake as install destinations. The
  81. # variable name minus 'dir' needs to be used as a prefix to the
  82. # appropriate Automake primary, e.g. lua_SCRIPS or luaexec_LIBRARIES.
  83. #
  84. # If an acceptable Lua interpreter is found, then ACTION-IF-FOUND is
  85. # performed, otherwise ACTION-IF-NOT-FOUND is preformed. If ACTION-IF-NOT-
  86. # FOUND is blank, then it will default to printing an error. To prevent
  87. # the default behavior, give ':' as an action.
  88. #
  89. # AX_LUA_HEADERS: Search for Lua headers. Requires that AX_PROG_LUA be
  90. # expanded before this macro. Adds precious variable LUA_INCLUDE, which
  91. # may contain Lua specific include flags, e.g. -I/usr/include/lua5.1. If
  92. # LUA_INCLUDE is blank, then this macro will attempt to find suitable
  93. # flags.
  94. #
  95. # LUA_INCLUDE can be used by Automake to compile Lua modules or
  96. # executables with embedded interpreters. The *_CPPFLAGS variables should
  97. # be used for this purpose, e.g. myprog_CPPFLAGS = $(LUA_INCLUDE).
  98. #
  99. # This macro searches for the header lua.h (and others). The search is
  100. # performed with a combination of CPPFLAGS, CPATH, etc, and LUA_INCLUDE.
  101. # If the search is unsuccessful, then some common directories are tried.
  102. # If the headers are then found, then LUA_INCLUDE is set accordingly.
  103. #
  104. # The paths automatically searched are:
  105. #
  106. # * /usr/include/luaX.Y
  107. # * /usr/include/lua/X.Y
  108. # * /usr/include/luaXY
  109. # * /usr/local/include/luaX.Y
  110. # * /usr/local/include/lua-X.Y
  111. # * /usr/local/include/lua/X.Y
  112. # * /usr/local/include/luaXY
  113. #
  114. # (Where X.Y is the Lua version number, e.g. 5.1.)
  115. #
  116. # The Lua version number found in the headers is always checked to match
  117. # the Lua interpreter's version number. Lua headers with mismatched
  118. # version numbers are not accepted.
  119. #
  120. # If headers are found, then ACTION-IF-FOUND is performed, otherwise
  121. # ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
  122. # it will default to printing an error. To prevent the default behavior,
  123. # set the action to ':'.
  124. #
  125. # AX_LUA_LIBS: Search for Lua libraries. Requires that AX_PROG_LUA be
  126. # expanded before this macro. Adds precious variable LUA_LIB, which may
  127. # contain Lua specific linker flags, e.g. -llua5.1. If LUA_LIB is blank,
  128. # then this macro will attempt to find suitable flags.
  129. #
  130. # LUA_LIB can be used by Automake to link Lua modules or executables with
  131. # embedded interpreters. The *_LIBADD and *_LDADD variables should be used
  132. # for this purpose, e.g. mymod_LIBADD = $(LUA_LIB).
  133. #
  134. # This macro searches for the Lua library. More technically, it searches
  135. # for a library containing the function lua_load. The search is performed
  136. # with a combination of LIBS, LIBRARY_PATH, and LUA_LIB.
  137. #
  138. # If the search determines that some linker flags are missing, then those
  139. # flags will be added to LUA_LIB.
  140. #
  141. # If libraries are found, then ACTION-IF-FOUND is performed, otherwise
  142. # ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
  143. # it will default to printing an error. To prevent the default behavior,
  144. # set the action to ':'.
  145. #
  146. # AX_LUA_READLINE: Search for readline headers and libraries. Requires the
  147. # AX_LIB_READLINE macro, which is provided by ax_lib_readline.m4 from the
  148. # Autoconf Archive.
  149. #
  150. # If a readline compatible library is found, then ACTION-IF-FOUND is
  151. # performed, otherwise ACTION-IF-NOT-FOUND is performed.
  152. #
  153. # LICENSE
  154. #
  155. # Copyright (c) 2015 Reuben Thomas <rrt@sc3d.org>
  156. # Copyright (c) 2014 Tim Perkins <tprk77@gmail.com>
  157. #
  158. # This program is free software: you can redistribute it and/or modify it
  159. # under the terms of the GNU General Public License as published by the
  160. # Free Software Foundation, either version 3 of the License, or (at your
  161. # option) any later version.
  162. #
  163. # This program is distributed in the hope that it will be useful, but
  164. # WITHOUT ANY WARRANTY; without even the implied warranty of
  165. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  166. # Public License for more details.
  167. #
  168. # You should have received a copy of the GNU General Public License along
  169. # with this program. If not, see <https://www.gnu.org/licenses/>.
  170. #
  171. # As a special exception, the respective Autoconf Macro's copyright owner
  172. # gives unlimited permission to copy, distribute and modify the configure
  173. # scripts that are the output of Autoconf when processing the Macro. You
  174. # need not follow the terms of the GNU General Public License when using
  175. # or distributing such scripts, even though portions of the text of the
  176. # Macro appear in them. The GNU General Public License (GPL) does govern
  177. # all other use of the material that constitutes the Autoconf Macro.
  178. #
  179. # This special exception to the GPL applies to versions of the Autoconf
  180. # Macro released by the Autoconf Archive. When you make and distribute a
  181. # modified version of the Autoconf Macro, you may extend this special
  182. # exception to the GPL to apply to your modified version as well.
  183. #serial 40
  184. dnl =========================================================================
  185. dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
  186. dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  187. dnl =========================================================================
  188. AC_DEFUN([AX_PROG_LUA],
  189. [
  190. dnl Check for required tools.
  191. AC_REQUIRE([AC_PROG_GREP])
  192. AC_REQUIRE([AC_PROG_SED])
  193. dnl Make LUA a precious variable.
  194. AC_ARG_VAR([LUA], [The Lua interpreter, e.g. /usr/bin/lua5.1])
  195. dnl Find a Lua interpreter.
  196. m4_define_default([_AX_LUA_INTERPRETER_LIST],
  197. [lua lua5.3 lua53 lua5.2 lua52 lua5.1 lua51 lua50])
  198. m4_if([$1], [],
  199. [ dnl No version check is needed. Find any Lua interpreter.
  200. AS_IF([test "x$LUA" = 'x'],
  201. [AC_PATH_PROGS([LUA], [_AX_LUA_INTERPRETER_LIST], [:])])
  202. ax_display_LUA='lua'
  203. AS_IF([test "x$LUA" != 'x:'],
  204. [ dnl At least check if this is a Lua interpreter.
  205. AC_MSG_CHECKING([if $LUA is a Lua interpreter])
  206. _AX_LUA_CHK_IS_INTRP([$LUA],
  207. [AC_MSG_RESULT([yes])],
  208. [ AC_MSG_RESULT([no])
  209. AC_MSG_ERROR([not a Lua interpreter])
  210. ])
  211. ])
  212. ],
  213. [ dnl A version check is needed.
  214. AS_IF([test "x$LUA" != 'x'],
  215. [ dnl Check if this is a Lua interpreter.
  216. AC_MSG_CHECKING([if $LUA is a Lua interpreter])
  217. _AX_LUA_CHK_IS_INTRP([$LUA],
  218. [AC_MSG_RESULT([yes])],
  219. [ AC_MSG_RESULT([no])
  220. AC_MSG_ERROR([not a Lua interpreter])
  221. ])
  222. dnl Check the version.
  223. m4_if([$2], [],
  224. [_ax_check_text="whether $LUA version >= $1"],
  225. [_ax_check_text="whether $LUA version >= $1, < $2"])
  226. AC_MSG_CHECKING([$_ax_check_text])
  227. _AX_LUA_CHK_VER([$LUA], [$1], [$2],
  228. [AC_MSG_RESULT([yes])],
  229. [ AC_MSG_RESULT([no])
  230. AC_MSG_ERROR([version is out of range for specified LUA])])
  231. ax_display_LUA=$LUA
  232. ],
  233. [ dnl Try each interpreter until we find one that satisfies VERSION.
  234. m4_if([$2], [],
  235. [_ax_check_text="for a Lua interpreter with version >= $1"],
  236. [_ax_check_text="for a Lua interpreter with version >= $1, < $2"])
  237. AC_CACHE_CHECK([$_ax_check_text],
  238. [ax_cv_pathless_LUA],
  239. [ for ax_cv_pathless_LUA in _AX_LUA_INTERPRETER_LIST none; do
  240. test "x$ax_cv_pathless_LUA" = 'xnone' && break
  241. _AX_LUA_CHK_IS_INTRP([$ax_cv_pathless_LUA], [], [continue])
  242. _AX_LUA_CHK_VER([$ax_cv_pathless_LUA], [$1], [$2], [break])
  243. done
  244. ])
  245. dnl Set $LUA to the absolute path of $ax_cv_pathless_LUA.
  246. AS_IF([test "x$ax_cv_pathless_LUA" = 'xnone'],
  247. [LUA=':'],
  248. [AC_PATH_PROG([LUA], [$ax_cv_pathless_LUA])])
  249. ax_display_LUA=$ax_cv_pathless_LUA
  250. ])
  251. ])
  252. AS_IF([test "x$LUA" = 'x:'],
  253. [ dnl Run any user-specified action, or abort.
  254. m4_default([$4], [AC_MSG_ERROR([cannot find suitable Lua interpreter])])
  255. ],
  256. [ dnl Query Lua for its version number.
  257. AC_CACHE_CHECK([for $ax_display_LUA version],
  258. [ax_cv_lua_version],
  259. [ dnl Get the interpreter version in X.Y format. This should work for
  260. dnl interpreters version 5.0 and beyond.
  261. ax_cv_lua_version=[`$LUA -e '
  262. -- return a version number in X.Y format
  263. local _, _, ver = string.find(_VERSION, "^Lua (%d+%.%d+)")
  264. print(ver)'`]
  265. ])
  266. AS_IF([test "x$ax_cv_lua_version" = 'x'],
  267. [AC_MSG_ERROR([invalid Lua version number])])
  268. AC_SUBST([LUA_VERSION], [$ax_cv_lua_version])
  269. AC_SUBST([LUA_SHORT_VERSION], [`echo "$LUA_VERSION" | $SED 's|\.||'`])
  270. dnl The following check is not supported:
  271. dnl At times (like when building shared libraries) you may want to know
  272. dnl which OS platform Lua thinks this is.
  273. AC_CACHE_CHECK([for $ax_display_LUA platform],
  274. [ax_cv_lua_platform],
  275. [ax_cv_lua_platform=[`$LUA -e 'print("unknown")'`]])
  276. AC_SUBST([LUA_PLATFORM], [$ax_cv_lua_platform])
  277. dnl Use the values of $prefix and $exec_prefix for the corresponding
  278. dnl values of LUA_PREFIX and LUA_EXEC_PREFIX. These are made distinct
  279. dnl variables so they can be overridden if need be. However, the general
  280. dnl consensus is that you shouldn't need this ability.
  281. AC_SUBST([LUA_PREFIX], ['${prefix}'])
  282. AC_SUBST([LUA_EXEC_PREFIX], ['${exec_prefix}'])
  283. dnl Lua provides no way to query the script directory, and instead
  284. dnl provides LUA_PATH. However, we should be able to make a safe educated
  285. dnl guess. If the built-in search path contains a directory which is
  286. dnl prefixed by $prefix, then we can store scripts there. The first
  287. dnl matching path will be used.
  288. AC_CACHE_CHECK([for $ax_display_LUA script directory],
  289. [ax_cv_lua_luadir],
  290. [ AS_IF([test "x$prefix" = 'xNONE'],
  291. [ax_lua_prefix=$ac_default_prefix],
  292. [ax_lua_prefix=$prefix])
  293. dnl Initialize to the default path.
  294. ax_cv_lua_luadir="$LUA_PREFIX/share/lua/$LUA_VERSION"
  295. dnl Try to find a path with the prefix.
  296. _AX_LUA_FND_PRFX_PTH([$LUA], [$ax_lua_prefix], [script])
  297. AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
  298. [ dnl Fix the prefix.
  299. _ax_strip_prefix=`echo "$ax_lua_prefix" | $SED 's|.|.|g'`
  300. ax_cv_lua_luadir=`echo "$ax_lua_prefixed_path" | \
  301. $SED "s|^$_ax_strip_prefix|$LUA_PREFIX|"`
  302. ])
  303. ])
  304. AC_SUBST([luadir], [$ax_cv_lua_luadir])
  305. AC_SUBST([pkgluadir], [\${luadir}/$PACKAGE])
  306. dnl Lua provides no way to query the module directory, and instead
  307. dnl provides LUA_PATH. However, we should be able to make a safe educated
  308. dnl guess. If the built-in search path contains a directory which is
  309. dnl prefixed by $exec_prefix, then we can store modules there. The first
  310. dnl matching path will be used.
  311. AC_CACHE_CHECK([for $ax_display_LUA module directory],
  312. [ax_cv_lua_luaexecdir],
  313. [ AS_IF([test "x$exec_prefix" = 'xNONE'],
  314. [ax_lua_exec_prefix=$ax_lua_prefix],
  315. [ax_lua_exec_prefix=$exec_prefix])
  316. dnl Initialize to the default path.
  317. ax_cv_lua_luaexecdir="$LUA_EXEC_PREFIX/lib/lua/$LUA_VERSION"
  318. dnl Try to find a path with the prefix.
  319. _AX_LUA_FND_PRFX_PTH([$LUA],
  320. [$ax_lua_exec_prefix], [module])
  321. AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
  322. [ dnl Fix the prefix.
  323. _ax_strip_prefix=`echo "$ax_lua_exec_prefix" | $SED 's|.|.|g'`
  324. ax_cv_lua_luaexecdir=`echo "$ax_lua_prefixed_path" | \
  325. $SED "s|^$_ax_strip_prefix|$LUA_EXEC_PREFIX|"`
  326. ])
  327. ])
  328. AC_SUBST([luaexecdir], [$ax_cv_lua_luaexecdir])
  329. AC_SUBST([pkgluaexecdir], [\${luaexecdir}/$PACKAGE])
  330. dnl Run any user specified action.
  331. $3
  332. ])
  333. ])
  334. dnl AX_WITH_LUA is now the same thing as AX_PROG_LUA.
  335. AC_DEFUN([AX_WITH_LUA],
  336. [
  337. AC_MSG_WARN([[$0 is deprecated, please use AX_PROG_LUA instead]])
  338. AX_PROG_LUA
  339. ])
  340. dnl =========================================================================
  341. dnl _AX_LUA_CHK_IS_INTRP(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  342. dnl =========================================================================
  343. AC_DEFUN([_AX_LUA_CHK_IS_INTRP],
  344. [
  345. dnl A minimal Lua factorial to prove this is an interpreter. This should work
  346. dnl for Lua interpreters version 5.0 and beyond.
  347. _ax_lua_factorial=[`$1 2>/dev/null -e '
  348. -- a simple factorial
  349. function fact (n)
  350. if n == 0 then
  351. return 1
  352. else
  353. return n * fact(n-1)
  354. end
  355. end
  356. print("fact(5) is " .. fact(5))'`]
  357. AS_IF([test "$_ax_lua_factorial" = 'fact(5) is 120'],
  358. [$2], [$3])
  359. ])
  360. dnl =========================================================================
  361. dnl _AX_LUA_CHK_VER(PROG, MINIMUM-VERSION, [TOO-BIG-VERSION],
  362. dnl [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  363. dnl =========================================================================
  364. AC_DEFUN([_AX_LUA_CHK_VER],
  365. [
  366. dnl Check that the Lua version is within the bounds. Only the major and minor
  367. dnl version numbers are considered. This should work for Lua interpreters
  368. dnl version 5.0 and beyond.
  369. _ax_lua_good_version=[`$1 -e '
  370. -- a script to compare versions
  371. function verstr2num(verstr)
  372. local _, _, majorver, minorver = string.find(verstr, "^(%d+)%.(%d+)")
  373. if majorver and minorver then
  374. return tonumber(majorver) * 100 + tonumber(minorver)
  375. end
  376. end
  377. local minver = verstr2num("$2")
  378. local _, _, trimver = string.find(_VERSION, "^Lua (.*)")
  379. local ver = verstr2num(trimver)
  380. local maxver = verstr2num("$3") or 1e9
  381. if minver <= ver and ver < maxver then
  382. print("yes")
  383. else
  384. print("no")
  385. end'`]
  386. AS_IF([test "x$_ax_lua_good_version" = "xyes"],
  387. [$4], [$5])
  388. ])
  389. dnl =========================================================================
  390. dnl _AX_LUA_FND_PRFX_PTH(PROG, PREFIX, SCRIPT-OR-MODULE-DIR)
  391. dnl =========================================================================
  392. AC_DEFUN([_AX_LUA_FND_PRFX_PTH],
  393. [
  394. dnl Get the script or module directory by querying the Lua interpreter,
  395. dnl filtering on the given prefix, and selecting the shallowest path. If no
  396. dnl path is found matching the prefix, the result will be an empty string.
  397. dnl The third argument determines the type of search, it can be 'script' or
  398. dnl 'module'. Supplying 'script' will perform the search with package.path
  399. dnl and LUA_PATH, and supplying 'module' will search with package.cpath and
  400. dnl LUA_CPATH. This is done for compatibility with Lua 5.0.
  401. ax_lua_prefixed_path=[`$1 -e '
  402. -- get the path based on search type
  403. local searchtype = "$3"
  404. local paths = ""
  405. if searchtype == "script" then
  406. paths = (package and package.path) or LUA_PATH
  407. elseif searchtype == "module" then
  408. paths = (package and package.cpath) or LUA_CPATH
  409. end
  410. -- search for the prefix
  411. local prefix = "'$2'"
  412. local minpath = ""
  413. local mindepth = 1e9
  414. string.gsub(paths, "(@<:@^;@:>@+)",
  415. function (path)
  416. path = string.gsub(path, "%?.*$", "")
  417. path = string.gsub(path, "/@<:@^/@:>@*$", "")
  418. if string.find(path, prefix) then
  419. local depth = string.len(string.gsub(path, "@<:@^/@:>@", ""))
  420. if depth < mindepth then
  421. minpath = path
  422. mindepth = depth
  423. end
  424. end
  425. end)
  426. print(minpath)'`]
  427. ])
  428. dnl =========================================================================
  429. dnl AX_LUA_HEADERS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  430. dnl =========================================================================
  431. AC_DEFUN([AX_LUA_HEADERS],
  432. [
  433. dnl Check for LUA_VERSION.
  434. AC_MSG_CHECKING([if LUA_VERSION is defined])
  435. AS_IF([test "x$LUA_VERSION" != 'x'],
  436. [AC_MSG_RESULT([yes])],
  437. [ AC_MSG_RESULT([no])
  438. AC_MSG_ERROR([cannot check Lua headers without knowing LUA_VERSION])
  439. ])
  440. dnl Make LUA_INCLUDE a precious variable.
  441. AC_ARG_VAR([LUA_INCLUDE], [The Lua includes, e.g. -I/usr/include/lua5.1])
  442. dnl Some default directories to search.
  443. LUA_SHORT_VERSION=`echo "$LUA_VERSION" | $SED 's|\.||'`
  444. m4_define_default([_AX_LUA_INCLUDE_LIST],
  445. [ /usr/include/lua$LUA_VERSION \
  446. /usr/include/lua-$LUA_VERSION \
  447. /usr/include/lua/$LUA_VERSION \
  448. /usr/include/lua$LUA_SHORT_VERSION \
  449. /usr/local/include/lua$LUA_VERSION \
  450. /usr/local/include/lua-$LUA_VERSION \
  451. /usr/local/include/lua/$LUA_VERSION \
  452. /usr/local/include/lua$LUA_SHORT_VERSION \
  453. ])
  454. dnl Try to find the headers.
  455. _ax_lua_saved_cppflags=$CPPFLAGS
  456. CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
  457. AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
  458. CPPFLAGS=$_ax_lua_saved_cppflags
  459. dnl Try some other directories if LUA_INCLUDE was not set.
  460. AS_IF([test "x$LUA_INCLUDE" = 'x' &&
  461. test "x$ac_cv_header_lua_h" != 'xyes'],
  462. [ dnl Try some common include paths.
  463. for _ax_include_path in _AX_LUA_INCLUDE_LIST; do
  464. test ! -d "$_ax_include_path" && continue
  465. AC_MSG_CHECKING([for Lua headers in])
  466. AC_MSG_RESULT([$_ax_include_path])
  467. AS_UNSET([ac_cv_header_lua_h])
  468. AS_UNSET([ac_cv_header_lualib_h])
  469. AS_UNSET([ac_cv_header_lauxlib_h])
  470. AS_UNSET([ac_cv_header_luaconf_h])
  471. _ax_lua_saved_cppflags=$CPPFLAGS
  472. CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
  473. AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
  474. CPPFLAGS=$_ax_lua_saved_cppflags
  475. AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
  476. [ LUA_INCLUDE="-I$_ax_include_path"
  477. break
  478. ])
  479. done
  480. ])
  481. AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
  482. [ dnl Make a program to print LUA_VERSION defined in the header.
  483. dnl TODO It would be really nice if we could do this without compiling a
  484. dnl program, then it would work when cross compiling. But I'm not sure how
  485. dnl to do this reliably. For now, assume versions match when cross compiling.
  486. AS_IF([test "x$cross_compiling" != 'xyes'],
  487. [ AC_CACHE_CHECK([for Lua header version],
  488. [ax_cv_lua_header_version],
  489. [ _ax_lua_saved_cppflags=$CPPFLAGS
  490. CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
  491. AC_RUN_IFELSE(
  492. [ AC_LANG_SOURCE([[
  493. #include <lua.h>
  494. #include <stdlib.h>
  495. #include <stdio.h>
  496. int main(int argc, char ** argv)
  497. {
  498. if(argc > 1) printf("%s", LUA_VERSION);
  499. exit(EXIT_SUCCESS);
  500. }
  501. ]])
  502. ],
  503. [ ax_cv_lua_header_version=`./conftest$EXEEXT p | \
  504. $SED -n "s|^Lua \(@<:@0-9@:>@\{1,\}\.@<:@0-9@:>@\{1,\}\).\{0,\}|\1|p"`
  505. ],
  506. [ax_cv_lua_header_version='unknown'])
  507. CPPFLAGS=$_ax_lua_saved_cppflags
  508. ])
  509. dnl Compare this to the previously found LUA_VERSION.
  510. AC_MSG_CHECKING([if Lua header version matches $LUA_VERSION])
  511. AS_IF([test "x$ax_cv_lua_header_version" = "x$LUA_VERSION"],
  512. [ AC_MSG_RESULT([yes])
  513. ax_header_version_match='yes'
  514. ],
  515. [ AC_MSG_RESULT([no])
  516. ax_header_version_match='no'
  517. ])
  518. ],
  519. [ AC_MSG_WARN([cross compiling so assuming header version number matches])
  520. ax_header_version_match='yes'
  521. ])
  522. ])
  523. dnl Was LUA_INCLUDE specified?
  524. AS_IF([test "x$ax_header_version_match" != 'xyes' &&
  525. test "x$LUA_INCLUDE" != 'x'],
  526. [AC_MSG_ERROR([cannot find headers for specified LUA_INCLUDE])])
  527. dnl Test the final result and run user code.
  528. AS_IF([test "x$ax_header_version_match" = 'xyes'], [$1],
  529. [m4_default([$2], [AC_MSG_ERROR([cannot find Lua includes])])])
  530. ])
  531. dnl AX_LUA_HEADERS_VERSION no longer exists, use AX_LUA_HEADERS.
  532. AC_DEFUN([AX_LUA_HEADERS_VERSION],
  533. [
  534. AC_MSG_WARN([[$0 is deprecated, please use AX_LUA_HEADERS instead]])
  535. ])
  536. dnl =========================================================================
  537. dnl AX_LUA_LIBS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  538. dnl =========================================================================
  539. AC_DEFUN([AX_LUA_LIBS],
  540. [
  541. dnl TODO Should this macro also check various -L flags?
  542. dnl Check for LUA_VERSION.
  543. AC_MSG_CHECKING([if LUA_VERSION is defined])
  544. AS_IF([test "x$LUA_VERSION" != 'x'],
  545. [AC_MSG_RESULT([yes])],
  546. [ AC_MSG_RESULT([no])
  547. AC_MSG_ERROR([cannot check Lua libs without knowing LUA_VERSION])
  548. ])
  549. dnl Make LUA_LIB a precious variable.
  550. AC_ARG_VAR([LUA_LIB], [The Lua library, e.g. -llua5.1])
  551. AS_IF([test "x$LUA_LIB" != 'x'],
  552. [ dnl Check that LUA_LIBS works.
  553. _ax_lua_saved_libs=$LIBS
  554. LIBS="$LIBS $LUA_LIB"
  555. AC_SEARCH_LIBS([lua_load], [],
  556. [_ax_found_lua_libs='yes'],
  557. [_ax_found_lua_libs='no'])
  558. LIBS=$_ax_lua_saved_libs
  559. dnl Check the result.
  560. AS_IF([test "x$_ax_found_lua_libs" != 'xyes'],
  561. [AC_MSG_ERROR([cannot find libs for specified LUA_LIB])])
  562. ],
  563. [ dnl First search for extra libs.
  564. _ax_lua_extra_libs=''
  565. _ax_lua_saved_libs=$LIBS
  566. LIBS="$LIBS $LUA_LIB"
  567. AC_SEARCH_LIBS([exp], [m])
  568. AC_SEARCH_LIBS([dlopen], [dl])
  569. LIBS=$_ax_lua_saved_libs
  570. AS_IF([test "x$ac_cv_search_exp" != 'xno' &&
  571. test "x$ac_cv_search_exp" != 'xnone required'],
  572. [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_exp"])
  573. AS_IF([test "x$ac_cv_search_dlopen" != 'xno' &&
  574. test "x$ac_cv_search_dlopen" != 'xnone required'],
  575. [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_dlopen"])
  576. dnl Try to find the Lua libs.
  577. _ax_lua_saved_libs=$LIBS
  578. LIBS="$LIBS $LUA_LIB"
  579. AC_SEARCH_LIBS([lua_load],
  580. [ lua$LUA_VERSION \
  581. lua$LUA_SHORT_VERSION \
  582. lua-$LUA_VERSION \
  583. lua-$LUA_SHORT_VERSION \
  584. lua \
  585. ],
  586. [_ax_found_lua_libs='yes'],
  587. [_ax_found_lua_libs='no'],
  588. [$_ax_lua_extra_libs])
  589. LIBS=$_ax_lua_saved_libs
  590. AS_IF([test "x$ac_cv_search_lua_load" != 'xno' &&
  591. test "x$ac_cv_search_lua_load" != 'xnone required'],
  592. [LUA_LIB="$ac_cv_search_lua_load $_ax_lua_extra_libs"])
  593. ])
  594. dnl Test the result and run user code.
  595. AS_IF([test "x$_ax_found_lua_libs" = 'xyes'], [$1],
  596. [m4_default([$2], [AC_MSG_ERROR([cannot find Lua libs])])])
  597. ])
  598. dnl =========================================================================
  599. dnl AX_LUA_READLINE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  600. dnl =========================================================================
  601. AC_DEFUN([AX_LUA_READLINE],
  602. [
  603. AX_LIB_READLINE
  604. AS_IF([test "x$ac_cv_header_readline_readline_h" != 'x' &&
  605. test "x$ac_cv_header_readline_history_h" != 'x'],
  606. [ LUA_LIBS_CFLAGS="-DLUA_USE_READLINE $LUA_LIBS_CFLAGS"
  607. $1
  608. ],
  609. [$2])
  610. ])