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' )
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'
34 return 'config: target=%s config=%s' % ( self.target_selected, self.config_selected )
36 def _processTarget( self, ops ):
37 self.target_selected = ops
39 def _processConfig( self, ops ):
40 self.config_selected = ops
42 def _processCC( self, ops ):
45 def _processCXX( self, ops ):
48 def _processInstallDir( self, ops ):
49 self.install_directory = os.path.normpath( os.path.expanduser( ops[0] ) )
51 def setupParser( self, operators ):
52 operators['target'] = self._processTarget
53 operators['config'] = self._processConfig
54 operators['cc'] = self._processCC
55 operators['cxx'] = self._processCXX
56 operators['install_directory'] = self._processInstallDir
58 def emit_radiant( self ):
60 for config_name in self.config_selected:
62 config['name'] = config_name
63 config['shared'] = False
64 Export( 'utils', 'settings', 'config' )
65 build_dir = os.path.join( 'build', config_name, 'radiant' )
66 BuildDir( build_dir, '.', duplicate = 0 )
67 # left out jpeg6, splines (FIXME: I think jpeg6 is not used at all, can trash?)
69 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' ]:
71 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
72 Export( 'lib_objects' )
73 radiant = SConscript( os.path.join( build_dir, 'SConscript.radiant' ) )
74 Default( InstallAs( os.path.join( self.install_directory, 'radiant.bin' ), radiant ) )
76 # PIC versions of the libs for the modules
77 shlib_objects_extra = {}
78 for project in [ 'libs/synapse/synapse.vcproj', 'libs/mathlib/mathlib.vcproj', 'libs/picomodel/picomodel.vcproj', 'libs/cmdlib/cmdlib.vcproj' ]:
79 ( libpath, libname ) = os.path.split( project )
80 libname = os.path.splitext( libname )[0]
81 config['shared'] = True
82 Export( 'project', 'config' )
83 build_dir = os.path.join( 'build', config_name, 'shobjs' )
84 BuildDir( build_dir, '.', duplicate = 0 )
85 shlib_objects_extra[libname] = SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
87 for project in [ 'plugins/vfspk3/vfspk3.vcproj',
88 'plugins/vfspak/vfspak.vcproj',
89 'plugins/vfswad/vfswad.vcproj',
90 'plugins/eclassfgd/fgd.vcproj',
91 'plugins/entity/entity.vcproj',
92 'plugins/image/image.vcproj',
93 'plugins/model/model.vcproj',
94 'plugins/imagepng/imagepng.vcproj',
95 'plugins/imagewal/imagewal.vcproj',
96 'plugins/imagem8/imagem8.vcproj',
97 'plugins/spritemodel/spritemodel.vcproj',
98 'plugins/textool/TexTool.vcproj',
99 # 'plugins/sample/sample.vcproj',
100 'plugins/map/map.vcproj',
101 'plugins/mapxml/mapxml.vcproj',
102 'plugins/shaders/shaders.vcproj',
103 'plugins/surface/surface.vcproj',
104 'plugins/surface_ufoai/surface_ufoai.vcproj',
105 'plugins/surface_quake2/surface_quake2.vcproj',
106 'plugins/surface_heretic2/surface_heretic2.vcproj',
107 # FIXME Needs splines
108 # 'contrib/camera/camera.vcproj',
110 # FIXME What is this? Empty dir for me - remove me?
111 # 'contrib/patches/patches.vcproj',
112 # 'plugins/archivewad/archivewad.vcproj',
114 'contrib/prtview/PrtView.vcproj',
115 'contrib/hydratoolz/hydratoolz.vcproj',
116 'contrib/bobtoolz/bobToolz_gtk.vcproj',
117 'contrib/gtkgensurf/gtkgensurf.vcproj',
118 'contrib/ufoai/ufoai.vcproj',
119 'contrib/bkgrnd2d/bkgrnd2d.vcproj'
121 ( libpath, libname ) = os.path.split( project )
122 libname = os.path.splitext( libname )[0]
123 shlib_objects = shlib_objects_extra['synapse']
124 if ( libname == 'entity' ):
125 shlib_objects += shlib_objects_extra['mathlib']
126 elif ( libname == 'model' ):
127 shlib_objects += shlib_objects_extra['picomodel']
128 # elif ( libname == 'spritemodel' ):
129 # shlib_objects += shlib_objects_extra['mathlib']
130 # elif ( libname == 'TexTool' ):
131 # shlib_objects += shlib_objects_extra['mathlib']
132 elif ( libname == 'map' ):
133 shlib_objects += shlib_objects_extra['cmdlib']
134 Export( 'project', 'shlib_objects' )
135 module = SConscript( os.path.join( build_dir, 'SConscript.module' ) )
136 Default( InstallAs( os.path.join( self.install_directory, 'modules/%s.so' % libname ), module ) )
138 def emit_q3map2( self ):
140 for config_name in self.config_selected:
142 config['name'] = config_name
143 config['shared'] = False
144 Export( 'utils', 'settings', 'config' )
145 build_dir = os.path.join( 'build', config_name, 'q3map2' )
146 BuildDir( build_dir, '.', duplicate = 0 )
148 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' ]:
150 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
151 Export( 'lib_objects' )
152 q3map2 = SConscript( os.path.join( build_dir, 'SConscript.q3map2' ) )
153 Default( InstallAs( os.path.join( self.install_directory, 'q3map2' ), q3map2 ) )
158 self.target_selected.index( 'radiant' )
164 self.target_selected.index( 'q3map2' )
170 def SetupEnvironment( self, env, config, useGtk = False, useGtkGL = False, useJPEG = False, useZ = False, usePNG = False ):
172 env['CXX'] = self.cxx
173 ( ret, xml2 ) = commands.getstatusoutput( 'xml2-config --cflags' )
175 print 'xml2-config failed'
177 xml2libs = commands.getoutput( 'xml2-config --libs' )
178 env.Append( LINKFLAGS = xml2libs.split( ' ' ) )
179 baseflags = [ '-pipe', '-Wall', '-fmessage-length=0', '-fvisibility=hidden', xml2.split( ' ' ) ]
180 # baseflags += [ '-m32' ]
182 if ( self.platform == 'Darwin' ):
183 env.Append( CPPPATH = [ '/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include' ] )
186 ( ret, gtk2 ) = commands.getstatusoutput( 'pkg-config gtk+-2.0 --cflags' )
188 print 'pkg-config gtk+-2.0 failed'
190 baseflags += gtk2.split( ' ' )
191 gtk2libs = commands.getoutput( 'pkg-config gtk+-2.0 --libs' )
192 env.Append( LINKFLAGS = gtk2libs.split( ' ' ) )
194 # always setup at least glib
195 ( ret, glib ) = commands.getstatusoutput( 'pkg-config glib-2.0 --cflags' )
197 print 'pkg-config glib-2.0 failed'
199 baseflags += glib.split( ' ' )
200 gliblibs = commands.getoutput( 'pkg-config glib-2.0 --libs' )
201 env.Append( LINKFLAGS = gliblibs.split( ' ' ) )
204 ( ret, gtkgl ) = commands.getstatusoutput( 'pkg-config gtkglext-1.0 --cflags' )
206 print 'pkg-config gtkglext-1.0 failed'
208 baseflags += gtkgl.split( ' ' )
209 gtkgllibs = commands.getoutput( 'pkg-config gtkglext-1.0 --libs' )
210 env.Append( LINKFLAGS = gtkgllibs.split( ' ' ) )
212 env.Append( LIBS = 'jpeg' )
215 env.Append( LIBS = pnglibs.split( ' ' ) )
217 env.Append( LIBS = 'z' )
219 env.Append( CFLAGS = baseflags )
220 env.Append( CXXFLAGS = baseflags + [ '-fpermissive', '-fvisibility-inlines-hidden' ] )
221 env.Append( CPPPATH = [ 'include', 'libs' ] )
222 env.Append( CPPDEFINES = [ 'Q_NO_STLPORT' ] )
223 if ( config == 'debug' ):
224 env.Append( CFLAGS = [ '-g' ] )
225 env.Append( CXXFLAGS = [ '-g' ] )
226 env.Append( CPPDEFINES = [ '_DEBUG' ] )
228 env.Append( CFLAGS = [ '-O3', '-Winline', '-ffast-math', '-fno-unsafe-math-optimizations', '-fno-strict-aliasing' ] )
229 env.Append( CXXFLAGS = [ '-O3', '-Winline', '-ffast-math', '-fno-unsafe-math-optimizations','-fno-strict-aliasing' ] )
230 #env.Append( CFLAGS = [ '-march=pentium3' ] )
232 # env.Append( LINKFLAGS = [ '-m32' ] )
234 # parse the config statement line to produce/update an existing config list
235 # the configs expose a list of keywords and accepted values, which the engine parses out
237 def __init__( self ):
240 def _processOp( self, ops ):
241 assert( len( ops ) == 1 )
243 if ( op == 'clear' ):
245 self.current_config = None
246 elif ( op == 'pop' ):
248 self.current_config = None
249 elif ( op == 'push' ):
250 self.configs.append( self.current_config )
251 self.current_config = Config()
252 self._setupParser( self.current_config )
254 def _setupParser( self, c ):
255 self.operators = { 'op' : self._processOp }
256 c.setupParser( self.operators )
258 def _parseStatement( self, s ):
259 statement_re = re.compile( '(.*)=(.*)' )
260 value_list_re = re.compile( '([^,]*),?' )
261 if ( not statement_re.match( s ) ):
262 print 'syntax error (statement match): %s' % repr( s )
264 statement_split = statement_re.split( s )
265 if ( len( statement_split ) != 4 ):
266 print 'syntax error (statement split): %s' % repr( s )
268 ( foo, name, value, bar ) = statement_split
269 value_split = value_list_re.split( value )
270 if ( len( value_split ) < 2 or len( value_split ) % 2 != 1 ):
271 print 'syntax error (value split): %s' % ( repr( value_split ) )
275 value_split.reverse()
277 while ( len( value_split ) != 0 ):
278 value_array.append( value_split.pop() )
281 print traceback.print_exception( sys.exc_type, sys.exc_value, sys.exc_traceback )
282 print 'syntax error (value to array): %s' % ( repr( value_split ) )
285 return ( name, value_array )
287 def parseStatements( self, _configs, statements ):
288 self.current_config = None
289 self.configs = _configs
290 if ( self.configs is None ):
294 if ( self.current_config is None ):
295 # use a provided config, or create a default one
296 if ( len( self.configs ) > 0 ):
297 self.current_config = self.configs.pop()
299 self.current_config = Config()
300 # setup the operator table for this config
301 # NOTE: have that in self._processOp too
302 self._setupParser( self.current_config )
304 ret = self._parseStatement( s )
306 print 'stop statement parse at %s' % repr( s )
308 ( name, value_array ) = ret
310 processor = self.operators[name]
312 print 'unknown operator %s - stop statement parse at %s' % ( repr( name ), repr( s ) )
314 processor( value_array )
316 if ( not self.current_config is None ):
317 self.configs.append( self.current_config )
318 # make sure there is at least one config
319 if ( len( self.configs ) == 0 ):
320 print 'pushing a default config'
321 self.configs.append( Config() )
326 class TestConfigParse( unittest.TestCase ):
329 self.parser = ConfigParser()
331 def testBasicParse( self ):
332 # test basic config parsing
333 # needs to cleanly stop at the first config statement that is not recognized
334 configs = self.parser.parseStatements( None, [ 'game=missionpack', 'config=qvm', 'foobar' ] )
335 print repr( configs )
337 def testMultiParse( self ):
338 # multiple configs seperated by commas
339 configs = self.parser.parseStatements( None, [ 'target=server,game,cgame' ] )
340 print repr( configs )
343 # test the operator for multiple configs
344 configs = self.parser.parseStatements( None, [ 'target=core', 'config=release', 'op=push', 'target=game,cgame,ui', 'config=debug' ] )
345 print repr( configs )
347 if __name__ == '__main__':