fixed problem with force_vote command
[twcon.git] / bam.lua
blobefff7cb6d0247b4456324d1efa735e2c76f3ae41
1 CheckVersion("0.4")
3 Import("configure.lua")
4 Import("other/sdl/sdl.lua")
5 Import("other/freetype/freetype.lua")
7 --- Setup Config -------
8 config = NewConfig()
9 config:Add(OptCCompiler("compiler"))
10 config:Add(OptTestCompileC("stackprotector", "int main(){return 0;}", "-fstack-protector -fstack-protector-all"))
11 config:Add(OptLibrary("zlib", "zlib.h", false))
12 config:Add(SDL.OptFind("sdl", true))
13 config:Add(FreeType.OptFind("freetype", true))
14 config:Finalize("config.lua")
16 -- data compiler
17 function Script(name)
18 if family == "windows" then
19 return str_replace(name, "/", "\\")
20 end
21 return "python " .. name
22 end
24 function CHash(output, ...)
25 local inputs = TableFlatten({...})
27 output = Path(output)
29 -- compile all the files
30 local cmd = Script("scripts/cmd5.py") .. " "
31 for index, inname in ipairs(inputs) do
32 cmd = cmd .. Path(inname) .. " "
33 end
35 cmd = cmd .. " > " .. output
37 AddJob(output, "cmd5 " .. output, cmd)
38 for index, inname in ipairs(inputs) do
39 AddDependency(output, inname)
40 end
41 AddDependency(output, "scripts/cmd5.py")
42 return output
43 end
45 --[[
46 function DuplicateDirectoryStructure(orgpath, srcpath, dstpath)
47 for _,v in pairs(CollectDirs(srcpath .. "/")) do
48 MakeDirectory(dstpath .. "/" .. string.sub(v, string.len(orgpath)+2))
49 DuplicateDirectoryStructure(orgpath, v, dstpath)
50 end
51 end
53 DuplicateDirectoryStructure("src", "src", "objs")
56 function ResCompile(scriptfile)
57 scriptfile = Path(scriptfile)
58 if config.compiler.driver == "cl" then
59 output = PathBase(scriptfile) .. ".res"
60 AddJob(output, "rc " .. scriptfile, "rc /fo " .. output .. " " .. scriptfile)
61 elseif config.compiler.driver == "gcc" then
62 output = PathBase(scriptfile) .. ".coff"
63 AddJob(output, "windres " .. scriptfile, "windres -i " .. scriptfile .. " -o " .. output)
64 end
65 AddDependency(output, scriptfile)
66 return output
67 end
69 function Dat2c(datafile, sourcefile, arrayname)
70 datafile = Path(datafile)
71 sourcefile = Path(sourcefile)
73 AddJob(
74 sourcefile,
75 "dat2c " .. PathFilename(sourcefile) .. " = " .. PathFilename(datafile),
76 Script("scripts/dat2c.py").. "\" " .. sourcefile .. " " .. datafile .. " " .. arrayname
78 AddDependency(sourcefile, datafile)
79 return sourcefile
80 end
82 function ContentCompile(action, output)
83 output = Path(output)
84 AddJob(
85 output,
86 action .. " > " .. output,
87 --Script("datasrc/compile.py") .. "\" ".. Path(output) .. " " .. action
88 Script("datasrc/compile.py") .. " " .. action .. " > " .. Path(output)
90 AddDependency(output, Path("datasrc/content.py")) -- do this more proper
91 AddDependency(output, Path("datasrc/network.py"))
92 AddDependency(output, Path("datasrc/compile.py"))
93 AddDependency(output, Path("datasrc/datatypes.py"))
94 return output
95 end
97 -- Content Compile
98 network_source = ContentCompile("network_source", "src/game/generated/protocol.cpp")
99 network_header = ContentCompile("network_header", "src/game/generated/protocol.h")
100 client_content_source = ContentCompile("client_content_source", "src/game/generated/client_data.cpp")
101 client_content_header = ContentCompile("client_content_header", "src/game/generated/client_data.h")
102 server_content_source = ContentCompile("server_content_source", "src/game/generated/server_data.cpp")
103 server_content_header = ContentCompile("server_content_header", "src/game/generated/server_data.h")
105 AddDependency(network_source, network_header)
106 AddDependency(client_content_source, client_content_header)
107 AddDependency(server_content_source, server_content_header)
109 nethash = CHash("src/game/generated/nethash.c", "src/engine/shared/protocol.h", "src/game/generated/protocol.h", "src/game/tuning.h", "src/game/gamecore.cpp", network_header)
111 client_link_other = {}
112 client_depends = {}
114 if family == "windows" then
115 table.insert(client_depends, CopyToDirectory(".", "other\\sdl\\vc2005libs\\SDL.dll"))
117 if config.compiler.driver == "cl" then
118 client_link_other = {ResCompile("other/icons/teeworlds_cl.rc")}
119 elseif config.compiler.driver == "gcc" then
120 client_link_other = {ResCompile("other/icons/teeworlds_gcc.rc")}
124 function Intermediate_Output(settings, input)
125 return "objs/" .. string.sub(PathBase(input), string.len("src/")+1) .. settings.config_ext
128 function build(settings)
129 --settings.objdir = Path("objs")
130 settings.cc.Output = Intermediate_Output
132 if config.compiler.driver == "cl" then
133 settings.cc.flags:Add("/wd4244")
134 else
135 settings.cc.flags:Add("-Wall", "-fno-exceptions")
136 if platform == "macosx" then
137 settings.cc.flags:Add("-mmacosx-version-min=10.5", "-isysroot /Developer/SDKs/MacOSX10.5.sdk")
138 settings.link.flags:Add("-mmacosx-version-min=10.5", "-isysroot /Developer/SDKs/MacOSX10.5.sdk")
139 elseif config.stackprotector.value == 1 then
140 settings.cc.flags:Add("-fstack-protector", "-fstack-protector-all")
141 settings.link.flags:Add("-fstack-protector", "-fstack-protector-all")
145 -- set some platform specific settings
146 settings.cc.includes:Add("src")
148 if family == "unix" then
149 if platform == "macosx" then
150 settings.link.frameworks:Add("Carbon")
151 settings.link.frameworks:Add("AppKit")
152 else
153 settings.link.libs:Add("pthread")
155 elseif family == "windows" then
156 settings.link.libs:Add("gdi32")
157 settings.link.libs:Add("user32")
158 settings.link.libs:Add("ws2_32")
159 settings.link.libs:Add("ole32")
160 settings.link.libs:Add("shell32")
163 -- compile zlib if needed
164 if config.zlib.value == 1 then
165 settings.link.libs:Add("z")
166 if config.zlib.include_path then
167 settings.cc.includes:Add(config.zlib.include_path)
169 zlib = {}
170 else
171 zlib = Compile(settings, Collect("src/engine/external/zlib/*.c"))
172 settings.cc.includes:Add("src/engine/external/zlib")
175 -- build the small libraries
176 wavpack = Compile(settings, Collect("src/engine/external/wavpack/*.c"))
177 pnglite = Compile(settings, Collect("src/engine/external/pnglite/*.c"))
179 -- build game components
180 engine_settings = settings:Copy()
181 server_settings = engine_settings:Copy()
182 client_settings = engine_settings:Copy()
183 launcher_settings = engine_settings:Copy()
185 if family == "unix" then
186 if platform == "macosx" then
187 client_settings.link.frameworks:Add("OpenGL")
188 client_settings.link.frameworks:Add("AGL")
189 client_settings.link.frameworks:Add("Carbon")
190 client_settings.link.frameworks:Add("Cocoa")
191 launcher_settings.link.frameworks:Add("Cocoa")
192 else
193 client_settings.link.libs:Add("X11")
194 client_settings.link.libs:Add("GL")
195 client_settings.link.libs:Add("GLU")
198 elseif family == "windows" then
199 client_settings.link.libs:Add("opengl32")
200 client_settings.link.libs:Add("glu32")
201 client_settings.link.libs:Add("winmm")
204 -- apply sdl settings
205 config.sdl:Apply(client_settings)
206 -- apply freetype settings
207 config.freetype:Apply(client_settings)
209 engine = Compile(engine_settings, Collect("src/engine/shared/*.cpp", "src/base/*.c"))
210 client = Compile(client_settings, Collect("src/engine/client/*.cpp"))
211 server = Compile(server_settings, Collect("src/engine/server/*.cpp"))
213 versionserver = Compile(settings, Collect("src/versionsrv/*.cpp"))
214 masterserver = Compile(settings, Collect("src/mastersrv/*.cpp"))
215 game_shared = Compile(settings, Collect("src/game/*.cpp"), nethash, network_source)
216 game_client = Compile(settings, CollectRecursive("src/game/client/*.cpp"), client_content_source)
217 game_server = Compile(settings, CollectRecursive("src/game/server/*.cpp"), server_content_source)
218 game_editor = Compile(settings, Collect("src/game/editor/*.cpp"))
220 -- build tools (TODO: fix this so we don't get double _d_d stuff)
221 tools_src = Collect("src/tools/*.cpp", "src/tools/*.c")
223 client_osxlaunch = {}
224 server_osxlaunch = {}
225 if platform == "macosx" then
226 client_osxlaunch = Compile(client_settings, "src/osxlaunch/client.m")
227 server_osxlaunch = Compile(launcher_settings, "src/osxlaunch/server.m")
230 tools = {}
231 for i,v in ipairs(tools_src) do
232 toolname = PathFilename(PathBase(v))
233 tools[i] = Link(settings, toolname, Compile(settings, v), engine, zlib)
236 -- build client, server, version server and master server
237 client_exe = Link(client_settings, "teeworlds", game_shared, game_client,
238 engine, client, game_editor, zlib, pnglite, wavpack,
239 client_link_other, client_osxlaunch)
241 server_exe = Link(server_settings, "teeworlds_srv", engine, server,
242 game_shared, game_server, zlib)
244 serverlaunch = {}
245 if platform == "macosx" then
246 serverlaunch = Link(launcher_settings, "serverlaunch", server_osxlaunch)
249 versionserver_exe = Link(server_settings, "versionsrv", versionserver,
250 engine, zlib)
252 masterserver_exe = Link(server_settings, "mastersrv", masterserver,
253 engine, zlib)
255 -- make targets
256 c = PseudoTarget("client".."_"..settings.config_name, client_exe, client_depends)
257 s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch)
258 g = PseudoTarget("game".."_"..settings.config_name, client_exe, server_exe)
260 v = PseudoTarget("versionserver".."_"..settings.config_name, versionserver_exe)
261 m = PseudoTarget("masterserver".."_"..settings.config_name, masterserver_exe)
262 t = PseudoTarget("tools".."_"..settings.config_name, tools)
264 all = PseudoTarget(settings.config_name, c, s, v, m, t)
265 return all
269 debug_settings = NewSettings()
270 debug_settings.config_name = "debug"
271 debug_settings.config_ext = "_d"
272 debug_settings.debug = 1
273 debug_settings.optimize = 0
274 debug_settings.cc.defines:Add("CONF_DEBUG")
276 release_settings = NewSettings()
277 release_settings.config_name = "release"
278 release_settings.config_ext = ""
279 release_settings.debug = 0
280 release_settings.optimize = 1
281 release_settings.cc.defines:Add("CONF_RELEASE")
283 if platform == "macosx" and arch == "ia32" then
284 debug_settings_ppc = debug_settings:Copy()
285 debug_settings_ppc.config_name = "debug_ppc"
286 debug_settings_ppc.config_ext = "_ppc_d"
287 debug_settings_ppc.cc.flags:Add("-arch ppc")
288 debug_settings_ppc.link.flags:Add("-arch ppc")
289 debug_settings_ppc.cc.defines:Add("CONF_DEBUG")
291 release_settings_ppc = release_settings:Copy()
292 release_settings_ppc.config_name = "release_ppc"
293 release_settings_ppc.config_ext = "_ppc"
294 release_settings_ppc.cc.flags:Add("-arch ppc")
295 release_settings_ppc.link.flags:Add("-arch ppc")
296 release_settings_ppc.cc.defines:Add("CONF_RELEASE")
298 debug_settings_x86 = debug_settings:Copy()
299 debug_settings_x86.config_name = "debug_x86"
300 debug_settings_x86.config_ext = "_x86_d"
301 debug_settings_x86.cc.flags:Add("-arch i386")
302 debug_settings_x86.link.flags:Add("-arch i386")
303 debug_settings_x86.cc.defines:Add("CONF_DEBUG")
305 release_settings_x86 = release_settings:Copy()
306 release_settings_x86.config_name = "release_x86"
307 release_settings_x86.config_ext = "_x86"
308 release_settings_x86.cc.flags:Add("-arch i386")
309 release_settings_x86.link.flags:Add("-arch i386")
310 release_settings_x86.cc.defines:Add("CONF_RELEASE")
312 ppc_d = build(debug_settings_ppc)
313 x86_d = build(debug_settings_x86)
314 ppc_r = build(release_settings_ppc)
315 x86_r = build(release_settings_x86)
316 DefaultTarget("game_debug_x86")
317 PseudoTarget("release", ppc_r, x86_r)
318 PseudoTarget("debug", ppc_d, x86_d)
320 PseudoTarget("server_release", "server_release_x86", "server_release_ppc")
321 PseudoTarget("server_debug", "server_debug_x86", "server_debug_ppc")
322 PseudoTarget("client_release", "client_release_x86", "client_release_ppc")
323 PseudoTarget("client_debug", "client_debug_x86", "client_debug_ppc")
324 else
325 build(debug_settings)
326 build(release_settings)
327 DefaultTarget("game_debug")