Update saphire build system, now cleaner and more efficient.

This commit is contained in:
TSnake41 2021-10-16 23:41:39 +02:00
parent 37ef1b240c
commit 89b1ebf081
2 changed files with 96 additions and 148 deletions

View File

@ -16,6 +16,8 @@
]] ]]
local saphire = require "saphire" local saphire = require "saphire"
local c = require "saphire-c"
local Future = require "saphire-future"
local los = require "los" local los = require "los"
local cc = os.getenv "CC" or "cc" local cc = os.getenv "CC" or "cc"
@ -23,14 +25,12 @@ local ar = os.getenv "AR" or "ar"
local windres = os.getenv "WINDRES" or "windres" local windres = os.getenv "WINDRES" or "windres"
-- TODO: Use current lua interpreter -- TODO: Use current lua interpreter
local lua = "luajit"--os.getenv "LUA" or "luajit\\src\\luajit" local lua = os.getenv "LUA" or "luajit\\src\\luajit"
local lua_ready = os.getenv "LUA" or false local needs_luajit_built = not (os.getenv "LUA")
local cflags = os.getenv "CFLAGS" or "-O2 -s" local cflags = os.getenv "CFLAGS" or "-O2 -s"
local ldflags = os.getenv "LDFLAGS" or "-O2 -s -lm" local ldflags = os.getenv "LDFLAGS" or "-O2 -s -lm"
local windres = os.getenv "WINDRES" or "windres"
local modules = "raymath rlgl easings gestures physac raygui" local modules = "raymath rlgl easings gestures physac raygui"
cflags = cflags .. " -Iluajit/src -Iraygui/src -Iraylib/src" cflags = cflags .. " -Iluajit/src -Iraygui/src -Iraylib/src"
@ -42,162 +42,102 @@ if los.type() == "linux" then
ldflags = ldflags .. " -ldl -pthread" ldflags = ldflags .. " -ldl -pthread"
elseif los.type() == "win32" then elseif los.type() == "win32" then
ldflags = ldflags .. " -lopengl32 -lgdi32 -lwinmm -static " ldflags = ldflags .. " -lopengl32 -lgdi32 -lwinmm -static "
exe_ldflags = exe_ldflags .. "src/res/icon.res"
end end
local function build_c(src, obj, name, flags) local libluajit
if saphire.targets.clean then if saphire.targets.clean then
return { libluajit = {
command = "rm -f " .. obj, command = "make -C luajit clean",
name = name name = "LuaJIT"
} }
end else
libluajit = {
return { command = string.format("make -C luajit amalg CC=%s BUILDMODE=static MACOSX_DEPLOYMENT_TARGET=10.13", cc),
command = string.format("%s -c -o %s %s %s %s", cc, obj, src, flags or "", cflags), name = "LuaJIT"
name = name,
display = obj
} }
end end
saphire.do_single(libluajit)
libluajit[1] = "luajit/src/libluajit.a"
local function build_a(objs, lib, name) local libraylib = Future "raylib/src/libraylib.a"
saphire.do_subdir("raylib/src", false, "build/buildRaylib.lua", libraylib)
local function lua2c(files, output, name)
if saphire.targets.clean then if saphire.targets.clean then
return { return string.format("rm -f %s", output)
command = "rm -f " .. lib, else
name = name return string.format("%s tools/lua2str.lua %s %s %s", lua, output, name, table.concat(files, " "))
}
end end
return {
command = string.format("%s rcs %s %s", ar, lib, table.concat(objs, " ")),
name = name
}
end end
local function build_e(files, output, name, flags) local function genbind(output, modules)
if saphire.targets.clean then if saphire.targets.clean then
return { return string.format("rm -f %s", output)
command = "rm -f " .. output, else
name = name return string.format("%s tools/genbind.lua src/autogen/bind.c %s", lua, modules)
}
end end
return {
command = string.format("%s -o %s %s %s %s %s",
cc, output, table.concat(files, " "), flags or "", ldflags, exe_ldflags),
name = name,
display = string.format("%s -o %s", cc, output)
}
end end
local function build_res(src, output, name) local raylua_src = {
if saphire.targets.clean then c.src("src/raylua.c", function ()
return { -- Generate bind.c and boot.c
command = "rm -f " .. output, if needs_luajit_built then
name = name -- LuaJIT needs to be built
} libluajit:wait()
end
return {
command = string.format("%s %s -O coff %s", windres, src, output),
name = name
}
end
local function lua2c(files, output, name, dname)
--while not lua_ready do
-- coroutine.yield()
--end
if saphire.targets.clean then
return {
command = "rm -f " .. output,
name = dname
}
end
return {
command = string.format("%s tools/lua2str.lua %s %s %s", lua, output, name, table.concat(files, " ")),
name = dname
}
end
saphire.do_multi({
function () -- LuaJIT
-- TODO: Improve LuaJIT building
--saphire.do_subdir("luajit", true, "build/buildLuaJIT.lua")
if saphire.targets.clean then
saphire.do_single({
command = "make -C luajit clean",
name = "LuaJIT"
}, true)
else
saphire.do_single({
command = string.format("make -C luajit amalg CC=%s BUILDMODE=static MACOSX_DEPLOYMENT_TARGET=10.13", cc),
name = "LuaJIT"
}, true)
end end
lua_ready = true saphire.do_multi({
end, {
function () -- Raylib command = lua2c(
saphire.do_subdir("raylib/src", true, "build/buildRaylib.lua") { "src/raylib.lua", "src/compat.lua", "src/raylua.lua" },
end, "src/autogen/boot.c",
function () -- libraylua.a "raylua_boot_lua"
saphire.do_single(lua2c( ),
{ "src/raylib.lua", "src/compat.lua", "src/raylua.lua" }, name = "boot.c"
"src/autogen/boot.c", },
"raylua_boot_lua", {
"libraylua.a" command = genbind("src/autogen/bind.c", modules),
), true) name = "bind.c"
}
}, true)
end)
}
local raylua_obj = c.compile(raylua_src, cflags, "raylua", cc)
if saphire.targets.clean then local libraylua = c.lib("libraylua.a", raylua_obj, "raylua", ar)
saphire.do_single({
command = "rm -f src/autogen/bind.c",
name = "libraylua.a"
}, true)
else
saphire.do_single({
command = string.format("%s tools/genbind.lua src/autogen/bind.c %s", lua, modules),
name = "libraylua.a"
}, true)
end
saphire.do_single(build_c("src/raylua.c", "src/raylua.o", "libraylua.a"), true) local raylua_s_src = {
saphire.do_single(build_a({ "src/raylua.o" }, "libraylua.a", "libraylua.a"), true) "src/raylua_s.c"
end, }
function () -- src/raylua_builder.o local raylua_s_objs = c.compile(raylua_s_src, cflags, "raylua_s", cc)
saphire.do_single(lua2c({ "src/raylua_builder.lua" }, "src/autogen/builder.c", "raylua_builder_lua", "raylua_e"), true)
saphire.do_single(build_c("src/raylua_builder.c", "src/raylua_builder.o", "raylua_e"), true)
end,
function () -- Ressources
if los.type() == "win32" then
saphire.do_single(build_res("src/res/icon.rc", "src/res/icon.res", "icon"), true)
end
end,
function ()
local entries = {
{ "src/raylua_s.o", "src/raylua_s.c" },
{ "src/raylua_e.o", "src/raylua_e.c" },
{ "src/lib/miniz.o", "src/lib/miniz.c" },
{ "src/raylua_self.o", "src/raylua_self.c" }
}
saphire.do_multi(saphire.map(entries, function(entry) local raylua_e_src = {
return build_c(entry[2], entry[1], "raylua") c.src("src/raylua_builder.c", function ()
end), true) saphire.do_single(lua2c({ "src/raylua_builder.lua" }, "src/autogen/builder.c", "raylua_builder_lua"), true)
end end),
}, true) "src/raylua_e.c",
"src/lib/miniz.c",
"src/raylua_self.c",
}
local raylua_e_objs = c.compile(raylua_e_src, cflags, "raylua_e", cc)
saphire.do_multi({ local icon
-- raylua_s if los.type() == "win32" then
build_e({ "src/raylua_s.o", "libraylua.a" }, "raylua_s", "raylua_s"), icon = c.res("src/res/icon.rc", { "src/res/icon.ico" }, "icon", windres)
-- raylua_e end
build_e({
"src/raylua_e.o", local raylua_s = c.link("raylua_s",
"src/raylua_self.o", saphire.merge(raylua_s_objs, { libraylua, libraylib, libluajit, icon }),
"src/raylua_builder.o", ldflags,
"src/lib/miniz.o", false,
"libraylua.a" "raylua_s",
}, "raylua_e", "raylua_e") cc
}, true) )
local raylua_e = c.link("raylua_e",
saphire.merge(raylua_e_objs, { libraylua, libraylib, libluajit, icon }),
ldflags,
false,
"raylua_e",
cc
)

View File

@ -1,3 +1,5 @@
local future = arg[1]
local saphire = require "saphire" local saphire = require "saphire"
local c = require "saphire-c" local c = require "saphire-c"
@ -5,7 +7,6 @@ local cc = os.getenv "CC" or "cc"
local ar = os.getenv "AR" or "ar" local ar = os.getenv "AR" or "ar"
local cflags = os.getenv "CFLAGS" or "-O2 -s" local cflags = os.getenv "CFLAGS" or "-O2 -s"
local ldflags = os.getenv "LDFLAGS" or "-O2 -s -lm"
local include_paths = "-I. -Iexternal/glfw/include -Iexternal/glfw/deps/mingw" local include_paths = "-I. -Iexternal/glfw/include -Iexternal/glfw/deps/mingw"
@ -33,9 +34,11 @@ for i,v in ipairs(vars) do
vars[v[1]] = v[2] vars[v[1]] = v[2]
end end
local flags = string.format("%s -D%s -D%s %s", cflags, vars.PLATFORM, vars.GRAPHICS, include_paths)
local src = { local src = {
-- ["obj.o"] = { src... } -- ["obj.o"] = { src... }
{ "rcore.o", { "rcore.c", "raylib.h", "rlgl.h", "utils.h", "raymath.h", "camera.h", "rgestures.h" } }, { "rcore.o", { "rcore.c", "raylib.h", "rlgl.h", "utils.h", "raymath.h", "rcamera.h", "rgestures.h" } },
{ "rglfw.o", { "rglfw.c", flags = os.getenv "GLFW_OSX" or "" } }, { "rglfw.o", { "rglfw.c", flags = os.getenv "GLFW_OSX" or "" } },
{ "rshapes.o", { "rshapes.c", "raylib.h", "rlgl.h" } }, { "rshapes.o", { "rshapes.c", "raylib.h", "rlgl.h" } },
{ "rtextures.o", { "rtextures.c", "raylib.h", "rlgl.h", "utils.h" } }, { "rtextures.o", { "rtextures.c", "raylib.h", "rlgl.h", "utils.h" } },
@ -45,5 +48,10 @@ local src = {
{ "raudio.o", { "raudio.c", "raylib.h" } } { "raudio.o", { "raudio.c", "raylib.h" } }
} }
local objs = c.compile(src, table.concat({ "-D" .. vars.PLATFORM, "-D" .. vars.GRAPHICS, include_paths }, " ")) local objs = c.compile(src, flags, "raylib", cc)
local libraylib = c.lib("libraylib.a", objs) local libraylib = c.lib("libraylib.a", objs, "raylib")
libraylib:wait()
if future then
future:resolve()
end