Skip to content

Commit cdd9e17

Browse files
committed
Append custom CFLAGS to LuaRocks config
Ref #33.
1 parent cd483f5 commit cdd9e17

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

hererocks.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def program_exists(prog):
195195
def using_cl():
196196
return opts.target.startswith("vs")
197197

198+
198199
def get_default_lua_target():
199200
for plat, lua_target in platform_to_lua_target.items():
200201
if sys.platform.startswith(plat):
@@ -1463,42 +1464,57 @@ def is_luarocks_2_0(self):
14631464

14641465
return False
14651466

1466-
@staticmethod
1467-
def get_cmake_generator(lua_identifiers):
1468-
lua_target = lua_identifiers["target"]
1467+
def get_cmake_generator(self):
1468+
lua_target = self.lua_identifiers["target"]
14691469

14701470
if lua_target == "mingw":
14711471
return "MinGW Makefiles"
14721472
elif lua_target.startswith("vs"):
1473-
vs_year = lua_identifiers["vs year"]
1474-
vs_arch = lua_identifiers["vs arch"]
1473+
vs_year = self.lua_identifiers["vs year"]
1474+
vs_arch = self.lua_identifiers["vs arch"]
14751475
vs_short_version = vs_year_to_version[vs_year][:-2]
14761476
return "Visual Studio {} 20{}{}".format(
14771477
vs_short_version, vs_year, " Win64" if vs_arch == "x64" else "")
14781478

1479+
@staticmethod
1480+
def get_default_cflags():
1481+
if using_cl():
1482+
return "/nologo /MD /O2"
1483+
elif opts.target == "mingw":
1484+
return "-O2"
1485+
else:
1486+
return "-O2 -fPIC"
1487+
1488+
def get_config_path(self):
1489+
if os.name == "nt":
1490+
return os.path.join(
1491+
opts.location, "luarocks", "config-{}.lua".format(self.lua_identifiers["major version"]))
1492+
else:
1493+
return os.path.join(
1494+
opts.location, "etc", "luarocks", "config-{}.lua".format(self.lua_identifiers["major version"]))
1495+
14791496
def build(self):
1480-
lua_identifiers = self.all_identifiers.get("lua", self.all_identifiers.get("LuaJIT"))
1497+
self.lua_identifiers = self.all_identifiers.get("lua", self.all_identifiers.get("LuaJIT"))
14811498

1482-
if lua_identifiers is None:
1499+
if self.lua_identifiers is None:
14831500
sys.exit("Error: can't install LuaRocks: Lua is not present in {}".format(opts.location))
14841501

14851502
self.fetch()
14861503

14871504
if os.name == "nt":
14881505
print("Building and installing LuaRocks" + self.version_suffix)
1489-
14901506
help_text = get_output("install.bat", "/?")
14911507
args = [
14921508
"install.bat",
14931509
"/P", os.path.join(opts.location, "luarocks"),
14941510
"/LUA", opts.location,
14951511
"/F"
14961512
]
1497-
if lua_identifiers["target"] == "mingw":
1513+
if self.lua_identifiers["target"] == "mingw":
14981514
args += ["/MW"]
14991515
# Since LuaRocks 2.0.13
15001516
if "/LV" in help_text:
1501-
args += ["/LV", lua_identifiers["major version"]]
1517+
args += ["/LV", self.lua_identifiers["major version"]]
15021518
# Since LuaRocks 2.1.2
15031519
if "/NOREG" in help_text:
15041520
args += ["/NOREG", "/Q"]
@@ -1517,14 +1533,11 @@ def build(self):
15171533
else:
15181534
sys.exit("Error: can't find {} in {}".format(script, os.path.join(opts.location, "luarocks")))
15191535

1520-
cmake_generator = self.get_cmake_generator(lua_identifiers)
1536+
cmake_generator = self.get_cmake_generator()
15211537

15221538
if cmake_generator is not None:
1523-
config_path = os.path.join(
1524-
opts.location, "luarocks", "config-{}.lua".format(lua_identifiers["major version"]))
1525-
1526-
with open(config_path, "ab") as config_h:
1527-
config_h.write('\r\ncmake_generator = "{}"\r\n'.format(cmake_generator).encode("UTF-8"))
1539+
with open(self.get_config_path(), "a") as config_h:
1540+
config_h.write('\ncmake_generator = "{}"\n'.format(cmake_generator))
15281541

15291542
else:
15301543
print("Building LuaRocks" + self.version_suffix)
@@ -1541,6 +1554,10 @@ def install(self):
15411554
print("Installing LuaRocks" + self.version_suffix)
15421555
run("make", "install")
15431556

1557+
if self.lua_identifiers["c flags"] != "":
1558+
with open(self.get_config_path(), "a") as config_h:
1559+
config_h.write('\nvariables = {{CFLAGS = "{} {}"}}\n'.format(self.get_default_cflags(), self.lua_identifiers["c flags"]))
1560+
15441561
def get_manifest_name():
15451562
return os.path.join(opts.location, "hererocks.manifest")
15461563

0 commit comments

Comments
 (0)