From cdd9e172e33a961e0800f8d8e3bc4d790955128b Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Tue, 21 Mar 2017 13:55:07 +0300 Subject: [PATCH] Append custom CFLAGS to LuaRocks config Ref #33. --- hererocks.py | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/hererocks.py b/hererocks.py index efc1ca0..2bf1c4a 100755 --- a/hererocks.py +++ b/hererocks.py @@ -195,6 +195,7 @@ def program_exists(prog): def using_cl(): return opts.target.startswith("vs") + def get_default_lua_target(): for plat, lua_target in platform_to_lua_target.items(): if sys.platform.startswith(plat): @@ -1463,30 +1464,45 @@ def is_luarocks_2_0(self): return False - @staticmethod - def get_cmake_generator(lua_identifiers): - lua_target = lua_identifiers["target"] + def get_cmake_generator(self): + lua_target = self.lua_identifiers["target"] if lua_target == "mingw": return "MinGW Makefiles" elif lua_target.startswith("vs"): - vs_year = lua_identifiers["vs year"] - vs_arch = lua_identifiers["vs arch"] + vs_year = self.lua_identifiers["vs year"] + vs_arch = self.lua_identifiers["vs arch"] vs_short_version = vs_year_to_version[vs_year][:-2] return "Visual Studio {} 20{}{}".format( vs_short_version, vs_year, " Win64" if vs_arch == "x64" else "") + @staticmethod + def get_default_cflags(): + if using_cl(): + return "/nologo /MD /O2" + elif opts.target == "mingw": + return "-O2" + else: + return "-O2 -fPIC" + + def get_config_path(self): + if os.name == "nt": + return os.path.join( + opts.location, "luarocks", "config-{}.lua".format(self.lua_identifiers["major version"])) + else: + return os.path.join( + opts.location, "etc", "luarocks", "config-{}.lua".format(self.lua_identifiers["major version"])) + def build(self): - lua_identifiers = self.all_identifiers.get("lua", self.all_identifiers.get("LuaJIT")) + self.lua_identifiers = self.all_identifiers.get("lua", self.all_identifiers.get("LuaJIT")) - if lua_identifiers is None: + if self.lua_identifiers is None: sys.exit("Error: can't install LuaRocks: Lua is not present in {}".format(opts.location)) self.fetch() if os.name == "nt": print("Building and installing LuaRocks" + self.version_suffix) - help_text = get_output("install.bat", "/?") args = [ "install.bat", @@ -1494,11 +1510,11 @@ def build(self): "/LUA", opts.location, "/F" ] - if lua_identifiers["target"] == "mingw": + if self.lua_identifiers["target"] == "mingw": args += ["/MW"] # Since LuaRocks 2.0.13 if "/LV" in help_text: - args += ["/LV", lua_identifiers["major version"]] + args += ["/LV", self.lua_identifiers["major version"]] # Since LuaRocks 2.1.2 if "/NOREG" in help_text: args += ["/NOREG", "/Q"] @@ -1517,14 +1533,11 @@ def build(self): else: sys.exit("Error: can't find {} in {}".format(script, os.path.join(opts.location, "luarocks"))) - cmake_generator = self.get_cmake_generator(lua_identifiers) + cmake_generator = self.get_cmake_generator() if cmake_generator is not None: - config_path = os.path.join( - opts.location, "luarocks", "config-{}.lua".format(lua_identifiers["major version"])) - - with open(config_path, "ab") as config_h: - config_h.write('\r\ncmake_generator = "{}"\r\n'.format(cmake_generator).encode("UTF-8")) + with open(self.get_config_path(), "a") as config_h: + config_h.write('\ncmake_generator = "{}"\n'.format(cmake_generator)) else: print("Building LuaRocks" + self.version_suffix) @@ -1541,6 +1554,10 @@ def install(self): print("Installing LuaRocks" + self.version_suffix) run("make", "install") + if self.lua_identifiers["c flags"] != "": + with open(self.get_config_path(), "a") as config_h: + config_h.write('\nvariables = {{CFLAGS = "{} {}"}}\n'.format(self.get_default_cflags(), self.lua_identifiers["c flags"])) + def get_manifest_name(): return os.path.join(opts.location, "hererocks.manifest")