2 # http://scons.sourceforge.net
4 import commands, re, sys, os, pickle, string, popen2
5 from makeversion import radiant_makeversion, get_version
6 from osx_setup import do_osx_setup
8 # to access some internal stuff
11 conf_filename='site.conf'
12 # there is a default hardcoded value, you can override on command line, those are saved between runs
13 # we only handle strings
14 serialized=['CC', 'CXX', 'JOBS', 'BUILD', 'SETUP']
16 # help -------------------------------------------
19 Usage: scons [OPTIONS] [TARGET] [CONFIG]
21 [OPTIONS] and [TARGET] are covered in command line options, use scons -H
23 [CONFIG]: KEY="VALUE" [...]
24 a number of configuration options saved between runs in the """ + conf_filename + """ file
25 erase """ + conf_filename + """ to start with default settings again
29 Specify C and C++ compilers (defaults gcc and g++)
31 You can use ccache and distcc, for instance:
32 CC="ccache distcc gcc" CXX="ccache distcc g++"
36 ex: JOBS="4" is a good setting on SMP machines
39 Use debug/release to select build settings
40 ex: BUILD="release" - default is debug
41 OSX: use BUILD="info" to generate the set of release files
44 Build a setup - default 0
48 # end help ---------------------------------------
50 # sanity -----------------------------------------
52 # get a recent python release
53 # that is broken in current version:
54 # http://sourceforge.net/tracker/index.php?func=detail&aid=794145&group_id=30337&atid=398971
55 #EnsurePythonVersion(2,1)
57 EnsureSConsVersion( 0, 96 )
58 print 'SCons ' + SCons.__version__
60 # end sanity -------------------------------------
62 # system detection -------------------------------
64 # TODO: detect Darwin / OSX
67 g_cpu = commands.getoutput('uname -m')
68 exp = re.compile('.*i?86.*')
69 if (g_cpu == 'Power Macintosh' or g_cpu == 'ppc'):
71 elif exp.match(g_cpu):
77 OS = commands.getoutput('uname')
78 print "OS=\"" + OS + "\""
81 # libc .. do the little magic!
82 libc = commands.getoutput('/lib/libc.so.6 |grep "GNU C "|grep version|awk -F "version " \'{ print $2 }\'|cut -b -3')
84 # end system detection ---------------------------
86 # default settings -------------------------------
94 g_build_root = 'build'
96 # end default settings ---------------------------
98 # site settings ----------------------------------
101 if (os.path.exists(conf_filename)):
102 site_file = open(conf_filename, 'r')
103 p = pickle.Unpickler(site_file)
105 print 'Loading build configuration from ' + conf_filename
106 for k, v in site_dict.items():
107 exec_cmd = k + '=\"' + v + '\"'
111 # end site settings ------------------------------
113 # command line settings --------------------------
116 if (ARGUMENTS.has_key(k)):
117 exec_cmd = k + '=\"' + ARGUMENTS[k] + '\"'
118 print 'Command line: ' + exec_cmd
121 # end command line settings ----------------------
123 # sanity check -----------------------------------
125 if (SETUP == '1' and BUILD != 'release' and BUILD != 'info'):
126 print 'Forcing release build for setup'
129 def GetGCCVersion(name):
130 ret = commands.getstatusoutput('%s -dumpversion' % name)
133 vers = string.split(ret[1], '.')
134 if ( len(vers) == 2 ):
135 return [ vers[0], vers[1], 0 ]
136 elif ( len(vers) == 3 ):
140 ver_cc = GetGCCVersion(CC)
141 ver_cxx = GetGCCVersion(CXX)
143 if ( ver_cc is None or ver_cxx is None or ver_cc[0] < '3' or ver_cxx[0] < '3' or ver_cc != ver_cxx ):
144 print 'Compiler version check failed - need gcc 3.x or later:'
145 print 'CC: %s %s\nCXX: %s %s' % ( CC, repr(ver_cc), CXX, repr(ver_cxx) )
148 # end sanity check -------------------------------
150 # save site configuration ----------------------
153 exec_cmd = 'site_dict[\'' + k + '\'] = ' + k
156 site_file = open(conf_filename, 'w')
157 p = pickle.Pickler(site_file)
161 # end save site configuration ------------------
163 # general configuration, target selection --------
165 SConsignFile( "scons.signatures" )
167 g_build = g_build_root + '/' + BUILD
169 SetOption('num_jobs', JOBS)
173 warningFlags = '-W -Wall -Wcast-align -Wcast-qual -Wno-unused-parameter '
174 warningFlagsCXX = '-Wno-non-virtual-dtor -Wreorder ' # -Wold-style-cast
175 CCFLAGS = '' + warningFlags
176 CXXFLAGS = '-pipe -DQ_NO_STLPORT ' + warningFlags + warningFlagsCXX
178 if (BUILD == 'debug'):
179 CXXFLAGS += '-g -D_DEBUG '
180 CCFLAGS += '-g -D_DEBUG '
181 elif (BUILD == 'release'):
184 elif ( BUILD == 'info' ):
185 print 'Preparing OSX release'
186 ( line, major, minor ) = get_version()
187 do_osx_setup( major, minor, 'osx-radiant-%s.run' % line )
190 print 'Unknown build configuration ' + BUILD
194 if ( OS == 'Linux' ):
197 # 2112833 /opt/gtkradiant/radiant.x86
198 # 35282 /opt/gtkradiant/modules/archivezip.so
199 # 600099 /opt/gtkradiant/modules/entity.so
202 # 2237060 /opt/gtkradiant/radiant.x86
203 # 110605 /opt/gtkradiant/modules/archivezip.so
204 # 730222 /opt/gtkradiant/modules/entity.so
206 # EVIL HACK - force static-linking for libstdc++ - create a symbolic link to the static libstdc++ in the root
207 os.system("ln -s `g++ -print-file-name=libstdc++.a`")
209 #if not os.path.exists("./install"):
210 # os.mkdir("./install")
211 #os.system("cp `g++ -print-file-name=libstdc++.so` ./install")
213 CXXFLAGS += '-fno-exceptions -fno-rtti '
214 LINKFLAGS += '-Wl,-fini,fini_stub -L. -static-libgcc '
215 if ( OS == 'Darwin' ):
216 CCFLAGS += '-force_cpusubtype_ALL -fPIC '
217 CXXFLAGS += '-force_cpusubtype_ALL -fPIC -fno-exceptions -fno-rtti '
218 CPPPATH.append('/sw/include')
219 CPPPATH.append('/usr/X11R6/include')
220 LINKFLAGS += '-L/sw/lib -L/usr/lib -L/usr/X11R6/lib '
222 CPPPATH.append('libs')
224 # extend the standard Environment a bit
225 class idEnvironment(Environment):
228 Environment.__init__(self,
236 LINKFLAGS = LINKFLAGS)
239 self['CXXFLAGS'] += '`pkg-config glib-2.0 --cflags` '
240 self['CCFLAGS'] += '`pkg-config glib-2.0 --cflags` '
241 self['LINKFLAGS'] += '-lglib-2.0 '
244 self['CXXFLAGS'] += '`xml2-config --cflags` '
245 self['CCFLAGS'] += '`xml2-config --cflags` '
246 self['LINKFLAGS'] += '-lxml2 '
249 self['CXXFLAGS'] += '`pkg-config gtk+-2.0 --cflags` '
250 self['CCFLAGS'] += '`pkg-config gtk+-2.0 --cflags` '
251 self['LINKFLAGS'] += '-lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpango-1.0 -lgdk_pixbuf-2.0 '
253 def useGtkGLExt(self):
254 self['CXXFLAGS'] += '`pkg-config gtkglext-1.0 --cflags` '
255 self['CCFLAGS'] += '`pkg-config gtkglext-1.0 --cflags` '
256 self['LINKFLAGS'] += '-lgtkglext-x11-1.0 -lgdkglext-x11-1.0 '
259 self['CXXFLAGS'] += '`libpng-config --cflags` '
260 self['CCFLAGS'] += '`libpng-config --cflags` '
261 self['LINKFLAGS'] += '`libpng-config --ldflags` '
264 self['LINKFLAGS'] += '-lmhash '
267 self['LINKFLAGS'] += '-lz '
269 def usePThread(self):
270 if ( OS == 'Darwin' ):
271 self['LINKFLAGS'] += '-lpthread -Wl,-stack_size,0x400000 '
273 self['LINKFLAGS'] += '-lpthread '
275 def CheckLDD(self, target, source, env):
277 if (not os.path.isfile(file.abspath)):
278 print('ERROR: CheckLDD: target %s not found\n' % target[0])
280 # not using os.popen3 as I want to check the return code
281 ldd = popen2.Popen3('`which ldd` -r %s' % target[0], 1)
282 stdout_lines = ldd.fromchild.readlines()
283 stderr_lines = ldd.childerr.readlines()
288 print "ERROR: ldd command returned with exit code %d" % ldd_ret
289 os.system('rm %s' % target[0])
291 for i_line in stderr_lines:
293 regex = re.compile('undefined symbol: (.*)\t\\((.*)\\)\n')
294 if ( regex.match(i_line) ):
295 symbol = regex.sub('\\1', i_line)
297 env['ALLOWED_SYMBOLS'].index(symbol)
301 print "ERROR: failed to parse ldd stderr line: %s" % i_line
302 os.system('rm %s' % target[0])
305 print "ERROR: undefined symbols"
306 os.system('rm %s' % target[0])
309 def SharedLibrarySafe(self, target, source, LIBS=[], LIBPATH='.'):
310 result = self.SharedLibrary(target, source, LIBS=LIBS, LIBPATH=LIBPATH)
312 AddPostAction(target + '.so', self.CheckLDD)
315 g_env = idEnvironment()
318 GLOBALS = 'g_env INSTALL SETUP g_cpu'
320 radiant_makeversion('\\ngcc version: %s.%s.%s' % ( ver_cc[0], ver_cc[1], ver_cc[2] ) )
322 # end general configuration ----------------------
324 # targets ----------------------------------------
328 Export('GLOBALS ' + GLOBALS)
329 BuildDir(g_build, '.', duplicate = 0)
330 SConscript(g_build + '/SConscript')
332 # end targets ------------------------------------