Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 333 lines (260 sloc) 9.54 kB
0991a5c @tbradshaw The GtkRadiant sources as originally released under the GPL license.
tbradshaw authored
1 # scons build script
2 # http://scons.sourceforge.net
3
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
7
8 # to access some internal stuff
9 import SCons
10
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']
15
16 # help -------------------------------------------
17
18 Help("""
19 Usage: scons [OPTIONS] [TARGET] [CONFIG]
20
21 [OPTIONS] and [TARGET] are covered in command line options, use scons -H
22
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
26
27 CC
28 CXX
29 Specify C and C++ compilers (defaults gcc and g++)
30 ex: CC="gcc-3.2"
31 You can use ccache and distcc, for instance:
32 CC="ccache distcc gcc" CXX="ccache distcc g++"
33
34 JOBS
35 Parallel build
36 ex: JOBS="4" is a good setting on SMP machines
37
38 BUILD
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
42
43 SETUP
44 Build a setup - default 0
45 """
46 )
47
48 # end help ---------------------------------------
49
50 # sanity -----------------------------------------
51
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)
56 # above 0.90
57 EnsureSConsVersion( 0, 96 )
58 print 'SCons ' + SCons.__version__
59
60 # end sanity -------------------------------------
61
62 # system detection -------------------------------
63
64 # TODO: detect Darwin / OSX
65
66 # CPU type
67 g_cpu = commands.getoutput('uname -m')
68 exp = re.compile('.*i?86.*')
69 if (g_cpu == 'Power Macintosh' or g_cpu == 'ppc'):
70 g_cpu = 'ppc'
71 elif exp.match(g_cpu):
72 g_cpu = 'x86'
73 else:
74 g_cpu = 'cpu'
75
76 # OS
77 OS = commands.getoutput('uname')
78 print "OS=\"" + OS + "\""
79
80 if (OS == 'Linux'):
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')
83
84 # end system detection ---------------------------
85
86 # default settings -------------------------------
87
88 CC='gcc'
89 CXX='g++'
90 JOBS='1'
91 BUILD='debug'
92 INSTALL='#install'
93 SETUP='0'
94 g_build_root = 'build'
95
96 # end default settings ---------------------------
97
98 # site settings ----------------------------------
99
100 site_dict = {}
101 if (os.path.exists(conf_filename)):
102 site_file = open(conf_filename, 'r')
103 p = pickle.Unpickler(site_file)
104 site_dict = p.load()
105 print 'Loading build configuration from ' + conf_filename
106 for k, v in site_dict.items():
107 exec_cmd = k + '=\"' + v + '\"'
108 print exec_cmd
109 exec(exec_cmd)
110
111 # end site settings ------------------------------
112
113 # command line settings --------------------------
114
115 for k in serialized:
116 if (ARGUMENTS.has_key(k)):
117 exec_cmd = k + '=\"' + ARGUMENTS[k] + '\"'
118 print 'Command line: ' + exec_cmd
119 exec(exec_cmd)
120
121 # end command line settings ----------------------
122
123 # sanity check -----------------------------------
124
125 if (SETUP == '1' and BUILD != 'release' and BUILD != 'info'):
126 print 'Forcing release build for setup'
127 BUILD = 'release'
128
129 def GetGCCVersion(name):
130 ret = commands.getstatusoutput('%s -dumpversion' % name)
131 if ( ret[0] != 0 ):
132 return None
133 vers = string.split(ret[1], '.')
134 if ( len(vers) == 2 ):
135 return [ vers[0], vers[1], 0 ]
136 elif ( len(vers) == 3 ):
137 return vers
138 return None
139
140 ver_cc = GetGCCVersion(CC)
141 ver_cxx = GetGCCVersion(CXX)
142
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) )
146 Exit(1)
147
148 # end sanity check -------------------------------
149
150 # save site configuration ----------------------
151
152 for k in serialized:
153 exec_cmd = 'site_dict[\'' + k + '\'] = ' + k
154 exec(exec_cmd)
155
156 site_file = open(conf_filename, 'w')
157 p = pickle.Pickler(site_file)
158 p.dump(site_dict)
159 site_file.close()
160
161 # end save site configuration ------------------
162
163 # general configuration, target selection --------
164
165 SConsignFile( "scons.signatures" )
166
167 g_build = g_build_root + '/' + BUILD
168
169 SetOption('num_jobs', JOBS)
170
171 LINK = CXX
172 # common flags
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
177 CPPPATH = []
178 if (BUILD == 'debug'):
179 CXXFLAGS += '-g -D_DEBUG '
180 CCFLAGS += '-g -D_DEBUG '
181 elif (BUILD == 'release'):
182 CXXFLAGS += '-O2 '
183 CCFLAGS += '-O2 '
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 )
188 sys.exit( 0 )
189 else:
190 print 'Unknown build configuration ' + BUILD
191 sys.exit( 0 )
192
193 LINKFLAGS = ''
194 if ( OS == 'Linux' ):
195
196 # static
197 # 2112833 /opt/gtkradiant/radiant.x86
198 # 35282 /opt/gtkradiant/modules/archivezip.so
199 # 600099 /opt/gtkradiant/modules/entity.so
200
201 # dynamic
202 # 2237060 /opt/gtkradiant/radiant.x86
203 # 110605 /opt/gtkradiant/modules/archivezip.so
204 # 730222 /opt/gtkradiant/modules/entity.so
205
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`")
208
209 #if not os.path.exists("./install"):
210 # os.mkdir("./install")
211 #os.system("cp `g++ -print-file-name=libstdc++.so` ./install")
212
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 '
221
222 CPPPATH.append('libs')
223
224 # extend the standard Environment a bit
225 class idEnvironment(Environment):
226
227 def __init__(self):
228 Environment.__init__(self,
229 ENV = os.environ,
230 CC = CC,
231 CXX = CXX,
232 LINK = LINK,
233 CCFLAGS = CCFLAGS,
234 CXXFLAGS = CXXFLAGS,
235 CPPPATH = CPPPATH,
236 LINKFLAGS = LINKFLAGS)
237
238 def useGlib2(self):
239 self['CXXFLAGS'] += '`pkg-config glib-2.0 --cflags` '
240 self['CCFLAGS'] += '`pkg-config glib-2.0 --cflags` '
241 self['LINKFLAGS'] += '-lglib-2.0 '
242
243 def useXML2(self):
244 self['CXXFLAGS'] += '`xml2-config --cflags` '
245 self['CCFLAGS'] += '`xml2-config --cflags` '
246 self['LINKFLAGS'] += '-lxml2 '
247
248 def useGtk2(self):
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 '
252
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 '
257
258 def usePNG(self):
259 self['CXXFLAGS'] += '`libpng-config --cflags` '
260 self['CCFLAGS'] += '`libpng-config --cflags` '
261 self['LINKFLAGS'] += '`libpng-config --ldflags` '
262
263 def useMHash(self):
264 self['LINKFLAGS'] += '-lmhash '
265
266 def useZLib(self):
267 self['LINKFLAGS'] += '-lz '
268
269 def usePThread(self):
270 if ( OS == 'Darwin' ):
271 self['LINKFLAGS'] += '-lpthread -Wl,-stack_size,0x400000 '
272 else:
273 self['LINKFLAGS'] += '-lpthread '
274
275 def CheckLDD(self, target, source, env):
276 file = target[0]
277 if (not os.path.isfile(file.abspath)):
278 print('ERROR: CheckLDD: target %s not found\n' % target[0])
279 Exit(1)
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()
284 ldd_ret = ldd.wait()
285 del ldd
286 have_undef = 0
287 if ( ldd_ret != 0 ):
288 print "ERROR: ldd command returned with exit code %d" % ldd_ret
289 os.system('rm %s' % target[0])
290 Exit()
291 for i_line in stderr_lines:
292 print repr(i_line)
293 regex = re.compile('undefined symbol: (.*)\t\\((.*)\\)\n')
294 if ( regex.match(i_line) ):
295 symbol = regex.sub('\\1', i_line)
296 try:
297 env['ALLOWED_SYMBOLS'].index(symbol)
298 except:
299 have_undef = 1
300 else:
301 print "ERROR: failed to parse ldd stderr line: %s" % i_line
302 os.system('rm %s' % target[0])
303 Exit(1)
304 if ( have_undef ):
305 print "ERROR: undefined symbols"
306 os.system('rm %s' % target[0])
307 Exit(1)
308
309 def SharedLibrarySafe(self, target, source, LIBS=[], LIBPATH='.'):
310 result = self.SharedLibrary(target, source, LIBS=LIBS, LIBPATH=LIBPATH)
311 if (OS != 'Darwin'):
312 AddPostAction(target + '.so', self.CheckLDD)
313 return result
314
315 g_env = idEnvironment()
316
317 # export the globals
318 GLOBALS = 'g_env INSTALL SETUP g_cpu'
319
320 radiant_makeversion('\\ngcc version: %s.%s.%s' % ( ver_cc[0], ver_cc[1], ver_cc[2] ) )
321
322 # end general configuration ----------------------
323
324 # targets ----------------------------------------
325
326 Default('.')
327
328 Export('GLOBALS ' + GLOBALS)
329 BuildDir(g_build, '.', duplicate = 0)
330 SConscript(g_build + '/SConscript')
331
332 # end targets ------------------------------------
Something went wrong with that request. Please try again.