Initial community commit

This commit is contained in:
Jef 2024-09-24 14:54:57 +02:00
parent 537bcbc862
commit fc06254474
16440 changed files with 4239995 additions and 2 deletions

View file

@ -0,0 +1,98 @@
--
-- Embed the Lua scripts into src/host/scripts.c as static data buffers.
-- I embed the actual scripts, rather than Lua bytecodes, because the
-- bytecodes are not portable to different architectures, which causes
-- issues in Mac OS X Universal builds.
--
local scriptdir = path.getdirectory(_SCRIPT)
local function stripfile(fname)
local f = io.open(fname)
local s = assert(f:read("*a"))
f:close()
-- strip tabs
s = s:gsub("[\t]", "")
-- strip any CRs
s = s:gsub("[\r]", "")
-- strip out comments
s = s:gsub("\n%-%-[^\n]*", "")
-- escape backslashes
s = s:gsub("\\", "\\\\")
-- strip duplicate line feeds
s = s:gsub("\n+", "\n")
-- strip out leading comments
s = s:gsub("^%-%-\n", "")
-- escape line feeds
s = s:gsub("\n", "\\n")
-- escape double quote marks
s = s:gsub("\"", "\\\"")
return s
end
local function writeline(out, s, continues)
out:write("\t\"")
out:write(s)
out:write(iif(continues, "\"\n", "\",\n"))
end
local function writefile(out, fname, contents)
local max = 1024
out:write("\t/* " .. fname .. " */\n")
-- break up large strings to fit in Visual Studio's string length limit
local start = 1
local len = contents:len()
while start <= len do
local n = len - start
if n > max then n = max end
local finish = start + n
-- make sure I don't cut an escape sequence
while contents:sub(finish, finish) == "\\" do
finish = finish - 1
end
writeline(out, contents:sub(start, finish), finish < len)
start = finish + 1
end
out:write("\n")
end
function doembed()
-- load the manifest of script files
scripts = dofile(path.join(scriptdir, "../src/_manifest.lua"))
-- main script always goes at the end
table.insert(scripts, "_premake_main.lua")
-- open scripts.c and write the file header
local out = io.open(path.join(scriptdir, "../src/host/scripts.c"), "w+b")
out:write("/* Premake's Lua scripts, as static data buffers for release mode builds */\n")
out:write("/* DO NOT EDIT - this file is autogenerated - see BUILD.txt */\n")
out:write("/* To regenerate this file, run: premake4 embed */ \n\n")
out:write("const char* builtin_scripts[] = {\n")
for i,fn in ipairs(scripts) do
print(fn)
local s = stripfile(path.join(scriptdir,"../src/" .. fn))
writefile(out, fn, s)
end
out:write("\t0\n};\n");
out:close()
end

View file

@ -0,0 +1,144 @@
--
-- Premake 4.x build configuration script
--
--
-- Define the project. Put the release configuration first so it will be the
-- default when folks build using the makefile. That way they don't have to
-- worry about the /scripts argument and all that.
--
premake.make.override = { "TARGET" }
solution "genie"
configurations {
"Release",
"Debug"
}
location (_OPTIONS["to"])
project "genie"
targetname "genie"
language "C"
kind "ConsoleApp"
flags {
"ExtraWarnings",
"No64BitChecks",
"StaticRuntime"
}
includedirs {
"../src/host/lua-5.3.0/src"
}
files {
"../**.lua",
"../src/**.h",
"../src/**.c",
"../src/host/scripts.c",
}
excludes {
"../src/premake.lua",
"../src/host/lua-5.3.0/src/lua.c",
"../src/host/lua-5.3.0/src/luac.c",
"../src/host/lua-5.3.0/**.lua",
"../src/host/lua-5.3.0/etc/*.c",
}
buildoptions {
"-m64",
}
configuration "Debug"
defines { "_DEBUG", "LUA_COMPAT_MODULE" }
flags { "Symbols" }
configuration "Release"
defines { "NDEBUG", "LUA_COMPAT_MODULE" }
flags { "OptimizeSize" }
configuration "vs*"
defines { "_CRT_SECURE_NO_WARNINGS" }
configuration "windows"
targetdir "../bin/windows"
links { "ole32" }
configuration "linux"
targetdir "../bin/linux"
links { "dl" }
configuration "bsd"
targetdir "../bin/bsd"
configuration "linux or bsd"
defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" }
buildoptions { "-Wno-implicit-fallthrough" }
links { "m" }
linkoptions { "-rdynamic" }
configuration "macosx"
targetdir "../bin/darwin"
defines { "LUA_USE_MACOSX" }
links { "CoreServices.framework" }
configuration { "macosx", "gmake" }
buildoptions { "-mmacosx-version-min=10.6" }
linkoptions { "-mmacosx-version-min=10.6" }
configuration {}
--
-- A more thorough cleanup.
--
if _ACTION == "clean" then
os.rmdir("bin")
os.rmdir("build")
end
--
-- Use the --to=path option to control where the project files get generated. I use
-- this to create project files for each supported toolset, each in their own folder,
-- in preparation for deployment.
--
newoption {
trigger = "to",
value = "path",
description = "Set the output location for the generated files"
}
--
-- Use the embed action to convert all of the Lua scripts into C strings, which
-- can then be built into the executable. Always embed the scripts before creating
-- a release build.
--
dofile("embed.lua")
newaction {
trigger = "embed",
description = "Embed scripts in scripts.c; required before release builds",
execute = doembed
}
--
-- Use the release action to prepare source and binary packages for a new release.
-- This action isn't complete yet; a release still requires some manual work.
--
dofile("release.lua")
newaction {
trigger = "release",
description = "Prepare a new release (incomplete)",
execute = dorelease
}

View file

@ -0,0 +1,47 @@
function dorelease()
--
-- Helper function: runs a command (formatted, with optional arguments) and
-- suppresses any output. Works on both Windows and POSIX. Might be a good
-- candidate for a core function.
--
local function exec(cmd, ...)
cmd = string.format(cmd, ...)
local z = os.execute(cmd .. " > output.log 2> error.log")
os.remove("output.log")
os.remove("error.log")
return z
end
print("Updating version number...")
local f = io.popen("git rev-list --count HEAD")
local rev = string.match(f:read("*a"), ".*%S")
f:close()
f = io.popen("git log --format=format:%H -1")
local sha1 = f:read("*a")
f:close()
io.output("src/host/version.h")
io.write("#define VERSION " ..rev .. "\n")
io.write("#define VERSION_STR \"version " ..rev .. " (commit " .. sha1 .. ")\"\n")
io.close()
print("Updating embedded scripts...")
local z = exec(_PREMAKE_COMMAND .. " embed")
if z ~= true then
error("** Failed to update the embedded scripts", 0)
end
print("Generating project files...")
exec(_PREMAKE_COMMAND .. " /to=../build/gmake.windows /os=windows gmake")
exec(_PREMAKE_COMMAND .. " /to=../build/gmake.linux /os=linux gmake")
exec(_PREMAKE_COMMAND .. " /to=../build/gmake.darwin /os=macosx /platform=universal32 gmake")
print("")
print( "Finished.")
end