Make the c_compiler variables private
As always in life, it's better to make things private by default
@@ -16,12 +16,12 @@ local util = require "pallene.util"
local c_compiler = {}
-c_compiler.CC = "cc"
-c_compiler.CPPFLAGS = "-I./vm/src"
-c_compiler.CFLAGS_BASE = "-std=c99 -g -fPIC"
-c_compiler.CFLAGS_WARN = "-Wall -Wundef -Wpedantic -Wno-unused"
-c_compiler.S_FLAGS = "-fverbose-asm"
-c_compiler.USER_CFlAGS = os.getenv("CFLAGS") or ""
+local CC = "cc"
+local CPPFLAGS = "-I./vm/src"
+local CFLAGS_BASE = "-std=c99 -g -fPIC"
+local CFLAGS_WARN = "-Wall -Wundef -Wpedantic -Wno-unused"
+local S_FLAGS = "-fverbose-asm"
+local USER_CFlAGS = os.getenv("CFLAGS") or ""
local function get_uname()
local ok, err, uname = util.outputs_of_execute("uname -s")
@@ -29,14 +29,15 @@ local function get_uname()
return uname
end
+local CFLAGS_SHARED
if string.find(get_uname(), "Darwin") then
- c_compiler.CFLAGS_SHARED = "-shared -undefined dynamic_lookup"
+ CFLAGS_SHARED = "-shared -undefined dynamic_lookup"
else
- c_compiler.CFLAGS_SHARED = "-shared"
+ CFLAGS_SHARED = "-shared"
end
local function run_cc(args)
- local cmd = c_compiler.CC .. " " .. table.concat(args, " ")
+ local cmd = CC .. " " .. table.concat(args, " ")
local ok = util.execute(cmd)
if not ok then
return false, {
@@ -50,12 +51,12 @@ end
-- The third argument is the mod_name, which is not used by c_compiler.compile_c_to_s
function c_compiler.compile_c_to_s(in_filename, out_filename, _, opt_level)
return run_cc({
- c_compiler.CPPFLAGS,
- c_compiler.CFLAGS_BASE,
- c_compiler.CFLAGS_WARN,
- c_compiler.S_FLAGS,
+ CPPFLAGS,
+ CFLAGS_BASE,
+ CFLAGS_WARN,
+ S_FLAGS,
opt_level and "-O"..opt_level or "",
- c_compiler.USER_CFlAGS,
+ USER_CFlAGS,
"-x c",
"-o", util.shell_quote(out_filename),
"-S", util.shell_quote(in_filename),
@@ -75,7 +76,7 @@ function c_compiler.compile_o_to_so(in_filename, out_filename)
-- There is no need to add the '-x' flag when compiling an object file without a '.o' extension.
-- According to GCC, any file name with no recognized suffix is treated as an object file.
return run_cc({
- c_compiler.CFLAGS_SHARED,
+ CFLAGS_SHARED,
"-o", util.shell_quote(out_filename),
util.shell_quote(in_filename),
})
