1 import sys, traceback, platform, re, commands, platform
3 if __name__ != '__main__':
4 from SCons.Script import *
8 # config = debug release
9 # aliases are going to be very needed here
10 # we have dependency situations too
14 # not used atm, but useful to keep a list in mind
15 # may use them eventually for the 'all' and other aliases expansions?
16 target_choices = utils.Enum( 'radiant', 'q3map2', 'setup' )
17 config_choices = utils.Enum( 'debug', 'release' )
20 # 'all' -> for each choices
21 # 'gamecode' for the targets, 'game' 'cgame' 'ui'
25 self.target_selected = [ 'radiant', 'q3map2' ]
26 self.config_selected = [ 'release' ]
27 # those are global to each config
28 self.platform = platform.system()
31 self.install_directory = 'install'
33 # platforms for which to assemble a setup
34 self.setup_platforms = [ 'local', 'x86', 'x64', 'win32' ]
35 # paks to assemble in the setup
36 self.setup_packs = [ 'Q3Pack', 'UrTPack' ]
39 return 'config: target=%s config=%s' % ( self.target_selected, self.config_selected )
41 def _processTarget( self, ops ):
42 self.target_selected = ops
44 def _processConfig( self, ops ):
45 self.config_selected = ops
47 def _processCC( self, ops ):
50 def _processCXX( self, ops ):
53 def _processInstallDir( self, ops ):
54 self.install_directory = os.path.normpath( os.path.expanduser( ops[0] ) )
56 def _processSetupPlatforms( self, ops ):
57 self.setup_platforms = ops
59 def _processSetupPacks( self, ops ):
60 self.setup_packs = ops
62 def setupParser( self, operators ):
63 operators['target'] = self._processTarget
64 operators['config'] = self._processConfig
65 operators['cc'] = self._processCC
66 operators['cxx'] = self._processCXX
67 operators['install_directory'] = self._processInstallDir
68 operators['setup_platforms'] = self._processSetupPlatforms
69 operators['setup_packs'] = self._processSetupPacks
71 def emit_radiant( self ):
73 for config_name in self.config_selected:
75 config['name'] = config_name
76 config['shared'] = False
77 Export( 'utils', 'settings', 'config' )
78 build_dir = os.path.join( 'build', config_name, 'radiant' )
79 BuildDir( build_dir, '.', duplicate = 0 )
80 # left out jpeg6, splines (FIXME: I think jpeg6 is not used at all, can trash?)
82 for project in [ 'libs/synapse/synapse.vcproj', 'libs/cmdlib/cmdlib.vcproj', 'libs/mathlib/mathlib.vcproj', 'libs/l_net/l_net.vcproj', 'libs/ddslib/ddslib.vcproj', 'libs/picomodel/picomodel.vcproj', 'libs/md5lib/md5lib.vcproj' ]:
84 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
85 Export( 'lib_objects' )
86 radiant = SConscript( os.path.join( build_dir, 'SConscript.radiant' ) )
87 Default( InstallAs( os.path.join( self.install_directory, 'radiant.bin' ), radiant ) )
89 # PIC versions of the libs for the modules
90 shlib_objects_extra = {}
91 for project in [ 'libs/synapse/synapse.vcproj', 'libs/mathlib/mathlib.vcproj', 'libs/picomodel/picomodel.vcproj', 'libs/cmdlib/cmdlib.vcproj' ]:
92 ( libpath, libname ) = os.path.split( project )
93 libname = os.path.splitext( libname )[0]
94 config['shared'] = True
95 Export( 'project', 'config' )
96 build_dir = os.path.join( 'build', config_name, 'shobjs' )
97 BuildDir( build_dir, '.', duplicate = 0 )
98 shlib_objects_extra[libname] = SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
100 for project in [ 'plugins/vfspk3/vfspk3.vcproj',
101 'plugins/vfspak/vfspak.vcproj',
102 'plugins/vfswad/vfswad.vcproj',
103 'plugins/eclassfgd/fgd.vcproj',
104 'plugins/entity/entity.vcproj',
105 'plugins/image/image.vcproj',
106 'plugins/model/model.vcproj',
107 'plugins/imagepng/imagepng.vcproj',
108 'plugins/imagewal/imagewal.vcproj',
109 'plugins/imagem8/imagem8.vcproj',
110 'plugins/spritemodel/spritemodel.vcproj',
111 'plugins/textool/TexTool.vcproj',
112 # 'plugins/sample/sample.vcproj',
113 'plugins/map/map.vcproj',
114 'plugins/mapxml/mapxml.vcproj',
115 'plugins/shaders/shaders.vcproj',
116 'plugins/surface/surface.vcproj',
117 'plugins/surface_ufoai/surface_ufoai.vcproj',
118 'plugins/surface_quake2/surface_quake2.vcproj',
119 'plugins/surface_heretic2/surface_heretic2.vcproj',
120 # FIXME Needs splines
121 # 'contrib/camera/camera.vcproj',
123 # FIXME What is this? Empty dir for me - remove me?
124 # 'contrib/patches/patches.vcproj',
125 # 'plugins/archivewad/archivewad.vcproj',
127 'contrib/prtview/PrtView.vcproj',
128 'contrib/hydratoolz/hydratoolz.vcproj',
129 'contrib/bobtoolz/bobToolz_gtk.vcproj',
130 'contrib/gtkgensurf/gtkgensurf.vcproj',
131 'contrib/ufoai/ufoai.vcproj',
132 'contrib/bkgrnd2d/bkgrnd2d.vcproj'
134 ( libpath, libname ) = os.path.split( project )
135 libname = os.path.splitext( libname )[0]
136 shlib_objects = shlib_objects_extra['synapse']
137 if ( libname == 'entity' ):
138 shlib_objects += shlib_objects_extra['mathlib']
139 elif ( libname == 'model' ):
140 shlib_objects += shlib_objects_extra['picomodel']
141 # elif ( libname == 'spritemodel' ):
142 # shlib_objects += shlib_objects_extra['mathlib']
143 # elif ( libname == 'TexTool' ):
144 # shlib_objects += shlib_objects_extra['mathlib']
145 elif ( libname == 'map' ):
146 shlib_objects += shlib_objects_extra['cmdlib']
147 Export( 'project', 'shlib_objects' )
148 module = SConscript( os.path.join( build_dir, 'SConscript.module' ) )
149 Default( InstallAs( os.path.join( self.install_directory, 'modules/%s.so' % libname ), module ) )
151 def emit_q3map2( self ):
153 for config_name in self.config_selected:
155 config['name'] = config_name
156 config['shared'] = False
157 Export( 'utils', 'settings', 'config' )
158 build_dir = os.path.join( 'build', config_name, 'q3map2' )
159 BuildDir( build_dir, '.', duplicate = 0 )
161 for project in [ 'libs/cmdlib/cmdlib.vcproj', 'libs/mathlib/mathlib.vcproj', 'libs/l_net/l_net.vcproj', 'libs/ddslib/ddslib.vcproj', 'libs/picomodel/picomodel.vcproj', 'libs/md5lib/md5lib.vcproj' ]:
163 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
164 Export( 'lib_objects' )
165 q3map2 = SConscript( os.path.join( build_dir, 'SConscript.q3map2' ) )
166 Default( InstallAs( os.path.join( self.install_directory, 'q3map2' ), q3map2 ) )
171 self.target_selected.index( 'radiant' )
177 self.target_selected.index( 'q3map2' )
184 self.target_selected.index( 'setup' )
190 def SetupEnvironment( self, env, config, useGtk = False, useGtkGL = False, useJPEG = False, useZ = False, usePNG = False ):
192 env['CXX'] = self.cxx
193 ( ret, xml2 ) = commands.getstatusoutput( 'xml2-config --cflags' )
195 print 'xml2-config failed'
197 xml2libs = commands.getoutput( 'xml2-config --libs' )
198 env.Append( LINKFLAGS = xml2libs.split( ' ' ) )
199 baseflags = [ '-pipe', '-Wall', '-fmessage-length=0', '-fvisibility=hidden', xml2.split( ' ' ) ]
200 # baseflags += [ '-m32' ]
202 if ( self.platform == 'Darwin' ):
203 env.Append( CPPPATH = [ '/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include' ] )
206 ( ret, gtk2 ) = commands.getstatusoutput( 'pkg-config gtk+-2.0 --cflags' )
208 print 'pkg-config gtk+-2.0 failed'
210 baseflags += gtk2.split( ' ' )
211 gtk2libs = commands.getoutput( 'pkg-config gtk+-2.0 --libs' )
212 env.Append( LINKFLAGS = gtk2libs.split( ' ' ) )
214 # always setup at least glib
215 ( ret, glib ) = commands.getstatusoutput( 'pkg-config glib-2.0 --cflags' )
217 print 'pkg-config glib-2.0 failed'
219 baseflags += glib.split( ' ' )
220 gliblibs = commands.getoutput( 'pkg-config glib-2.0 --libs' )
221 env.Append( LINKFLAGS = gliblibs.split( ' ' ) )
224 ( ret, gtkgl ) = commands.getstatusoutput( 'pkg-config gtkglext-1.0 --cflags' )
226 print 'pkg-config gtkglext-1.0 failed'
228 baseflags += gtkgl.split( ' ' )
229 gtkgllibs = commands.getoutput( 'pkg-config gtkglext-1.0 --libs' )
230 env.Append( LINKFLAGS = gtkgllibs.split( ' ' ) )
232 env.Append( LIBS = 'jpeg' )
235 env.Append( LIBS = pnglibs.split( ' ' ) )
237 env.Append( LIBS = 'z' )
239 env.Append( CFLAGS = baseflags )
240 env.Append( CXXFLAGS = baseflags + [ '-fpermissive', '-fvisibility-inlines-hidden' ] )
241 env.Append( CPPPATH = [ 'include', 'libs' ] )
242 env.Append( CPPDEFINES = [ 'Q_NO_STLPORT' ] )
243 if ( config == 'debug' ):
244 env.Append( CFLAGS = [ '-g' ] )
245 env.Append( CXXFLAGS = [ '-g' ] )
246 env.Append( CPPDEFINES = [ '_DEBUG' ] )
248 env.Append( CFLAGS = [ '-O3', '-Winline', '-ffast-math', '-fno-unsafe-math-optimizations', '-fno-strict-aliasing' ] )
249 env.Append( CXXFLAGS = [ '-O3', '-Winline', '-ffast-math', '-fno-unsafe-math-optimizations','-fno-strict-aliasing' ] )
251 def CheckoutOrUpdate( self, svnurl, path ):
252 if ( os.path.exists( path ) ):
253 # NOTE: check the svnurl matches?
254 cmd = 'svn update "%s"' % path
257 cmd = 'svn checkout %s "%s"' % ( svnurl, path )
258 ret = os.system( cmd )
260 raise 'checkout or update failed'
263 def FetchGamePaks( self, path ):
264 for pak in self.setup_packs:
265 if ( pak == 'Q3Pack' or pak == 'UrTPack' ):
266 svnurl = 'https://zerowing.idsoftware.com/svn/radiant.gamepacks/%s/trunk' % pak
267 self.CheckoutOrUpdate( svnurl, os.path.join( path, 'installs', pak ) )
270 for platform in self.setup_platforms:
271 if ( platform == 'local' ):
272 # special case, fetch external paks under the local install directory
273 self.FetchGamePaks( self.install_directory )
275 # parse the config statement line to produce/update an existing config list
276 # the configs expose a list of keywords and accepted values, which the engine parses out
278 def __init__( self ):
281 def _processOp( self, ops ):
282 assert( len( ops ) == 1 )
284 if ( op == 'clear' ):
286 self.current_config = None
287 elif ( op == 'pop' ):
289 self.current_config = None
290 elif ( op == 'push' ):
291 self.configs.append( self.current_config )
292 self.current_config = Config()
293 self._setupParser( self.current_config )
295 def _setupParser( self, c ):
296 self.operators = { 'op' : self._processOp }
297 c.setupParser( self.operators )
299 def _parseStatement( self, s ):
300 statement_re = re.compile( '(.*)=(.*)' )
301 value_list_re = re.compile( '([^,]*),?' )
302 if ( not statement_re.match( s ) ):
303 print 'syntax error (statement match): %s' % repr( s )
305 statement_split = statement_re.split( s )
306 if ( len( statement_split ) != 4 ):
307 print 'syntax error (statement split): %s' % repr( s )
309 ( foo, name, value, bar ) = statement_split
310 value_split = value_list_re.split( value )
311 if ( len( value_split ) < 2 or len( value_split ) % 2 != 1 ):
312 print 'syntax error (value split): %s' % ( repr( value_split ) )
316 value_split.reverse()
318 while ( len( value_split ) != 0 ):
319 value_array.append( value_split.pop() )
322 print traceback.print_exception( sys.exc_type, sys.exc_value, sys.exc_traceback )
323 print 'syntax error (value to array): %s' % ( repr( value_split ) )
326 return ( name, value_array )
328 def parseStatements( self, _configs, statements ):
329 self.current_config = None
330 self.configs = _configs
331 if ( self.configs is None ):
335 if ( self.current_config is None ):
336 # use a provided config, or create a default one
337 if ( len( self.configs ) > 0 ):
338 self.current_config = self.configs.pop()
340 self.current_config = Config()
341 # setup the operator table for this config
342 # NOTE: have that in self._processOp too
343 self._setupParser( self.current_config )
345 ret = self._parseStatement( s )
347 print 'stop statement parse at %s' % repr( s )
349 ( name, value_array ) = ret
351 processor = self.operators[name]
353 print 'unknown operator %s - stop statement parse at %s' % ( repr( name ), repr( s ) )
355 processor( value_array )
357 if ( not self.current_config is None ):
358 self.configs.append( self.current_config )
359 # make sure there is at least one config
360 if ( len( self.configs ) == 0 ):
361 print 'pushing a default config'
362 self.configs.append( Config() )
367 class TestConfigParse( unittest.TestCase ):
370 self.parser = ConfigParser()
372 def testBasicParse( self ):
373 # test basic config parsing
374 # needs to cleanly stop at the first config statement that is not recognized
375 configs = self.parser.parseStatements( None, [ 'game=missionpack', 'config=qvm', 'foobar' ] )
376 print repr( configs )
378 def testMultiParse( self ):
379 # multiple configs seperated by commas
380 configs = self.parser.parseStatements( None, [ 'target=server,game,cgame' ] )
381 print repr( configs )
384 # test the operator for multiple configs
385 configs = self.parser.parseStatements( None, [ 'target=core', 'config=release', 'op=push', 'target=game,cgame,ui', 'config=debug' ] )
386 print repr( configs )
388 if __name__ == '__main__':