about summary refs log tree commit diff
path: root/default.bam
blob: 3c6c285e15445c3840c574ef9d231d04742406cb (plain)
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
CheckVersion("0.1")

--- Setup Config --------
config = NewConfig()
config:add(OptFindCompiler())
config:add(OptTestCompileC("stackprotector", "int main(){return 0;}", "-fstack-protector -fstack-protector-all"))
config:add(OptFindLibrary("zlib", "zlib.h", false))
config:add(OptFindLibrary("glfw", "glfw.h", false))
config:add(OptFindLibrary("portaudio", "portaudio.h_FAIL", false))

config:add(OptFindLibrary("coreaudio", "AudioUnit/AudioUnit.h", false))
config:add(OptFindLibrary("alsa", "alsa/asoundlib.h", false))
config:add(OptFindLibrary("oss_sys", "sys/soundcard.h", false))
config:add(OptFindLibrary("oss_linux", "linux/soundcard.h", false))
config:add(OptFindLibrary("oss_machine", "machine/soundcard.h", false))
config:add(OptFindLibrary("dsound", "dsound.h", true))

function OptFindSDL(name, required)
	local check = function(option)
		option.value = nil
		option.use_sdlconfig = nil
		option.use_win32sdl = nil
		option.lib_path = nil
		
		if ExecuteSilent("sdl-config") > 0 and ExecuteSilent("sdl-config --cflags") == 0 then
			option.value = 1
			option.use_sdlconfig = 1
		end
		
		if platform == "win32" then
			option.value = 1
			option.use_win32sdl = 1
		end
		
		if platform == "macosx" then
			option.value = 1
		end
	end
	
	local apply = function(option, settings)
		if option.use_sdlconfig then
			settings.cc.flags = settings.cc.flags .. " -I/usr/include/SDL "
			settings.linker.flags = settings.linker.flags .. " `sdl-config --libs` "
		else
			if platform == "macosx" then
				client_settings.linker.frameworks:add("SDL")
				client_settings.cc.includes:add("/Library/Frameworks/SDL.framework/Headers")
			end
		end

		if option.use_win32sdl then
			settings.cc.includes:add("other/sdl_include")
			settings.linker.libpath:add("other/vc2005_sdllibs")
			settings.linker.libs:add("SDL")
			settings.linker.libs:add("SDLmain")
		end
	end
	
	local save = function(option, output)
		output:option(option, "value")
		output:option(option, "use_sdlconfig")
		output:option(option, "use_win32sdl")
	end
	
	local display = function(option)
		if option.value then
			if option.use_sdlconfig then
				return "using sdl-config"
			end
			if option.use_win32sdl then
				return "using supplied win32 libraries"
			end
		else
			if option.required then
				return "not found (required)"
			else
				return "not found (optional)"
			end
		end
	end
	
	local o = MakeOption(name, 0, check, save, display)
	o.apply = apply
	o.include_path = nil
	o.lib_path = nil
	o.required = required
	return o
end

config:add(OptFindSDL("sdl", false))


--- Auto detect ------
if not config:load("config.bam") then
	print("--- Auto Configuration ---")
	config:autodetect()
	config:save("config.bam")
	print("--- ")
end

-- data compiler
function Script(name)
	if family == "windows" then
		return str_replace(name, "/", "\\")
	end
	return "python " .. name
end

--dc_compiler = Script("scripts/compiler.py")
--netobj_compiler = Script("scripts/netobj.py")
dat2c_compiler = Script("scripts/dat2c.py")
cmd5_tool = Script("scripts/cmd5.py")
content_compiler = Script("datasrc/compile.py")

function CHash(output, ...)
	local inputs = {}
	local ih = collect_input(arg)
	
	output = Path(output)
	
	-- compile all the files
	local cmd = cmd5_tool .. " "
	for index, inname in ih do
		cmd = cmd .. Path(inname) .. " " 
	end
	
	cmd = cmd .. " > " .. output
	
	bam_add_job(output, "cmd5 " .. output, cmd)
	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(output, "rc " .. scriptfile, "rc /fo " .. output .. " " .. scriptfile)
	bam_add_dependency(output, scriptfile)
	return output
end

function Dat2c(datafile, sourcefile, arrayname)
	datafile = Path(datafile)
	sourcefile = Path(sourcefile)

	bam_add_job(
		sourcefile,
		"dat2c " .. PathFilename(sourcefile) .. " = " .. PathFilename(datafile),
		dat2c_compiler .. " " .. datafile .. " " .. arrayname .. " > " .. sourcefile
	)
	bam_add_dependency(sourcefile, datafile)
	return sourcefile
end

function ContentCompile(action, output)
	output = Path(output)
	bam_add_job(
		output,
		action .. " > " .. output,
		Script("datasrc/compile.py") .. " " .. action .. " > " .. Path(output)
	)
	bam_add_dependency(output, Path("datasrc/content.py")) -- do this more proper
	bam_add_dependency(output, Path("datasrc/network.py"))
	bam_add_dependency(output, Path("datasrc/compile.py"))
	bam_add_dependency(output, Path("datasrc/datatypes.py"))
	return output
end

-- Content Compile
network_source = ContentCompile("network_source", "src/game/generated/g_protocol.cpp")
network_header = ContentCompile("network_header", "src/game/generated/g_protocol.hpp")
client_content_source = ContentCompile("client_content_source", "src/game/generated/gc_data.cpp")
client_content_header = ContentCompile("client_content_header", "src/game/generated/gc_data.hpp")
server_content_source = ContentCompile("server_content_source", "src/game/generated/gs_data.cpp")
server_content_header = ContentCompile("server_content_header", "src/game/generated/gs_data.hpp")

bam_add_dependency(network_source, network_header)
bam_add_dependency(client_content_source, client_content_header)
bam_add_dependency(server_content_source, server_content_header)

nethash = CHash(
	"src/game/generated/nethash.c",
	"src/engine/e_protocol.h",
	"src/game/generated/g_protocol.hpp",
	"src/game/tuning.hpp",
	"src/game/gamecore.cpp", network_header)

client_link_other = {}
if config.compiler.value == "cl" then
	client_link_other = {ResCompile("other/icons/teeworlds.rc")}
end

function intermediate_output_func(dir, input, settings)
	if not (dir == "") then
		return Path(dir .. "/" .. PathBase(PathFilename(input)) .. settings.config_ext)
	end
	return PathBase(input) .. settings.config_ext
end

function build(settings)
	settings.objdir = Path("objs")
	settings.cc.output = intermediate_output_func
	
	use_sdl = config.sdl.value
	if use_sdl == 0 then use_sdl = nil end
	
	if config.compiler.value == "cl" then
		settings.cc.flags = "/wd4244"
		settings.linker.flags = ""
	else
		settings.cc.flags = "-Wall -fno-exceptions "
		settings.linker.flags = ""
		if platform == "macosx" then
			settings.cc.flags = settings.cc.flags .. " -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
			settings.linker.flags = settings.linker.flags .. " -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
		elseif config.stackprotector.value == 1 then
			settings.cc.flags = settings.cc.flags .. " -fstack-protector -fstack-protector-all"
		end
	end

	-- set some platform specific settings
	settings.cc.includes:add("src")

	if family == "unix" then
   		if platform == "macosx" then
			glfw_platform = "macosx"
			pa_platform = "mac_osx"
			settings.linker.frameworks:add("Carbon")
			settings.linker.frameworks:add("AppKit")
		else
			glfw_platform = "x11"
			pa_platform = "unix"
			settings.linker.libs:add("pthread")
		end
	elseif family == "windows" then
		glfw_platform = "win32"
		pa_platform = "win"
		settings.linker.libs:add("gdi32")
		settings.linker.libs:add("user32")
		settings.linker.libs:add("ws2_32")
		settings.linker.libs:add("ole32")
		settings.linker.libs:add("shell32")
	end
	
	if use_sdl then
		glfw = {}
		portaudio = {}
	else
		settings.cc.defines:add("CONFIG_NO_SDL")
		
		-- build glfw if needed (not tested)
		if config.glfw.value == 1 then
			settings.linker.libs:add("glfw")
			if config.glfw.include_path then
				settings.cc.includes:add(config.glfw.include_path)
			end
			glfw = {}
		else
			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"))
			
			settings.cc.includes:add("src/engine/external/glfw/include")
		end

		-- build portaudio
		if config.portaudio.value == 1 then
			settings.linker.libs:add("portaudio")
			if config.portaudio.include_path then
				settings.cc.includes:add(config.portaudio.include_path)
			end
			portaudio = {}
		else
			pa_settings = settings:copy()

			pa_hostapis = {}		
			if config.alsa.value == 1 then pa_hostapis["alsa"] = 1 end
			if config.dsound.value == 1 then
				pa_hostapis["dsound"] = 1
			else
				pa_settings.cc.defines:add("PA_NO_DS")
			end
			if config.coreaudio.value == 1 then pa_hostapis["coreaudio"] = 1 end
			
			if config.oss_sys.value == 1 then
				pa_hostapis["oss"] = 1
				pa_settings.cc.defines:add("HAVE_SYS_SOUNDCARD_H")
			elseif config.oss_linux.value == 1 then
				pa_hostapis["oss"] = 1
				pa_settings.cc.defines:add("HAVE_LINUX_SOUNDCARD_H")
			elseif config.oss_machine.value == 1 then
				pa_hostapis["oss"] = 1
				pa_settings.cc.defines:add("HAVE_MACHINE_SOUNDCARD_H")
			end
			
			pa_settings.cc.defines:add("PA_NO_WMME")
			pa_settings.cc.defines:add("PA_NO_ASIO")
			pa_settings.cc.includes:add("src/engine/external/portaudio/include")
			pa_settings.cc.includes:add("src/engine/external/portaudio/src/common")
			pa_settings.cc.includes:add("src/engine/external/portaudio/src/os/" .. pa_platform)
			
			pa_api_files = {}
			for api,v in pa_hostapis do
				pa_settings.cc.defines:add("PA_USE_"..string.upper(api))
				pa_api_files[api] = Collect("src/engine/external/portaudio/src/hostapi/" .. api .. "/*.c")
			end
			
			portaudio = Compile(pa_settings,
				Collect("src/engine/external/portaudio/src/common/*.c"),
				Collect("src/engine/external/portaudio/src/os/" .. pa_platform .. "/*.c"),
				pa_api_files)
			
			settings.cc.includes:add("src/engine/external/portaudio/include")
		end		
	end
	
	
	-- compile zlib if needed
	if config.zlib.value == 1 then
		settings.linker.libs:add("z")
		if config.zlib.include_path then
			settings.cc.includes:add(config.zlib.include_path)
		end
		zlib = {}
	else
		zlib = Compile(settings, Collect("src/engine/external/zlib/*.c"))
		settings.cc.includes:add("src/engine/external/zlib")
	end

	-- build the small libraries
	wavpack = Compile(settings, Collect("src/engine/external/wavpack/*.c"))
	pnglite = Compile(settings, Collect("src/engine/external/pnglite/*.c"))
	
	-- build game components
	engine_settings = settings:copy()
	
	if config.compiler.value == "cl" then
		engine_settings.cc.flags = "/wd4244"
	else
   		if platform == "macosx" then
			engine_settings.cc.flags = "-Wall -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
			engine_settings.linker.flags = "-mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
		else
			engine_settings.cc.flags = "-Wall"
			engine_settings.linker.flags = ""
		end
	end

	-- server
	server_settings = engine_settings:copy()

	-- client
	client_settings = engine_settings:copy()

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

			if config.coreaudio.value == 1 then
				client_settings.linker.frameworks:add("CoreAudio")
				client_settings.linker.frameworks:add("AudioToolbox")
				client_settings.linker.frameworks:add("AudioUnit")
			end

			if use_sdl then
				client_settings.linker.frameworks:add("SDL")
				client_settings.cc.includes:add("/Library/Frameworks/SDL.framework/Headers")
			end
		else
			if config.alsa.value == 1 then
            	client_settings.linker.libs:add("asound")
            end
            
			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")
		client_settings.linker.libs:add("glu32")
		client_settings.linker.libs:add("winmm")

		if config.dsound.value == 1 then
			client_settings.linker.libs:add("dsound")
		end
	end

	-- apply sdl settings
	if use_sdl then config.sdl:apply(client_settings) end
	
	engine = Compile(engine_settings, Collect("src/engine/*.c", "src/base/*.c"))
	client = Compile(client_settings, Collect("src/engine/client/*.c"))
	server = Compile(server_settings, Collect("src/engine/server/*.c"))
	
	versionserver = Compile(settings, Collect("src/versionsrv/*.cpp"))
	masterserver = Compile(settings, Collect("src/mastersrv/*.cpp"))
	game_shared = Compile(settings, Collect("src/game/*.cpp"), nethash, network_source)
	game_client = Compile(settings, Collect(
		"src/game/client/*.cpp",
		"src/game/client/components/*.cpp"), client_content_source)
	game_server = Compile(settings, Collect(
		"src/game/server/*.cpp",
		"src/game/server/entities/*.cpp",
		"src/game/server/gamemodes/*.cpp"), server_content_source)
	game_editor = Compile(settings, Collect("src/game/editor/*.cpp"))

	-- build tools (TODO: fix this so we don't get double _d_d stuff)
	tools_src = Collect("src/tools/*.cpp", "src/tools/*.c")

	osxlaunch = {}
	if platform == "macosx" and use_sdl then
		osxlaunch = Compile(client_settings, Collect("src/osxlaunch/*.m"))
	end
	
	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, version server and master server
	client_exe = Link(client_settings, "teeworlds", game_shared, game_client,
		engine, client, game_editor, glfw, portaudio, zlib, pnglite, wavpack,
		client_link_other, osxlaunch)

	server_exe = Link(server_settings, "teeworlds_srv", engine, server,
		game_shared, game_server, zlib)
		
	versionserver_exe = Link(server_settings, "versionsrv", versionserver,
		engine, zlib)

	masterserver_exe = Link(server_settings, "mastersrv", masterserver,
		engine, zlib)

	-- make targets
	c = PseudoTarget("client".."_"..settings.config_name, client_exe)
	s = PseudoTarget("server".."_"..settings.config_name, server_exe)
	v = PseudoTarget("versionserver".."_"..settings.config_name, versionserver_exe)
	m = PseudoTarget("masterserver".."_"..settings.config_name, masterserver_exe)
	t = PseudoTarget("tools".."_"..settings.config_name, tools)

	Target(c)
	Target(s)
	Target(v)
	Target(m)
	Target(t)
	
	all = PseudoTarget(settings.config_name, c, s, v, m, t)

	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)