New Wiimote Plugin: Keep track of the io_write report sizes instead of just sending...
[dolphin.git] / SConstruct
blobaf1e46198fd9f11b46fbc4450f0320b03fb4873a
1 # -*- python -*-
3 import os
4 import sys
5 import platform
7 # Home made tests
8 sys.path.append('SconsTests')
9 import wxconfig
10 import utils
12 # Some features need at least SCons 1.2
13 EnsureSConsVersion(1, 2)
15 # Handle command line options
16 vars = Variables('args.cache')
18 vars.AddVariables(
19 BoolVariable('verbose', 'Set to show compilation lines', False),
20 BoolVariable('bundle', 'Set to create distribution bundle', False),
21 BoolVariable('lint', 'Set for lint build (fail on warnings)', False),
22 BoolVariable('nowx', 'Set for building with no WX libs', False),
23 PathVariable('wxconfig', 'Path to wxconfig', None),
24 EnumVariable('flavor', 'Choose a build flavor', 'release',
25 allowed_values = ('release','devel','debug','fastlog','prof'),
26 ignorecase = 2),
29 if not sys.platform == 'win32' and not sys.platform == 'darwin':
30 vars.AddVariables(
31 PathVariable('destdir',
32 'Temporary install location (for package building)',
33 None, PathVariable.PathAccept),
34 EnumVariable('install',
35 'Choose a local or global installation', 'local',
36 allowed_values = ('local', 'global'), ignorecase = 2),
37 PathVariable('prefix',
38 'Installation prefix (only used for a global build)',
39 '/usr', PathVariable.PathAccept),
40 PathVariable('userdir',
41 'Set the name of the user data directory in home',
42 '.dolphin-emu', PathVariable.PathAccept),
43 BoolVariable('opencl', 'Build with OpenCL', False),
44 EnumVariable('pgo', 'Profile-Guided Optimization (generate or use)',
45 'none', allowed_values = ('none', 'generate', 'use'),
46 ignorecase = 2),
47 BoolVariable('shared_glew', 'Use system shared libGLEW', True),
48 BoolVariable('shared_lzo', 'Use system shared liblzo2', True),
49 BoolVariable('shared_sdl', 'Use system shared libSDL', True),
50 BoolVariable('shared_sfml', 'Use system shared libsfml-network', True),
51 BoolVariable('shared_soil', 'Use system shared libSOIL', True),
52 BoolVariable('shared_zlib', 'Use system shared libz', True),
53 ('CC', 'The C compiler', 'gcc'),
54 ('CXX', 'The C++ compiler', 'g++'),
57 env = Environment(ENV = os.environ, variables = vars)
58 Export('env')
60 # Die on unknown variables
61 unknown = vars.UnknownVariables()
62 if unknown:
63 print "Unknown variables:", unknown.keys()
64 Exit(1)
66 # Save the given command line options
67 vars.Save('args.cache', env)
69 cppDefines = [
70 ( '_FILE_OFFSET_BITS', 64),
71 '_LARGEFILE_SOURCE',
72 'GCC_HASCLASSVISIBILITY',
75 ccFlags = [
76 '-Wall',
77 '-Wpacked',
78 '-Wpointer-arith',
79 '-Wshadow',
80 '-Wwrite-strings',
81 '-fPIC',
82 '-fno-exceptions',
83 '-fno-strict-aliasing',
84 '-fvisibility=hidden',
85 '-msse2',
88 if env['CCVERSION'] >= '4.3.0': ccFlags += [
89 '-Wno-array-bounds', # False positives
90 '-Wno-unused-result', # Too many syscalls
93 # Build flavor
94 if env['flavor'] == 'debug':
95 ccFlags.append('-ggdb')
96 cppDefines.append('_DEBUG') #enables LOGGING
97 # FIXME: this disable wx debugging how do we make it work?
98 cppDefines.append('NDEBUG')
99 elif env['flavor'] == 'devel':
100 ccFlags.append('-ggdb')
101 elif env['flavor'] == 'fastlog':
102 ccFlags.append('-O3')
103 cppDefines.append('DEBUGFAST')
104 elif env['flavor'] == 'prof':
105 ccFlags.append('-O3')
106 ccFlags.append('-ggdb')
107 elif env['flavor'] == 'release':
108 ccFlags.append('-O3')
109 ccFlags.append('-fomit-frame-pointer');
111 if env['flavor'] == 'debug':
112 extra = '-debug'
113 elif env['flavor'] == 'prof':
114 extra = '-prof'
115 else:
116 extra = ''
118 if env['lint']:
119 ccFlags.append('-Werror')
121 # Verbose compile
122 if not env['verbose']:
123 env['ARCOMSTR'] = "Archiving $TARGET"
124 env['ASCOMSTR'] = "Assembling $TARGET"
125 env['ASPPCOMSTR'] = "Assembling $TARGET"
126 env['CCCOMSTR'] = "Compiling $TARGET"
127 env['CXXCOMSTR'] = "Compiling $TARGET"
128 env['LINKCOMSTR'] = "Linking $TARGET"
129 env['RANLIBCOMSTR'] = "Indexing $TARGET"
130 env['SHCCCOMSTR'] = "Compiling $TARGET"
131 env['SHCXXCOMSTR'] = "Compiling $TARGET"
132 env['SHLINKCOMSTR'] = "Linking $TARGET"
133 env['TARCOMSTR'] = "Creating $TARGET"
135 # Object files
136 env['build_dir'] = 'Build' + os.sep + platform.system() + \
137 '-' + platform.machine() + '-' + env['flavor']
139 # Static libs go here
140 env['local_libs'] = '#' + env['build_dir'] + os.sep + 'libs' + os.sep
142 # Default install path
143 if not env.has_key('install') or env['install'] == 'local':
144 env['prefix'] = 'Binary' + os.sep + platform.system() + \
145 '-' + platform.machine() + extra
147 # Configuration tests section
148 tests = {'CheckWXConfig' : wxconfig.CheckWXConfig,
149 'CheckPKGConfig' : utils.CheckPKGConfig,
150 'CheckPKG' : utils.CheckPKG,
151 'CheckSDL' : utils.CheckSDL,
152 'CheckPortaudio' : utils.CheckPortaudio,
155 rev = utils.GenerateRevFile(env['flavor'],
156 "Source/Core/Common/Src/svnrev_template.h",
157 "Source/Core/Common/Src/svnrev.h")
159 env['CCFLAGS'] = ccFlags
160 env['CPPDEFINES'] = cppDefines
161 env['CPPPATH'] = ['#Source/PluginSpecs']
162 env['CXXFLAGS'] = ['-fvisibility-inlines-hidden']
163 env['LIBPATH'] = []
164 env['LIBS'] = []
165 env['RPATH'] = []
167 # OS X specifics
168 if sys.platform == 'darwin':
169 gccflags = ['-arch', 'x86_64', '-arch', 'i386', '-mmacosx-version-min=10.5']
170 env['CCFLAGS'] += gccflags
171 env['CCFLAGS'] += ['-Wextra-tokens', '-Wnewline-eof']
172 env['CC'] = "gcc-4.2 -ObjC"
173 env['CXX'] = "g++-4.2 -ObjC++"
174 env['FRAMEWORKS'] += ['AppKit', 'CoreFoundation', 'CoreServices']
175 env['FRAMEWORKS'] += ['AudioUnit', 'CoreAudio']
176 env['FRAMEWORKS'] += ['IOBluetooth', 'IOKit', 'OpenGL']
177 env['LIBS'] += ['iconv']
178 env['LINKFLAGS'] += gccflags
179 env['LINKFLAGS'] += ['-Z', '-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib',
180 '-F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks',
181 '-F/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks']
182 if platform.mac_ver()[0] < '10.6.0':
183 env['HAVE_OPENCL'] = 0
184 else:
185 env['HAVE_OPENCL'] = 1
186 env['LINKFLAGS'] += ['-weak_framework', 'OpenCL']
187 if env['nowx']:
188 env['HAVE_WX'] = 0
189 else:
190 conf = env.Configure(custom_tests = tests)
191 env['HAVE_WX'] = conf.CheckWXConfig(2.9,
192 ['aui', 'adv', 'core', 'base', 'gl'], 0)
193 conf.Finish()
194 # wx-config wants us to link with the OS X QuickTime framework
195 # which is not available for x86_64 and we don't use it anyway.
196 # Strip it out to silence some harmless linker warnings.
197 # In the 10.5 SDK, Carbon is only partially built for x86_64.
198 frameworks = env['FRAMEWORKS']
199 wxconfig.ParseWXConfig(env)
200 if env['CPPDEFINES'].count('WXUSINGDLL'):
201 env['FRAMEWORKS'] = frameworks
202 env['CPPPATH'] += ['#Externals']
203 env['FRAMEWORKS'] += ['Cg']
204 env['LINKFLAGS'] += ['-FExternals/Cg']
205 env['shared_zlib'] = True
206 env['data_dir'] = '#' + env['prefix'] + '/Dolphin.app/Contents/Resources'
207 env['plugin_dir'] = '#' + env['prefix'] + '/Dolphin.app/Contents/PlugIns'
208 env.Install(env['data_dir'], 'Data/Sys')
209 env.Install(env['data_dir'], 'Data/User')
210 if env['bundle']:
211 app = env['prefix'] + '/Dolphin.app'
212 dmg = env['prefix'] + '/Dolphin-r' + rev + '.dmg'
213 env.Command(dmg, app, 'rm -f ' + dmg +
214 ' && hdiutil create -srcfolder ' + app + ' -format UDBZ ' + dmg +
215 ' && hdiutil internet-enable -yes ' + dmg)
217 elif sys.platform == 'win32':
218 env['tools'] = ['mingw']
220 else:
221 env['CCFLAGS'] += ['-pthread']
222 env['CXXFLAGS'] += ['-Wno-deprecated'] # XXX <hash_map>
223 env['CPPPATH'].insert(0, '#')
224 env['LINKFLAGS'] += ['-pthread']
225 conf = env.Configure(custom_tests = tests, config_h="#config.h")
227 if not conf.CheckPKGConfig('0.15.0'):
228 print "Can't find pkg-config, some tests will fail"
230 if env['shared_glew']:
231 env['shared_glew'] = conf.CheckPKG('GLEW')
232 if env['shared_sdl']:
233 env['shared_sdl'] = conf.CheckPKG('SDL')
234 if env['shared_zlib']:
235 env['shared_zlib'] = conf.CheckPKG('z')
236 if env['shared_lzo']:
237 env['shared_lzo'] = conf.CheckPKG('lzo2')
238 # TODO: Check the version of sfml. It should be at least version 1.5
239 if env['shared_sfml']:
240 env['shared_sfml'] = conf.CheckPKG('sfml-network') and \
241 conf.CheckCXXHeader("SFML/Network/Ftp.hpp")
242 if env['shared_soil']:
243 env['shared_soil'] = conf.CheckPKG('SOIL')
244 for var in env.items():
245 if var[0].startswith('shared_') and var[1] == False:
246 print "Shared library " + var[0][7:] + " not detected, " \
247 "falling back to the static library"
249 if env['nowx']:
250 env['HAVE_WX'] = 0
251 else:
252 env['HAVE_WX'] = conf.CheckWXConfig(2.8,
253 ['aui', 'adv', 'core', 'base'], 0)
254 conf.Define('HAVE_WX', env['HAVE_WX'])
255 wxconfig.ParseWXConfig(env)
256 if not env['HAVE_WX']:
257 print "WX libraries not found - see config.log"
258 Exit(1)
260 env['HAVE_BLUEZ'] = conf.CheckPKG('bluez')
261 conf.Define('HAVE_BLUEZ', env['HAVE_BLUEZ'])
263 env['HAVE_ALSA'] = conf.CheckPKG('alsa')
264 conf.Define('HAVE_ALSA', env['HAVE_ALSA'])
265 env['HAVE_AO'] = conf.CheckPKG('ao')
266 conf.Define('HAVE_AO', env['HAVE_AO'])
267 env['HAVE_OPENAL'] = conf.CheckPKG('openal')
268 conf.Define('HAVE_OPENAL', env['HAVE_OPENAL'])
269 env['HAVE_PORTAUDIO'] = conf.CheckPortaudio(1890)
270 conf.Define('HAVE_PORTAUDIO', env['HAVE_PORTAUDIO'])
271 env['HAVE_PULSEAUDIO'] = conf.CheckPKG('libpulse-simple')
272 conf.Define('HAVE_PULSEAUDIO', env['HAVE_PULSEAUDIO'])
274 env['HAVE_X11'] = conf.CheckPKG('x11')
275 env['HAVE_XRANDR'] = env['HAVE_X11'] and conf.CheckPKG('xrandr')
276 conf.Define('HAVE_XRANDR', env['HAVE_XRANDR'])
277 conf.Define('HAVE_X11', env['HAVE_X11'])
279 # Check for GTK 2.0 or newer
280 if env['HAVE_WX'] and not conf.CheckPKG('gtk+-2.0'):
281 print "gtk+-2.0 developement headers not detected"
282 print "gtk+-2.0 is required to build the WX GUI"
283 Exit(1)
285 if not conf.CheckPKG('GL'):
286 print "Must have OpenGL to build"
287 Exit(1)
288 if not conf.CheckPKG('GLU'):
289 print "Must have GLU to build"
290 Exit(1)
291 if not conf.CheckPKG('Cg') and sys.platform == 'linux2':
292 print "Must have Cg toolkit from NVidia to build"
293 Exit(1)
294 if not conf.CheckPKG('CgGL') and sys.platform == 'linux2':
295 print "Must have CgGL to build"
296 Exit(1)
298 if env['opencl']:
299 env['HAVE_OPENCL'] = conf.CheckPKG('OpenCL')
300 conf.Define('HAVE_OPENCL', env['HAVE_OPENCL'])
301 else:
302 env['HAVE_OPENCL'] = 0
304 # PGO - Profile Guided Optimization
305 if env['pgo']=='generate':
306 ccFlags.append('-fprofile-generate')
307 env['LINKFLAGS']='-fprofile-generate'
308 if env['pgo']=='use':
309 ccFlags.append('-fprofile-use')
310 env['LINKFLAGS']='-fprofile-use'
312 # Profiling
313 if (env['flavor'] == 'prof'):
314 proflibs = [ '/usr/lib/oprofile', '/usr/local/lib/oprofile' ]
315 env['LIBPATH'].append(proflibs)
316 env['RPATH'].append(proflibs)
317 if conf.CheckPKG('opagent'):
318 conf.Define('USE_OPROFILE', 1)
319 else:
320 print "Can't build prof without oprofile, disabling"
322 tarname = 'dolphin-' + rev
323 env['TARFLAGS'] = '-cj'
324 env['TARSUFFIX'] = '.tar.bz2'
326 if env['install'] == 'local':
327 env['binary_dir'] = '#' + env['prefix']
328 env['data_dir'] = '#' + env['prefix']
329 env['plugin_dir'] = '#' + env['prefix'] + '/plugins'
330 if env['bundle']:
331 env.Tar(tarname, env['prefix'])
332 else:
333 env['prefix'] = Dir(env['prefix']).abspath
334 env['binary_dir'] = env['prefix'] + '/bin'
335 env['data_dir'] = env['prefix'] + "/share/dolphin-emu"
336 env['plugin_dir'] = env['prefix'] + '/lib/dolphin-emu'
337 conf.Define('DATA_DIR', "\"" + env['data_dir'] + "\"")
338 conf.Define('LIBS_DIR', "\"" + env['prefix'] + '/lib/' + "\"")
339 # Setup destdir for package building
340 # Warning: The program will not run from this location.
341 # It is assumed the package will later install it to the prefix.
342 if env.has_key('destdir'):
343 env['destdir'] = Dir(env['destdir']).abspath
344 env['binary_dir'] = env['destdir'] + env['binary_dir']
345 env['data_dir'] = env['destdir'] + env['data_dir']
346 env['plugin_dir'] = env['destdir'] + env['plugin_dir']
347 env['prefix'] = env['destdir'] + env['prefix']
348 if env['bundle']:
349 env.Command(tarname + env['TARSUFFIX'], env['prefix'],
350 'tar ' + env['TARFLAGS'] + 'C ' + env['destdir'] + \
351 ' -f ' + tarname + env['TARSUFFIX'] + ' ' + \
352 env['prefix'].split(env['destdir'], 1)[1][1:])
354 conf.Define('USER_DIR', "\"" + env['userdir'] + "\"")
356 # After all configuration tests are done
357 conf.Finish()
359 # Data install
360 env.InstallAs(env['data_dir'] + '/sys', 'Data/Sys')
361 env.InstallAs(env['data_dir'] + '/user', 'Data/User')
363 env.Alias('install', env['prefix'])
365 # Local (static) libraries must be first in the search path for the build in
366 # order that they can override system libraries, but they must not be found
367 # during autoconfiguration as they will then be detected as system libraries.
368 env['LIBPATH'].insert(0, env['local_libs'])
370 dirs = []
372 if not env.has_key('shared_glew') or not env['shared_glew']:
373 env['CPPPATH'] += ['#Externals/GLew/include']
374 dirs += ['Externals/GLew']
375 if not env.has_key('shared_lzo') or not env['shared_lzo']:
376 env['CPPPATH'] += ['#Externals/LZO']
377 dirs += ['Externals/LZO']
378 if not env.has_key('shared_sdl') or not env['shared_sdl']:
379 env['CPPPATH'] += ['#Externals/SDL']
380 env['CPPPATH'] += ['#Externals/SDL/include']
381 dirs += ['Externals/SDL']
382 if not env.has_key('shared_soil') or not env['shared_soil']:
383 env['CPPPATH'] += ['#Externals/SOIL']
384 dirs += ['Externals/SOIL']
385 if not env.has_key('shared_sfml') or not env['shared_sfml']:
386 env['CPPPATH'] += ['#Externals/SFML/include']
387 dirs += ['Externals/SFML/src']
388 if not env.has_key('shared_zlib') or not env['shared_zlib']:
389 env['CPPPATH'] += ['#Externals/zlib']
390 dirs += ['Externals/zlib']
392 dirs += [
393 'Externals/Bochs_disasm',
394 #'Externals/CLRun',
395 'Externals/Lua',
396 'Externals/MemcardManager',
397 'Externals/WiiUse/Src',
398 #'Externals/OpenAL',
399 #'Externals/dylibbundler',
400 #'Externals/wxWidgets',
401 'Source/Core/AudioCommon/Src',
402 'Source/Core/Common/Src',
403 'Source/Core/Core/Src',
404 'Source/Core/DSPCore/Src',
405 'Source/Core/DebuggerUICommon/Src',
406 'Source/Core/DebuggerWX/Src',
407 'Source/Core/DiscIO/Src',
408 'Source/Core/DolphinWX/Src',
409 'Source/Core/InputCommon/Src',
410 'Source/Core/InputUICommon/Src',
411 'Source/Core/VideoCommon/Src',
412 'Source/DSPTool/Src',
413 'Source/Plugins/Plugin_DSP_HLE/Src',
414 'Source/Plugins/Plugin_DSP_LLE/Src',
415 #'Source/Plugins/Plugin_VideoDX9/Src',
416 #'Source/Plugins/Plugin_VideoDX11/Src',
417 'Source/Plugins/Plugin_VideoOGL/Src',
418 'Source/Plugins/Plugin_VideoSoftware/Src',
419 'Source/Plugins/Plugin_Wiimote/Src',
420 'Source/Plugins/Plugin_WiimoteNew/Src',
421 'Source/UnitTests',
424 for subdir in dirs:
425 SConscript(dirs = subdir, duplicate = 0, exports = 'env',
426 variant_dir = env['build_dir'] + os.sep + subdir)
427 if subdir.count('Externals') or subdir.count('Source/Core'):
428 env['CPPPATH'] += ['#' + subdir]
430 # Print a nice progress indication when not compiling
431 Progress(['-\r', '\\\r', '|\r', '/\r'], interval = 5)
433 # Generate help
434 Help(vars.GenerateHelpText(env))