Skip to content

Commit 86a0785

Browse files
committed
Adds support for compiling shared library for Luac
- compiles lua with .so shared lib per default - added --shared to add building shared lib (and -fPIC addition) Fixes #31 Signed-off-by: Guyzmo <[email protected]>
1 parent cd483f5 commit 86a0785

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

hererocks.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,9 @@ def add_options_to_version_suffix(self):
649649
if opts.no_readline:
650650
options.append(("readline", "false"))
651651

652+
if opts.shared:
653+
options.append(("shared", "true"))
654+
652655
if options:
653656
self.version_suffix += " (" + (", ".join(
654657
opt + ": " + value for opt, value in options)) + ")"
@@ -1042,14 +1045,17 @@ def __init__(self, version):
10421045

10431046
if opts.target == "mingw" or using_cl():
10441047
self.dll_file = "lua5" + self.major_version[2] + ".dll"
1048+
self.so_file = None
10451049
else:
10461050
self.dll_file = None
1051+
self.so_file = "liblua5" + self.major_version[2] + ".so"
10471052

10481053
def set_identifiers(self):
10491054
super(RioLua, self).set_identifiers()
10501055

10511056
self.identifiers["readline"] = str(not opts.no_readline).lower()
10521057
self.identifiers["patched"] = str(opts.patch).lower()
1058+
self.identifiers["shared"] = str(not opts.shared).lower()
10531059

10541060
def major_version_from_version(self):
10551061
return self.version[:3]
@@ -1191,6 +1197,8 @@ def make(self):
11911197
cc = ["cl", "/nologo", "/MD", "/O2", "/W3", "/c", "/D_CRT_SECURE_NO_DEPRECATE"]
11921198
else:
11931199
cflags = ["-O2", "-Wall", "-Wextra"] + cflags
1200+
if not opts.shared:
1201+
cflags = ["-fPIC"] + cflags
11941202

11951203
lflags.append("-lm")
11961204
static_cflags = list(cflags)
@@ -1230,6 +1238,11 @@ def make(self):
12301238
run("ar", "rcu", self.arch_file, lib_objs)
12311239
run("ranlib", self.arch_file)
12321240
run(cc, "-o", self.luac_file, luac_objs, self.arch_file, lflags)
1241+
if not opts.shared:
1242+
so_lflags = ["-ldl",
1243+
"-Wl,--whole-archive,--soname={}".format(self.so_file),
1244+
"-Wl,--no-as-needed"] + lflags + [self.arch_file, "-Wl,--no-whole-archive"]
1245+
run(cc, "-o", self.so_file, "-shared", so_lflags)
12331246

12341247
if opts.target == "mingw":
12351248
run(cc, "-shared", "-o", self.dll_file, lib_objs)
@@ -1265,6 +1278,8 @@ def make_install(self):
12651278
"lua.h", "luaconf.h", "lualib.h", "lauxlib.h", lua_hpp)
12661279

12671280
copy_files(os.path.join(opts.location, "lib"), self.arch_file)
1281+
if self.so_file and not opts.shared:
1282+
copy_files(os.path.join(opts.location, "lib"), self.so_file)
12681283

12691284
class LuaJIT(Lua):
12701285
name = "LuaJIT"
@@ -1792,6 +1807,8 @@ def main(argv=None):
17921807
"vs13_32", "vs13_64", "vs15_32", "vs15_64"
17931808
], metavar="{linux,macosx,freebsd,mingw,posix,generic,mingw,vs,vs_XX,vsXX_YY}",
17941809
default=get_default_lua_target())
1810+
parser.add_argument("--shared", help="Don't make a shared library when building standard Lua.",
1811+
action="store_true", default=False)
17951812
parser.add_argument("--no-readline", help="Don't use readline library when building standard Lua.",
17961813
action="store_true", default=False)
17971814
parser.add_argument("--downloads",

0 commit comments

Comments
 (0)