-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathrelease.lua
More file actions
164 lines (133 loc) · 4.59 KB
/
release.lua
File metadata and controls
164 lines (133 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
--[[
release.lua
Prepares a public release
Use 'premake5 --file=release.lua --help' for help
--]]
newaction {
trigger = "prepare",
description = "Automatically makes 'n builds a release build, preparing it to be zipped into a public release",
execute = function() main() end
}
newoption {
trigger = "toolset",
value = "tools",
description = "The toolset used to compile the release build (vs20xx or gcc)",
}
newoption {
trigger = "final-release",
description = "Public release build."
}
toolset = _OPTIONS["toolset"]
final_flag = _OPTIONS["final-release"] and " --final-release" or ""
action = (toolset == "gcc" and "gmake" or toolset)
compiler = (toolset == "gcc" and "gcc" or "cl")
build = (toolset == "gcc" and "make" or "msbuild")
function main()
if not toolset then
print("No toolset defined.\nAborting.")
exit()
end
if toolset ~= "gcc" and not toolset:match("^vs") then
print("Unsupported toolset '" .. toolset .. "' (use a vs* premake action or gcc).\nAborting.")
exit()
end
require_tools()
local install = function()
print "Making release directory tree..."
execute("premake5 install ./release/binaries/")
os.copyfile("./release/binaries/modloader/.data/Readme.md", "./release/binaries/Readme.txt")
os.copyfile("./release/binaries/modloader/.data/Leia-me.md", "./release/binaries/Leia-me.txt")
os.mkdir("./release/binaries/modloader/.profiles")
end
print "Cleaning workspace..."
execute("premake5 clean")
print "Generating build files..."
if toolset == "gcc" then
execute(string.format("premake5 %s --cc=%s --outdir=build_temp%s", action, compiler, final_flag))
else
execute(string.format("premake5 %s --outdir=build_temp%s", action, final_flag))
end
print "Building..."
if build == "msbuild" then
-- also use 'set CL=/MP' at release.bat
execute("msbuild build_temp/modloader.sln /p:configuration=Release /p:platform=Win32 /m")
install()
pdbpackage()
elseif compiler == "gcc" then
local cwd = os.getcwd()
os.chdir("build_temp")
execute("mingw32-make CC=gcc")
os.chdir(cwd)
-- Strip binaries (ALWAYS)
gccstrip()
-- striping is not related to symbols, to have symbols send --export-all-symbols to the linker
install()
else
print("Internal error")
exit()
end
os.rmdir("build_temp")
end
function pdbpackage()
print("Packaging stripped debug symbols (release/symbols/)...")
os.mkdir("release/symbols")
os.mkdir("release/symbols/modloader/.data/plugins/gta3")
execute('pdbcopy "bin/modloader.pdb" "release/symbols/modloader.pdb" -p')
for i, file in ipairs(os.matchfiles("bin/plugins/gta3/*.pdb")) do
local name = path.getname(file)
execute(string.format(
'pdbcopy "bin/plugins/gta3/%s" "release/symbols/modloader/.data/plugins/gta3/%s" -p',
name, name
))
end
end
function gccstrip()
print "Stripping GCC symbols..."
local cwd = os.getcwd()
os.chdir("bin")
for i, file in ipairs(os.matchfiles("*.asi")) do
execute(string.format([[strip "%s"]], file))
end
for i, file in ipairs(os.matchfiles("**.dll")) do
execute(string.format([[strip "%s"]], file))
end
os.chdir(cwd)
end
function require_tools()
require_on_path("premake5",
"Install Premake 5 and add it to PATH.")
if build == "msbuild" then
require_on_path("msbuild",
"Install Visual Studio with MSBuild, then run this from the x86 Native Tools Command Prompt.")
require_on_path("pdbcopy",
"Install the Debugging Tools for Windows component from the Windows SDK," ..
" then add %ProgramFiles(x86)%\\Windows Kits\\10\\Debuggers\\x86 to PATH.")
elseif compiler == "gcc" then
require_on_path("mingw32-make",
"Install MinGW and add mingw32-make to PATH.")
end
end
function require_on_path(name, hint)
if not os.ishost("windows") then
return
end
local found = os.outputof("where " .. name .. " 2>nul")
if not found or found == "" then
print("Error: " .. name .. " is not on PATH.")
if hint then
print(hint)
end
exit()
end
end
function execute(command)
local result = os.execute(command)
if result == 0 or result == true then
return
end
print("Command failed: " .. command .. "\nAborting.")
exit()
end
function exit()
os.exit()
end