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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
-- data compiler
dc_compiler = "python scripts/compiler.py"
if family == "windows" then
dc_compiler = "scripts\\compiler.py"
end
dat2c_compiler = "python scripts/dat2c.py"
if family == "windows" then
dat2c_compiler = "scripts\\dat2c.py"
end
cmd5_tool = "python scripts/cmd5.py"
if family == "windows" then
cmd5_tool = "scripts\\cmd5.py"
end
function rc(output, input)
print("rc " .. PathFilename(input))
return os.execute("rc /fo " .. output .. " " .. input)
end
function cmd5(output, inputs)
print("cmd5 " .. PathFilename(output))
cmd = cmd5_tool .. " "
for i,v in inputs do
cmd = cmd .. v .. " "
end
cmd = cmd .. " > " .. output
return os.execute(cmd)
end
function dat2c(output, data, name)
print("dat2c " .. PathFilename(output) .. " = " .. PathFilename(data))
return os.execute(dat2c_compiler .. " " .. data .. " " .. name .. " > " .. output)
end
function dc_header(output, data, script)
print("dc_header " .. PathFilename(output) .. " = " .. PathFilename(data) .. " ~ " .. PathFilename(script))
return os.execute(dc_compiler .. " " .. data .. " " .. script .. " -h " .. output)
end
function dc_source(output, data, script, headerfile)
print("dc_source " .. PathFilename(output) .. "+" .. PathFilename(headerfile) .. " = " .. PathFilename(data) .. " ~ " .. PathFilename(script))
cmd = dc_compiler .. " " .. data .. " " .. script .. " -s " .. output .. " " .. headerfile
return os.execute(cmd)
end
function dc_data(output, data, script)
print("dc_data " .. PathFilename(output) .. " = " .. PathFilename(data) .. " ~ " .. PathFilename(script))
return os.execute(dc_compiler .. " " .. data .. " " .. script .. " -d " .. output)
end
function dc_cdata(output, data, script)
print("dc_cdata " .. PathFilename(output) .. " = " .. PathFilename(data) .. " ~ " .. PathFilename(script))
return os.execute(dc_compiler .. " " .. data .. " " .. script .. " -c " .. output)
end
function CHash(output, ...)
local inputs = {}
local ih = collect_input(arg)
output = Path(output)
-- compile all the files
for index, inname in ih do
table.insert(inputs, Path(inname))
end
bam_add_job("cmd5", output, inputs)
for index, inname in inputs do
bam_add_dependency(output, inname)
end
return output
end
function ResCompile(scriptfile)
scriptfile = Path(scriptfile)
output = PathBase(scriptfile) .. ".res"
bam_add_job("rc", output, scriptfile)
bam_add_dependency(output, scriptfile)
return output
end
function Dat2c(datafile, sourcefile, arrayname)
datafile = Path(datafile)
sourcefile = Path(sourcefile)
bam_add_job("dat2c", sourcefile, datafile, arrayname)
bam_add_dependency(sourcefile, datafile)
return sourcefile
end
function DataCompile(datafile, scriptfile, headerfile, sourcefile, outputdatafile)
datafile = Path(datafile)
scriptfile = Path(scriptfile)
headerfile = Path(headerfile)
bam_add_job("dc_header", headerfile, datafile, scriptfile)
bam_add_dependency(headerfile, datafile)
bam_add_dependency(headerfile, scriptfile)
if sourcefile then
sourcefile = Path(sourcefile)
bam_add_job("dc_source", sourcefile, datafile, scriptfile, headerfile)
bam_add_dependency(sourcefile, datafile)
bam_add_dependency(sourcefile, scriptfile)
bam_add_dependency(sourcefile, headerfile)
end
if outputdatafile then
outputdatafile = Path(outputdatafile)
bam_add_job("dc_cdata", outputdatafile, datafile, scriptfile)
bam_add_dependency(outputdatafile, datafile)
bam_add_dependency(outputdatafile, scriptfile)
end
return {cdata = outputdatafile, header=headerfile, source=sourcefile}
end
serverdata = DataCompile(
"datasrc/teewars.ds",
"datasrc/server.dts",
"src/game/generated/gs_data.h",
"src/game/generated/gs_data.cpp",
"src/game/generated/gs_internaldata.cpp")
clientdata = DataCompile(
"datasrc/teewars.ds",
"datasrc/client.dts",
"src/game/generated/gc_data.h",
"src/game/generated/gc_data.cpp",
"src/game/generated/gc_internaldata.cpp")
networkdata = DataCompile(
"datasrc/teewars.ds",
"datasrc/network.dts",
"src/game/generated/g_protocol_ids.h",
"src/game/generated/g_protocol_ids.cpp")
nethash = CHash(
"src/game/generated/nethash.c",
"src/engine/e_protocol.h",
"src/game/g_protocol.h",
"src/game/g_tuning.h",
"src/game/g_game.cpp", networkdata.header)
client_link_other = {}
if family == "windows" then
client_link_other = {ResCompile("other/icons/teewars.rc")}
end
-- [TODO: Should be in C]
function file_ext(s)
for ext in string.gfind(s, "%.%a+$") do
return string.sub(ext, 2)
end
return ""
end
function intermediate_output_func(dir, input, extension)
if not (dir == "") then
return Path(dir .. "/" .. PathBase(PathFilename(input)) .. extension)
end
return PathBase(input) .. extension
end
function build(settings)
settings.objdir = Path("objs")
settings.cc.output = intermediate_output_func
if family == "windows" then
settings.cc.flags = "/wd4244"
else
settings.cc.flags = "-Wall -fstack-protector -fstack-protector-all"
settings.linker.flags = ""
end
-- set some platform specific settings
settings.cc.includes:add("src")
settings.cc.includes:add("src/external/zlib")
if family == "unix" then
if platform == "macosx" then
glfw_platform = "macosx"
else
glfw_platform = "x11"
settings.linker.libs:add("pthread")
end
elseif family == "windows" then
glfw_platform = "win32"
settings.linker.libs:add("gdi32.lib")
settings.linker.libs:add("user32.lib")
settings.linker.libs:add("ws2_32.lib")
settings.linker.libs:add("ole32.lib")
settings.linker.libs:add("shell32.lib")
end
-- build glfw
glfw_settings = settings:copy()
glfw_settings.cc.includes:add("src/external/glfw/include")
glfw_settings.cc.includes:add("src/engine/external/glfw/lib")
glfw_settings.cc.includes:add("src/engine/external/glfw/lib/" .. glfw_platform)
glfw = Compile(glfw_settings, Collect(
"src/engine/external/glfw/lib/*.c",
"src/engine/external/glfw/lib/" .. glfw_platform .. "/*.c"))
-- build teewars components
engine_settings = settings:copy()
if family == "windows" then
engine_settings.cc.flags = "/wd4244"
else
if platform == "macosx" then
engine_settings.cc.flags = "-Wall"
else
engine_settings.cc.flags = "-Wall -pedantic-errors"
end
engine_settings.linker.flags = ""
end
-- server
server_settings = engine_settings:copy()
-- client
client_settings = engine_settings:copy()
client_settings.cc.includes:add("src/external/glfw/include")
if family == "unix" then
if platform == "macosx" then
client_settings.linker.frameworks:add("OpenGL")
client_settings.linker.frameworks:add("AGL")
client_settings.linker.frameworks:add("Carbon")
client_settings.linker.frameworks:add("Cocoa")
client_settings.linker.frameworks:add("CoreAudio")
client_settings.linker.frameworks:add("AudioToolbox")
client_settings.linker.frameworks:add("AudioUnit")
else
client_settings.linker.libs:add("asound")
client_settings.linker.libs:add("X11")
client_settings.linker.libs:add("GL")
client_settings.linker.libs:add("GLU")
end
elseif family == "windows" then
client_settings.linker.libs:add("opengl32.lib")
client_settings.linker.libs:add("glu32.lib")
client_settings.linker.libs:add("dsound.lib")
end
external_settings = settings:copy()
zlib = Compile(external_settings, Collect("src/engine/external/zlib/*.c"))
wavpack = Compile(external_settings, Collect("src/engine/external/wavpack/*.c"))
pnglite = Compile(external_settings, Collect("src/engine/external/pnglite/*.c"))
portaudio = Compile(external_settings, Collect("src/engine/external/pa.c"))
engine = Compile(engine_settings, Collect("src/engine/*.c"))
client = Compile(client_settings, Collect("src/engine/client/*.c"))
server = Compile(server_settings, Collect("src/engine/server/*.c"))
masterserver = Compile(settings, Collect("src/mastersrv/*.cpp"))
game_shared = Compile(settings, Collect("src/game/*.cpp"), nethash)
game_client = Compile(settings, Collect("src/game/client/*.cpp"), clientdata.source, clientdata.cdata)
game_server = Compile(settings, Collect("src/game/server/*.cpp"), serverdata.source, serverdata.cdata)
game_editor = Compile(settings, Collect("src/game/editor/*.cpp"))
if platform == "macosx" then
osxlaunch = Compile(settings, Collect("src/osxlaunch/*.m"))
end
-- build tools (TODO: fix this so we don't get double _d_d stuff)
tools_src = Collect("src/tools/*.cpp", "src/tools/*.c")
objs = Compile(settings, tools_src)
tools = {}
for i,v in objs do
toolname = PathFilename(PathBase(v))
tools[i] = Link(settings, toolname, v, engine, zlib)
end
-- build client, server and master server
client_exe = Link(client_settings, "teewars", game_shared, game_client,
engine, client, game_editor, glfw, portaudio, zlib, pnglite, wavpack,
client_link_other)
server_exe = Link(server_settings, "teewars_srv", engine, server,
game_shared, game_server, zlib)
masterserver_exe = Link(server_settings, "mastersrv", masterserver,
engine, zlib)
if platform == "macosx" then
osxlaunch_exe = Link(client_settings, "TeeLaunch", osxlaunch)
end
-- make targets
c = PseudoTarget("client".."_"..settings.config_name, client_exe)
s = PseudoTarget("server".."_"..settings.config_name, server_exe)
m = PseudoTarget("masterserver".."_"..settings.config_name, masterserver_exe)
t = PseudoTarget("tools".."_"..settings.config_name, tools)
Target(c)
Target(s)
Target(m)
Target(t)
if platform == "macosx" then
o = PseudoTarget("TeeLaunch".."_"..settings.config_name, osxlaunch_exe)
all = PseudoTarget(settings.config_name, c, s, m, t, o)
else
all = PseudoTarget(settings.config_name, c, s, m, t)
end
Target(all)
return all
end
debug_settings = NewSettings()
debug_settings.config_name = "debug"
debug_settings.config_ext = "_d"
debug_settings.debug = 1
debug_settings.cc.optimize = 0
release_settings = NewSettings()
release_settings.config_name = "release"
release_settings.config_ext = ""
release_settings.debug = 0
release_settings.cc.optimize = 1
DefaultTarget(build(debug_settings))
build(release_settings)
|