1 import sys, traceback, platform, re, commands, platform, subprocess
3 if __name__ != '__main__':
4 from SCons.Script import *
6 import utils, urllib2, zipfile, shutil
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', ] # 'UFOAIPack', 'Q2WPack', 'ReactionPack' ]
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 VariantDir( build_dir, '.', duplicate = 0 )
81 for project in [ 'libs/synapse/synapse.vcproj', 'libs/cmdlib/cmdlib.vcproj', 'libs/mathlib/mathlib.vcproj', 'libs/l_net/l_net.vcproj' ]:
83 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
84 Export( 'lib_objects' )
85 radiant = SConscript( os.path.join( build_dir, 'SConscript.radiant' ) )
86 Default( InstallAs( os.path.join( self.install_directory, 'radiant.bin' ), radiant ) )
88 # PIC versions of the libs for the modules
89 shlib_objects_extra = {}
90 for project in [ 'libs/synapse/synapse.vcproj', 'libs/mathlib/mathlib.vcproj', 'libs/picomodel/picomodel.vcproj', 'libs/cmdlib/cmdlib.vcproj', 'libs/splines/splines.vcproj' ]:
91 ( libpath, libname ) = os.path.split( project )
92 libname = os.path.splitext( libname )[0]
93 config['shared'] = True
94 Export( 'project', 'config' )
95 build_dir = os.path.join( 'build', config_name, 'shobjs' )
96 VariantDir( build_dir, '.', duplicate = 0 )
97 shlib_objects_extra[libname] = SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
99 for project in [ 'plugins/vfspk3/vfspk3.vcproj',
100 'plugins/vfspak/vfspak.vcproj',
101 'plugins/vfswad/vfswad.vcproj',
102 'plugins/eclassfgd/fgd.vcproj',
103 'plugins/entity/entity.vcproj',
104 'plugins/image/image.vcproj',
105 'plugins/model/model.vcproj',
106 'plugins/imagepng/imagepng.vcproj',
107 'plugins/imagewal/imagewal.vcproj',
108 'plugins/imagehl/imagehl.vcproj',
109 'plugins/imagem8/imagem8.vcproj',
110 'plugins/spritemodel/spritemodel.vcproj',
111 'plugins/textool/textool.vcproj',
112 'plugins/map/map.vcproj',
113 'plugins/mapxml/mapxml.vcproj',
114 'plugins/shaders/shaders.vcproj',
115 'plugins/surface/surface.vcproj',
116 'plugins/surface_ufoai/surface_ufoai.vcproj',
117 'plugins/surface_quake2/surface_quake2.vcproj',
118 'plugins/surface_heretic2/surface_heretic2.vcproj',
119 'contrib/camera/camera.vcproj',
120 'contrib/prtview/prtview.vcproj',
121 'contrib/hydratoolz/hydratoolz.vcproj',
122 'contrib/bobtoolz/bobtoolz.vcproj',
123 'contrib/gtkgensurf/gtkgensurf.vcproj',
124 'contrib/ufoai/ufoai.vcproj',
125 'contrib/bkgrnd2d/bkgrnd2d.vcproj'
127 ( libpath, libname ) = os.path.split( project )
128 libname = os.path.splitext( libname )[0]
129 # The old code assigned shlib_objects to shlib_objects_extra['synapse'],
130 # and this resulted in a non-copy. Stuff is added to shlib_objects below.
131 # So we need the explicit copy so we don't modify shlib_objects_extra['synapse'].
132 shlib_objects = shlib_objects_extra['synapse'][:]
133 if ( libname == 'camera' ):
134 shlib_objects += shlib_objects_extra['splines']
135 elif ( libname == 'entity' ):
136 shlib_objects += shlib_objects_extra['mathlib']
137 elif ( libname == 'map' ):
138 shlib_objects += shlib_objects_extra['cmdlib']
139 elif ( libname == 'model' ):
140 shlib_objects += shlib_objects_extra['picomodel']
141 shlib_objects += shlib_objects_extra['mathlib']
142 elif ( libname == 'spritemodel' ):
143 shlib_objects += shlib_objects_extra['mathlib']
144 elif ( libname == 'textool' ):
145 shlib_objects += shlib_objects_extra['mathlib']
146 elif ( libname == 'bobtoolz' ):
147 shlib_objects += shlib_objects_extra['mathlib']
148 shlib_objects += shlib_objects_extra['cmdlib']
149 Export( 'project', 'shlib_objects' )
150 module = SConscript( os.path.join( build_dir, 'SConscript.module' ) )
151 Default( InstallAs( os.path.join( self.install_directory, 'modules/%s.so' % libname ), module ) )
153 def emit_q3map2( self ):
155 for config_name in self.config_selected:
157 config['name'] = config_name
158 config['shared'] = False
159 Export( 'utils', 'settings', 'config' )
160 build_dir = os.path.join( 'build', config_name, 'q3map2' )
161 VariantDir( build_dir, '.', duplicate = 0 )
163 for project in [ 'tools/quake3/common/quake3-common.vcproj', 'libs/mathlib/mathlib.vcproj', 'libs/l_net/l_net.vcproj', 'libs/ddslib/ddslib.vcproj', 'libs/picomodel/picomodel.vcproj', 'libs/md5lib/md5lib.vcproj' ]:
165 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
166 Export( 'lib_objects' )
167 q3map2 = SConscript( os.path.join( build_dir, 'SConscript.q3map2' ) )
168 Default( InstallAs( os.path.join( self.install_directory, 'q3map2' ), q3map2 ) )
173 self.target_selected.index( 'radiant' )
179 self.target_selected.index( 'q3map2' )
186 self.target_selected.index( 'setup' )
192 def SetupEnvironment( self, env, config, useGtk = False, useGtkGL = False, useJPEG = False, useZ = False, usePNG = False ):
194 env['CXX'] = self.cxx
195 ( ret, xml2 ) = commands.getstatusoutput( 'xml2-config --cflags' )
197 print 'xml2-config failed'
199 xml2libs = commands.getoutput( 'xml2-config --libs' )
200 env.Append( LINKFLAGS = xml2libs.split( ' ' ) )
201 baseflags = [ '-pipe', '-Wall', '-fmessage-length=0', '-fvisibility=hidden', xml2.split( ' ' ) ]
202 # baseflags += [ '-m32' ]
204 if ( self.platform == 'Darwin' ):
205 env.Append( CPPPATH = [ '/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include' ] )
208 ( ret, gtk2 ) = commands.getstatusoutput( 'pkg-config gtk+-2.0 --cflags' )
210 print 'pkg-config gtk+-2.0 failed'
212 baseflags += gtk2.split( ' ' )
213 gtk2libs = commands.getoutput( 'pkg-config gtk+-2.0 --libs' )
214 env.Append( LINKFLAGS = gtk2libs.split( ' ' ) )
216 # always setup at least glib
217 ( ret, glib ) = commands.getstatusoutput( 'pkg-config glib-2.0 --cflags' )
219 print 'pkg-config glib-2.0 failed'
221 baseflags += glib.split( ' ' )
222 gliblibs = commands.getoutput( 'pkg-config glib-2.0 --libs' )
223 env.Append( LINKFLAGS = gliblibs.split( ' ' ) )
226 ( ret, gtkgl ) = commands.getstatusoutput( 'pkg-config gtkglext-1.0 --cflags' )
228 print 'pkg-config gtkglext-1.0 failed'
230 baseflags += gtkgl.split( ' ' )
231 gtkgllibs = commands.getoutput( 'pkg-config gtkglext-1.0 --libs' )
232 env.Append( LINKFLAGS = gtkgllibs.split( ' ' ) )
234 env.Append( LIBS = 'jpeg' )
237 env.Append( LIBS = pnglibs.split( ' ' ) )
239 env.Append( LIBS = 'z' )
241 env.Append( CCFLAGS = baseflags )
242 env.Append( CXXFLAGS = baseflags + [ '-fpermissive', '-fvisibility-inlines-hidden' ] )
243 env.Append( CPPPATH = [ 'include', 'libs' ] )
244 env.Append( CPPDEFINES = [ 'Q_NO_STLPORT' ] )
245 if ( config == 'debug' ):
246 env.Append( CFLAGS = [ '-g' ] )
247 env.Append( CXXFLAGS = [ '-g' ] )
248 env.Append( CPPDEFINES = [ '_DEBUG' ] )
250 env.Append( CFLAGS = [ '-O2', '-fno-strict-aliasing' ] )
251 env.Append( CXXFLAGS = [ '-O2', '-fno-strict-aliasing' ] )
253 def CheckoutOrUpdate( self, svnurl, path ):
254 if ( os.path.exists( path ) ):
255 cmd = [ 'svn', 'update', path ]
257 cmd = [ 'svn', 'checkout', svnurl, path ]
259 subprocess.check_call( cmd )
262 def FetchGamePaks( self, path ):
263 for pak in self.setup_packs:
264 svnurl = 'svn://svn.icculus.org/gtkradiant-gamepacks/%s/trunk' % pak
265 self.CheckoutOrUpdate( svnurl, os.path.join( path, 'installs', pak ) )
267 def CopyTree( self, src, dst):
268 for root, dirs, files in os.walk( src ):
269 target_dir = os.path.join( dst, root[root.find( '/' )+1:] )
271 if ( not os.path.exists( target_dir ) ):
272 os.mkdir( target_dir )
275 shutil.copy( os.path.join( root, file ), os.path.join( target_dir, file ) )
281 self.setup_platforms.index( 'local' )
285 # special case, fetch external paks under the local install directory
286 self.FetchGamePaks( self.install_directory )
287 # NOTE: unrelated to self.setup_platforms - grab support files and binaries and install them
288 if ( self.platform == 'Windows' ):
289 backup_cwd = os.getcwd()
291 'gtk+-bundle-2.16.6-20100912-3-win32.zip',
292 'gtkglext-1.2.0-3-win32.zip',
293 'libxml2-2.7.3-2-win32.zip',
294 'jpeg-8c-4-win32.zip',
295 'STLport-5.2.1-4.zip'
297 if ( not os.path.exists( lib_archive ) ):
298 print( 'downloading %s' % lib_archive )
299 archive_web_request = urllib2.urlopen( 'http://icculus.org/gtkradiant/files/1.6.2/%s' % lib_archive )
300 archive_File = open( lib_archive, 'wb' )
302 data = archive_web_request.read( 1048576 ) #read 1mb at a time
305 archive_File.write( data )
307 archive_web_request.close()
310 print( 'unpacking %s' % lib_archive )
311 lib_archive_path = os.path.abspath( lib_archive )
312 os.chdir( os.path.dirname( backup_cwd ) )
314 archive_Zip = zipfile.ZipFile( lib_archive_path, 'r' )
315 archive_Zip.extractall()
318 os.chdir( backup_cwd )
320 # copy all the dependent runtime data to the install directory
321 srcdir = os.path.dirname( backup_cwd )
323 'gtk-2.16.6/bin/freetype6.dll',
324 'gtk-2.16.6/bin/intl.dll',
325 'gtk-2.16.6/bin/libasprintf-0.dll',
326 'gtk-2.16.6/bin/libatk-1.0-0.dll',
327 'gtk-2.16.6/bin/libcairo-2.dll',
328 'gtk-2.16.6/bin/libexpat-1.dll',
329 'gtk-2.16.6/bin/libfontconfig-1.dll',
330 'gtk-2.16.6/bin/libgailutil-18.dll',
331 'gtk-2.16.6/bin/libgcc_s_dw2-1.dll',
332 'gtk-2.16.6/bin/libgdk-win32-2.0-0.dll',
333 'gtk-2.16.6/bin/libgdk_pixbuf-2.0-0.dll',
334 'gtk-2.16.6/bin/libgio-2.0-0.dll',
335 'gtk-2.16.6/bin/libglib-2.0-0.dll',
336 'gtk-2.16.6/bin/libgmodule-2.0-0.dll',
337 'gtk-2.16.6/bin/libgobject-2.0-0.dll',
338 'gtk-2.16.6/bin/libgthread-2.0-0.dll',
339 'gtk-2.16.6/bin/libgtk-win32-2.0-0.dll',
340 'gtk-2.16.6/bin/libpango-1.0-0.dll',
341 'gtk-2.16.6/bin/libpangocairo-1.0-0.dll',
342 'gtk-2.16.6/bin/libpangoft2-1.0-0.dll',
343 'gtk-2.16.6/bin/libpangowin32-1.0-0.dll',
344 'gtk-2.16.6/bin/libpng14-14.dll',
345 'gtk-2.16.6/bin/zlib1.dll',
346 'gtk-2.16.6/lib/GNU.Gettext.dll',
347 'gtk-2.16.6/lib/gtk-2.0/2.10.0/engines/libpixmap.dll',
348 'gtk-2.16.6/lib/gtk-2.0/2.10.0/engines/libwimp.dll',
349 'gtk-2.16.6/lib/gtk-2.0/modules/libgail.dll',
350 'gtkglext-1.2.0/bin/libgdkglext-win32-1.0-0.dll',
351 'gtkglext-1.2.0/bin/libgtkglext-win32-1.0-0.dll',
352 'libxml2-2.7.3/bin/libxml2-2.dll'
354 shutil.copy( os.path.join( srcdir, dll ), 'install' )
359 'gtkglext-1.2.0/share',
360 'libxml2-2.7.3/share'
362 self.CopyTree( os.path.join( srcdir, extra ), 'install' )
364 # parse the config statement line to produce/update an existing config list
365 # the configs expose a list of keywords and accepted values, which the engine parses out
367 def __init__( self ):
370 def _processOp( self, ops ):
371 assert( len( ops ) == 1 )
373 if ( op == 'clear' ):
375 self.current_config = None
376 elif ( op == 'pop' ):
378 self.current_config = None
379 elif ( op == 'push' ):
380 self.configs.append( self.current_config )
381 self.current_config = Config()
382 self._setupParser( self.current_config )
384 def _setupParser( self, c ):
385 self.operators = { 'op' : self._processOp }
386 c.setupParser( self.operators )
388 def _parseStatement( self, s ):
389 statement_re = re.compile( '(.*)=(.*)' )
390 value_list_re = re.compile( '([^,]*),?' )
391 if ( not statement_re.match( s ) ):
392 print 'syntax error (statement match): %s' % repr( s )
394 statement_split = statement_re.split( s )
395 if ( len( statement_split ) != 4 ):
396 print 'syntax error (statement split): %s' % repr( s )
398 ( foo, name, value, bar ) = statement_split
399 value_split = value_list_re.split( value )
400 if ( len( value_split ) < 2 or len( value_split ) % 2 != 1 ):
401 print 'syntax error (value split): %s' % ( repr( value_split ) )
405 value_split.reverse()
407 while ( len( value_split ) != 0 ):
408 value_array.append( value_split.pop() )
411 print traceback.print_exception( sys.exc_type, sys.exc_value, sys.exc_traceback )
412 print 'syntax error (value to array): %s' % ( repr( value_split ) )
415 return ( name, value_array )
417 def parseStatements( self, _configs, statements ):
418 self.current_config = None
419 self.configs = _configs
420 if ( self.configs is None ):
424 if ( self.current_config is None ):
425 # use a provided config, or create a default one
426 if ( len( self.configs ) > 0 ):
427 self.current_config = self.configs.pop()
429 self.current_config = Config()
430 # setup the operator table for this config
431 # NOTE: have that in self._processOp too
432 self._setupParser( self.current_config )
434 ret = self._parseStatement( s )
436 print 'stop statement parse at %s' % repr( s )
438 ( name, value_array ) = ret
440 processor = self.operators[name]
442 print 'unknown operator %s - stop statement parse at %s' % ( repr( name ), repr( s ) )
444 processor( value_array )
446 if ( not self.current_config is None ):
447 self.configs.append( self.current_config )
448 # make sure there is at least one config
449 if ( len( self.configs ) == 0 ):
450 print 'pushing a default config'
451 self.configs.append( Config() )
456 class TestConfigParse( unittest.TestCase ):
459 self.parser = ConfigParser()
461 def testBasicParse( self ):
462 # test basic config parsing
463 # needs to cleanly stop at the first config statement that is not recognized
464 configs = self.parser.parseStatements( None, [ 'game=missionpack', 'config=qvm', 'foobar' ] )
465 print repr( configs )
467 def testMultiParse( self ):
468 # multiple configs seperated by commas
469 configs = self.parser.parseStatements( None, [ 'target=server,game,cgame' ] )
470 print repr( configs )
473 # test the operator for multiple configs
474 configs = self.parser.parseStatements( None, [ 'target=core', 'config=release', 'op=push', 'target=game,cgame,ui', 'config=debug' ] )
475 print repr( configs )
477 if __name__ == '__main__':