1 import sys, traceback, platform, re, commands
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' )
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' ]
26 self.config_selected = [ 'release' ]
27 # those are global to each config
32 return 'config: target=%s config=%s' % ( self.target_selected, self.config_selected )
34 def _processTarget( self, ops ):
35 self.target_selected = ops
37 def _processConfig( self, ops ):
38 self.config_selected = ops
40 def _processCC( self, ops ):
43 def _processCXX( self, ops ):
46 def setupParser( self, operators ):
47 operators['target'] = self._processTarget
48 operators['config'] = self._processConfig
49 operators['cc'] = self._processCC
50 operators['cxx'] = self._processCXX
54 for config in self.config_selected:
55 Export( 'utils', 'settings', 'config' )
56 build_dir = os.path.join( 'build', config )
57 BuildDir( build_dir, '.', duplicate = 0 )
58 # left out jpeg6, splines
60 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' ]:
62 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
63 Export( 'lib_objects' )
64 SConscript( os.path.join( build_dir, 'SConscript.radiant' ) )
66 def SetupEnvironment( self, env, config, useGtk = False, useGtkGL = False ):
69 ( ret, xml2 ) = commands.getstatusoutput( 'xml2-config --cflags' )
71 print 'xml2-config failed'
73 xml2libs = commands.getoutput( 'xml2-config --libs' )
74 env.Append( LINKFLAGS = xml2libs.split( ' ' ) )
75 baseflags = [ '-m32', '-pipe', '-Wall', '-fmessage-length=0', '-fvisibility=hidden', xml2.split( ' ' ) ]
77 ( ret, gtk2 ) = commands.getstatusoutput( 'pkg-config gtk+-2.0 --cflags' )
79 print 'pkg-config gtk+-2.0 failed'
81 baseflags += gtk2.split( ' ' )
82 gtk2libs = commands.getoutput( 'pkg-config gtk+-2.0 --libs' )
83 env.Append( LINKFLAGS = gtk2libs.split( ' ' ) )
85 ( ret, glib ) = commands.getstatusoutput( 'pkg-config glib-2.0 --cflags' )
87 print 'pkg-config glib-2.0 failed'
89 baseflags += glib.split( ' ' )
91 ( ret, gtkgl ) = commands.getstatusoutput( 'pkg-config gtkglext-1.0 --cflags' )
93 print 'pkg-config gtkglext-1.0 failed'
95 baseflags += gtkgl.split( ' ' )
96 gtkgllibs = commands.getoutput( 'pkg-config gtkglext-1.0 --libs' )
97 env.Append( LINKFLAGS = gtkgllibs.split( ' ' ) )
99 env.Append( CFLAGS = baseflags )
100 env.Append( CXXFLAGS = baseflags + [ '-fpermissive', '-fvisibility-inlines-hidden' ] )
101 env.Append( CPPPATH = [ 'include', 'libs' ] )
102 env.Append( CPPDEFINES = [ 'Q_NO_STLPORT' ] )
103 if ( config == 'debug' ):
104 env.Append( CFLAGS = [ '-g' ] )
105 env.Append( CPPDEFINES = [ '_DEBUG' ] )
107 env.Append( CFLAGS = [ '-O3', '-march=pentium3', '-Winline', '-ffast-math', '-fno-unsafe-math-optimizations' ] )
109 # parse the config statement line to produce/update an existing config list
110 # the configs expose a list of keywords and accepted values, which the engine parses out
112 def __init__( self ):
115 def _processOp( self, ops ):
116 assert( len( ops ) == 1 )
118 if ( op == 'clear' ):
120 self.current_config = None
121 elif ( op == 'pop' ):
123 self.current_config = None
124 elif ( op == 'push' ):
125 self.configs.append( self.current_config )
126 self.current_config = Config()
127 self._setupParser( self.current_config )
129 def _setupParser( self, c ):
130 self.operators = { 'op' : self._processOp }
131 c.setupParser( self.operators )
133 def _parseStatement( self, s ):
134 statement_re = re.compile( '(.*)=(.*)' )
135 value_list_re = re.compile( '([^,]*),?' )
136 if ( not statement_re.match( s ) ):
137 print 'syntax error (statement match): %s' % repr( s )
139 statement_split = statement_re.split( s )
140 if ( len( statement_split ) != 4 ):
141 print 'syntax error (statement split): %s' % repr( s )
143 ( foo, name, value, bar ) = statement_split
144 value_split = value_list_re.split( value )
145 if ( len( value_split ) < 2 or len( value_split ) % 2 != 1 ):
146 print 'syntax error (value split): %s' % ( repr( value_split ) )
150 value_split.reverse()
152 while ( len( value_split ) != 0 ):
153 value_array.append( value_split.pop() )
156 print traceback.print_exception( sys.exc_type, sys.exc_value, sys.exc_traceback )
157 print 'syntax error (value to array): %s' % ( repr( value_split ) )
160 return ( name, value_array )
162 def parseStatements( self, _configs, statements ):
163 self.current_config = None
164 self.configs = _configs
165 if ( self.configs is None ):
169 if ( self.current_config is None ):
170 # use a provided config, or create a default one
171 if ( len( self.configs ) > 0 ):
172 self.current_config = self.configs.pop()
174 self.current_config = Config()
175 # setup the operator table for this config
176 # NOTE: have that in self._processOp too
177 self._setupParser( self.current_config )
179 ret = self._parseStatement( s )
181 print 'stop statement parse at %s' % repr( s )
183 ( name, value_array ) = ret
185 processor = self.operators[name]
187 print 'unknown operator %s - stop statement parse at %s' % ( repr( name ), repr( s ) )
189 processor( value_array )
191 if ( not self.current_config is None ):
192 self.configs.append( self.current_config )
193 # make sure there is at least one config
194 if ( len( self.configs ) == 0 ):
195 print 'pushing a default config'
196 self.configs.append( Config() )
201 class TestConfigParse( unittest.TestCase ):
204 self.parser = ConfigParser()
206 def testBasicParse( self ):
207 # test basic config parsing
208 # needs to cleanly stop at the first config statement that is not recognized
209 configs = self.parser.parseStatements( None, [ 'game=missionpack', 'config=qvm', 'foobar' ] )
210 print repr( configs )
212 def testMultiParse( self ):
213 # multiple configs seperated by commas
214 configs = self.parser.parseStatements( None, [ 'target=server,game,cgame' ] )
215 print repr( configs )
218 # test the operator for multiple configs
219 configs = self.parser.parseStatements( None, [ 'target=core', 'config=release', 'op=push', 'target=game,cgame,ui', 'config=debug' ] )
220 print repr( configs )
222 if __name__ == '__main__':