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 # Need a better way to do this. Automagical maybe is not the best thing, maybe it is.
35 if pltfrm.architecture()[0] == '64bit':
47 from tempfile import mkdtemp
53 EnsureSConsVersion(1,0,0)
55 BlenderEnvironment = tools.Blender.BlenderEnvironment
60 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 # BLENDERPATH is a unix only option to enable typical style paths this is
190 # spesifically a data-dir, which is used a lot but cant replace BF_INSTALLDIR
191 # because the blender binary is installed in $BF_INSTALLDIR/bin/blender
193 if env['WITH_BF_FHS']:
194 BLENDERPATH = os.path.join(env['BF_INSTALLDIR'], 'share', 'blender', env['BF_VERSION'])
196 BLENDERPATH = env['BF_INSTALLDIR']
198 # disable elbeem (fluidsim) compilation?
199 if env['BF_NO_ELBEEM'] == 1:
200 env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
201 env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
202 env['CCFLAGS'].append('-DDISABLE_ELBEEM')
204 if env['WITH_BF_OPENMP'] == 1:
205 if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
206 env['CCFLAGS'].append('/openmp')
207 env['CPPFLAGS'].append('/openmp')
208 env['CXXFLAGS'].append('/openmp')
210 if env['CC'].endswith('icc'): # to be able to handle CC=/opt/bla/icc case
211 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
212 env['CCFLAGS'].append('-openmp')
213 env['CPPFLAGS'].append('-openmp')
214 env['CXXFLAGS'].append('-openmp')
216 env.Append(CCFLAGS=['-fopenmp'])
217 env.Append(CPPFLAGS=['-fopenmp'])
218 env.Append(CXXFLAGS=['-fopenmp'])
220 #check for additional debug libnames
222 if env.has_key('BF_DEBUG_LIBS'):
223 B.quickdebug += env['BF_DEBUG_LIBS']
225 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
227 # see if this linux distro has libalut
229 if env['OURPLATFORM'] == 'linux2' :
230 if env['WITH_BF_OPENAL']:
231 mylib_test_source_file = """
233 int main(int argc, char **argv)
235 alutGetMajorVersion();
240 def CheckFreeAlut(context,env):
241 context.Message( B.bc.OKGREEN + "Linux platform detected:\n checking for FreeAlut... " + B.bc.ENDC )
243 result = context.TryLink(mylib_test_source_file, '.c')
244 context.Result(result)
247 env2 = env.Clone( LIBPATH = env['BF_OPENAL'] )
248 sconf_temp = mkdtemp()
249 conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, sconf_temp, '/dev/null' )
250 if conf.CheckFreeAlut( env2 ):
251 env['BF_OPENAL_LIB'] += ' alut'
254 for root, dirs, files in os.walk(sconf_temp, topdown=False):
256 os.remove(os.path.join(root, name))
258 os.rmdir(os.path.join(root, name))
259 if root: os.rmdir(root)
261 if len(B.quickdebug) > 0 and printdebug != 0:
262 print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
263 for l in B.quickdebug:
266 # remove stdc++ from LLIBS if we are building a statc linked CXXFLAGS
267 if env['WITH_BF_STATICCXX']:
268 if 'stdc++' in env['LLIBS']:
269 env['LLIBS'].remove('stdc++')
271 print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
273 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
274 if 'blenderplayer' in B.targets:
275 env['WITH_BF_PLAYER'] = True
277 if 'blendernogame' in B.targets:
278 env['WITH_BF_GAMEENGINE'] = False
280 if 'blenderlite' in B.targets:
282 target_env_defs['WITH_BF_GAMEENGINE'] = False
283 target_env_defs['WITH_BF_OPENAL'] = False
284 target_env_defs['WITH_BF_OPENEXR'] = False
285 target_env_defs['WITH_BF_ICONV'] = False
286 target_env_defs['WITH_BF_INTERNATIONAL'] = False
287 target_env_defs['WITH_BF_OPENJPEG'] = False
288 target_env_defs['WITH_BF_FFMPEG'] = False
289 target_env_defs['WITH_BF_QUICKTIME'] = False
290 target_env_defs['WITH_BF_REDCODE'] = False
291 target_env_defs['WITH_BF_DDS'] = False
292 target_env_defs['WITH_BF_ZLIB'] = False
293 target_env_defs['WITH_BF_SDL'] = False
294 target_env_defs['WITH_BF_JPEG'] = False
295 target_env_defs['WITH_BF_PNG'] = False
296 target_env_defs['WITH_BF_BULLET'] = False
297 target_env_defs['WITH_BF_BINRELOC'] = False
298 target_env_defs['BF_BUILDINFO'] = False
299 target_env_defs['BF_NO_ELBEEM'] = True
300 target_env_defs['WITH_BF_PYTHON'] = False
302 # Merge blenderlite, let command line to override
303 for k,v in target_env_defs.iteritems():
304 if k not in B.arguments:
307 if env['WITH_BF_SDL'] == False and env['OURPLATFORM'] in ('win32-vc', 'win32-ming', 'win64-vc'):
308 env['PLATFORM_LINKFLAGS'].remove('/ENTRY:mainCRTStartup')
309 env['PLATFORM_LINKFLAGS'].append('/ENTRY:main')
311 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
312 B.root_build_dir = env['BF_BUILDDIR']
313 B.doc_build_dir = os.path.join(BLENDERPATH, 'doc')
314 if not B.root_build_dir[-1]==os.sep:
315 B.root_build_dir += os.sep
316 if not B.doc_build_dir[-1]==os.sep:
317 B.doc_build_dir += os.sep
319 # We do a shortcut for clean when no quicklist is given: just delete
320 # builddir without reading in SConscripts
322 if 'clean' in B.targets:
325 if not quickie and do_clean:
326 if os.path.exists(B.doc_build_dir):
327 print B.bc.HEADER+'Cleaning doc dir...'+B.bc.ENDC
328 dirs = os.listdir(B.doc_build_dir)
330 if os.path.isdir(B.doc_build_dir + entry) == 1:
331 print "clean dir %s"%(B.doc_build_dir+entry)
332 shutil.rmtree(B.doc_build_dir+entry)
334 print "remove file %s"%(B.doc_build_dir+entry)
335 os.remove(B.root_build_dir+entry)
336 if os.path.exists(B.root_build_dir):
337 print B.bc.HEADER+'Cleaning build dir...'+B.bc.ENDC
338 dirs = os.listdir(B.root_build_dir)
340 if os.path.isdir(B.root_build_dir + entry) == 1:
341 print "clean dir %s"%(B.root_build_dir+entry)
342 shutil.rmtree(B.root_build_dir+entry)
344 print "remove file %s"%(B.root_build_dir+entry)
345 os.remove(B.root_build_dir+entry)
346 for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
347 'extern/xvidcore/build/generic/platform.inc', 'extern/ffmpeg/include']:
348 if os.path.exists(confile):
349 print "clean file %s"%confile
350 if os.path.isdir(confile):
351 for root, dirs, files in os.walk(confile):
353 os.remove(os.path.join(root, name))
356 print B.bc.OKGREEN+'...done'+B.bc.ENDC
358 print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
361 if not os.path.isdir ( B.root_build_dir):
362 os.makedirs ( B.root_build_dir )
363 os.makedirs ( B.root_build_dir + 'source' )
364 os.makedirs ( B.root_build_dir + 'intern' )
365 os.makedirs ( B.root_build_dir + 'extern' )
366 os.makedirs ( B.root_build_dir + 'lib' )
367 os.makedirs ( B.root_build_dir + 'bin' )
368 if not os.path.isdir(B.doc_build_dir):
369 os.makedirs ( B.doc_build_dir )
371 Help(opts.GenerateHelpText(env))
373 # default is new quieter output, but if you need to see the
374 # commands, do 'scons BF_QUIET=0'
375 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
377 B.set_quiet_output(env)
382 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
383 env.SConsignFile(B.root_build_dir+'scons-signatures')
386 ##### END SETUP ##########
390 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
391 SConscript(B.root_build_dir+'/intern/SConscript')
392 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
393 SConscript(B.root_build_dir+'/extern/SConscript')
394 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
395 SConscript(B.root_build_dir+'/source/SConscript')
397 # now that we have read all SConscripts, we know what
398 # libraries will be built. Create list of
399 # libraries to give as objects to linking phase
401 for tp in B.possible_types:
402 if not tp == 'player':
403 mainlist += B.create_blender_liblist(env, tp)
405 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
406 B.propose_priorities()
408 dobj = B.buildinfo(env, "dynamic") + B.resources
409 thestatlibs, thelibincs = B.setup_staticlibs(env)
410 thesyslibs = B.setup_syslibs(env)
412 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
413 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist, [], thestatlibs + thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
414 if env['WITH_BF_PLAYER']:
415 playerlist = B.create_blender_liblist(env, 'player')
416 playerlist += B.create_blender_liblist(env, 'intern')
417 playerlist += B.create_blender_liblist(env, 'extern')
418 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist, [], thestatlibs + thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
420 ##### Now define some targets
423 #------------ INSTALL
427 if env['OURPLATFORM']=='darwin':
428 for prg in B.program_list:
429 bundle = '%s.app' % prg[0]
430 bundledir = os.path.dirname(bundle)
431 for dp, dn, df in os.walk(bundle):
434 dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
435 source=[dp+os.sep+f for f in df]
436 blenderinstall.append(env.Install(dir=dir,source=source))
438 if env['WITH_BF_FHS']: dir= os.path.join(env['BF_INSTALLDIR'], 'bin')
439 else: dir= env['BF_INSTALLDIR']
441 blenderinstall = env.Install(dir=dir, source=B.program_list)
444 #- dont do .blender and scripts for darwin, it is already in the bundle
449 if env['OURPLATFORM']!='darwin':
450 for dp, dn, df in os.walk('bin/.blender'):
455 if not env['WITH_BF_INTERNATIONAL']:
458 if f == '.Blanguages':
460 if not env['WITH_BF_FREETYPE']:
461 if f.endswith('.ttf'):
464 dotblendlist.append(os.path.join(dp, f))
465 if env['WITH_BF_FHS']: dir= os.path.join(*([BLENDERPATH] + dp.split(os.sep)[2:])) # skip bin/.blender
466 else: dir= os.path.join(*([BLENDERPATH] + dp.split(os.sep)[1:])) # skip bin
468 # print dir+ os.sep + f
470 dottargetlist.append(dir + os.sep + f)
473 dotblenderinstall = []
474 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
475 td, tf = os.path.split(targetdir)
476 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
478 if env['WITH_BF_PYTHON']:
480 scriptpaths=['release/scripts']
481 for scriptpath in scriptpaths:
482 for dp, dn, df in os.walk(scriptpath):
486 if env['WITH_BF_FHS']: dir = BLENDERPATH
487 else: dir = os.path.join(env['BF_INSTALLDIR'], '.blender')
488 dir += os.sep + os.path.basename(scriptpath) + dp[len(scriptpath):]
490 source=[os.path.join(dp, 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'):
502 iconlist.append(os.path.join(tp, f))
503 icontargetlist.append( os.path.join(*([BLENDERPATH] + tp.split(os.sep)[2:] + [f])) )
506 for targetdir,srcfile in zip(icontargetlist, iconlist):
507 td, tf = os.path.split(targetdir)
508 iconinstall.append(env.Install(dir=td, source=srcfile))
510 # dlls for linuxcross
511 # TODO - add more libs, for now this lets blenderlite run
512 if env['OURPLATFORM']=='linuxcross':
513 dir=env['BF_INSTALLDIR']
514 source = ['../lib/windows/pthreads/lib/pthreadGC2.dll']
515 scriptinstall.append(env.Install(dir=dir, source=source))
520 for tp, tn, tf in os.walk('release/plugins'):
524 pluglist.append(os.path.join(tp, f))
525 plugtargetlist.append( os.path.join(*([BLENDERPATH] + tp.split(os.sep)[1:] + [f])) )
528 # header files for plugins
529 pluglist.append('source/blender/blenpluginapi/documentation.h')
530 plugtargetlist.append(os.path.join(BLENDERPATH, 'plugins', 'include', 'documentation.h'))
531 pluglist.append('source/blender/blenpluginapi/externdef.h')
532 plugtargetlist.append(os.path.join(BLENDERPATH, 'plugins', 'include', 'externdef.h'))
533 pluglist.append('source/blender/blenpluginapi/floatpatch.h')
534 plugtargetlist.append(os.path.join(BLENDERPATH, 'plugins', 'include', 'floatpatch.h'))
535 pluglist.append('source/blender/blenpluginapi/iff.h')
536 plugtargetlist.append(os.path.join(BLENDERPATH, 'plugins', 'include', 'iff.h'))
537 pluglist.append('source/blender/blenpluginapi/plugin.h')
538 plugtargetlist.append(os.path.join(BLENDERPATH, 'plugins', 'include', 'plugin.h'))
539 pluglist.append('source/blender/blenpluginapi/util.h')
540 plugtargetlist.append(os.path.join(BLENDERPATH, 'plugins', 'include', 'util.h'))
541 pluglist.append('source/blender/blenpluginapi/plugin.DEF')
542 plugtargetlist.append(os.path.join(BLENDERPATH, 'plugins', 'include', 'plugin.def'))
545 for targetdir,srcfile in zip(plugtargetlist, pluglist):
546 td, tf = os.path.split(targetdir)
547 plugininstall.append(env.Install(dir=td, source=srcfile))
551 for tp, tn, tf in os.walk('release/text'):
555 textlist.append(tp+os.sep+f)
557 textinstall = env.Install(dir=BLENDERPATH, source=textlist)
559 if env['OURPLATFORM']=='darwin':
560 allinstall = [blenderinstall, plugininstall, textinstall]
561 elif env['OURPLATFORM']=='linux2':
562 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall, iconinstall]
564 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
566 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc'):
567 if env['OURPLATFORM'] == 'win64-vc':
570 dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
571 '${BF_PNG_LIBPATH}/libpng.dll',
572 '${BF_ZLIB_LIBPATH}/zlib.dll',
573 '${BF_TIFF_LIBPATH}/${BF_TIFF_LIB}.dll']
574 dllsources += ['${BF_PTHREADS_LIBPATH}/${BF_PTHREADS_LIB}.dll']
575 if env['WITH_BF_SDL']:
576 if env['OURPLATFORM'] == 'win64-vc':
577 pass # we link statically already to SDL on win64
579 dllsources.append('${BF_SDL_LIBPATH}/SDL.dll')
580 if env['WITH_BF_PYTHON']:
582 dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
584 dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
585 if env['WITH_BF_ICONV']:
586 if env['OURPLATFORM'] == 'win64-vc':
587 pass # we link statically to iconv on win64
589 dllsources += ['${BF_ICONV_LIBPATH}/iconv.dll']
590 if env['WITH_BF_OPENAL']:
591 dllsources.append('${LCGDIR}/openal/lib/OpenAL32.dll')
592 dllsources.append('${LCGDIR}/openal/lib/wrap_oal.dll')
593 if env['WITH_BF_SNDFILE']:
594 dllsources.append('${LCGDIR}/sndfile/lib/libsndfile-1.dll')
595 if env['WITH_BF_FFMPEG']:
596 dllsources += ['${LCGDIR}/ffmpeg/lib/avcodec-52.dll',
597 '${LCGDIR}/ffmpeg/lib/avformat-52.dll',
598 '${LCGDIR}/ffmpeg/lib/avdevice-52.dll',
599 '${LCGDIR}/ffmpeg/lib/avutil-50.dll',
600 '${LCGDIR}/ffmpeg/lib/swscale-0.dll']
601 if env['WITH_BF_JACK']:
602 dllsources += ['${LCGDIR}/jack/lib/libjack.dll']
603 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
604 allinstall += windlls
606 installtarget = env.Alias('install', allinstall)
607 bininstalltarget = env.Alias('install-bin', blenderinstall)
609 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
610 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
611 nsisalias = env.Alias('nsis', nsiscmd)
613 if 'blender' in B.targets:
614 blenderexe= env.Alias('blender', B.program_list)
615 Depends(blenderexe,installtarget)
617 if env['WITH_BF_PLAYER']:
618 blenderplayer = env.Alias('blenderplayer', B.program_list)
619 Depends(blenderplayer,installtarget)
621 if not env['WITH_BF_GAMEENGINE']:
622 blendernogame = env.Alias('blendernogame', B.program_list)
623 Depends(blendernogame,installtarget)
625 if 'blenderlite' in B.targets:
626 blenderlite = env.Alias('blenderlite', B.program_list)
627 Depends(blenderlite,installtarget)
629 Depends(nsiscmd, allinstall)
631 Default(B.program_list)
633 if not env['WITHOUT_BF_INSTALL']:
634 Default(installtarget)
637 if env['WITH_BF_DOCS']:
639 except: epydoc = None
642 SConscript('source/gameengine/PyDoc/SConscript')
644 print "No epydoc install detected, Python API and Gameengine API Docs will not be generated "