2008-06-17 18:45:11 +00:00
|
|
|
project.name = "Premake4"
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
project.configs = { "Release", "Debug" }
|
|
|
|
|
2008-06-17 18:45:11 +00:00
|
|
|
-- Output directories
|
|
|
|
|
|
|
|
project.config["Debug"].bindir = "bin/debug"
|
|
|
|
project.config["Release"].bindir = "bin/release"
|
|
|
|
|
|
|
|
|
|
|
|
-- Packages
|
|
|
|
|
|
|
|
dopackage("src")
|
|
|
|
|
|
|
|
|
|
|
|
-- Cleanup code
|
|
|
|
|
|
|
|
function doclean(cmd, arg)
|
|
|
|
docommand(cmd, arg)
|
|
|
|
os.rmdir("bin")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
-- Functions copied from Premake4; can drop them once I'm self-hosting
|
2008-06-17 18:45:11 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
path = { }
|
2008-06-17 18:45:11 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
function string.findlast(s, pattern, plain)
|
|
|
|
local curr = 0
|
|
|
|
repeat
|
|
|
|
local next = s:find(pattern, curr + 1, plain)
|
|
|
|
if (next) then curr = next end
|
|
|
|
until (not next)
|
|
|
|
if (curr > 0) then
|
|
|
|
return curr
|
|
|
|
end
|
|
|
|
end
|
2008-06-17 18:45:11 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
function path.getbasename(p)
|
|
|
|
local fn = path.getname(p)
|
|
|
|
local i = fn:findlast(".", true)
|
|
|
|
if (i) then
|
|
|
|
return fn:sub(1, i - 1)
|
|
|
|
else
|
|
|
|
return fn
|
2008-06-17 18:45:11 +00:00
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function path.getname(p)
|
|
|
|
local i = p:findlast("/", true)
|
|
|
|
if (i) then
|
|
|
|
return p:sub(i + 1)
|
|
|
|
else
|
|
|
|
return p
|
2008-06-17 18:45:11 +00:00
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
end
|
2008-06-17 18:45:11 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- Compile scripts to bytecodes
|
|
|
|
|
|
|
|
function dumpfile(out, filename)
|
|
|
|
local func = loadfile(filename)
|
|
|
|
local dump = string.dump(func)
|
|
|
|
local len = string.len(dump)
|
|
|
|
out:write("\t\"")
|
|
|
|
for i=1,len do
|
|
|
|
out:write(string.format("\\%03o", string.byte(dump, i)))
|
2008-06-17 18:45:11 +00:00
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
out:write("\",\n")
|
|
|
|
return len
|
|
|
|
end
|
2008-06-17 18:45:11 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
function dumptmpl(out, filename)
|
|
|
|
local f = io.open(filename)
|
|
|
|
local tmpl = f:read("*a")
|
|
|
|
f:close()
|
|
|
|
|
|
|
|
local name = path.getbasename(filename)
|
|
|
|
local dump = "_TEMPLATES."..name.."=premake.template.loadstring('"..name.."',[["..tmpl.."]])"
|
|
|
|
local len = string.len(dump)
|
|
|
|
out:write("\t\"")
|
|
|
|
for i=1,len do
|
|
|
|
out:write(string.format("\\%03o", string.byte(dump, i)))
|
2008-06-17 18:45:11 +00:00
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
out:write("\",\n")
|
|
|
|
return len
|
|
|
|
end
|
|
|
|
|
|
|
|
function docompile(cmd, arg)
|
|
|
|
local sizes = { }
|
|
|
|
|
|
|
|
scripts, templates, actions = dofile("src/_manifest.lua")
|
|
|
|
|
|
|
|
local out = io.open("src/host/bytecode.c", "w+b")
|
|
|
|
out:write("/* Precompiled bytecodes for built-in Premake scripts */\n")
|
|
|
|
out:write("/* To regenerate this file, run `premake --compile` (Premake 3.x) */\n\n")
|
|
|
|
|
|
|
|
out:write("const char* builtin_bytecode[] = {\n")
|
2008-06-17 18:45:11 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
for i,fn in ipairs(scripts) do
|
|
|
|
print(fn)
|
|
|
|
s = dumpfile(out, "src/"..fn)
|
|
|
|
table.insert(sizes, s)
|
2008-06-17 18:45:11 +00:00
|
|
|
end
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
for i,fn in ipairs(templates) do
|
|
|
|
print(fn)
|
|
|
|
s = dumptmpl(out, "src/"..fn)
|
|
|
|
table.insert(sizes, s)
|
|
|
|
end
|
2008-06-17 18:45:11 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
for i,fn in ipairs(actions) do
|
|
|
|
print(fn)
|
|
|
|
s = dumpfile(out, "src/"..fn)
|
|
|
|
table.insert(sizes, s)
|
2008-06-17 18:45:11 +00:00
|
|
|
end
|
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
out:write("};\n\n");
|
|
|
|
out:write("int builtin_sizes[] = {\n")
|
|
|
|
|
|
|
|
for i,v in ipairs(sizes) do
|
|
|
|
out:write("\t"..v..",\n")
|
2008-06-17 18:45:11 +00:00
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
out:write("\t0\n};\n");
|
|
|
|
out:close()
|
2008-06-17 18:45:11 +00:00
|
|
|
|
2008-10-31 18:38:05 +00:00
|
|
|
print("Done.")
|
2008-06-17 18:45:11 +00:00
|
|
|
end
|