From 0ed6dd46fbebdeed9f99ef250b6e2279e6fe17b8 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 27 Feb 2016 18:59:03 -0800 Subject: [PATCH] Add support for using system LuaJIT rather than the bundled copy Closes #1904. --- Makefile.inc.in | 4 ++-- configure.ac | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile | 8 ++++---- src/auto4_lua.cpp | 2 +- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Makefile.inc.in b/Makefile.inc.in index 5a52d25cb..8d5566af3 100644 --- a/Makefile.inc.in +++ b/Makefile.inc.in @@ -79,7 +79,7 @@ CFLAGS_ICONV = @ICONV_CFLAGS@ CFLAGS_ICU = @ICU_I18N_CFLAGS@ CFLAGS_LIBASS = @LIBASS_CFLAGS@ CFLAGS_LIBPULSE = @LIBPULSE_CFLAGS@ -CFLAGS_LUA = -I$(TOP)vendor/luajit/include +CFLAGS_LUA = @LUAJIT_CFLAGS@ CFLAGS_OPENAL = @OPENAL_CFLAGS@ CFLAGS_OSS = @OSS_CFLAGS@ CFLAGS_PORTAUDIO = @PORTAUDIO_CFLAGS@ @@ -97,7 +97,7 @@ LIBS_ICONV = @ICONV_LIBS@ LIBS_ICU = @ICU_UC_LIBS@ @ICU_I18N_LIBS@ LIBS_LIBASS = @LIBASS_LIBS@ LIBS_LIBPULSE = @LIBPULSE_LIBS@ -LIBS_LUA = $(TOP)vendor/luajit/src/libluajit.a +LIBS_LUA = @LUAJIT_LIBS@ LIBS_OPENAL = @OPENAL_LIBS@ LIBS_PORTAUDIO = @PORTAUDIO_LIBS@ LIBS_PTHREAD = @PTHREAD_LIBS@ diff --git a/configure.ac b/configure.ac index 7492568bb..91902cf39 100644 --- a/configure.ac +++ b/configure.ac @@ -383,6 +383,51 @@ AGI_OPT_PKG(fftw3, [build without fftw support [auto]], [Enable fftw support]) AGI_OPT_PKG(hunspell, [build without hunspell spell-checking [auto]], [Enable Hunspell support]) AGI_OPT_PKG(uchardet, [build without automatic character set detection [auto]], [Enable uchardet support]) +######## +# LuaJIT +######## +system_luajit="bundled" +AC_ARG_WITH(system-luajit, AS_HELP_STRING([--without-system-luajit], [Use built-in LuaJIT [auto]])) +# Check if it's available at all +AS_IF([test x$with_system_luajit = xno], [], + [PKG_CHECK_MODULES(LUAJIT, luajit >= 2.0.0, [], [ + AS_IF([test x$with_system_luajit = xyes], + [AC_MSG_FAILURE([--with-sytem-luajit was specified, but luajit could not be found])]) + with_system_luajit="no"])]) + +# Check if it's compiled in Lua 5.2 mode +AS_IF([test x$with_system_luajit != xno], [ + aegisub_save_LIBS="$LIBS" + aegisub_save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $LUAJIT_CFLAGS" + LIBS="$LIBS $LUAJIT_LIBS" + AC_CACHE_CHECK( + [whether LuaJIT is compiled in 5.2 mode], [agi_cv_luajit_is_52], + [AC_RUN_IFELSE([AC_LANG_PROGRAM( + [[#include ]], + [[lua_State *L = luaL_newstate(); + if (!L) return 1; + // This is valid in lua 5.2, but a syntax error in 5.1 + const char testprogram[] = "function foo() while true do break return end end"; + return luaL_loadstring(L, testprogram) == LUA_ERRSYNTAX; + ]])], [agi_cv_luajit_is_52="yes"], [agi_cv_luajit_is_52="no"])]) + CPPFLAGS="$aegisub_save_CPPFLAGS" + LIBS="$aegisub_save_LIBS" + + if test $agi_cv_luajit_is_52 != yes; then + AS_IF([test x$with_system_luajit = xyes], + [AC_MSG_FAILURE([LuaJIT must be compiled in Lua 5.2 mode])]) + with_system_luajit="no" + else + with_system_luajit="yes" + system_luajit="system" + fi +]) + +AS_IF([test $with_system_luajit = no], + [AC_SUBST([LUAJIT_CFLAGS], ['-I$(TOP)vendor/luajit/include']) + AC_SUBST([LUAJIT_LIBS], ['$(TOP)vendor/luajit/src/libluajit.a'])]) + ###################################################### # Debugging support ###################################################### @@ -572,4 +617,5 @@ Misc Packages uchardet: $with_uchardet $uchardet_disabled Hunspell: $with_hunspell $hunspell_disabled FFTW3: $with_fftw3 $fftw3_disabled + LuaJIT: $system_luajit ]) diff --git a/src/Makefile b/src/Makefile index 1fb983ce2..0ee6c84c8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -198,10 +198,10 @@ $(d)subtitles_provider.o_FLAGS := $(CFLAGS_LIBASS) $(d)subtitles_provider_libass.o_FLAGS := $(CFLAGS_LIBASS) -Wno-c++11-narrowing $(d)text_file_reader.o_FLAGS := -D_X86_ $(d)video_provider_manager.o_FLAGS := $(CFLAGS_FFMS2) -$(d)auto4_lua.o_FLAGS := -I$(TOP)vendor/luajit/include -$(d)auto4_lua_assfile.o_FLAGS := -I$(TOP)vendor/luajit/include -$(d)auto4_lua_dialog.o_FLAGS := -I$(TOP)vendor/luajit/include -$(d)auto4_lua_progresssink.o_FLAGS := -I$(TOP)vendor/luajit/include +$(d)auto4_lua.o_FLAGS := $(CFLAGS_LUA) +$(d)auto4_lua_assfile.o_FLAGS := $(CFLAGS_LUA) +$(d)auto4_lua_dialog.o_FLAGS := $(CFLAGS_LUA) +$(d)auto4_lua_progresssink.o_FLAGS := $(CFLAGS_LUA) $(src_OBJ): $(d)libresrc/bitmap.h $(d)libresrc/default_config.h diff --git a/src/auto4_lua.cpp b/src/auto4_lua.cpp index 3ce9f2adb..245689679 100644 --- a/src/auto4_lua.cpp +++ b/src/auto4_lua.cpp @@ -396,7 +396,7 @@ namespace { name = GetPrettyFilename().string(); // create lua environment - L = lua_open(); + L = luaL_newstate(); if (!L) { description = "Could not initialize Lua state"; return;