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 BlenderEnvironment = tools.Blender.BlenderEnvironment
50 platform = sys.platform
55 ##### BEGIN SETUP #####
57 B.possible_types = ['core', 'common', 'blender', 'intern',
58 'international', 'game', 'game2',
59 'player', 'player2', 'system']
61 B.binarykind = ['blender' , 'blenderplayer']
62 ##################################
63 # target and argument validation #
64 ##################################
65 # XX cheating for BF_FANCY, we check for BF_FANCY before args are validated
66 use_color = ARGUMENTS.get('BF_FANCY', '1')
70 if not use_color=='1':
73 #on defaut white Os X terminal, some colors are totally unlegible
74 if platform=='darwin':
75 B.bc.OKGREEN = '\033[34m'
76 B.bc.WARNING = '\033[36m'
79 print B.bc.HEADER+'Command-line arguments'+B.bc.ENDC
80 B.arguments = btools.validate_arguments(ARGUMENTS, B.bc)
81 btools.print_arguments(B.arguments, B.bc)
84 print B.bc.HEADER+'Command-line targets'+B.bc.ENDC
85 B.targets = btools.validate_targets(COMMAND_LINE_TARGETS, B.bc)
86 btools.print_targets(B.targets, B.bc)
88 ##########################
89 # setting up environment #
90 ##########################
92 # handling cmd line arguments & config file
94 # first check cmdline for toolset and we create env to work on
95 quickie = B.arguments.get('BF_QUICK', None)
96 quickdebug = B.arguments.get('BF_QUICKDEBUG', None)
99 B.quickdebug=string.split(quickdebug, ',')
104 B.quickie=string.split(quickie,',')
108 toolset = B.arguments.get('BF_TOOLSET', None)
110 print "Using " + toolset
111 if toolset=='mstoolkit':
112 env = BlenderEnvironment(ENV = os.environ)
113 env.Tool('mstoolkit', ['tools'])
115 env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
117 btools.SetupSpawn(env)
119 env = BlenderEnvironment(ENV = os.environ)
122 print "Could not create a build environment"
126 cc = B.arguments.get('CC', None)
127 cxx = B.arguments.get('CXX', None)
133 if env['CC'] in ['cl', 'cl.exe'] and sys.platform=='win32':
134 platform = 'win32-vc'
135 elif env['CC'] in ['gcc'] and sys.platform=='win32':
136 platform = 'win32-mingw'
138 env.SConscriptChdir(0)
140 crossbuild = B.arguments.get('BF_CROSS', None)
141 if crossbuild and platform!='win32':
142 platform = 'linuxcross'
144 env['OURPLATFORM'] = platform
146 configfile = 'config'+os.sep+platform+'-config.py'
148 if os.path.exists(configfile):
149 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
151 print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
153 if crossbuild and env['PLATFORM'] != 'win32':
154 print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
155 env.Tool('crossmingw', ['tools'])
156 # todo: determine proper libs/includes etc.
157 # Needed for gui programs, console programs should do without it
158 env.Append(LINKFLAGS=['-mwindows'])
160 userconfig = B.arguments.get('BF_CONFIG', 'user-config.py')
161 # first read platform config. B.arguments will override
162 optfiles = [configfile]
163 if os.path.exists(userconfig):
164 print B.bc.OKGREEN + "Using user-config file: " + B.bc.ENDC + userconfig
165 optfiles += [userconfig]
167 print B.bc.WARNING + userconfig + " not found, no user overrides" + B.bc.ENDC
169 opts = btools.read_opts(optfiles, B.arguments)
172 if not env['BF_FANCY']:
175 # disable elbeem (fluidsim) compilation?
176 if env['BF_NO_ELBEEM'] == 1:
177 env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
178 env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
179 env['CCFLAGS'].append('-DDISABLE_ELBEEM')
181 if env['WITH_BF_OPENMP'] == 1:
182 if env['OURPLATFORM']=='win32-vc':
183 env['CCFLAGS'].append('/openmp')
184 env['CPPFLAGS'].append('/openmp')
185 env['CXXFLAGS'].append('/openmp')
187 if env['CC'][-3:] == 'icc': # to be able to handle CC=/opt/bla/icc case
188 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
189 env['CCFLAGS'].append('-openmp')
190 env['CPPFLAGS'].append('-openmp')
191 env['CXXFLAGS'].append('-openmp')
193 env.Append(CCFLAGS=['-fopenmp'])
194 env.Append(CPPFLAGS=['-fopenmp'])
195 env.Append(CXXFLAGS=['-fopenmp'])
196 # env.Append(LINKFLAGS=['-fprofile-generate'])
198 #check for additional debug libnames
200 if env.has_key('BF_DEBUG_LIBS'):
201 B.quickdebug += env['BF_DEBUG_LIBS']
203 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
205 # see if this linux distro has libalut
207 if env['OURPLATFORM'] == 'linux2' :
208 if env['WITH_BF_OPENAL']:
209 mylib_test_source_file = """
211 int main(int argc, char **argv)
213 alutGetMajorVersion();
218 def CheckFreeAlut(context,env):
219 context.Message( B.bc.OKGREEN + "Linux platform detected:\n checking for FreeAlut... " + B.bc.ENDC )
221 result = context.TryLink(mylib_test_source_file, '.c')
222 context.Result(result)
225 env2 = env.Copy( LIBPATH = env['BF_OPENAL'] )
226 sconf_temp = mkdtemp()
227 conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, sconf_temp, '/dev/null' )
228 if conf.CheckFreeAlut( env2 ):
229 env['BF_OPENAL_LIB'] += ' alut'
232 for root, dirs, files in os.walk(sconf_temp, topdown=False):
234 os.remove(os.path.join(root, name))
236 os.rmdir(os.path.join(root, name))
237 if root: os.rmdir(root)
239 if len(B.quickdebug) > 0 and printdebug != 0:
240 print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
241 for l in B.quickdebug:
244 # remove stdc++ from LLIBS if we are building a statc linked CXXFLAGS
245 if env['WITH_BF_STATICCXX']:
246 if 'stdc++' in env['LLIBS']:
247 env['LLIBS'] = env['LLIBS'].replace('stdc++', ' ')
249 print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
251 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
252 if 'blenderplayer' in B.targets:
253 env['WITH_BF_PLAYER'] = True
255 if 'blendernogame' in B.targets:
256 env['WITH_BF_GAMEENGINE'] = False
258 if 'blenderlite' in B.targets:
259 env['WITH_BF_GAMEENGINE'] = False
260 env['WITH_BF_OPENAL'] = False
261 env['WITH_BF_OPENEXR'] = False
262 env['WITH_BF_ICONV'] = False
263 env['WITH_BF_INTERNATIONAL'] = False
264 env['WITH_BF_OPENJPEG'] = False
265 env['WITH_BF_FFMPEG'] = False
266 env['WITH_BF_QUICKTIME'] = False
267 env['WITH_BF_YAFRAY'] = False
268 env['WITH_BF_REDCODE'] = False
269 env['WITH_BF_FTGL'] = False
270 env['WITH_BF_DDS'] = False
271 env['WITH_BF_ZLIB'] = False
272 env['WITH_BF_SDL'] = False
273 env['WITH_BF_JPEG'] = False
274 env['WITH_BF_PNG'] = False
275 env['WITH_BF_ODE'] = False
276 env['WITH_BF_BULLET'] = False
277 env['WITH_BF_BINRELOC'] = False
278 env['BF_BUILDINFO'] = False
279 env['BF_NO_ELBEEM'] = True
281 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
282 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
283 B.root_build_dir = env['BF_BUILDDIR']
284 B.doc_build_dir = env['BF_DOCDIR']
285 if not B.root_build_dir[-1]==os.sep:
286 B.root_build_dir += os.sep
287 if not B.doc_build_dir[-1]==os.sep:
288 B.doc_build_dir += os.sep
290 # We do a shortcut for clean when no quicklist is given: just delete
291 # builddir without reading in SConscripts
293 if 'clean' in B.targets:
296 if not quickie and do_clean:
297 if os.path.exists(B.doc_build_dir):
298 print B.bc.HEADER+'Cleaning doc dir...'+B.bc.ENDC
299 dirs = os.listdir(B.doc_build_dir)
301 if os.path.isdir(B.doc_build_dir + entry) == 1:
302 print "clean dir %s"%(B.doc_build_dir+entry)
303 shutil.rmtree(B.doc_build_dir+entry)
305 print "remove file %s"%(B.doc_build_dir+entry)
306 os.remove(B.root_build_dir+entry)
307 if os.path.exists(B.root_build_dir):
308 print B.bc.HEADER+'Cleaning build dir...'+B.bc.ENDC
309 dirs = os.listdir(B.root_build_dir)
311 if os.path.isdir(B.root_build_dir + entry) == 1:
312 print "clean dir %s"%(B.root_build_dir+entry)
313 shutil.rmtree(B.root_build_dir+entry)
315 print "remove file %s"%(B.root_build_dir+entry)
316 os.remove(B.root_build_dir+entry)
317 for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
318 'extern/xvidcore/build/generic/platform.inc']:
319 if os.path.exists(confile):
320 print "clean file %s"%confile
322 print B.bc.OKGREEN+'...done'+B.bc.ENDC
324 print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
327 if not os.path.isdir ( B.root_build_dir):
328 os.makedirs ( B.root_build_dir )
329 os.makedirs ( B.root_build_dir + 'source' )
330 os.makedirs ( B.root_build_dir + 'intern' )
331 os.makedirs ( B.root_build_dir + 'extern' )
332 os.makedirs ( B.root_build_dir + 'lib' )
333 os.makedirs ( B.root_build_dir + 'bin' )
334 if not os.path.isdir(B.doc_build_dir):
335 os.makedirs ( B.doc_build_dir )
337 Help(opts.GenerateHelpText(env))
339 # default is new quieter output, but if you need to see the
340 # commands, do 'scons BF_QUIET=0'
341 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
343 B.set_quiet_output(env)
348 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
349 env.SConsignFile(B.root_build_dir+'scons-signatures')
352 ##### END SETUP ##########
356 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
357 SConscript(B.root_build_dir+'/intern/SConscript')
358 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
359 SConscript(B.root_build_dir+'/extern/SConscript')
360 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
361 SConscript(B.root_build_dir+'/source/SConscript')
363 # now that we have read all SConscripts, we know what
364 # libraries will be built. Create list of
365 # libraries to give as objects to linking phase
367 for tp in B.possible_types:
368 if not tp == 'player' and not tp == 'player2':
369 mainlist += B.create_blender_liblist(env, tp)
371 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
372 B.propose_priorities()
374 dobj = B.buildinfo(env, "dynamic") + B.resources
375 thestatlibs, thelibincs = B.setup_staticlibs(env)
376 thesyslibs = B.setup_syslibs(env)
378 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
379 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
380 if env['WITH_BF_PLAYER']:
381 playerlist = B.create_blender_liblist(env, 'player')
382 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
384 ##### Now define some targets
387 #------------ INSTALL
391 if env['OURPLATFORM']=='darwin':
392 for prg in B.program_list:
393 bundle = '%s.app' % prg[0]
394 bundledir = os.path.dirname(bundle)
395 for dp, dn, df in os.walk(bundle):
400 dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
401 source=[dp+os.sep+f for f in df]
402 blenderinstall.append(env.Install(dir=dir,source=source))
404 blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
407 #- dont do .blender and scripts for darwin, it is already in the bundle
412 if env['OURPLATFORM']!='darwin':
413 for dp, dn, df in os.walk('bin/.blender'):
419 dotblendlist.append(dp+os.sep+f)
420 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
422 dotblenderinstall = []
423 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
424 td, tf = os.path.split(targetdir)
425 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
428 scriptpath='release/scripts'
429 for dp, dn, df in os.walk(scriptpath):
434 dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
435 source=[dp+os.sep+f for f in df]
436 scriptinstall.append(env.Install(dir=dir,source=source))
439 if env['OURPLATFORM']=='linux2':
443 for tp, tn, tf in os.walk('release/freedesktop/icons'):
449 print ">>>", env['BF_INSTALLDIR'], tp, f
450 iconlist.append(tp+os.sep+f)
451 icontargetlist.append(env['BF_INSTALLDIR']+tp[19:]+os.sep+f)
454 for targetdir,srcfile in zip(icontargetlist, iconlist):
455 td, tf = os.path.split(targetdir)
456 iconinstall.append(env.Install(dir=td, source=srcfile))
461 for tp, tn, tf in os.walk('release/plugins'):
467 print ">>>", env['BF_INSTALLDIR'], tp, f
468 pluglist.append(tp+os.sep+f)
469 plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
471 # header files for plugins
472 pluglist.append('source/blender/blenpluginapi/documentation.h')
473 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'documentation.h')
474 pluglist.append('source/blender/blenpluginapi/externdef.h')
475 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'externdef.h')
476 pluglist.append('source/blender/blenpluginapi/floatpatch.h')
477 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'floatpatch.h')
478 pluglist.append('source/blender/blenpluginapi/iff.h')
479 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'iff.h')
480 pluglist.append('source/blender/blenpluginapi/plugin.h')
481 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'plugin.h')
482 pluglist.append('source/blender/blenpluginapi/util.h')
483 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'util.h')
484 pluglist.append('source/blender/blenpluginapi/plugin.DEF')
485 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep + 'plugin.def')
488 for targetdir,srcfile in zip(plugtargetlist, pluglist):
489 td, tf = os.path.split(targetdir)
490 plugininstall.append(env.Install(dir=td, source=srcfile))
494 for tp, tn, tf in os.walk('release/text'):
500 textlist.append(tp+os.sep+f)
502 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
504 if env['OURPLATFORM']=='darwin':
505 allinstall = [blenderinstall, plugininstall, textinstall]
506 elif env['OURPLATFORM']=='linux2':
507 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall, iconinstall]
509 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
511 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
512 dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
513 '${LCGDIR}/png/lib/libpng.dll',
514 '#release/windows/extra/python25.zip',
515 '#release/windows/extra/zlib.pyd',
516 '${LCGDIR}/sdl/lib/SDL.dll',
517 '${LCGDIR}/zlib/lib/zlib.dll',
518 '${LCGDIR}/tiff/lib/libtiff.dll']
520 dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}_d.dll')
522 dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}.dll')
523 if env['OURPLATFORM'] == 'win32-mingw':
524 dllsources += ['${LCGDIR}/pthreads/lib/pthreadGC2.dll']
526 dllsources += ['${LCGDIR}/pthreads/lib/pthreadVC2.dll']
527 if env['WITH_BF_ICONV']:
528 dllsources += ['${LCGDIR}/iconv/lib/iconv.dll']
529 if env['WITH_BF_FFMPEG']:
530 dllsources += ['${LCGDIR}/ffmpeg/lib/avcodec-51.dll',
531 '${LCGDIR}/ffmpeg/lib/avformat-52.dll',
532 '${LCGDIR}/ffmpeg/lib/avdevice-52.dll',
533 '${LCGDIR}/ffmpeg/lib/avutil-49.dll',
534 '${LCGDIR}/ffmpeg/lib/libfaad-0.dll',
535 '${LCGDIR}/ffmpeg/lib/libfaac-0.dll',
536 '${LCGDIR}/ffmpeg/lib/libmp3lame-0.dll',
537 '${LCGDIR}/ffmpeg/lib/libx264-59.dll',
538 '${LCGDIR}/ffmpeg/lib/xvidcore.dll',
539 '${LCGDIR}/ffmpeg/lib/swscale-0.dll']
540 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
541 allinstall += windlls
543 installtarget = env.Alias('install', allinstall)
544 bininstalltarget = env.Alias('install-bin', blenderinstall)
546 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
547 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
548 nsisalias = env.Alias('nsis', nsiscmd)
550 if 'blender' in B.targets:
551 blenderexe= env.Alias('blender', B.program_list)
552 Depends(blenderexe,installtarget)
554 if env['WITH_BF_PLAYER']:
555 blenderplayer = env.Alias('blenderplayer', B.program_list)
556 Depends(blenderplayer,installtarget)
558 if not env['WITH_BF_GAMEENGINE']:
559 blendernogame = env.Alias('blendernogame', B.program_list)
560 Depends(blendernogame,installtarget)
562 if 'blenderlite' in B.targets:
563 blenderlite = env.Alias('blenderlite', B.program_list)
564 Depends(blenderlite,installtarget)
566 Depends(nsiscmd, allinstall)
568 Default(B.program_list)
570 if not env['WITHOUT_BF_INSTALL']:
571 Default(installtarget)
573 #------------ RELEASE
574 # TODO: zipup the installation
576 #------------ BLENDERPLAYER
577 # TODO: build stubs and link into blenderplayer
580 if env['WITH_BF_BPYDOC']:
581 SConscript(['source/blender/python/api2_2x/doc/SConscript'])