3 # ***** BEGIN GPL LICENSE BLOCK *****
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # The Original Code is Copyright (C) 2006, Blender Foundation
20 # All rights reserved.
22 # The Original Code is: all of this file.
24 # Contributor(s): Nathan Letwory.
26 # ***** END GPL LICENSE BLOCK *****
28 # Main entry-point for the SCons building system
29 # Set up some custom actions and target/argument handling
30 # Then read all SConscripts and build
32 import platform as pltfrm
34 if pltfrm.architecture()[0] == '64bit':
46 from tempfile import mkdtemp
52 EnsureSConsVersion(1,0,0)
54 BlenderEnvironment = tools.Blender.BlenderEnvironment
59 platform = sys.platform
64 ##### BEGIN SETUP #####
66 B.possible_types = ['core', 'player', 'intern', 'extern']
68 B.binarykind = ['blender' , 'blenderplayer']
69 ##################################
70 # target and argument validation #
71 ##################################
72 # XX cheating for BF_FANCY, we check for BF_FANCY before args are validated
73 use_color = ARGUMENTS.get('BF_FANCY', '1')
77 if not use_color=='1':
80 #on defaut white Os X terminal, some colors are totally unlegible
81 if platform=='darwin':
82 B.bc.OKGREEN = '\033[34m'
83 B.bc.WARNING = '\033[36m'
86 print B.bc.HEADER+'Command-line arguments'+B.bc.ENDC
87 B.arguments = btools.validate_arguments(ARGUMENTS, B.bc)
88 btools.print_arguments(B.arguments, B.bc)
91 print B.bc.HEADER+'Command-line targets'+B.bc.ENDC
92 B.targets = btools.validate_targets(COMMAND_LINE_TARGETS, B.bc)
93 btools.print_targets(B.targets, B.bc)
95 ##########################
96 # setting up environment #
97 ##########################
99 # handling cmd line arguments & config file
101 # first check cmdline for toolset and we create env to work on
102 quickie = B.arguments.get('BF_QUICK', None)
103 quickdebug = B.arguments.get('BF_QUICKDEBUG', None)
106 B.quickdebug=string.split(quickdebug, ',')
111 B.quickie=string.split(quickie,',')
115 toolset = B.arguments.get('BF_TOOLSET', None)
117 print "Using " + toolset
118 if toolset=='mstoolkit':
119 env = BlenderEnvironment(ENV = os.environ)
120 env.Tool('mstoolkit', ['tools'])
122 env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
123 # xxx commented out, as was supressing warnings under mingw..
125 # btools.SetupSpawn(env)
127 env = BlenderEnvironment(ENV = os.environ)
130 print "Could not create a build environment"
134 cc = B.arguments.get('CC', None)
135 cxx = B.arguments.get('CXX', None)
141 if env['CC'] in ['cl', 'cl.exe'] and sys.platform=='win32':
143 platform = 'win64-vc'
145 platform = 'win32-vc'
146 elif env['CC'] in ['gcc'] and sys.platform=='win32':
147 platform = 'win32-mingw'
149 env.SConscriptChdir(0)
151 crossbuild = B.arguments.get('BF_CROSS', None)
152 if crossbuild and platform not in ('win32-vc', 'win64-vc'):
153 platform = 'linuxcross'
155 env['OURPLATFORM'] = platform
157 configfile = 'config'+os.sep+platform+'-config.py'
159 if os.path.exists(configfile):
160 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
162 print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
164 if crossbuild and env['PLATFORM'] != 'win32':
165 print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
166 env.Tool('crossmingw', ['tools'])
167 # todo: determine proper libs/includes etc.
168 # Needed for gui programs, console programs should do without it
169 env.Append(LINKFLAGS=['-mwindows'])
171 userconfig = B.arguments.get('BF_CONFIG', 'user-config.py')
172 # first read platform config. B.arguments will override
173 optfiles = [configfile]
174 if os.path.exists(userconfig):
175 print B.bc.OKGREEN + "Using user-config file: " + B.bc.ENDC + userconfig
176 optfiles += [userconfig]
178 print B.bc.WARNING + userconfig + " not found, no user overrides" + B.bc.ENDC
180 opts = btools.read_opts(optfiles, B.arguments)
183 if not env['BF_FANCY']:
186 SetOption('num_jobs', int(env['BF_NUMJOBS']))
187 print "Build with %d parallel jobs" % (GetOption('num_jobs'))
189 # disable elbeem (fluidsim) compilation?
190 if env['BF_NO_ELBEEM'] == 1:
191 env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
192 env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
193 env['CCFLAGS'].append('-DDISABLE_ELBEEM')
195 if env['WITH_BF_OPENMP'] == 1:
196 if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
197 env['CCFLAGS'].append('/openmp')
198 env['CPPFLAGS'].append('/openmp')
199 env['CXXFLAGS'].append('/openmp')
201 if env['CC'][-3:] == 'icc': # to be able to handle CC=/opt/bla/icc case
202 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
203 env['CCFLAGS'].append('-openmp')
204 env['CPPFLAGS'].append('-openmp')
205 env['CXXFLAGS'].append('-openmp')
207 env.Append(CCFLAGS=['-fopenmp'])
208 env.Append(CPPFLAGS=['-fopenmp'])
209 env.Append(CXXFLAGS=['-fopenmp'])
210 # env.Append(LINKFLAGS=['-fprofile-generate'])
212 #check for additional debug libnames
214 if env.has_key('BF_DEBUG_LIBS'):
215 B.quickdebug += env['BF_DEBUG_LIBS']
217 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
219 # see if this linux distro has libalut
221 if env['OURPLATFORM'] == 'linux2' :
222 if env['WITH_BF_OPENAL']:
223 mylib_test_source_file = """
225 int main(int argc, char **argv)
227 alutGetMajorVersion();
232 def CheckFreeAlut(context,env):
233 context.Message( B.bc.OKGREEN + "Linux platform detected:\n checking for FreeAlut... " + B.bc.ENDC )
235 result = context.TryLink(mylib_test_source_file, '.c')
236 context.Result(result)
239 env2 = env.Clone( LIBPATH = env['BF_OPENAL'] )
240 sconf_temp = mkdtemp()
241 conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, sconf_temp, '/dev/null' )
242 if conf.CheckFreeAlut( env2 ):
243 env['BF_OPENAL_LIB'] += ' alut'
246 for root, dirs, files in os.walk(sconf_temp, topdown=False):
248 os.remove(os.path.join(root, name))
250 os.rmdir(os.path.join(root, name))
251 if root: os.rmdir(root)
253 if len(B.quickdebug) > 0 and printdebug != 0:
254 print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
255 for l in B.quickdebug:
258 # remove stdc++ from LLIBS if we are building a statc linked CXXFLAGS
259 if env['WITH_BF_STATICCXX']:
260 if 'stdc++' in env['LLIBS']:
261 env['LLIBS'].remove('stdc++')
263 print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
265 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
266 if 'blenderplayer' in B.targets:
267 env['WITH_BF_PLAYER'] = True
269 if 'blendernogame' in B.targets:
270 env['WITH_BF_GAMEENGINE'] = False
272 if 'blenderlite' in B.targets:
274 target_env_defs['WITH_BF_GAMEENGINE'] = False
275 target_env_defs['WITH_BF_OPENAL'] = False
276 target_env_defs['WITH_BF_OPENEXR'] = False
277 target_env_defs['WITH_BF_ICONV'] = False
278 target_env_defs['WITH_BF_INTERNATIONAL'] = False
279 target_env_defs['WITH_BF_OPENJPEG'] = False
280 target_env_defs['WITH_BF_FFMPEG'] = False
281 target_env_defs['WITH_BF_QUICKTIME'] = False
282 target_env_defs['WITH_BF_REDCODE'] = False
283 target_env_defs['WITH_BF_DDS'] = False
284 target_env_defs['WITH_BF_ZLIB'] = False
285 target_env_defs['WITH_BF_SDL'] = False
286 target_env_defs['WITH_BF_JPEG'] = False
287 target_env_defs['WITH_BF_PNG'] = False
288 target_env_defs['WITH_BF_ODE'] = False
289 target_env_defs['WITH_BF_BULLET'] = False
290 target_env_defs['WITH_BF_SOLID'] = False
291 target_env_defs['WITH_BF_BINRELOC'] = False
292 target_env_defs['BF_BUILDINFO'] = False
293 target_env_defs['BF_NO_ELBEEM'] = True
294 target_env_defs['WITH_BF_PYTHON'] = False
296 # Merge blenderlite, let command line to override
297 for k,v in target_env_defs.iteritems():
298 if k not in B.arguments:
301 if env['WITH_BF_SDL'] == False and env['OURPLATFORM'] in ('win32-vc', 'win32-ming', 'win64-vc'):
302 env['PLATFORM_LINKFLAGS'].remove('/ENTRY:mainCRTStartup')
303 env['PLATFORM_LINKFLAGS'].append('/ENTRY:main')
305 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
306 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
307 B.root_build_dir = env['BF_BUILDDIR']
308 B.doc_build_dir = env['BF_DOCDIR']
309 if not B.root_build_dir[-1]==os.sep:
310 B.root_build_dir += os.sep
311 if not B.doc_build_dir[-1]==os.sep:
312 B.doc_build_dir += os.sep
314 # We do a shortcut for clean when no quicklist is given: just delete
315 # builddir without reading in SConscripts
317 if 'clean' in B.targets:
320 if not quickie and do_clean:
321 if os.path.exists(B.doc_build_dir):
322 print B.bc.HEADER+'Cleaning doc dir...'+B.bc.ENDC
323 dirs = os.listdir(B.doc_build_dir)
325 if os.path.isdir(B.doc_build_dir + entry) == 1:
326 print "clean dir %s"%(B.doc_build_dir+entry)
327 shutil.rmtree(B.doc_build_dir+entry)
329 print "remove file %s"%(B.doc_build_dir+entry)
330 os.remove(B.root_build_dir+entry)
331 if os.path.exists(B.root_build_dir):
332 print B.bc.HEADER+'Cleaning build dir...'+B.bc.ENDC
333 dirs = os.listdir(B.root_build_dir)
335 if os.path.isdir(B.root_build_dir + entry) == 1:
336 print "clean dir %s"%(B.root_build_dir+entry)
337 shutil.rmtree(B.root_build_dir+entry)
339 print "remove file %s"%(B.root_build_dir+entry)
340 os.remove(B.root_build_dir+entry)
341 for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
342 'extern/xvidcore/build/generic/platform.inc', 'extern/ffmpeg/include']:
343 if os.path.exists(confile):
344 print "clean file %s"%confile
345 if os.path.isdir(confile):
346 for root, dirs, files in os.walk(confile):
348 os.remove(os.path.join(root, name))
351 print B.bc.OKGREEN+'...done'+B.bc.ENDC
353 print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
356 if not os.path.isdir ( B.root_build_dir):
357 os.makedirs ( B.root_build_dir )
358 os.makedirs ( B.root_build_dir + 'source' )
359 os.makedirs ( B.root_build_dir + 'intern' )
360 os.makedirs ( B.root_build_dir + 'extern' )
361 os.makedirs ( B.root_build_dir + 'lib' )
362 os.makedirs ( B.root_build_dir + 'bin' )
363 if not os.path.isdir(B.doc_build_dir):
364 os.makedirs ( B.doc_build_dir )
366 Help(opts.GenerateHelpText(env))
368 # default is new quieter output, but if you need to see the
369 # commands, do 'scons BF_QUIET=0'
370 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
372 B.set_quiet_output(env)
377 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
378 env.SConsignFile(B.root_build_dir+'scons-signatures')
381 ##### END SETUP ##########
385 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
386 SConscript(B.root_build_dir+'/intern/SConscript')
387 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
388 SConscript(B.root_build_dir+'/extern/SConscript')
389 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
390 SConscript(B.root_build_dir+'/source/SConscript')
392 # now that we have read all SConscripts, we know what
393 # libraries will be built. Create list of
394 # libraries to give as objects to linking phase
396 for tp in B.possible_types:
397 if not tp == 'player' and not tp == 'player2':
398 mainlist += B.create_blender_liblist(env, tp)
400 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
401 B.propose_priorities()
403 dobj = B.buildinfo(env, "dynamic") + B.resources
404 thestatlibs, thelibincs = B.setup_staticlibs(env)
405 thesyslibs = B.setup_syslibs(env)
407 if env['WITH_BF_PLAYER']:
408 print("Warning: Game player may not build on 2.5")
410 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
411 #env.BlenderProg(B.root_build_dir, "blender", dobj , [], mainlist + thestatlibs + thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
412 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist, [], thestatlibs + thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
413 if env['WITH_BF_PLAYER']:
414 playerlist = B.create_blender_liblist(env, 'player')
415 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist, [], thestatlibs + thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
417 ##### Now define some targets
420 #------------ INSTALL
424 if env['OURPLATFORM']=='darwin':
425 for prg in B.program_list:
426 bundle = '%s.app' % prg[0]
427 bundledir = os.path.dirname(bundle)
428 for dp, dn, df in os.walk(bundle):
433 dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
434 source=[dp+os.sep+f for f in df]
435 blenderinstall.append(env.Install(dir=dir,source=source))
437 blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
440 #- dont do .blender and scripts for darwin, it is already in the bundle
445 if env['OURPLATFORM']!='darwin':
446 for dp, dn, df in os.walk('bin/.blender'):
453 if not env['WITH_BF_INTERNATIONAL']:
456 if f == '.Blanguages':
458 if not env['WITH_BF_FREETYPE']:
459 if f.endswith('.ttf'):
462 dotblendlist.append(os.path.join(dp, f))
463 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
465 dotblenderinstall = []
466 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
467 td, tf = os.path.split(targetdir)
468 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
470 if env['WITH_BF_PYTHON']:
472 scriptpath='release/scripts'
473 for dp, dn, df in os.walk(scriptpath):
478 dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
479 source=[dp+os.sep+f for f in df]
480 scriptinstall.append(env.Install(dir=dir,source=source))
483 scriptpath='release/ui'
484 for dp, dn, df in os.walk(scriptpath):
489 dir=env['BF_INSTALLDIR']+'/.blender/ui'+dp[len(scriptpath):]
490 source=[dp+os.sep+f for f in df]
491 scriptinstall.append(env.Install(dir=dir,source=source))
494 if env['OURPLATFORM']=='linux2':
498 for tp, tn, tf in os.walk('release/freedesktop/icons'):
504 iconlist.append(tp+os.sep+f)
505 icontargetlist.append(env['BF_INSTALLDIR']+tp[19:]+os.sep+f)
508 for targetdir,srcfile in zip(icontargetlist, iconlist):
509 td, tf = os.path.split(targetdir)
510 iconinstall.append(env.Install(dir=td, source=srcfile))
512 # dlls for linuxcross
513 # TODO - add more libs, for now this lets blenderlite run
514 if env['OURPLATFORM']=='linuxcross':
515 dir=env['BF_INSTALLDIR']
516 source = ['../lib/windows/pthreads/lib/pthreadGC2.dll']
517 scriptinstall.append(env.Install(dir=dir, source=source))
522 for tp, tn, tf in os.walk('release/plugins'):
528 pluglist.append(tp+os.sep+f)
529 plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
531 # header files for plugins
532 pluglist.append('source/blender/blenpluginapi/documentation.h')
533 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'documentation.h')
534 pluglist.append('source/blender/blenpluginapi/externdef.h')
535 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'externdef.h')
536 pluglist.append('source/blender/blenpluginapi/floatpatch.h')
537 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'floatpatch.h')
538 pluglist.append('source/blender/blenpluginapi/iff.h')
539 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'iff.h')
540 pluglist.append('source/blender/blenpluginapi/plugin.h')
541 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'plugin.h')
542 pluglist.append('source/blender/blenpluginapi/util.h')
543 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'util.h')
544 pluglist.append('source/blender/blenpluginapi/plugin.DEF')
545 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep + 'plugin.def')
548 for targetdir,srcfile in zip(plugtargetlist, pluglist):
549 td, tf = os.path.split(targetdir)
550 plugininstall.append(env.Install(dir=td, source=srcfile))
554 for tp, tn, tf in os.walk('release/text'):
560 textlist.append(tp+os.sep+f)
562 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
564 if env['OURPLATFORM']=='darwin':
565 allinstall = [blenderinstall, plugininstall, textinstall]
566 elif env['OURPLATFORM']=='linux2':
567 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall, iconinstall]
569 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
571 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc'):
572 if env['OURPLATFORM'] == 'win64-vc':
575 dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
576 '${BF_PNG_LIBPATH}/libpng.dll',
577 '${BF_ZLIB_LIBPATH}/zlib.dll',
578 '${BF_TIFF_LIBPATH}/${BF_TIFF_LIB}.dll']
579 dllsources += ['${BF_PTHREADS_LIBPATH}/${BF_PTHREADS_LIB}.dll']
580 if env['WITH_BF_SDL']:
581 if env['OURPLATFORM'] == 'win64-vc':
582 pass # we link statically already to SDL on win64
584 dllsources.append('${BF_SDL_LIBPATH}/SDL.dll')
585 if env['WITH_BF_PYTHON']:
586 ver = env["BF_PYTHON_VERSION"].replace(".", "")
588 dllsources.append('#release/windows/extra/python' + ver + '.zip')
589 dllsources.append('#release/windows/extra/zlib.pyd')
591 dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_LIB}_d.dll')
593 dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_LIB}.dll')
594 if env['WITH_BF_ICONV']:
595 if env['OURPLATFORM'] == 'win64-vc':
596 pass # we link statically to iconv on win64
598 dllsources += ['${BF_ICONV_LIBPATH}/iconv.dll']
599 if env['WITH_BF_FFMPEG']:
600 dllsources += ['${LCGDIR}/ffmpeg/lib/avcodec-52.dll',
601 '${LCGDIR}/ffmpeg/lib/avformat-52.dll',
602 '${LCGDIR}/ffmpeg/lib/avdevice-52.dll',
603 '${LCGDIR}/ffmpeg/lib/avutil-50.dll',
604 '${LCGDIR}/ffmpeg/lib/libfaad-2.dll',
605 '${LCGDIR}/ffmpeg/lib/libfaac-0.dll',
606 '${LCGDIR}/ffmpeg/lib/libmp3lame-0.dll',
607 '${LCGDIR}/ffmpeg/lib/libx264-67.dll',
608 '${LCGDIR}/ffmpeg/lib/xvidcore.dll',
609 '${LCGDIR}/ffmpeg/lib/swscale-0.dll']
610 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
611 allinstall += windlls
613 installtarget = env.Alias('install', allinstall)
614 bininstalltarget = env.Alias('install-bin', blenderinstall)
616 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
617 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
618 nsisalias = env.Alias('nsis', nsiscmd)
620 if 'blender' in B.targets:
621 blenderexe= env.Alias('blender', B.program_list)
622 Depends(blenderexe,installtarget)
624 if env['WITH_BF_PLAYER']:
625 blenderplayer = env.Alias('blenderplayer', B.program_list)
626 Depends(blenderplayer,installtarget)
628 if not env['WITH_BF_GAMEENGINE']:
629 blendernogame = env.Alias('blendernogame', B.program_list)
630 Depends(blendernogame,installtarget)
632 if 'blenderlite' in B.targets:
633 blenderlite = env.Alias('blenderlite', B.program_list)
634 Depends(blenderlite,installtarget)
636 Depends(nsiscmd, allinstall)
638 Default(B.program_list)
640 if not env['WITHOUT_BF_INSTALL']:
641 Default(installtarget)
644 if env['WITH_BF_DOCS']:
646 except: epydoc = None
649 SConscript('source/blender/python/api2_2x/doc/SConscript')
650 SConscript('source/gameengine/PyDoc/SConscript')
652 print "No epydoc install detected, Python API and Gameengine API Docs will not be generated "