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' )
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
28 self.platform = platform.system()
29 if ( self.platform == 'Darwin' ):
37 return 'config: target=%s config=%s' % ( self.target_selected, self.config_selected )
39 def _processTarget( self, ops ):
40 self.target_selected = ops
42 def _processConfig( self, ops ):
43 self.config_selected = ops
45 def _processCC( self, ops ):
48 def _processCXX( self, ops ):
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
59 for config_name in self.config_selected:
61 config['name'] = config_name
62 config['shared'] = False
63 Export( 'utils', 'settings', 'config' )
64 build_dir = os.path.join( 'build', config_name )
65 BuildDir( build_dir, '.', duplicate = 0 )
66 # left out jpeg6, splines (FIXME: I think jpeg6 is not used at all, can trash?)
68 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' ]:
70 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
71 Export( 'lib_objects' )
72 radiant = SConscript( os.path.join( build_dir, 'SConscript.radiant' ) )
73 InstallAs( 'install/radiant.bin', radiant )
75 # PIC versions of the libs for the modules
76 shlib_objects_extra = {}
77 for project in [ 'libs/synapse/synapse.vcproj', 'libs/mathlib/mathlib.vcproj', 'libs/cmdlib/cmdlib.vcproj' ]:
78 ( libpath, libname ) = os.path.split( project )
79 libname = os.path.splitext( libname )[0]
80 config['shared'] = True
81 Export( 'project', 'config' )
82 build_dir = os.path.join( 'build', config_name, 'shobjs' )
83 BuildDir( build_dir, '.', duplicate = 0 )
84 shlib_objects_extra[libname] = SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
86 for project in [ 'plugins/vfspk3/vfspk3.vcproj',
87 'plugins/image/image.vcproj',
88 'plugins/entity/entity.vcproj',
89 'plugins/map/map.vcproj',
90 'plugins/mapxml/mapxml.vcproj',
91 'plugins/shaders/shaders.vcproj',
92 'plugins/surface/surface.vcproj'
94 ( libpath, libname ) = os.path.split( project )
95 libname = os.path.splitext( libname )[0]
96 shlib_objects = shlib_objects_extra['synapse']
97 if ( libname == 'entity' ):
98 shlib_objects += shlib_objects_extra['mathlib']
99 if ( libname == 'map' ):
100 shlib_objects += shlib_objects_extra['cmdlib']
101 Export( 'project', 'shlib_objects' )
102 module = SConscript( os.path.join( build_dir, 'SConscript.module' ) )
103 InstallAs( 'install/modules/%s.so' % libname, module )
105 def SetupEnvironment( self, env, config, useGtk = False, useGtkGL = False, useJPEG = False ):
107 env['CXX'] = self.cxx
108 ( ret, xml2 ) = commands.getstatusoutput( 'xml2-config --cflags' )
110 print 'xml2-config failed'
112 xml2libs = commands.getoutput( 'xml2-config --libs' )
113 env.Append( LINKFLAGS = xml2libs.split( ' ' ) )
114 baseflags = [ '-pipe', '-Wall', '-fmessage-length=0', '-fvisibility=hidden', xml2.split( ' ' ) ]
115 # baseflags += [ '-m32' ]
117 if ( self.platform == 'Darwin' ):
118 env.Append( CPPPATH = [ '/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include' ] )
121 ( ret, gtk2 ) = commands.getstatusoutput( 'pkg-config gtk+-2.0 --cflags' )
123 print 'pkg-config gtk+-2.0 failed'
125 baseflags += gtk2.split( ' ' )
126 gtk2libs = commands.getoutput( 'pkg-config gtk+-2.0 --libs' )
127 env.Append( LINKFLAGS = gtk2libs.split( ' ' ) )
129 # always setup at least glib
130 ( ret, glib ) = commands.getstatusoutput( 'pkg-config glib-2.0 --cflags' )
132 print 'pkg-config glib-2.0 failed'
134 baseflags += glib.split( ' ' )
135 gliblibs = commands.getoutput( 'pkg-config glib-2.0 --libs' )
136 env.Append( LINKFLAGS = gliblibs.split( ' ' ) )
139 ( ret, gtkgl ) = commands.getstatusoutput( 'pkg-config gtkglext-1.0 --cflags' )
141 print 'pkg-config gtkglext-1.0 failed'
143 baseflags += gtkgl.split( ' ' )
144 gtkgllibs = commands.getoutput( 'pkg-config gtkglext-1.0 --libs' )
145 env.Append( LINKFLAGS = gtkgllibs.split( ' ' ) )
147 env.Append( LIBS = 'jpeg' )
149 env.Append( CFLAGS = baseflags )
150 env.Append( CXXFLAGS = baseflags + [ '-fpermissive', '-fvisibility-inlines-hidden' ] )
151 env.Append( CPPPATH = [ 'include', 'libs' ] )
152 env.Append( CPPDEFINES = [ 'Q_NO_STLPORT' ] )
153 if ( config == 'debug' ):
154 env.Append( CFLAGS = [ '-g' ] )
155 env.Append( CXXFLAGS = [ '-g' ] )
156 env.Append( CPPDEFINES = [ '_DEBUG' ] )
158 env.Append( CFLAGS = [ '-O3', '-Winline', '-ffast-math', '-fno-unsafe-math-optimizations' ] )
159 env.Append( CXXFLAGS = [ '-O3', '-Winline', '-ffast-math', '-fno-unsafe-math-optimizations' ] )
160 #env.Append( CFLAGS = [ '-march=pentium3' ] )
162 # env.Append( LINKFLAGS = [ '-m32' ] )
164 # parse the config statement line to produce/update an existing config list
165 # the configs expose a list of keywords and accepted values, which the engine parses out
167 def __init__( self ):
170 def _processOp( self, ops ):
171 assert( len( ops ) == 1 )
173 if ( op == 'clear' ):
175 self.current_config = None
176 elif ( op == 'pop' ):
178 self.current_config = None
179 elif ( op == 'push' ):
180 self.configs.append( self.current_config )
181 self.current_config = Config()
182 self._setupParser( self.current_config )
184 def _setupParser( self, c ):
185 self.operators = { 'op' : self._processOp }
186 c.setupParser( self.operators )
188 def _parseStatement( self, s ):
189 statement_re = re.compile( '(.*)=(.*)' )
190 value_list_re = re.compile( '([^,]*),?' )
191 if ( not statement_re.match( s ) ):
192 print 'syntax error (statement match): %s' % repr( s )
194 statement_split = statement_re.split( s )
195 if ( len( statement_split ) != 4 ):
196 print 'syntax error (statement split): %s' % repr( s )
198 ( foo, name, value, bar ) = statement_split
199 value_split = value_list_re.split( value )
200 if ( len( value_split ) < 2 or len( value_split ) % 2 != 1 ):
201 print 'syntax error (value split): %s' % ( repr( value_split ) )
205 value_split.reverse()
207 while ( len( value_split ) != 0 ):
208 value_array.append( value_split.pop() )
211 print traceback.print_exception( sys.exc_type, sys.exc_value, sys.exc_traceback )
212 print 'syntax error (value to array): %s' % ( repr( value_split ) )
215 return ( name, value_array )
217 def parseStatements( self, _configs, statements ):
218 self.current_config = None
219 self.configs = _configs
220 if ( self.configs is None ):
224 if ( self.current_config is None ):
225 # use a provided config, or create a default one
226 if ( len( self.configs ) > 0 ):
227 self.current_config = self.configs.pop()
229 self.current_config = Config()
230 # setup the operator table for this config
231 # NOTE: have that in self._processOp too
232 self._setupParser( self.current_config )
234 ret = self._parseStatement( s )
236 print 'stop statement parse at %s' % repr( s )
238 ( name, value_array ) = ret
240 processor = self.operators[name]
242 print 'unknown operator %s - stop statement parse at %s' % ( repr( name ), repr( s ) )
244 processor( value_array )
246 if ( not self.current_config is None ):
247 self.configs.append( self.current_config )
248 # make sure there is at least one config
249 if ( len( self.configs ) == 0 ):
250 print 'pushing a default config'
251 self.configs.append( Config() )
256 class TestConfigParse( unittest.TestCase ):
259 self.parser = ConfigParser()
261 def testBasicParse( self ):
262 # test basic config parsing
263 # needs to cleanly stop at the first config statement that is not recognized
264 configs = self.parser.parseStatements( None, [ 'game=missionpack', 'config=qvm', 'foobar' ] )
265 print repr( configs )
267 def testMultiParse( self ):
268 # multiple configs seperated by commas
269 configs = self.parser.parseStatements( None, [ 'target=server,game,cgame' ] )
270 print repr( configs )
273 # test the operator for multiple configs
274 configs = self.parser.parseStatements( None, [ 'target=core', 'config=release', 'op=push', 'target=game,cgame,ui', 'config=debug' ] )
275 print repr( configs )
277 if __name__ == '__main__':