mame/3rdparty/genie/scripts/embed.lua
Julian Sikorski 1a5ac25f61 Sync with GENie upstream revision ce9f3c5 (#6262)
* Change makerules to take variable $(PROJECT_TYPE) instead of hardcoded 'gmake'

This allows to run `make projgen PROJECT_TYPE=ninja` to generate ninja build files instead.
and to build GENie using ninja by running `make release PROJECT_TYPE=ninja`.

Using ninja improves build times,
e.g. for macOS: 12.47s with gmake goes down to 2.05s with ninja.

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Set prefer project set as solution.startproject as default target

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Adding `GenerateMapFiles` flag.

Causes Visual Studio's linker to generate .map files for that
configuration.

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Add ninja support for 'wholearchive' libraries

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Fixup ninja.esc to gracefully ignore nil passed as value

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Use -Wl,-force_load for wholearchive libs when building for macosx

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Updated README.

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Add space after filename in 'Generating' message

This makes the filename 'clickable' to open in iTerm and VSCode

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Print generated filenames as quoted string

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Remove '...' after filename

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Pop cwd after pushing to run file

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Make paths in embed.lua rely on script dir

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Updated README.

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Fix issues caused by make-4.3 no longer adding spaces to variables in some cases The fix was found by @asavah.

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Fixed release script.

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Updated README.

Signed-off-by: Julian Sikorski <belegdol+github@gmail.com>

* Update scripts.c

Co-authored-by: Christian Helmich <kagekirin@gmail.com>
Co-authored-by: Johan Sköld <johan@skold.cc>
Co-authored-by: Бранимир Караџић <branimirkaradzic@gmail.com>
2020-02-06 12:49:15 +11:00

98 lines
2.4 KiB
Lua

--
-- 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