2 # http://scons.sourceforge.net
4 import commands, re, sys, os, pickle, string, popen2
5 from makeversion import radiant_makeversion, get_version
7 # to access some internal stuff
10 conf_filename='site.conf'
11 # there is a default hardcoded value, you can override on command line, those are saved between runs
12 # we only handle strings
13 serialized=['CC', 'CXX', 'JOBS', 'BUILD']
15 # help -------------------------------------------
18 Usage: scons [OPTIONS] [TARGET] [CONFIG]
20 [OPTIONS] and [TARGET] are covered in command line options, use scons -H
22 [CONFIG]: KEY="VALUE" [...]
23 a number of configuration options saved between runs in the """ + conf_filename + """ file
24 erase """ + conf_filename + """ to start with default settings again
28 Specify C and C++ compilers (defaults gcc and g++)
30 You can use ccache and distcc, for instance:
31 CC="ccache distcc gcc" CXX="ccache distcc g++"
35 ex: JOBS="4" is a good setting on SMP machines
38 Use debug/release to select build settings
39 ex: BUILD="debug" - default is debug
43 # end help ---------------------------------------
45 # sanity -----------------------------------------
47 # get a recent python release
48 # that is broken in current version:
49 # http://sourceforge.net/tracker/index.php?func=detail&aid=794145&group_id=30337&atid=398971
50 #EnsurePythonVersion(2,1)
52 EnsureSConsVersion( 0, 96 )
53 print 'SCons ' + SCons.__version__
55 # end sanity -------------------------------------
57 # system detection -------------------------------
59 # TODO: detect Darwin / OSX
62 g_cpu = commands.getoutput('uname -m')
63 exp = re.compile('.*i?86.*')
64 if (g_cpu == 'Power Macintosh' or g_cpu == 'ppc'):
66 elif exp.match(g_cpu):
72 OS = commands.getoutput('uname')
73 print "OS=\"" + OS + "\""
76 # libc .. do the little magic!
77 libc = commands.getoutput('/lib/libc.so.6 |grep "GNU C "|grep version|awk -F "version " \'{ print $2 }\'|cut -b -3')
79 # end system detection ---------------------------
81 # default settings -------------------------------
88 g_build_root = 'build'
90 # end default settings ---------------------------
92 # site settings ----------------------------------
95 if (os.path.exists(conf_filename)):
96 site_file = open(conf_filename, 'r')
97 p = pickle.Unpickler(site_file)
99 print 'Loading build configuration from ' + conf_filename
100 for k, v in site_dict.items():
101 exec_cmd = k + '=\"' + v + '\"'
105 # end site settings ------------------------------
107 # command line settings --------------------------
110 if (ARGUMENTS.has_key(k)):
111 exec_cmd = k + '=\"' + ARGUMENTS[k] + '\"'
112 print 'Command line: ' + exec_cmd
115 # end command line settings ----------------------
117 # sanity check -----------------------------------
120 def GetGCCVersion(name):
121 ret = commands.getstatusoutput('%s -dumpversion' % name)
124 vers = string.split(ret[1], '.')
125 if ( len(vers) == 2 ):
126 return [ vers[0], vers[1], 0 ]
127 elif ( len(vers) == 3 ):
131 ver_cc = GetGCCVersion(CC)
132 ver_cxx = GetGCCVersion(CXX)
134 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 ):
135 print 'Compiler version check failed - need gcc 3.x or later:'
136 print 'CC: %s %s\nCXX: %s %s' % ( CC, repr(ver_cc), CXX, repr(ver_cxx) )
139 # end sanity check -------------------------------
141 # save site configuration ----------------------
144 exec_cmd = 'site_dict[\'' + k + '\'] = ' + k
147 site_file = open(conf_filename, 'w')
148 p = pickle.Pickler(site_file)
152 # end save site configuration ------------------
154 # general configuration, target selection --------
156 SConsignFile( "scons.signatures" )
158 g_build = g_build_root + '/' + BUILD
160 SetOption('num_jobs', JOBS)
164 warningFlags = '-W -Wall -Wcast-align -Wcast-qual -Wno-unused-parameter '
165 warningFlagsCXX = '-Wno-non-virtual-dtor -Wreorder ' # -Wold-style-cast
166 # POSIX macro: platform supports posix IEEE Std 1003.1:2001
167 # XWINDOWS macro: platform supports X-Windows API
168 CCFLAGS = '-DPOSIX -DXWINDOWS ' + warningFlags
169 CXXFLAGS = '-pipe -DPOSIX -DXWINDOWS ' + warningFlags + warningFlagsCXX
171 if (BUILD == 'debug'):
172 CXXFLAGS += '-g3 -D_DEBUG '
173 CCFLAGS += '-g3 -D_DEBUG '
174 elif (BUILD == 'release' or BUILD == 'final'):
178 print 'Unknown build configuration ' + BUILD
182 if ( OS == 'Linux' ):
184 if ( BUILD == 'final' ):
186 # 2112833 /opt/gtkradiant/radiant.x86
187 # 35282 /opt/gtkradiant/modules/archivezip.so
188 # 600099 /opt/gtkradiant/modules/entity.so
191 # 2237060 /opt/gtkradiant/radiant.x86
192 # 110605 /opt/gtkradiant/modules/archivezip.so
193 # 730222 /opt/gtkradiant/modules/entity.so
195 # EVIL HACK - force static-linking for libstdc++ - create a symbolic link to the static libstdc++ in the root
196 os.system("ln -s `g++ -print-file-name=libstdc++.a`")
198 #if not os.path.exists("./install"):
199 # os.mkdir("./install")
200 #os.system("cp `g++ -print-file-name=libstdc++.so` ./install")
202 # -fPIC might be worth removing when building for 32-bit x86
204 CXXFLAGS += '-fPIC -fno-exceptions -fno-rtti '
205 LINKFLAGS += '-fPIC -Wl,-fini,fini_stub -L. -static-libgcc '
207 if ( OS == 'Darwin' ):
208 CCFLAGS += '-force_cpusubtype_ALL -fPIC '
209 CXXFLAGS += '-force_cpusubtype_ALL -fPIC -fno-exceptions -fno-rtti '
210 CPPPATH.append('/sw/include')
211 CPPPATH.append('/usr/X11R6/include')
212 LINKFLAGS += '-L/sw/lib -L/usr/lib -L/usr/X11R6/lib '
214 CPPPATH.append('libs')
216 # extend the standard Environment a bit
217 class idEnvironment(Environment):
220 Environment.__init__(self,
228 LINKFLAGS = LINKFLAGS)
231 self['CXXFLAGS'] += '`pkg-config glib-2.0 --cflags` '
232 self['CCFLAGS'] += '`pkg-config glib-2.0 --cflags` '
234 self['LINKFLAGS'] += '-lglib-2.0 '
236 self['LINKFLAGS'] += '`pkg-config glib-2.0 --libs` '
240 self['CXXFLAGS'] += '`xml2-config --cflags` '
241 self['CCFLAGS'] += '`xml2-config --cflags` '
243 self['LINKFLAGS'] += '-lxml2 '
245 self['LINKFLAGS'] += '`xml2-config --libs` '
248 self['CXXFLAGS'] += '`pkg-config gtk+-2.0 --cflags` '
249 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 self['LINKFLAGS'] += '`pkg-config gtk+-2.0 --libs-only-L` `pkg-config gtk+-2.0 --libs-only-l` '
255 def useGtkGLExt(self):
256 self['CXXFLAGS'] += '`pkg-config gtkglext-1.0 --cflags` '
257 self['CCFLAGS'] += '`pkg-config gtkglext-1.0 --cflags` '
258 #if BUILD == 'final':
259 self['LINKFLAGS'] += '-lgtkglext-x11-1.0 -lgdkglext-x11-1.0 '
260 # apparently pkg-config for gtkglext includes --export-dynamic, which b0rks everything.
262 # self['LINKFLAGS'] += 'pkg-config gtkglext-1.0 --libs-only-L` `pkg-config gtkglext-1.0 --libs-only-l` '
265 self['CXXFLAGS'] += '`libpng-config --cflags` '
266 self['CCFLAGS'] += '`libpng-config --cflags` '
267 self['LINKFLAGS'] += '`libpng-config --ldflags` '
270 self['LINKFLAGS'] += '-lmhash '
273 self['LINKFLAGS'] += '-lz '
275 def usePThread(self):
276 if ( OS == 'Darwin' ):
277 self['LINKFLAGS'] += '-lpthread -Wl,-stack_size,0x400000 '
279 self['LINKFLAGS'] += '-lpthread '
281 def CheckLDD(self, target, source, env):
283 if (not os.path.isfile(file.abspath)):
284 print('ERROR: CheckLDD: target %s not found\n' % target[0])
286 # not using os.popen3 as I want to check the return code
287 ldd = popen2.Popen3('`which ldd` -r %s' % target[0], 1)
288 stdout_lines = ldd.fromchild.readlines()
289 stderr_lines = ldd.childerr.readlines()
294 print "ERROR: ldd command returned with exit code %d" % ldd_ret
295 os.system('rm %s' % target[0])
297 for i_line in stderr_lines:
299 regex = re.compile('undefined symbol: (.*)\t\\((.*)\\)\n')
300 if ( regex.match(i_line) ):
301 symbol = regex.sub('\\1', i_line)
303 env['ALLOWED_SYMBOLS'].index(symbol)
307 print "ERROR: failed to parse ldd stderr line: %s" % i_line
308 os.system('rm %s' % target[0])
311 print "ERROR: undefined symbols"
312 os.system('rm %s' % target[0])
315 def SharedLibrarySafe(self, target, source, LIBS=[], LIBPATH='.'):
316 result = self.SharedLibrary(target, source, LIBS=LIBS, LIBPATH=LIBPATH)
318 AddPostAction(target + '.so', self.CheckLDD)
321 g_env = idEnvironment()
324 GLOBALS = 'g_env INSTALL g_cpu'
326 radiant_makeversion('\\ngcc version: %s.%s.%s' % ( ver_cc[0], ver_cc[1], ver_cc[2] ) )
328 # end general configuration ----------------------
330 # targets ----------------------------------------
334 Export('GLOBALS ' + GLOBALS)
335 BuildDir(g_build, '.', duplicate = 0)
336 SConscript(g_build + '/SConscript')
338 # end targets ------------------------------------