summaryrefslogtreecommitdiff
path: root/configure.lua
diff options
context:
space:
mode:
Diffstat (limited to 'configure.lua')
-rw-r--r--configure.lua169
1 files changed, 168 insertions, 1 deletions
diff --git a/configure.lua b/configure.lua
index 2e34888..49ba1f0 100644
--- a/configure.lua
+++ b/configure.lua
@@ -393,6 +393,173 @@ if system == "unix" then
end
if system == "windows" then
- print("windows isn't done yet.")
+ local outfile = io.open("build.ninja", "w")
+ if not outfile then
+ print("Failed to open build.ninja.")
+ exit(3)
+ end
+ outfile:write("# generated by configure.lua\n\n")
+ local function staticlib(name, dir, tab, ext)
+ for _, fname in ipairs(tab) do
+ outfile:write(string.format("build %s/%s.obj: cpp %s/%s.%s\n", dir, fname, dir, fname, ext))
+ end
+ outfile:write("build " .. dir .. "/" .. name .. ".lib: lib ")
+ for i = 1, #tab - 1 do
+ local fname = tab[i]
+ outfile:write(dir .. "/" .. fname .. ".obj ")
+ end
+ outfile:write(dir .. "/" .. tab[#tab] .. ".obj\n")
+ outfile:write("\n")
+ end
+ local function tool(name, dir, tab, ext, libs, deps)
+ for _, fname in ipairs(tab) do
+ outfile:write(string.format("build %s/%s.obj: cpp %s/%s.%s\n", dir, fname, dir, fname, ext))
+ end
+ outfile:write("build " .. name .. ".exe: link ")
+ for i = 1, #tab - 1 do
+ local fname = tab[i]
+ outfile:write(dir .. "/" .. fname .. ".obj ")
+ end
+ outfile:write(dir .. "/" .. tab[#tab] .. ".obj")
+ if #libs > 0 then
+ for _, l in ipairs(libs) do
+ outfile:write(" " .. l)
+ end
+ end
+ outfile:write("\n")
+ if #deps > 0 then
+ outfile:write(" libs = ")
+ for _, d in ipairs(deps) do
+ outfile:write(d .. " ")
+ end
+ end
+ outfile:write("\n\n")
+ end
+ all_assets = {}
+ local function assets(tab, tool, exts, extd, deps)
+ local depstr = ""
+ if deps then
+ for _, dep in ipairs(deps) do
+ depstr = depstr .. " " .. dep
+ end
+ end
+ for _, fname in ipairs(tab) do
+ outfile:write(string.format("build data/%s.%s: %s intermediate/%s.%s | %s.exe", fname, extd, tool, fname, exts, tool))
+ all_assets[#all_assets + 1] = "data/" .. fname .. "." .. extd
+ outfile:write(depstr .. "\n")
+ end
+ outfile:write("\n")
+ end
+ local function textures(tab, tool)
+ for _, item in ipairs(tab) do
+ local fname = item[1]
+ local exts = item[2]
+ local format = item[3]
+ local extd = "tex"
+ outfile:write(string.format("build data/%s.%s: %s intermediate/%s.%s | %s.exe\n", fname, extd, tool, fname, exts, tool))
+ outfile:write(" format = " .. format .. "\n")
+ all_assets[#all_assets + 1] = "data/" .. fname .. "." .. extd
+ end
+ outfile:write("\n")
+ end
+ local function pack()
+ outfile:write("build pack: packer ")
+ for _, asset in ipairs(all_assets) do
+ outfile:write(asset .. " ")
+ end
+ outfile:write("| packer.exe\n")
+ end
+ outfile:write("cflags = /nologo /Z7 /DDEBUG /MD /std:c++20 /Isc\\glslang /Iqstd /Icfg /Dplat_win /Dplat_x86 /Dallocation_default_alignment=8\n")
+ outfile:write("\n")
+ outfile:write("rule cpp\n")
+ outfile:write(" command = cl $cflags $in /c /Fo: \"$out\"\n")
+ outfile:write(" deps = msvc\n\n")
+ outfile:write("rule link\n")
+ outfile:write(" command = cl /nologo $in /Fe: \"$out\" /link /DEBUG $libs\n\n")
+ outfile:write("rule lib\n")
+ outfile:write(" command = lib /nologo $in /out:\"$out\"\n\n")
+ for _, fname in ipairs(config.c2) do
+ outfile:write("build " .. fname .. ".obj: cpp " .. fname .. ".cpp\n")
+ end
+ outfile:write("build c2.exe: link qstd/qstd.lib ")
+ for i = 1, #config.c2 - 1 do
+ local fname = config.c2[i]
+ outfile:write(fname .. ".obj ")
+ end
+ outfile:write(config.c2[#config.c2] .. ".obj\n")
+ outfile:write(" libs = user32.lib\n")
+ outfile:write("\n")
+ staticlib("qstd", "qstd", config.qstd, "c")
+ staticlib("cfg", "cfg", config.cfg, "c")
+ tool(
+ "shadercompiler",
+ "sc",
+ config.sc,
+ "cpp",
+ { "qstd/qstd.lib", "cfg/cfg.lib" },
+ {
+ "/LIBPATH:sc/glslang/build/glslang/Release",
+ "/LIBPATH:sc/glslang/build/SPIRV/Release",
+ "/LIBPATH:sc/glslang/build/glslang/OSDependent/Windows/Release",
+ "/LIBPATH:sc/glslang/build/External/spirv-tools/source/Release",
+ "/LIBPATH:sc/glslang/build/External/spirv-tools/source/link/Release",
+ "/LIBPATH:sc/glslang/build/External/spirv-tools/source/opt/Release",
+ "glslang.lib",
+ "glslang-default-resource-limits.lib",
+ "SPIRV.lib",
+ "MachineIndependent.lib",
+ "SPVRemapper.lib",
+ "OSDependent.lib",
+ "GenericCodeGen.lib",
+ "SPIRV-Tools-link.lib",
+ "SPIRV-Tools-opt.lib",
+ "SPIRV-Tools.lib"
+ }
+ )
+ tool(
+ "packer",
+ ".",
+ config.packer,
+ "c",
+ { "qstd/qstd.lib" },
+ {}
+ )
+ tool(
+ "convtexture",
+ ".",
+ config.convtexture,
+ "c",
+ { "qstd/qstd.lib" },
+ {}
+ )
+ tool(
+ "convmodel",
+ ".",
+ config.convmodel,
+ "c",
+ { "qstd/qstd.lib" },
+ {}
+ )
+ tool(
+ "convmaterial",
+ ".",
+ config.convmaterial,
+ "c",
+ { "qstd/qstd.lib", "cfg/cfg.lib" },
+ {}
+ )
+ local function tool_rule(name)
+ outfile:write(string.format("rule %s\n command = %s.exe $in $out\n\n", name, name))
+ end
+ tool_rule("shadercompiler")
+ tool_rule("convmaterial")
+ outfile:write("rule convmodel\n command = convmodel.exe data $in $out\n\n")
+ outfile:write("rule convtexture\n command = convtexture.exe $in $out $format\n\n")
+ outfile:write("rule packer\n command = packer.exe $out -data $in\n\n")
+ assets(config.shaders, "shadercompiler", "glsl", "csh")
+ assets(config.models, "convmodel", "glb", "mdl", all_assets)
+ assets(config.materials, "convmaterial", "mat", "mat")
+ textures(config.textures, "convtexture")
+ pack()
end