37 EnsureSConsVersion(0, 97) |
37 EnsureSConsVersion(0, 97) |
38 |
38 |
39 Decider('MD5-timestamp') |
39 Decider('MD5-timestamp') |
40 SConsignFile('build/.sconsign.dblite') |
40 SConsignFile('build/.sconsign.dblite') |
41 |
41 |
42 if sys.platform == 'win32': |
42 env = Environment(tools = ['default'], CPPPATH = ['.','#include','#build/include']) |
43 tools = ['mingw'] |
|
44 else: |
|
45 tools = ['default'] |
|
46 |
|
47 env = Environment(tools = tools, CPPPATH = ['.','#include','#build/include']) |
|
48 |
43 |
49 vars = Variables(files=['build/.varscache']) |
44 vars = Variables(files=['build/.varscache']) |
50 vars.AddVariables( |
45 vars.AddVariables( |
51 BoolVariable('simd', 'allow SSE intrinsics', True), |
46 BoolVariable('simd', 'allow SSE intrinsics', True), |
52 ('precision', 'floating point number precision (single/double)', "single"), |
47 ('precision', 'floating point number precision (single/double)', "single"), |
53 ('flags', 'add additional compiler flags', ""), |
48 ('flags', 'add additional compiler flags', ""), |
54 BoolVariable('force_flags', "use only flags specified by 'flags' option (do not autodetect arch/sse flags)", False), |
49 BoolVariable('force_flags', "use only flags specified by 'flags' option (do not autodetect arch/sse flags)", False), |
55 ('ldflags', 'add additional linker flags', ""), |
50 ('ldflags', 'add additional linker flags', ""), |
56 BoolVariable('profile', "enable gcc's profiling support (-pg)", False), |
51 BoolVariable('profile', "enable gcc's profiling support (-pg)", False), |
|
52 BoolVariable('intelc', 'use Intel C++ Compiler, if available', False), |
57 ) |
53 ) |
58 if env['PLATFORM'] == 'win32': |
|
59 vars.AddVariables( |
|
60 BoolVariable('mingw', 'use Mingw and GCC compiler, if available', False), |
|
61 ('pythonpath', 'path to Python installation', |
|
62 'C:\\Python%c%c' % (sys.version[0], sys.version[2])), |
|
63 ) |
|
64 else: |
|
65 vars.AddVariables( |
|
66 BoolVariable('intelc', 'use Intel C++ Compiler, if available', False), |
|
67 ) |
|
68 |
54 |
69 |
55 |
70 vars.Update(env) |
56 vars.Update(env) |
71 vars.Save('build/.varscache', env) |
57 vars.Save('build/.varscache', env) |
72 Help(vars.GenerateHelpText(env)) |
58 Help(vars.GenerateHelpText(env)) |
114 else: |
98 else: |
115 gccversion = '' |
99 gccversion = '' |
116 context.Result(False) |
100 context.Result(False) |
117 return gcc |
101 return gcc |
118 |
102 |
119 def CheckMSVC(context): |
|
120 global msvc, msvcversion |
|
121 context.Message('Checking for MSVC compiler... ') |
|
122 testenv = Environment() |
|
123 msvc = "msvc" in testenv['TOOLS'] |
|
124 if msvc: |
|
125 msvcversion = testenv['MSVS_VERSION'] |
|
126 context.Result(msvcversion) |
|
127 else: |
|
128 msvcversion = '' |
|
129 context.Result(False) |
|
130 return msvc |
|
131 |
|
132 def CheckCPUFlags(context): |
103 def CheckCPUFlags(context): |
133 global cpu, cpuflags_gcc, cpuflags_intelc |
104 global cpu, cpuflags_gcc, cpuflags_intelc |
134 context.Message('Checking CPU arch and flags... ') |
105 context.Message('Checking CPU arch and flags... ') |
135 env.Execute('@$CC tools/cpuflags.c -o tools/cpuflags') |
106 env.Execute('@$CC tools/cpuflags.c -o tools/cpuflags') |
136 (cpu, cpuflags_gcc, cpuflags_intelc) = os.popen('tools'+os.sep+'cpuflags %s %s' |
107 (cpu, cpuflags_gcc, cpuflags_intelc) = os.popen('tools'+os.sep+'cpuflags %s %s' |
142 log_file="#build/config.log" |
113 log_file="#build/config.log" |
143 config_h="#build/include/config.h" |
114 config_h="#build/include/config.h" |
144 conf = Configure(env, conf_dir=conf_dir, log_file=log_file, config_h=config_h, |
115 conf = Configure(env, conf_dir=conf_dir, log_file=log_file, config_h=config_h, |
145 clean=False, help=False, |
116 clean=False, help=False, |
146 custom_tests = { |
117 custom_tests = { |
147 'CheckPlatform' : CheckPlatform, 'CheckCPUFlags' : CheckCPUFlags, |
118 'CheckPlatform' : CheckPlatform, |
148 'CheckIntelC' : CheckIntelC, 'CheckGCC' : CheckGCC, 'CheckMSVC' : CheckMSVC}) |
119 'CheckCPUFlags' : CheckCPUFlags, |
|
120 'CheckIntelC' : CheckIntelC, |
|
121 'CheckGCC' : CheckGCC, |
|
122 }) |
149 conf.CheckPlatform() |
123 conf.CheckPlatform() |
150 |
124 |
151 conf.CheckGCC() |
125 conf.CheckGCC() |
152 if platform == 'win32': |
126 conf.CheckIntelC() |
153 conf.CheckMSVC() |
|
154 intelc = False |
|
155 else: |
|
156 conf.CheckIntelC() |
|
157 msvc=False |
|
158 |
127 |
159 if intelc and (not gcc or conf.env['intelc']): |
128 if intelc and (not gcc or conf.env['intelc']): |
160 Tool('intelc').generate(conf.env) |
129 Tool('intelc').generate(conf.env) |
161 cc = 'intelc' |
130 cc = 'intelc' |
162 elif msvc and (not gcc or not conf.env['mingw']): |
|
163 Tool('default').generate(conf.env) |
|
164 conf.Define("MSVC") |
|
165 cc = 'msvc' |
|
166 elif gcc: |
131 elif gcc: |
167 cc = 'gcc' |
132 cc = 'gcc' |
168 else: |
133 else: |
169 cc = 'none' |
134 cc = 'none' |
170 |
135 |
171 if cc == 'intelc' or cc == 'gcc': |
136 if cc == 'intelc' or cc == 'gcc': |
172 conf.CheckCPUFlags() |
137 conf.CheckCPUFlags() |
173 |
|
174 if platform == 'win32' and cc == 'gcc': |
|
175 conf.env.Append(LIBPATH=["C:/mingw/lib", "C:/msys/mingw/lib"]) |
|
176 conf.env.Append(CPPPATH=["C:/mingw/include", "C:/msys/mingw/include"]) |
|
177 |
138 |
178 add_flags = '' |
139 add_flags = '' |
179 if cc == 'gcc': |
140 if cc == 'gcc': |
180 add_flags += cpuflags_gcc + ' -ffast-math ' |
141 add_flags += cpuflags_gcc + ' -ffast-math ' |
181 if cc == 'intelc': |
142 if cc == 'intelc': |
182 add_flags += cpuflags_intelc + ' ' |
143 add_flags += cpuflags_intelc + ' ' |
183 if cc == 'msvc': |
|
184 add_flags += '/fp:fast ' |
|
185 if conf.env['simd']: |
|
186 add_flags += '/arch:SSE ' |
|
187 |
144 |
188 if conf.env['force_flags']: |
145 if conf.env['force_flags']: |
189 add_flags = conf.env['flags'] + ' ' |
146 add_flags = conf.env['flags'] + ' ' |
190 else: |
147 else: |
191 add_flags += conf.env['flags'] + ' ' |
148 add_flags += conf.env['flags'] + ' ' |
201 elif cc == 'gcc': |
158 elif cc == 'gcc': |
202 conf.env.Append(CCFLAGS="-O3 -Wall -pipe " + add_flags) |
159 conf.env.Append(CCFLAGS="-O3 -Wall -pipe " + add_flags) |
203 # Other useful flags: |
160 # Other useful flags: |
204 # -Wunsafe-loop-optimizations -Wpointer-arith -Wcast-align -Wconversion |
161 # -Wunsafe-loop-optimizations -Wpointer-arith -Wcast-align -Wconversion |
205 # -Wmissing-noreturn -Winline -Wdisabled-optimization |
162 # -Wmissing-noreturn -Winline -Wdisabled-optimization |
206 elif cc == 'msvc': |
|
207 conf.env.Append(CCFLAGS="/Ox /Ob2 /GS- /Gy /GF /GR- /Zp16 /MD /EHsc /vmb " + add_flags) |
|
208 else: |
163 else: |
209 print "No supported compiler found." |
164 print "No supported compiler found." |
210 Exit(1) |
165 Exit(1) |
211 |
166 |
212 print "Using compiler: " + cc |
167 print "Using compiler: " + cc |
218 if conf.env['ldflags']: |
173 if conf.env['ldflags']: |
219 conf.env.Append(LINKFLAGS=conf.env['ldflags']) |
174 conf.env.Append(LINKFLAGS=conf.env['ldflags']) |
220 |
175 |
221 |
176 |
222 # configure pthread |
177 # configure pthread |
223 pthread = True |
178 conf.env.Append(CCFLAGS="-pthread ") |
224 if platform == 'win32': |
|
225 if cc == 'msvc': |
|
226 if not conf.CheckLib('pthreadVC2'): |
|
227 pthread = False |
|
228 elif cc == 'gcc': |
|
229 if not conf.CheckLib('pthreadGC2'): |
|
230 pthread = False |
|
231 else: |
|
232 conf.env.Append(CCFLAGS="-pthread ") |
|
233 |
|
234 if not pthread: |
|
235 print 'Error: Cannot build without pthread.' |
|
236 Exit(1) |
|
237 |
179 |
238 |
180 |
239 # configure libpng |
181 # configure libpng |
240 conf.CheckLibWithHeader('zlib', 'zlib.h', 'C') |
182 conf.CheckLibWithHeader('zlib', 'zlib.h', 'C') |
241 if conf.CheckLibWithHeader('libpng', 'png.h', 'C'): |
183 if conf.CheckLibWithHeader('libpng', 'png.h', 'C'): |
245 |
187 |
246 |
188 |
247 # configure Python |
189 # configure Python |
248 pyenv = env.Clone() |
190 pyenv = env.Clone() |
249 have_python = True |
191 have_python = True |
250 if platform == 'win32': |
192 try: |
251 pythonver = '%c%c' % (sys.version[0], sys.version[2]) |
193 pyenv.ParseConfig('python-config --includes --libs') |
252 pythonlib = 'python'+pythonver |
194 except: |
253 pythonpath = [env['pythonpath']] |
195 have_python = False |
254 pyenv.Append(CPPPATH=[s+'\\include' for s in pythonpath]) |
|
255 pyenv.Append(LIBPATH=[s+'\\libs' for s in pythonpath]) |
|
256 pyenv.Replace(SHLIBSUFFIX='.pyd') |
|
257 conf = Configure(pyenv, conf_dir=conf_dir, log_file=log_file, config_h=config_h, |
|
258 clean=False, help=False) |
|
259 if not conf.CheckLib(pythonlib): |
|
260 have_python = False |
|
261 pyenv = conf.Finish() |
|
262 else: |
|
263 try: |
|
264 pyenv.ParseConfig('python-config --includes --libs') |
|
265 except: |
|
266 have_python = False |
|
267 |
196 |
268 if not have_python: |
197 if not have_python: |
269 print "Error: Python is required." |
198 print "Error: Python is required." |
270 Exit(1) |
199 Exit(1) |
271 |
200 |
272 # configure SDL |
201 # configure SDL |
273 sdlenv = env.Clone() |
202 sdlenv = env.Clone() |
274 if cc == 'msvc': |
203 try: |
275 sdlenv.Append(LIBS=['SDL', 'SDLmain']) |
204 sdlenv.ParseConfig('sdl-config --cflags') |
276 sdlenv.Append(LINKFLAGS="/SUBSYSTEM:WINDOWS") |
205 sdlenv.ParseConfig('sdl-config --libs') |
277 else: |
206 except: |
278 try: |
207 pass |
279 sdlenv.ParseConfig('sdl-config --cflags') |
|
280 sdlenv.ParseConfig('sdl-config --libs') |
|
281 except: |
|
282 pass |
|
283 |
208 |
284 def CheckSDL(context): |
209 def CheckSDL(context): |
285 global have_sdl |
210 global have_sdl |
286 context.Message('Checking for SDL... ') |
211 context.Message('Checking for SDL... ') |
287 if context.TryLink("#include <SDL.h>\n"+ |
212 if context.TryLink("#include <SDL.h>\n"+ |
302 ### build targets |
227 ### build targets |
303 |
228 |
304 Export('env pyenv sdlenv have_sdl cc') |
229 Export('env pyenv sdlenv have_sdl cc') |
305 lib = SConscript('src/SConscript', variant_dir='build/lib', duplicate=0, |
230 lib = SConscript('src/SConscript', variant_dir='build/lib', duplicate=0, |
306 exports={'buildmodule':False}) |
231 exports={'buildmodule':False}) |
307 if cc == 'msvc': |
232 pymodule = SConscript('src/SConscript', variant_dir='build/pymodule', duplicate=0, |
308 (pymodule, modvcproj) = SConscript('src/SConscript', variant_dir='build/pymodule', duplicate=0, |
233 exports={'buildmodule':True}) |
309 exports={'buildmodule':True}) |
234 SConscript('ccdemos/SConscript', variant_dir='build/ccdemos', duplicate=0, exports='lib') |
310 ccdemvcproj = SConscript('ccdemos/SConscript', variant_dir='build/ccdemos', duplicate=0, exports='lib') |
235 SConscript('demos/SConscript', exports='pymodule') |
311 demosvcproj = SConscript('demos/SConscript', exports='pymodule') |
|
312 else: |
|
313 pymodule = SConscript('src/SConscript', variant_dir='build/pymodule', duplicate=0, |
|
314 exports={'buildmodule':True}) |
|
315 SConscript('ccdemos/SConscript', variant_dir='build/ccdemos', duplicate=0, exports='lib') |
|
316 SConscript('demos/SConscript', exports='pymodule') |
|
317 |
236 |
318 SConscript('tests/SConscript', variant_dir='build/tests', duplicate=0, exports='lib') |
237 SConscript('tests/SConscript', variant_dir='build/tests', duplicate=0, exports='lib') |
319 SConscript('models/SConscript') |
238 SConscript('models/SConscript') |
320 |
239 |
321 env.Alias('demos', ['cc-demos', 'python-demos']) |
240 env.Alias('demos', ['cc-demos', 'python-demos']) |
325 env.Alias('no-docs', ['libs', 'demos', 'models']) |
244 env.Alias('no-docs', ['libs', 'demos', 'models']) |
326 env.Alias('no-download', ['libs', 'demos', 'local-models']) |
245 env.Alias('no-download', ['libs', 'demos', 'local-models']) |
327 env.Alias('all', ['no-docs', 'docs']) |
246 env.Alias('all', ['no-docs', 'docs']) |
328 env.Alias('pyrit', 'no-download') |
247 env.Alias('pyrit', 'no-download') |
329 Default('pyrit') |
248 Default('pyrit') |
330 |
|
331 if cc == 'msvc': |
|
332 vcsol = env.MSVSSolution( |
|
333 target = 'pyrit' + env['MSVSSOLUTIONSUFFIX'], |
|
334 projects = [modvcproj, ccdemvcproj, demosvcproj], |
|
335 variant = 'Release') |
|
336 |
|
337 env.Depends(vcsol, [modvcproj, ccdemvcproj, demosvcproj]); |
|
338 env.Alias('vcproj', vcsol) |
|