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()
29 if ( self.platform == 'Darwin' ):
38 return 'config: target=%s config=%s' % ( self.target_selected, self.config_selected )
40 def _processTarget( self, ops ):
41 self.target_selected = ops
43 def _processConfig( self, ops ):
44 self.config_selected = ops
46 def _processCC( self, ops ):
49 def _processCXX( self, ops ):
52 def _processInstall( self, ops ):
54 if ( ops == 'yes' or ops == 'true' or ops == 'True' or ops == '1' or ops == True ):
59 def setupParser( self, operators ):
60 operators['target'] = self._processTarget
61 operators['config'] = self._processConfig
62 operators['cc'] = self._processCC
63 operators['cxx'] = self._processCXX
64 operators['install'] = self._processInstall
66 def InstallAs( self, target, source ):
68 iret = InstallAs( target, source )
73 def emit_radiant( self ):
75 for config_name in self.config_selected:
77 config['name'] = config_name
78 config['shared'] = False
79 Export( 'utils', 'settings', 'config' )
80 build_dir = os.path.join( 'build', config_name, 'radiant' )
81 BuildDir( build_dir, '.', duplicate = 0 )
82 # left out jpeg6, splines (FIXME: I think jpeg6 is not used at all, can trash?)
84 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' ]:
86 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
87 Export( 'lib_objects' )
88 radiant = SConscript( os.path.join( build_dir, 'SConscript.radiant' ) )
89 self.InstallAs( 'install/radiant.bin', radiant )
91 # PIC versions of the libs for the modules
92 shlib_objects_extra = {}
93 for project in [ 'libs/synapse/synapse.vcproj', 'libs/mathlib/mathlib.vcproj', 'libs/cmdlib/cmdlib.vcproj' ]:
94 ( libpath, libname ) = os.path.split( project )
95 libname = os.path.splitext( libname )[0]
96 config['shared'] = True
97 Export( 'project', 'config' )
98 build_dir = os.path.join( 'build', config_name, 'shobjs' )
99 BuildDir( build_dir, '.', duplicate = 0 )
100 shlib_objects_extra[libname] = SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
102 for project in [ 'plugins/vfspk3/vfspk3.vcproj',
103 'plugins/vfspak/vfspak.vcproj',
104 'plugins/vfswad/vfswad.vcproj',
105 'plugins/eclassfgd/fgd.vcproj',
106 'plugins/entity/entity.vcproj',
107 'plugins/image/image.vcproj',
108 # FIXME: Fix linker flags - xml2, z
109 # 'plugins/imagepng/imagepng.vcproj',
110 'plugins/imagewal/imagewal.vcproj',
111 'plugins/imagem8/imagem8.vcproj',
112 'plugins/spritemodel/spritemodel.vcproj',
113 'plugins/textool/TexTool.vcproj',
114 'plugins/map/map.vcproj',
115 'plugins/mapxml/mapxml.vcproj',
116 'plugins/shaders/shaders.vcproj',
117 'plugins/surface/surface.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 # 'contrib/archivewad/archivewad.vcproj',
127 # FIXME Doesn't compile cleanly
128 # 'contrib/prtview/PrtView.vcproj',
129 'contrib/hydratoolz/hydratoolz.vcproj',
130 'contrib/bobtoolz/bobToolz_gtk.vcproj',
131 'contrib/gtkgensurf/gtkgensurf.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 == 'spritemodel' ):
140 # shlib_objects += shlib_objects_extra['mathlib']
141 # elif ( libname == 'TexTool' ):
142 # shlib_objects += shlib_objects_extra['mathlib']
143 elif ( libname == 'map' ):
144 shlib_objects += shlib_objects_extra['cmdlib']
145 Export( 'project', 'shlib_objects' )
146 module = SConscript( os.path.join( build_dir, 'SConscript.module' ) )
147 self.InstallAs( 'install/modules/%s.so' % libname, module )
149 def emit_q3map2( self ):
151 for config_name in self.config_selected:
153 config['name'] = config_name
154 config['shared'] = False
155 Export( 'utils', 'settings', 'config' )
156 build_dir = os.path.join( 'build', config_name, 'q3map2' )
157 BuildDir( build_dir, '.', duplicate = 0 )
159 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' ]:
161 lib_objects += SConscript( os.path.join( build_dir, 'SConscript.lib' ) )
162 Export( 'lib_objects' )
163 q3map2 = SConscript( os.path.join( build_dir, 'SConscript.q3map2' ) )
164 self.InstallAs( 'install/q3map2.bin', q3map2 )
169 self.target_selected.index( 'radiant' )
175 self.target_selected.index( 'q3map2' )
181 def SetupEnvironment( self, env, config, useGtk = False, useGtkGL = False, useJPEG = False ):
183 env['CXX'] = self.cxx
184 ( ret, xml2 ) = commands.getstatusoutput( 'xml2-config --cflags' )
186 print 'xml2-config failed'
188 xml2libs = commands.getoutput( 'xml2-config --libs' )
189 env.Append( LINKFLAGS = xml2libs.split( ' ' ) )
190 baseflags = [ '-pipe', '-Wall', '-fmessage-length=0', '-fvisibility=hidden', xml2.split( ' ' ) ]
191 # baseflags += [ '-m32' ]
193 if ( self.platform == 'Darwin' ):
194 env.Append( CPPPATH = [ '/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include' ] )
197 ( ret, gtk2 ) = commands.getstatusoutput( 'pkg-config gtk+-2.0 --cflags' )
199 print 'pkg-config gtk+-2.0 failed'
201 baseflags += gtk2.split( ' ' )
202 gtk2libs = commands.getoutput( 'pkg-config gtk+-2.0 --libs' )
203 env.Append( LINKFLAGS = gtk2libs.split( ' ' ) )
205 # always setup at least glib
206 ( ret, glib ) = commands.getstatusoutput( 'pkg-config glib-2.0 --cflags' )
208 print 'pkg-config glib-2.0 failed'
210 baseflags += glib.split( ' ' )
211 gliblibs = commands.getoutput( 'pkg-config glib-2.0 --libs' )
212 env.Append( LINKFLAGS = gliblibs.split( ' ' ) )
215 ( ret, gtkgl ) = commands.getstatusoutput( 'pkg-config gtkglext-1.0 --cflags' )
217 print 'pkg-config gtkglext-1.0 failed'
219 baseflags += gtkgl.split( ' ' )
220 gtkgllibs = commands.getoutput( 'pkg-config gtkglext-1.0 --libs' )
221 env.Append( LINKFLAGS = gtkgllibs.split( ' ' ) )
223 env.Append( LIBS = 'jpeg' )
225 env.Append( CFLAGS = baseflags )
226 env.Append( CXXFLAGS = baseflags + [ '-fpermissive', '-fvisibility-inlines-hidden' ] )
227 env.Append( CPPPATH = [ 'include', 'libs' ] )
228 env.Append( CPPDEFINES = [ 'Q_NO_STLPORT' ] )
229 if ( config == 'debug' ):
230 env.Append( CFLAGS = [ '-g' ] )
231 env.Append( CXXFLAGS = [ '-g' ] )
232 env.Append( CPPDEFINES = [ '_DEBUG' ] )
234 env.Append( CFLAGS = [ '-O3', '-Winline', '-ffast-math', '-fno-unsafe-math-optimizations', '-fno-strict-aliasing' ] )
235 env.Append( CXXFLAGS = [ '-O3', '-Winline', '-ffast-math', '-fno-unsafe-math-optimizations','-fno-strict-aliasing' ] )
236 #env.Append( CFLAGS = [ '-march=pentium3' ] )
238 # env.Append( LINKFLAGS = [ '-m32' ] )
240 # parse the config statement line to produce/update an existing config list
241 # the configs expose a list of keywords and accepted values, which the engine parses out
243 def __init__( self ):
246 def _processOp( self, ops ):
247 assert( len( ops ) == 1 )
249 if ( op == 'clear' ):
251 self.current_config = None
252 elif ( op == 'pop' ):
254 self.current_config = None
255 elif ( op == 'push' ):
256 self.configs.append( self.current_config )
257 self.current_config = Config()
258 self._setupParser( self.current_config )
260 def _setupParser( self, c ):
261 self.operators = { 'op' : self._processOp }
262 c.setupParser( self.operators )
264 def _parseStatement( self, s ):
265 statement_re = re.compile( '(.*)=(.*)' )
266 value_list_re = re.compile( '([^,]*),?' )
267 if ( not statement_re.match( s ) ):
268 print 'syntax error (statement match): %s' % repr( s )
270 statement_split = statement_re.split( s )
271 if ( len( statement_split ) != 4 ):
272 print 'syntax error (statement split): %s' % repr( s )
274 ( foo, name, value, bar ) = statement_split
275 value_split = value_list_re.split( value )
276 if ( len( value_split ) < 2 or len( value_split ) % 2 != 1 ):
277 print 'syntax error (value split): %s' % ( repr( value_split ) )
281 value_split.reverse()
283 while ( len( value_split ) != 0 ):
284 value_array.append( value_split.pop() )
287 print traceback.print_exception( sys.exc_type, sys.exc_value, sys.exc_traceback )
288 print 'syntax error (value to array): %s' % ( repr( value_split ) )
291 return ( name, value_array )
293 def parseStatements( self, _configs, statements ):
294 self.current_config = None
295 self.configs = _configs
296 if ( self.configs is None ):
300 if ( self.current_config is None ):
301 # use a provided config, or create a default one
302 if ( len( self.configs ) > 0 ):
303 self.current_config = self.configs.pop()
305 self.current_config = Config()
306 # setup the operator table for this config
307 # NOTE: have that in self._processOp too
308 self._setupParser( self.current_config )
310 ret = self._parseStatement( s )
312 print 'stop statement parse at %s' % repr( s )
314 ( name, value_array ) = ret
316 processor = self.operators[name]
318 print 'unknown operator %s - stop statement parse at %s' % ( repr( name ), repr( s ) )
320 processor( value_array )
322 if ( not self.current_config is None ):
323 self.configs.append( self.current_config )
324 # make sure there is at least one config
325 if ( len( self.configs ) == 0 ):
326 print 'pushing a default config'
327 self.configs.append( Config() )
332 class TestConfigParse( unittest.TestCase ):
335 self.parser = ConfigParser()
337 def testBasicParse( self ):
338 # test basic config parsing
339 # needs to cleanly stop at the first config statement that is not recognized
340 configs = self.parser.parseStatements( None, [ 'game=missionpack', 'config=qvm', 'foobar' ] )
341 print repr( configs )
343 def testMultiParse( self ):
344 # multiple configs seperated by commas
345 configs = self.parser.parseStatements( None, [ 'target=server,game,cgame' ] )
346 print repr( configs )
349 # test the operator for multiple configs
350 configs = self.parser.parseStatements( None, [ 'target=core', 'config=release', 'op=push', 'target=game,cgame,ui', 'config=debug' ] )
351 print repr( configs )
353 if __name__ == '__main__':