Files
basalt/buildscripts/basalt.lua

81 lines
2.4 KiB
Lua

-- TODO:
local vulkan_sdk_dir = os.getenv("VULKAN_SDK")
local args = {...}
local output_name = "basalt.lib"
local include_dirs = "-I\"" .. table.concat({
"include",
"thirdparty/glfw/include",
"thirdparty/glm",
vulkan_sdk_dir .. "/Include",
vulkan_sdk_dir .. "/Include/vulkan",
}, "\" -I\"") .. '\"'
local src_dirs = {
"src"
}
local compiler_flags = table.concat({
"-c",
"-g",
"-O0"
}, ' ')
local library_dirs = '-L\"' .. table.concat({
}, '\" -L\"') .. '"'
local library_linker_inputs = '-l' .. table.concat({
}, ' -l')
local linker_flags = table.concat({
'rc'
}, ' ')
if include_dirs == "-I\"\"" then include_dirs = "" end
if library_dirs == "-L\"\"" then library_dirs = "" end
if library_linker_inputs == "-l" then library_linker_inputs = "" end
local compiler = require("buildscripts.helpers.compiler");
-- NOTE: This is not scalable
-- It does not care what source folder the object comes from
local function srcobj_mapping(src_file, obj_file)
-- Return the object file that the source file should be associated with
if (src_file ~= nil and obj_file == nil) then
return "obj/" .. src_file .. ".o"
-- Return the source files associated with an object file
elseif (src_file == nil and obj_file ~= nil) then
return {obj_file:sub(5, -3)}
else error("Invalid usage of srcobj mapping function: type(src_file) = " .. type(src_file) .. ", type(obj_file) = " .. type(obj_file)) end
end
local cpp_extensions = {
['.cpp']=true,
['.hpp']=true
}
local source_files = compiler.get_newer_src_files(src_dirs, cpp_extensions, srcobj_mapping)
local translation_units = compiler.generate_translation_units(source_files, srcobj_mapping)
for i,k in ipairs(translation_units) do
print("Running command clang++.exe " .. compiler_flags .. ' ' .. include_dirs .. ' ' .. table.concat(k.src, " ") .. ' -o ' .. k.obj)
end
local err, stdout, stderr = compiler.compile_translation_units("clang++.exe", 4, translation_units, compiler_flags, include_dirs)
for i,ec in ipairs(err) do
if (ec ~= 0) then
print("Invocation ".. tostring(i) .. " failed with exit code " .. tostring(ec) .. " and output;")
print()
print(stderr[i])
print()
print(stdout[i])
print()
end
end
local err, stdout, stderr = compiler.link_translation_units("llvm-ar", {'obj'}, {['.o']=true}, "bin/" .. output_name, library_dirs, library_linker_inputs, linker_flags)
if err ~= 0 then
print("Error linking translation units together")
print()
print(stdout)
print()
print(stderr)
print()
end