From d530681cde96bb5cb09f9364e49969ca4443e981 Mon Sep 17 00:00:00 2001 From: Guyzmo Date: Sat, 25 Feb 2017 13:36:37 +0100 Subject: [PATCH] Adds support for compiling shared library for Luac - compiles lua with .so shared lib per default - added --no-shared to skip building shared lib (and avoid -fPIC addition) Fixes #31 Signed-off-by: Guyzmo --- hererocks.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hererocks.py b/hererocks.py index efc1ca0..5bc0d5e 100755 --- a/hererocks.py +++ b/hererocks.py @@ -649,6 +649,9 @@ def add_options_to_version_suffix(self): if opts.no_readline: options.append(("readline", "false")) + if opts.no_shared: + options.append(("shared", "false")) + if options: self.version_suffix += " (" + (", ".join( opt + ": " + value for opt, value in options)) + ")" @@ -1042,14 +1045,17 @@ def __init__(self, version): if opts.target == "mingw" or using_cl(): self.dll_file = "lua5" + self.major_version[2] + ".dll" + self.so_file = None else: self.dll_file = None + self.so_file = "liblua5" + self.major_version[2] + ".so" def set_identifiers(self): super(RioLua, self).set_identifiers() self.identifiers["readline"] = str(not opts.no_readline).lower() self.identifiers["patched"] = str(opts.patch).lower() + self.identifiers["shared"] = str(not opts.no_shared).lower() def major_version_from_version(self): return self.version[:3] @@ -1191,6 +1197,8 @@ def make(self): cc = ["cl", "/nologo", "/MD", "/O2", "/W3", "/c", "/D_CRT_SECURE_NO_DEPRECATE"] else: cflags = ["-O2", "-Wall", "-Wextra"] + cflags + if not opts.no_shared: + cflags = ["-fPIC"] + cflags lflags.append("-lm") static_cflags = list(cflags) @@ -1230,6 +1238,11 @@ def make(self): run("ar", "rcu", self.arch_file, lib_objs) run("ranlib", self.arch_file) run(cc, "-o", self.luac_file, luac_objs, self.arch_file, lflags) + if not opts.no_shared: + so_lflags = [ "-ldl", + "-Wl,--whole-archive,--soname={}".format(self.so_file), + "-Wl,--no-as-needed"] + lflags + [self.arch_file, "-Wl,--no-whole-archive"] + run(cc, "-o", self.so_file, "-shared", so_lflags) if opts.target == "mingw": run(cc, "-shared", "-o", self.dll_file, lib_objs) @@ -1265,6 +1278,8 @@ def make_install(self): "lua.h", "luaconf.h", "lualib.h", "lauxlib.h", lua_hpp) copy_files(os.path.join(opts.location, "lib"), self.arch_file) + if self.so_file and not opts.no_shared: + copy_files(os.path.join(opts.location, "lib"), self.so_file) class LuaJIT(Lua): name = "LuaJIT" @@ -1792,6 +1807,8 @@ def main(argv=None): "vs13_32", "vs13_64", "vs15_32", "vs15_64" ], metavar="{linux,macosx,freebsd,mingw,posix,generic,mingw,vs,vs_XX,vsXX_YY}", default=get_default_lua_target()) + parser.add_argument("--no-shared", help="Don't make a shared library when building standard Lua.", + action="store_true", default=False) parser.add_argument("--no-readline", help="Don't use readline library when building standard Lua.", action="store_true", default=False) parser.add_argument("--downloads",