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
39 from tempfile import mkdtemp
45 EnsureSConsVersion(1,0,0)
47 BlenderEnvironment = tools.Blender.BlenderEnvironment
52 platform = sys.platform
57 ##### BEGIN SETUP #####
59 B.possible_types = ['core', 'common', 'blender', 'intern',
60 'international', 'game', 'game2',
61 'player', 'player2', 'system']
63 B.binarykind = ['blender' , 'blenderplayer']
64 ##################################
65 # target and argument validation #
66 ##################################
67 # XX cheating for BF_FANCY, we check for BF_FANCY before args are validated
68 use_color = ARGUMENTS.get('BF_FANCY', '1')
72 if not use_color=='1':
75 #on defaut white Os X terminal, some colors are totally unlegible
76 if platform=='darwin':
77 B.bc.OKGREEN = '\033[34m'
78 B.bc.WARNING = '\033[36m'
81 print B.bc.HEADER+'Command-line arguments'+B.bc.ENDC
82 B.arguments = btools.validate_arguments(ARGUMENTS, B.bc)
83 btools.print_arguments(B.arguments, B.bc)
86 print B.bc.HEADER+'Command-line targets'+B.bc.ENDC
87 B.targets = btools.validate_targets(COMMAND_LINE_TARGETS, B.bc)
88 btools.print_targets(B.targets, B.bc)
90 ##########################
91 # setting up environment #
92 ##########################
94 # handling cmd line arguments & config file
96 # first check cmdline for toolset and we create env to work on
97 quickie = B.arguments.get('BF_QUICK', None)
98 quickdebug = B.arguments.get('BF_QUICKDEBUG', None)
101 B.quickdebug=string.split(quickdebug, ',')
106 B.quickie=string.split(quickie,',')
110 toolset = B.arguments.get('BF_TOOLSET', None)
112 print "Using " + toolset
113 if toolset=='mstoolkit':
114 env = BlenderEnvironment(ENV = os.environ)
115 env.Tool('mstoolkit', ['tools'])
117 env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
118 # xxx commented out, as was supressing warnings under mingw..
120 # btools.SetupSpawn(env)
122 env = BlenderEnvironment(ENV = os.environ)
125 print "Could not create a build environment"
129 cc = B.arguments.get('CC', None)
130 cxx = B.arguments.get('CXX', None)
136 if env['CC'] in ['cl', 'cl.exe'] and sys.platform=='win32':
137 platform = 'win32-vc'
138 elif env['CC'] in ['gcc'] and sys.platform=='win32':
139 platform = 'win32-mingw'
141 env.SConscriptChdir(0)
143 crossbuild = B.arguments.get('BF_CROSS', None)
144 if crossbuild and platform!='win32':
145 platform = 'linuxcross'
147 env['OURPLATFORM'] = platform
149 configfile = 'config'+os.sep+platform+'-config.py'
151 if os.path.exists(configfile):
152 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
154 print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
156 if crossbuild and env['PLATFORM'] != 'win32':
157 print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
158 env.Tool('crossmingw', ['tools'])
159 # todo: determine proper libs/includes etc.
160 # Needed for gui programs, console programs should do without it
161 env.Append(LINKFLAGS=['-mwindows'])
163 userconfig = B.arguments.get('BF_CONFIG', 'user-config.py')
164 # first read platform config. B.arguments will override
165 optfiles = [configfile]
166 if os.path.exists(userconfig):
167 print B.bc.OKGREEN + "Using user-config file: " + B.bc.ENDC + userconfig
168 optfiles += [userconfig]
170 print B.bc.WARNING + userconfig + " not found, no user overrides" + B.bc.ENDC
172 opts = btools.read_opts(optfiles, B.arguments)
175 if not env['BF_FANCY']:
178 SetOption('num_jobs', int(env['BF_NUMJOBS']))
179 print "Build with %d parallel jobs" % (GetOption('num_jobs'))
181 # disable elbeem (fluidsim) compilation?
182 if env['BF_NO_ELBEEM'] == 1:
183 env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
184 env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
185 env['CCFLAGS'].append('-DDISABLE_ELBEEM')
187 if env['WITH_BF_OPENMP'] == 1:
188 if env['OURPLATFORM']=='win32-vc':
189 env['CCFLAGS'].append('/openmp')
190 env['CPPFLAGS'].append('/openmp')
191 env['CXXFLAGS'].append('/openmp')
193 if env['CC'][-3:] == 'icc': # to be able to handle CC=/opt/bla/icc case
194 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
195 env['CCFLAGS'].append('-openmp')
196 env['CPPFLAGS'].append('-openmp')
197 env['CXXFLAGS'].append('-openmp')
199 env.Append(CCFLAGS=['-fopenmp'])
200 env.Append(CPPFLAGS=['-fopenmp'])
201 env.Append(CXXFLAGS=['-fopenmp'])
202 # env.Append(LINKFLAGS=['-fprofile-generate'])
204 #check for additional debug libnames
206 if env.has_key('BF_DEBUG_LIBS'):
207 B.quickdebug += env['BF_DEBUG_LIBS']
209 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
211 # see if this linux distro has libalut
213 if env['OURPLATFORM'] == 'linux2' :
214 if env['WITH_BF_OPENAL']:
215 mylib_test_source_file = """
217 int main(int argc, char **argv)
219 alutGetMajorVersion();
224 def CheckFreeAlut(context,env):
225 context.Message( B.bc.OKGREEN + "Linux platform detected:\n checking for FreeAlut... " + B.bc.ENDC )
227 result = context.TryLink(mylib_test_source_file, '.c')
228 context.Result(result)
231 env2 = env.Clone( LIBPATH = env['BF_OPENAL'] )
232 sconf_temp = mkdtemp()
233 conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, sconf_temp, '/dev/null' )
234 if conf.CheckFreeAlut( env2 ):
235 env['BF_OPENAL_LIB'] += ' alut'
238 for root, dirs, files in os.walk(sconf_temp, topdown=False):
240 os.remove(os.path.join(root, name))
242 os.rmdir(os.path.join(root, name))
243 if root: os.rmdir(root)
245 if len(B.quickdebug) > 0 and printdebug != 0:
246 print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
247 for l in B.quickdebug:
250 # remove stdc++ from LLIBS if we are building a statc linked CXXFLAGS
251 if env['WITH_BF_STATICCXX']:
252 if 'stdc++' in env['LLIBS']:
253 env['LLIBS'].remove('stdc++')
255 print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
257 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
258 if 'blenderplayer' in B.targets:
259 env['WITH_BF_PLAYER'] = True
261 if 'blendernogame' in B.targets:
262 env['WITH_BF_GAMEENGINE'] = False
264 if 'blenderlite' in B.targets:
266 target_env_defs['WITH_BF_GAMEENGINE'] = False
267 target_env_defs['WITH_BF_OPENAL'] = False
268 target_env_defs['WITH_BF_OPENEXR'] = False
269 target_env_defs['WITH_BF_ICONV'] = False
270 target_env_defs['WITH_BF_INTERNATIONAL'] = False
271 target_env_defs['WITH_BF_OPENJPEG'] = False
272 target_env_defs['WITH_BF_FFMPEG'] = False
273 target_env_defs['WITH_BF_QUICKTIME'] = False
274 target_env_defs['WITH_BF_YAFRAY'] = False
275 target_env_defs['WITH_BF_REDCODE'] = False
276 target_env_defs['WITH_BF_FTGL'] = False
277 target_env_defs['WITH_BF_DDS'] = False
278 target_env_defs['WITH_BF_ZLIB'] = False
279 target_env_defs['WITH_BF_SDL'] = False
280 target_env_defs['WITH_BF_JPEG'] = False
281 target_env_defs['WITH_BF_PNG'] = False
282 target_env_defs['WITH_BF_ODE'] = False
283 target_env_defs['WITH_BF_BULLET'] = False
284 target_env_defs['WITH_BF_SOLID'] = False
285 target_env_defs['WITH_BF_BINRELOC'] = False
286 target_env_defs['BF_BUILDINFO'] = False
287 target_env_defs['BF_NO_ELBEEM'] = True
288 target_env_defs['WITH_BF_PYTHON'] = False
290 # Merge blenderlite, let command line to override
291 for k,v in target_env_defs.iteritems():
292 if k not in B.arguments:
295 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
296 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
297 B.root_build_dir = env['BF_BUILDDIR']
298 B.doc_build_dir = env['BF_DOCDIR']
299 if not B.root_build_dir[-1]==os.sep:
300 B.root_build_dir += os.sep
301 if not B.doc_build_dir[-1]==os.sep:
302 B.doc_build_dir += os.sep
304 # We do a shortcut for clean when no quicklist is given: just delete
305 # builddir without reading in SConscripts
307 if 'clean' in B.targets:
310 if not quickie and do_clean:
311 if os.path.exists(B.doc_build_dir):
312 print B.bc.HEADER+'Cleaning doc dir...'+B.bc.ENDC
313 dirs = os.listdir(B.doc_build_dir)
315 if os.path.isdir(B.doc_build_dir + entry) == 1:
316 print "clean dir %s"%(B.doc_build_dir+entry)
317 shutil.rmtree(B.doc_build_dir+entry)
319 print "remove file %s"%(B.doc_build_dir+entry)
320 os.remove(B.root_build_dir+entry)
321 if os.path.exists(B.root_build_dir):
322 print B.bc.HEADER+'Cleaning build dir...'+B.bc.ENDC
323 dirs = os.listdir(B.root_build_dir)
325 if os.path.isdir(B.root_build_dir + entry) == 1:
326 print "clean dir %s"%(B.root_build_dir+entry)
327 shutil.rmtree(B.root_build_dir+entry)
329 print "remove file %s"%(B.root_build_dir+entry)
330 os.remove(B.root_build_dir+entry)
331 for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
332 'extern/xvidcore/build/generic/platform.inc', 'extern/ffmpeg/include']:
333 if os.path.exists(confile):
334 print "clean file %s"%confile
335 if os.path.isdir(confile):
336 for root, dirs, files in os.walk(confile):
338 os.remove(os.path.join(root, name))
341 print B.bc.OKGREEN+'...done'+B.bc.ENDC
343 print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
346 if not os.path.isdir ( B.root_build_dir):
347 os.makedirs ( B.root_build_dir )
348 os.makedirs ( B.root_build_dir + 'source' )
349 os.makedirs ( B.root_build_dir + 'intern' )
350 os.makedirs ( B.root_build_dir + 'extern' )
351 os.makedirs ( B.root_build_dir + 'lib' )
352 os.makedirs ( B.root_build_dir + 'bin' )
353 if not os.path.isdir(B.doc_build_dir):
354 os.makedirs ( B.doc_build_dir )
356 Help(opts.GenerateHelpText(env))
358 # default is new quieter output, but if you need to see the
359 # commands, do 'scons BF_QUIET=0'
360 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
362 B.set_quiet_output(env)
367 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
368 env.SConsignFile(B.root_build_dir+'scons-signatures')
371 ##### END SETUP ##########
375 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
376 SConscript(B.root_build_dir+'/intern/SConscript')
377 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
378 SConscript(B.root_build_dir+'/extern/SConscript')
379 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
380 SConscript(B.root_build_dir+'/source/SConscript')
382 # now that we have read all SConscripts, we know what
383 # libraries will be built. Create list of
384 # libraries to give as objects to linking phase
386 for tp in B.possible_types:
387 if not tp == 'player' and not tp == 'player2':
388 mainlist += B.create_blender_liblist(env, tp)
390 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
391 B.propose_priorities()
393 dobj = B.buildinfo(env, "dynamic") + B.resources
394 thestatlibs, thelibincs = B.setup_staticlibs(env)
395 thesyslibs = B.setup_syslibs(env)
397 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
398 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
399 if env['WITH_BF_PLAYER']:
400 playerlist = B.create_blender_liblist(env, 'player')
401 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
403 ##### Now define some targets
406 #------------ INSTALL
410 if env['OURPLATFORM']=='darwin':
411 for prg in B.program_list:
412 bundle = '%s.app' % prg[0]
413 bundledir = os.path.dirname(bundle)
414 for dp, dn, df in os.walk(bundle):
419 dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
420 source=[dp+os.sep+f for f in df]
421 blenderinstall.append(env.Install(dir=dir,source=source))
423 blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
426 #- dont do .blender and scripts for darwin, it is already in the bundle
431 if env['OURPLATFORM']!='darwin':
432 for dp, dn, df in os.walk('bin/.blender'):
439 if not env['WITH_BF_INTERNATIONAL']:
442 if f == '.Blanguages':
444 if not env['WITH_BF_FREETYPE']:
445 if f.endswith('.ttf'):
448 dotblendlist.append(os.path.join(dp, f))
449 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
451 dotblenderinstall = []
452 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
453 td, tf = os.path.split(targetdir)
454 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
456 if env['WITH_BF_PYTHON']:
458 scriptpath='release/scripts'
459 for dp, dn, df in os.walk(scriptpath):
464 dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
465 source=[dp+os.sep+f for f in df]
466 scriptinstall.append(env.Install(dir=dir,source=source))
469 if env['OURPLATFORM']=='linux2':
473 for tp, tn, tf in os.walk('release/freedesktop/icons'):
479 iconlist.append(tp+os.sep+f)
480 icontargetlist.append(env['BF_INSTALLDIR']+tp[19:]+os.sep+f)
483 for targetdir,srcfile in zip(icontargetlist, iconlist):
484 td, tf = os.path.split(targetdir)
485 iconinstall.append(env.Install(dir=td, source=srcfile))
487 # dlls for linuxcross
488 # TODO - add more libs, for now this lets blenderlite run
489 if env['OURPLATFORM']=='linuxcross':
490 dir=env['BF_INSTALLDIR']
491 source = ['../lib/windows/pthreads/lib/pthreadGC2.dll']
492 scriptinstall.append(env.Install(dir=dir, source=source))
497 for tp, tn, tf in os.walk('release/plugins'):
503 pluglist.append(tp+os.sep+f)
504 plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
506 # header files for plugins
507 pluglist.append('source/blender/blenpluginapi/documentation.h')
508 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'documentation.h')
509 pluglist.append('source/blender/blenpluginapi/externdef.h')
510 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'externdef.h')
511 pluglist.append('source/blender/blenpluginapi/floatpatch.h')
512 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'floatpatch.h')
513 pluglist.append('source/blender/blenpluginapi/iff.h')
514 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'iff.h')
515 pluglist.append('source/blender/blenpluginapi/plugin.h')
516 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'plugin.h')
517 pluglist.append('source/blender/blenpluginapi/util.h')
518 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'util.h')
519 pluglist.append('source/blender/blenpluginapi/plugin.DEF')
520 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep + 'plugin.def')
523 for targetdir,srcfile in zip(plugtargetlist, pluglist):
524 td, tf = os.path.split(targetdir)
525 plugininstall.append(env.Install(dir=td, source=srcfile))
529 for tp, tn, tf in os.walk('release/text'):
535 textlist.append(tp+os.sep+f)
537 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
539 if env['OURPLATFORM']=='darwin':
540 allinstall = [blenderinstall, plugininstall, textinstall]
541 elif env['OURPLATFORM']=='linux2':
542 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall, iconinstall]
544 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
546 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
547 dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
548 '${BF_PNG_LIBPATH}/libpng.dll',
549 '${BF_ZLIB_LIBPATH}/zlib.dll',
550 '${BF_TIFF_LIBPATH}/${BF_TIFF_LIB}.dll']
551 dllsources += ['${BF_PTHREADS_LIBPATH}/${BF_PTHREADS_LIB}.dll']
552 if env['WITH_BF_SDL']:
553 dllsources.append('${BF_SDL_LIBPATH}/SDL.dll')
554 if env['WITH_BF_PYTHON']:
555 ver = env["BF_PYTHON_VERSION"].replace(".", "")
557 dllsources.append('#release/windows/extra/python' + ver + '.zip')
558 dllsources.append('#release/windows/extra/zlib.pyd')
560 dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_LIB}_d.dll')
562 dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_LIB}.dll')
563 if env['WITH_BF_ICONV']:
564 dllsources += ['${BF_ICONV_LIBPATH}/iconv.dll']
565 if env['WITH_BF_FFMPEG']:
566 dllsources += ['${LCGDIR}/ffmpeg/lib/avcodec-52.dll',
567 '${LCGDIR}/ffmpeg/lib/avformat-52.dll',
568 '${LCGDIR}/ffmpeg/lib/avdevice-52.dll',
569 '${LCGDIR}/ffmpeg/lib/avutil-50.dll',
570 '${LCGDIR}/ffmpeg/lib/libfaad-2.dll',
571 '${LCGDIR}/ffmpeg/lib/libfaac-0.dll',
572 '${LCGDIR}/ffmpeg/lib/libmp3lame-0.dll',
573 '${LCGDIR}/ffmpeg/lib/libx264-67.dll',
574 '${LCGDIR}/ffmpeg/lib/xvidcore.dll',
575 '${LCGDIR}/ffmpeg/lib/swscale-0.dll']
576 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
577 allinstall += windlls
579 installtarget = env.Alias('install', allinstall)
580 bininstalltarget = env.Alias('install-bin', blenderinstall)
582 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
583 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
584 nsisalias = env.Alias('nsis', nsiscmd)
586 if 'blender' in B.targets:
587 blenderexe= env.Alias('blender', B.program_list)
588 Depends(blenderexe,installtarget)
590 if env['WITH_BF_PLAYER']:
591 blenderplayer = env.Alias('blenderplayer', B.program_list)
592 Depends(blenderplayer,installtarget)
594 if not env['WITH_BF_GAMEENGINE']:
595 blendernogame = env.Alias('blendernogame', B.program_list)
596 Depends(blendernogame,installtarget)
598 if 'blenderlite' in B.targets:
599 blenderlite = env.Alias('blenderlite', B.program_list)
600 Depends(blenderlite,installtarget)
602 Depends(nsiscmd, allinstall)
604 Default(B.program_list)
606 if not env['WITHOUT_BF_INSTALL']:
607 Default(installtarget)
609 #------------ RELEASE
610 # TODO: zipup the installation
612 #------------ BLENDERPLAYER
613 # TODO: build stubs and link into blenderplayer
616 if env['WITH_BF_DOCS']:
618 except: epydoc = None
621 SConscript('source/blender/python/api2_2x/doc/SConscript')
622 SConscript('source/gameengine/PyDoc/SConscript')
624 print "No epydoc install detected, Python API and Gameengine API Docs will not be generated "