wesnoth/scons/lua.py

43 lines
1.5 KiB
Python
Raw Normal View History

2009-03-23 01:26:52 +00:00
# vi: syntax=python:et:ts=4
from pkgconfig import run_pkg_config
from config_check_utils import find_include
from os.path import join
2009-03-23 01:26:52 +00:00
def CheckLua(context, require_version):
env = context.env
backup = env.Clone().Dictionary()
2009-03-23 01:26:52 +00:00
2009-03-24 14:05:11 +00:00
context.Message("Checking for Lua development files version " + require_version + "... ")
2009-03-23 01:26:52 +00:00
version = ".".join(require_version.split(".")[0:2])
if env.get("luadir"):
env.Append(LIBPATH = ["$luadir"], CPPPATH = ["$luadir/include"], LIBS = "lua" + version)
found = True
else:
found = run_pkg_config(context, "lua >= " + require_version) or run_pkg_config(context, "lua" + version + " >= " + require_version) or run_pkg_config(context, "lua-" + version + " >= " + require_version)
if not found:
try:
prefix, include = find_include([env["prefix"]], "lualib.h", "", not env["host"])[0]
found = True
context.Log("Found Lua header " + include + ".\n")
env.Append(LIBPATH = [join(prefix, "lib")], CPPPATH = [join(prefix, "include")], LIBS = ["lua"])
except IndexError:
pass
2009-03-23 01:26:52 +00:00
result = found and context.TryLink("""
#include <lualib.h>
#include <lauxlib.h>
2009-03-23 01:26:52 +00:00
int main() { luaL_newstate(); }
""", ".c")
if result:
context.Result("yes")
return True
else:
context.Result("no")
env.Replace(**backup)
2009-03-23 01:26:52 +00:00
return False
config_checks = { "CheckLua" : CheckLua }