3 Import("configure.lua")
4 Import("other/sdl/sdl.lua")
5 Import("other/freetype/freetype.lua")
7 --- Setup Config -------
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")
18 if family
== "windows" then
19 return str_replace(name
, "/", "\\")
21 return "python " .. name
24 function CHash(output
, ...)
25 local inputs
= TableFlatten({...})
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
) .. " "
35 cmd
= cmd
.. " > " .. output
37 AddJob(output
, "cmd5 " .. output
, cmd
)
38 for index
, inname
in ipairs(inputs
) do
39 AddDependency(output
, inname
)
41 AddDependency(output
, "scripts/cmd5.py")
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)
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
)
65 AddDependency(output
, scriptfile
)
69 function Dat2c(datafile
, sourcefile
, arrayname
)
70 datafile
= Path(datafile
)
71 sourcefile
= Path(sourcefile
)
75 "dat2c " .. PathFilename(sourcefile
) .. " = " .. PathFilename(datafile
),
76 Script("scripts/dat2c.py").. "\" " .. sourcefile
.. " " .. datafile
.. " " .. arrayname
78 AddDependency(sourcefile
, datafile
)
82 function ContentCompile(action
, 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"))
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.cpp", "src/engine/shared/protocol.h", "src/game/generated/protocol.h", "src/game/tuning.h", "src/game/gamecore.cpp", network_header
)
111 client_link_other
= {}
113 server_link_other
= {}
115 if family
== "windows" then
116 table.insert(client_depends
, CopyToDirectory(".", "other\\freetype\\lib\\freetype.dll"))
117 table.insert(client_depends
, CopyToDirectory(".", "other\\sdl\\vc2005libs\\SDL.dll"))
119 if config
.compiler
.driver
== "cl" then
120 client_link_other
= {ResCompile("other/icons/teeworlds_cl.rc")}
121 server_link_other
= {ResCompile("other/icons/teeworlds_srv_cl.rc")}
122 elseif config
.compiler
.driver
== "gcc" then
123 client_link_other
= {ResCompile("other/icons/teeworlds_gcc.rc")}
124 server_link_other
= {ResCompile("other/icons/teeworlds_srv_gcc.rc")}
128 function Intermediate_Output(settings
, input
)
129 return "objs/" .. string.sub(PathBase(input
), string.len("src/")+1) .. settings
.config_ext
132 function build(settings
)
133 --settings.objdir = Path("objs")
134 settings
.cc
.Output
= Intermediate_Output
136 if config
.compiler
.driver
== "cl" then
137 settings
.cc
.flags
:Add("/wd4244")
139 settings
.cc
.flags
:Add("-Wall", "-fno-exceptions")
140 if platform
== "macosx" then
141 settings
.cc
.flags
:Add("-mmacosx-version-min=10.5", "-isysroot /Developer/SDKs/MacOSX10.5.sdk")
142 settings
.link
.flags
:Add("-mmacosx-version-min=10.5", "-isysroot /Developer/SDKs/MacOSX10.5.sdk")
143 elseif config
.stackprotector
.value
== 1 then
144 settings
.cc
.flags
:Add("-fstack-protector", "-fstack-protector-all")
145 settings
.link
.flags
:Add("-fstack-protector", "-fstack-protector-all")
149 -- set some platform specific settings
150 settings
.cc
.includes
:Add("src")
152 if family
== "unix" then
153 if platform
== "macosx" then
154 settings
.link
.frameworks
:Add("Carbon")
155 settings
.link
.frameworks
:Add("AppKit")
157 settings
.link
.libs
:Add("pthread")
159 elseif family
== "windows" then
160 settings
.link
.libs
:Add("gdi32")
161 settings
.link
.libs
:Add("user32")
162 settings
.link
.libs
:Add("ws2_32")
163 settings
.link
.libs
:Add("ole32")
164 settings
.link
.libs
:Add("shell32")
167 -- compile zlib if needed
168 if config
.zlib
.value
== 1 then
169 settings
.link
.libs
:Add("z")
170 if config
.zlib
.include_path
then
171 settings
.cc
.includes
:Add(config
.zlib
.include_path
)
175 zlib
= Compile(settings
, Collect("src/engine/external/zlib/*.c"))
176 settings
.cc
.includes
:Add("src/engine/external/zlib")
179 -- build the small libraries
180 wavpack
= Compile(settings
, Collect("src/engine/external/wavpack/*.c"))
181 pnglite
= Compile(settings
, Collect("src/engine/external/pnglite/*.c"))
183 -- build game components
184 engine_settings
= settings
:Copy()
185 server_settings
= engine_settings
:Copy()
186 client_settings
= engine_settings
:Copy()
187 launcher_settings
= engine_settings
:Copy()
189 if family
== "unix" then
190 if platform
== "macosx" then
191 client_settings
.link
.frameworks
:Add("OpenGL")
192 client_settings
.link
.frameworks
:Add("AGL")
193 client_settings
.link
.frameworks
:Add("Carbon")
194 client_settings
.link
.frameworks
:Add("Cocoa")
195 launcher_settings
.link
.frameworks
:Add("Cocoa")
197 client_settings
.link
.libs
:Add("X11")
198 client_settings
.link
.libs
:Add("GL")
199 client_settings
.link
.libs
:Add("GLU")
202 elseif family
== "windows" then
203 client_settings
.link
.libs
:Add("opengl32")
204 client_settings
.link
.libs
:Add("glu32")
205 client_settings
.link
.libs
:Add("winmm")
208 -- apply sdl settings
209 config
.sdl
:Apply(client_settings
)
210 -- apply freetype settings
211 config
.freetype
:Apply(client_settings
)
213 engine
= Compile(engine_settings
, Collect("src/engine/shared/*.cpp", "src/base/*.c"))
214 client
= Compile(client_settings
, Collect("src/engine/client/*.cpp"))
215 server
= Compile(server_settings
, Collect("src/engine/server/*.cpp"))
217 versionserver
= Compile(settings
, Collect("src/versionsrv/*.cpp"))
218 masterserver
= Compile(settings
, Collect("src/mastersrv/*.cpp"))
219 game_shared
= Compile(settings
, Collect("src/game/*.cpp"), nethash
, network_source
)
220 game_client
= Compile(settings
, CollectRecursive("src/game/client/*.cpp"), client_content_source
)
221 game_server
= Compile(settings
, CollectRecursive("src/game/server/*.cpp"), server_content_source
)
222 game_editor
= Compile(settings
, Collect("src/game/editor/*.cpp"))
224 -- build tools (TODO: fix this so we don't get double _d_d stuff)
225 tools_src
= Collect("src/tools/*.cpp", "src/tools/*.c")
227 client_osxlaunch
= {}
228 server_osxlaunch
= {}
229 if platform
== "macosx" then
230 client_osxlaunch
= Compile(client_settings
, "src/osxlaunch/client.m")
231 server_osxlaunch
= Compile(launcher_settings
, "src/osxlaunch/server.m")
235 for i
,v
in ipairs(tools_src
) do
236 toolname
= PathFilename(PathBase(v
))
237 tools
[i
] = Link(settings
, toolname
, Compile(settings
, v
), engine
, zlib
, pnglite
)
240 -- build client, server, version server and master server
241 client_exe
= Link(client_settings
, "teeworlds", game_shared
, game_client
,
242 engine
, client
, game_editor
, zlib
, pnglite
, wavpack
,
243 client_link_other
, client_osxlaunch
)
245 server_exe
= Link(server_settings
, "teeworlds_srv", engine
, server
,
246 game_shared
, game_server
, zlib
, server_link_other
)
249 if platform
== "macosx" then
250 serverlaunch
= Link(launcher_settings
, "serverlaunch", server_osxlaunch
)
253 versionserver_exe
= Link(server_settings
, "versionsrv", versionserver
,
256 masterserver_exe
= Link(server_settings
, "mastersrv", masterserver
,
260 c
= PseudoTarget("client".."_"..settings
.config_name
, client_exe
, client_depends
)
261 s
= PseudoTarget("server".."_"..settings
.config_name
, server_exe
, serverlaunch
)
262 g
= PseudoTarget("game".."_"..settings
.config_name
, client_exe
, server_exe
)
264 v
= PseudoTarget("versionserver".."_"..settings
.config_name
, versionserver_exe
)
265 m
= PseudoTarget("masterserver".."_"..settings
.config_name
, masterserver_exe
)
266 t
= PseudoTarget("tools".."_"..settings
.config_name
, tools
)
268 all
= PseudoTarget(settings
.config_name
, c
, s
, v
, m
, t
)
273 debug_settings
= NewSettings()
274 debug_settings
.config_name
= "debug"
275 debug_settings
.config_ext
= "_d"
276 debug_settings
.debug
= 1
277 debug_settings
.optimize
= 0
278 debug_settings
.cc
.defines
:Add("CONF_DEBUG")
280 release_settings
= NewSettings()
281 release_settings
.config_name
= "release"
282 release_settings
.config_ext
= ""
283 release_settings
.debug
= 0
284 release_settings
.optimize
= 1
285 release_settings
.cc
.defines
:Add("CONF_RELEASE")
287 if platform
== "macosx" and arch
== "ia32" then
288 debug_settings_ppc
= debug_settings
:Copy()
289 debug_settings_ppc
.config_name
= "debug_ppc"
290 debug_settings_ppc
.config_ext
= "_ppc_d"
291 debug_settings_ppc
.cc
.flags
:Add("-arch ppc")
292 debug_settings_ppc
.link
.flags
:Add("-arch ppc")
293 debug_settings_ppc
.cc
.defines
:Add("CONF_DEBUG")
295 release_settings_ppc
= release_settings
:Copy()
296 release_settings_ppc
.config_name
= "release_ppc"
297 release_settings_ppc
.config_ext
= "_ppc"
298 release_settings_ppc
.cc
.flags
:Add("-arch ppc")
299 release_settings_ppc
.link
.flags
:Add("-arch ppc")
300 release_settings_ppc
.cc
.defines
:Add("CONF_RELEASE")
302 debug_settings_x86
= debug_settings
:Copy()
303 debug_settings_x86
.config_name
= "debug_x86"
304 debug_settings_x86
.config_ext
= "_x86_d"
305 debug_settings_x86
.cc
.flags
:Add("-arch i386")
306 debug_settings_x86
.link
.flags
:Add("-arch i386")
307 debug_settings_x86
.cc
.defines
:Add("CONF_DEBUG")
309 release_settings_x86
= release_settings
:Copy()
310 release_settings_x86
.config_name
= "release_x86"
311 release_settings_x86
.config_ext
= "_x86"
312 release_settings_x86
.cc
.flags
:Add("-arch i386")
313 release_settings_x86
.link
.flags
:Add("-arch i386")
314 release_settings_x86
.cc
.defines
:Add("CONF_RELEASE")
316 ppc_d
= build(debug_settings_ppc
)
317 x86_d
= build(debug_settings_x86
)
318 ppc_r
= build(release_settings_ppc
)
319 x86_r
= build(release_settings_x86
)
320 DefaultTarget("game_debug_x86")
321 PseudoTarget("release", ppc_r
, x86_r
)
322 PseudoTarget("debug", ppc_d
, x86_d
)
324 PseudoTarget("server_release", "server_release_x86", "server_release_ppc")
325 PseudoTarget("server_debug", "server_debug_x86", "server_debug_ppc")
326 PseudoTarget("client_release", "client_release_x86", "client_release_ppc")
327 PseudoTarget("client_debug", "client_debug_x86", "client_debug_ppc")
329 build(debug_settings
)
330 build(release_settings
)
331 DefaultTarget("game_debug")