3 # ***** BEGIN GPL/BL DUAL 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. The Blender
9 # Foundation also sells licenses for use in proprietary software under
10 # the Blender License. See http://www.blender.org/BL/ for information
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software Foundation,
20 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # The Original Code is Copyright (C) 2006, Blender Foundation
23 # All rights reserved.
25 # The Original Code is: all of this file.
27 # Contributor(s): Nathan Letwory.
29 # ***** END GPL/BL DUAL LICENSE BLOCK *****
31 # Main entry-point for the SCons building system
32 # Set up some custom actions and target/argument handling
33 # Then read all SConscripts and build
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)
119 env = BlenderEnvironment(ENV = os.environ)
122 print "Could not create a build environment"
125 env.SConscriptChdir(0)
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'
139 #if platform == 'win32-mingw':
148 slash= re.compile(r"\\")
152 b = slash.sub(r"\\\\", b[1:-1])
153 return "\"" + b + "\""
157 def my_spawn(sh, escape, cmd, args, spawnenv):
159 spawnenv[var] = spawnenv[var].encode('ascii', 'replace')
161 sAttrs = win32security.SECURITY_ATTRIBUTES()
162 StartupInfo = win32process.STARTUPINFO()
163 if cmd=='ar' and args[1]=='r':
165 newargs = string.join(map(myesc, args[1:]), ' ')
166 cmdline = cmd + " " + newargs
168 # check for any special operating system commands
171 win32file.DeleteFile(arg)
174 # otherwise execute the command.
175 hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(None, cmdline, None, None, 1, 0, spawnenv, None, StartupInfo)
176 win32event.WaitForSingleObject(hProcess, win32event.INFINITE)
177 exit_code = win32process.GetExitCodeProcess(hProcess)
178 win32file.CloseHandle(hProcess);
179 win32file.CloseHandle(hThread);
182 env['SPAWN'] = my_spawn
184 print "install win32all from http://sourceforge.net/project/showfiles.php?group_id=78018"
186 crossbuild = B.arguments.get('BF_CROSS', None)
187 if crossbuild and platform!='win32':
188 platform = 'linuxcross'
190 env['OURPLATFORM'] = platform
192 configfile = B.arguments.get('BF_CONFIG', 'config'+os.sep+platform+'-config.py')
194 if os.path.exists(configfile):
195 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
197 print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
199 if crossbuild and env['PLATFORM'] != 'win32':
200 print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
201 env.Tool('crossmingw', ['tools'])
202 # todo: determine proper libs/includes etc.
203 # Needed for gui programs, console programs should do without it
204 env.Append(LINKFLAGS=['-mwindows'])
206 # first read platform config. B.arguments will override
207 optfiles = [configfile]
208 if os.path.exists('user-config.py'):
209 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + 'user-config.py'
210 optfiles += ['user-config.py']
212 print B.bc.WARNING + 'user-config.py' + " not found, no user overrides" + B.bc.ENDC
214 opts = btools.read_opts(optfiles, B.arguments)
217 # disable elbeem (fluidsim) compilation?
218 if env['BF_NO_ELBEEM'] == 1:
219 env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
220 env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
221 env['CCFLAGS'].append('-DDISABLE_ELBEEM')
223 #check for additional debug libnames
225 if env.has_key('BF_DEBUG_LIBS'):
226 B.quickdebug += env['BF_DEBUG_LIBS']
228 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
230 # see if this linux distro has libalut
232 if env['OURPLATFORM'] == 'linux2' :
233 if env['WITH_BF_OPENAL']:
234 mylib_test_source_file = """
236 int main(int argc, char **argv)
238 alutGetMajorVersion();
243 def CheckFreeAlut(context,env):
244 context.Message( B.bc.OKGREEN + "Linux platform detected:\n checking for FreeAlut... " + B.bc.ENDC )
246 result = context.TryLink(mylib_test_source_file, '.c')
247 context.Result(result)
250 env2 = env.Copy( LIBPATH = env['BF_OPENAL'] )
251 conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, '.sconf_temp', '/dev/null' )
252 if conf.CheckFreeAlut( env2 ):
253 env['BF_OPENAL_LIB'] += ' alut'
255 for root, dirs, files in os.walk('.sconf_temp', topdown=False):
257 os.remove(os.path.join(root, name))
259 os.rmdir(os.path.join(root, name))
262 if len(B.quickdebug) > 0 and printdebug != 0:
263 print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
264 for l in B.quickdebug:
267 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
268 if 'blenderplayer' in B.targets:
269 env['WITH_BF_PLAYER'] = True
271 if 'blendernogame' in B.targets:
272 env['WITH_BF_GAMEENGINE'] = False
274 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
275 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
276 B.root_build_dir = env['BF_BUILDDIR']
277 env['BUILDDIR'] = B.root_build_dir
278 if not B.root_build_dir[-1]==os.sep:
279 B.root_build_dir += os.sep
281 def NSIS_Installer():
283 if env['OURPLATFORM'] != 'win32-vc' and env['OURPLATFORM'] != 'win32-mingw':
284 print "NSIS installer is only available on Windows."
287 install_base_dir = os.getcwd() + "\\"
289 if not os.path.exists(install_base_dir+env['BF_INSTALLDIR']+'/plugins/include'):
290 os.mkdir(install_base_dir+env['BF_INSTALLDIR']+'/plugins/include')
292 for f in glob.glob('source/blender/blenpluginapi/*.h'):
293 shutil.copy(f,install_base_dir+env['BF_INSTALLDIR']+'/plugins/include')
295 shutil.copy('source/blender/blenpluginapi/plugin.def',install_base_dir+env['BF_INSTALLDIR']+'/plugins/include/')
299 version = v.read()[:-1]
300 shortver = version.split('.')[0] + version.split('.')[1]
303 #### change to suit install dir ####
304 inst_dir = install_base_dir + env['BF_INSTALLDIR']
306 os.chdir("windows/installer")
308 ns = open("00.sconsblender.nsi","r")
310 ns_cnt = str(ns.read())
315 rootdir = os.listdir(inst_dir+"\\")
316 for rootitem in rootdir:
317 if os.path.isdir(inst_dir+"\\"+ rootitem) == 0:
318 rootlist.append("File " + inst_dir + "\\" + rootitem)
319 rootstring = string.join(rootlist, "\n ")
321 ns_cnt = string.replace(ns_cnt, "[ROOTDIRCONTS]", rootstring)
325 for rootitem in rootdir:
326 if os.path.isdir(inst_dir + rootitem) == 0:
327 delrootlist.append("Delete $INSTDIR\\" + rootitem)
328 delrootstring = string.join(delrootlist, "\n ")
329 delrootstring += "\n"
330 ns_cnt = string.replace(ns_cnt, "[DELROOTDIRCONTS]", delrootstring)
334 scriptpath = "%s%s" % (inst_dir, "\\.blender\\scripts")
335 scriptdir = os.listdir(scriptpath)
336 for scriptitem in scriptdir:
337 scriptfile = "%s\\%s" % (scriptpath, scriptitem)
338 if os.path.isdir(scriptfile) == 0:
339 scriptlist.append("File %s" % scriptfile)
340 scriptstring = string.join(scriptlist, "\n ")
341 scriptstring += "\n\n"
342 ns_cnt = string.replace(ns_cnt, "[SCRIPTCONTS]", scriptstring)
344 # do scripts\bpymodules
346 bpymodpath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpymodules")
347 bpymoddir = os.listdir(bpymodpath)
349 for bpymoditem in bpymoddir:
350 bpymodfile = "%s\\%s" % (bpymodpath, bpymoditem)
351 if os.path.isdir(bpymodfile) == 0:
352 bpymodlist.append("File %s" % bpymodfile)
353 bpymodstring = string.join(bpymodlist, "\n ")
354 bpymodstring += "\n\n"
355 ns_cnt = string.replace(ns_cnt, "[SCRIPTMODCONTS]", bpymodstring)
357 # do scripts\bpymodules\colladaimex
359 bpymodpath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpymodules\\ColladaImEx")
360 bpymoddir = os.listdir(bpymodpath)
362 for bpymoditem in bpymoddir:
363 bpymodfile = "%s\\%s" % (bpymodpath, bpymoditem)
364 if os.path.isdir(bpymodfile) == 0:
365 colladalist.append("File %s" % bpymodfile)
366 bpymodstring = string.join(colladalist, "\n ")
367 bpymodstring += "\n\n"
368 ns_cnt = string.replace(ns_cnt, "[SCRIPTMODCOLLADACONT]", bpymodstring)
372 bpydatapath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpydata")
373 bpydatadir = os.listdir(bpydatapath)
374 for bpydataitem in bpydatadir:
375 bpydatafile = "%s\\%s" % (bpydatapath, bpydataitem)
376 if os.path.isdir(bpydatafile) == 0:
377 bpydatalist.append("File %s" % bpydatafile)
378 bpydatastring = string.join(bpydatalist, "\n ")
379 bpydatastring += "\n\n"
380 ns_cnt = string.replace(ns_cnt, "[SCRIPTDATACONTS]", bpydatastring)
384 plugincludepath = "%s%s" % (inst_dir, "\\plugins\\include")
385 plugincludedir = os.listdir(plugincludepath)
386 for plugincludeitem in plugincludedir:
387 plugincludefile = "%s\\%s" % (plugincludepath, plugincludeitem)
388 if os.path.isdir(plugincludefile) == 0:
389 if plugincludefile.find('.h') or plugincludefile.find('.DEF'):
390 plugincludelist.append("File %s" % plugincludefile)
391 plugincludestring = string.join(plugincludelist, "\n ")
392 plugincludestring += "\n\n"
393 ns_cnt = string.replace(ns_cnt, "[PLUGINCONTS]", plugincludestring)
395 # do scripts\bpydata\config
397 cfgpath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpydata\\config")
398 cfgdir = os.listdir(cfgpath)
399 for cfgitem in cfgdir:
400 cfgfile = "%s\\%s" % (cfgpath, cfgitem)
401 if os.path.isdir(cfgfile) == 0:
402 cfglist.append("File %s" % cfgfile)
403 cfgstring = string.join(cfglist, "\n ")
405 ns_cnt = string.replace(ns_cnt, "[SCRIPTDATACFGCONTS]", cfgstring)
409 dotblenddir = os.listdir(inst_dir+"\\.blender")
410 for dotblenditem in dotblenddir:
411 if os.path.isdir(inst_dir + "\\.blender\\" + dotblenditem) == 0:
412 dotblendlist.append("File " + inst_dir + "\\.blender\\" + dotblenditem)
413 dotblendstring = string.join(dotblendlist, "\n ")
414 dotblendstring += "\n\n"
415 ns_cnt = string.replace(ns_cnt, "[DOTBLENDERCONTS]", dotblendstring)
420 langdir = os.listdir(inst_dir + "\\.blender\\locale")
421 for langitem in langdir:
422 if os.path.isdir(inst_dir + "\\.blender\\locale\\" + langitem) == 1:
423 langfiles.append("SetOutPath $BLENDERHOME\\.blender\\locale\\" + langitem + "\\LC_MESSAGES")
424 langfiles.append("File " + inst_dir + "\\.blender\\locale\\" + langitem + "\\LC_MESSAGES\\blender.mo")
425 langstring = string.join(langfiles, "\n ")
427 ns_cnt = string.replace(ns_cnt, "[LANGUAGECONTS]", langstring)
430 ns_cnt = string.replace(ns_cnt, "DISTDIR", inst_dir+"\\")
431 ns_cnt = string.replace(ns_cnt, "SHORTVER", shortver)
432 ns_cnt = string.replace(ns_cnt, "VERSION", version)
434 new_nsis = open("00.blender_tmp.nsi", 'w')
435 new_nsis.write(ns_cnt)
438 sys.stdout = os.popen("makensis 00.blender_tmp.nsi", 'w')
441 if 'nsis' in B.targets:
445 # We do a shortcut for clean when no quicklist is given: just delete
446 # builddir without reading in SConscripts
448 if 'clean' in B.targets:
451 if not quickie and do_clean:
452 print B.bc.HEADER+'Cleaning...'+B.bc.ENDC
453 dirs = os.listdir(B.root_build_dir)
455 if os.path.isdir(B.root_build_dir + dir) == 1:
456 print "clean dir %s"%(B.root_build_dir+dir)
457 shutil.rmtree(B.root_build_dir+dir)
458 print B.bc.OKGREEN+'...done'+B.bc.ENDC
461 if not os.path.isdir ( B.root_build_dir):
462 os.makedirs ( B.root_build_dir )
463 os.makedirs ( B.root_build_dir + 'source' )
464 os.makedirs ( B.root_build_dir + 'intern' )
465 os.makedirs ( B.root_build_dir + 'extern' )
466 os.makedirs ( B.root_build_dir + 'lib' )
467 os.makedirs ( B.root_build_dir + 'bin' )
469 Help(opts.GenerateHelpText(env))
471 # default is new quieter output, but if you need to see the
472 # commands, do 'scons BF_QUIET=0'
473 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
474 if bf_quietoutput=='1':
475 B.set_quiet_output(env)
480 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
481 env.SConsignFile(B.root_build_dir+'scons-signatures')
484 ##### END SETUP ##########
487 #Export('root_build_dir') # this one is still needed for makesdna
488 ##TODO: improve makesdna usage
490 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
491 SConscript(B.root_build_dir+'/intern/SConscript')
492 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
493 SConscript(B.root_build_dir+'/extern/SConscript')
494 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
495 SConscript(B.root_build_dir+'/source/SConscript')
497 # now that we have read all SConscripts, we know what
498 # libraries will be built. Create list of
499 # libraries to give as objects to linking phase
501 for tp in B.possible_types:
502 if not tp == 'player' and not tp == 'player2':
503 mainlist += B.create_blender_liblist(env, tp)
505 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
506 B.propose_priorities()
508 dobj = B.buildinfo(env, "dynamic") + B.resources
509 thestatlibs, thelibincs = B.setup_staticlibs(env)
510 thesyslibs = B.setup_syslibs(env)
512 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
513 if env['WITH_BF_PLAYER']:
514 playerlist = B.create_blender_liblist(env, 'player')
515 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
517 ##### Now define some targets
520 #------------ INSTALL
524 if env['OURPLATFORM']=='darwin':
525 for prg in B.program_list:
526 bundle = '%s.app' % prg[0]
527 bundledir = os.path.dirname(bundle)
528 for dp, dn, df in os.walk(bundle):
533 dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
534 source=[dp+os.sep+f for f in df]
535 blenderinstall.append(env.Install(dir=dir,source=source))
537 blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
542 for dp, dn, df in os.walk('bin/.blender'):
548 dotblendlist.append(dp+os.sep+f)
549 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
551 dotblenderinstall = []
552 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
553 td, tf = os.path.split(targetdir)
554 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
558 scriptpath='release/scripts'
559 for dp, dn, df in os.walk(scriptpath):
564 dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
565 source=[dp+os.sep+f for f in df]
566 scriptinstall.append(env.Install(dir=dir,source=source))
571 for tp, tn, tf in os.walk('release/plugins'):
577 pluglist.append(tp+os.sep+f)
578 plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
581 for targetdir,srcfile in zip(plugtargetlist, pluglist):
582 td, tf = os.path.split(targetdir)
583 plugininstall.append(env.Install(dir=td, source=srcfile))
587 for tp, tn, tf in os.walk('release/text'):
593 textlist.append(tp+os.sep+f)
595 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
597 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
599 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
600 dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
601 '${LCGDIR}/png/lib/libpng.dll',
602 '#release/windows/extra/python25.zip',
603 # '#release/windows/extra/zlib.pyd',
604 '${LCGDIR}/sdl/lib/SDL.dll',
605 '${LCGDIR}/zlib/lib/zlib.dll',
606 '${LCGDIR}/tiff/lib/libtiff.dll']
608 dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}.dll')
610 dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}.dll')
611 if env['OURPLATFORM'] == 'win32-mingw':
612 dllsources += ['${LCGDIR}/pthreads/lib/pthreadGC2.dll']
614 dllsources += ['${LCGDIR}/pthreads/lib/pthreadVC2.dll']
615 if env['WITH_BF_ICONV']:
616 dllsources += ['${LCGDIR}/iconv/lib/iconv.dll']
617 if env['WITH_BF_FFMPEG']:
618 dllsources += ['${LCGDIR}/ffmpeg/lib/avcodec-51.dll',
619 '${LCGDIR}/ffmpeg/lib/avformat-51.dll',
620 '${LCGDIR}/ffmpeg/lib/avutil-49.dll']
621 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
622 allinstall += windlls
624 installtarget = env.Alias('install', allinstall)
625 bininstalltarget = env.Alias('install-bin', blenderinstall)
627 if env['WITH_BF_PLAYER']:
628 blenderplayer = env.Alias('blenderplayer', B.program_list)
629 Depends(blenderplayer,installtarget)
631 if not env['WITH_BF_GAMEENGINE']:
632 blendernogame = env.Alias('blendernogame', B.program_list)
633 Depends(blendernogame,installtarget)
635 Default(B.program_list)
636 Default(installtarget)
638 #------------ RELEASE
639 # TODO: zipup the installation
641 #------------ BLENDERPLAYER
642 # TODO: build stubs and link into blenderplayer