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 btools.SetupSpawn(env)
121 env = BlenderEnvironment(ENV = os.environ)
124 print "Could not create a build environment"
128 cc = B.arguments.get('CC', None)
129 cxx = B.arguments.get('CXX', None)
135 if env['CC'] in ['cl', 'cl.exe'] and sys.platform=='win32':
136 platform = 'win32-vc'
137 elif env['CC'] in ['gcc'] and sys.platform=='win32':
138 platform = 'win32-mingw'
140 env.SConscriptChdir(0)
142 crossbuild = B.arguments.get('BF_CROSS', None)
143 if crossbuild and platform!='win32':
144 platform = 'linuxcross'
146 env['OURPLATFORM'] = platform
148 configfile = B.arguments.get('BF_CONFIG', 'config'+os.sep+platform+'-config.py')
150 if os.path.exists(configfile):
151 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
153 print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
155 if crossbuild and env['PLATFORM'] != 'win32':
156 print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
157 env.Tool('crossmingw', ['tools'])
158 # todo: determine proper libs/includes etc.
159 # Needed for gui programs, console programs should do without it
160 env.Append(LINKFLAGS=['-mwindows'])
162 # first read platform config. B.arguments will override
163 optfiles = [configfile]
164 if os.path.exists('user-config.py'):
165 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + 'user-config.py'
166 optfiles += ['user-config.py']
168 print B.bc.WARNING + 'user-config.py' + " not found, no user overrides" + B.bc.ENDC
170 opts = btools.read_opts(optfiles, B.arguments)
173 # disable elbeem (fluidsim) compilation?
174 if env['BF_NO_ELBEEM'] == 1:
175 env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
176 env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
177 env['CCFLAGS'].append('-DDISABLE_ELBEEM')
179 #check for additional debug libnames
181 if env.has_key('BF_DEBUG_LIBS'):
182 B.quickdebug += env['BF_DEBUG_LIBS']
184 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
186 # see if this linux distro has libalut
188 if env['OURPLATFORM'] == 'linux2' :
189 if env['WITH_BF_OPENAL']:
190 mylib_test_source_file = """
192 int main(int argc, char **argv)
194 alutGetMajorVersion();
199 def CheckFreeAlut(context,env):
200 context.Message( B.bc.OKGREEN + "Linux platform detected:\n checking for FreeAlut... " + B.bc.ENDC )
202 result = context.TryLink(mylib_test_source_file, '.c')
203 context.Result(result)
206 env2 = env.Copy( LIBPATH = env['BF_OPENAL'] )
207 conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, '.sconf_temp', '/dev/null' )
208 if conf.CheckFreeAlut( env2 ):
209 env['BF_OPENAL_LIB'] += ' alut'
211 for root, dirs, files in os.walk('.sconf_temp', topdown=False):
213 os.remove(os.path.join(root, name))
215 os.rmdir(os.path.join(root, name))
218 if len(B.quickdebug) > 0 and printdebug != 0:
219 print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
220 for l in B.quickdebug:
223 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
224 if 'blenderplayer' in B.targets:
225 env['WITH_BF_PLAYER'] = True
227 if 'blendernogame' in B.targets:
228 env['WITH_BF_GAMEENGINE'] = False
230 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
231 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
232 B.root_build_dir = env['BF_BUILDDIR']
233 env['BUILDDIR'] = B.root_build_dir
234 if not B.root_build_dir[-1]==os.sep:
235 B.root_build_dir += os.sep
237 def NSIS_Installer():
239 if env['OURPLATFORM'] != 'win32-vc' and env['OURPLATFORM'] != 'win32-mingw':
240 print "NSIS installer is only available on Windows."
243 install_base_dir = os.getcwd() + "\\"
245 if not os.path.exists(install_base_dir+env['BF_INSTALLDIR']+'/plugins/include'):
246 os.mkdir(install_base_dir+env['BF_INSTALLDIR']+'/plugins/include')
248 for f in glob.glob('source/blender/blenpluginapi/*.h'):
249 shutil.copy(f,install_base_dir+env['BF_INSTALLDIR']+'/plugins/include')
251 shutil.copy('source/blender/blenpluginapi/plugin.def',install_base_dir+env['BF_INSTALLDIR']+'/plugins/include/')
255 version = v.read()[:-1]
256 shortver = version.split('.')[0] + version.split('.')[1]
259 #### change to suit install dir ####
260 inst_dir = install_base_dir + env['BF_INSTALLDIR']
262 os.chdir("windows/installer")
264 ns = open("00.sconsblender.nsi","r")
266 ns_cnt = str(ns.read())
271 rootdir = os.listdir(inst_dir+"\\")
272 for rootitem in rootdir:
273 if os.path.isdir(inst_dir+"\\"+ rootitem) == 0:
274 rootlist.append("File " + inst_dir + "\\" + rootitem)
275 rootstring = string.join(rootlist, "\n ")
277 ns_cnt = string.replace(ns_cnt, "[ROOTDIRCONTS]", rootstring)
281 for rootitem in rootdir:
282 if os.path.isdir(inst_dir + rootitem) == 0:
283 delrootlist.append("Delete $INSTDIR\\" + rootitem)
284 delrootstring = string.join(delrootlist, "\n ")
285 delrootstring += "\n"
286 ns_cnt = string.replace(ns_cnt, "[DELROOTDIRCONTS]", delrootstring)
290 scriptpath = "%s%s" % (inst_dir, "\\.blender\\scripts")
291 scriptdir = os.listdir(scriptpath)
292 for scriptitem in scriptdir:
293 scriptfile = "%s\\%s" % (scriptpath, scriptitem)
294 if os.path.isdir(scriptfile) == 0:
295 scriptlist.append("File %s" % scriptfile)
296 scriptstring = string.join(scriptlist, "\n ")
297 scriptstring += "\n\n"
298 ns_cnt = string.replace(ns_cnt, "[SCRIPTCONTS]", scriptstring)
300 # do scripts\bpymodules
302 bpymodpath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpymodules")
303 bpymoddir = os.listdir(bpymodpath)
305 for bpymoditem in bpymoddir:
306 bpymodfile = "%s\\%s" % (bpymodpath, bpymoditem)
307 if os.path.isdir(bpymodfile) == 0:
308 bpymodlist.append("File %s" % bpymodfile)
309 bpymodstring = string.join(bpymodlist, "\n ")
310 bpymodstring += "\n\n"
311 ns_cnt = string.replace(ns_cnt, "[SCRIPTMODCONTS]", bpymodstring)
313 # do scripts\bpymodules\colladaimex
315 bpymodpath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpymodules\\ColladaImEx")
316 bpymoddir = os.listdir(bpymodpath)
318 for bpymoditem in bpymoddir:
319 bpymodfile = "%s\\%s" % (bpymodpath, bpymoditem)
320 if os.path.isdir(bpymodfile) == 0:
321 colladalist.append("File %s" % bpymodfile)
322 bpymodstring = string.join(colladalist, "\n ")
323 bpymodstring += "\n\n"
324 ns_cnt = string.replace(ns_cnt, "[SCRIPTMODCOLLADACONT]", bpymodstring)
328 bpydatapath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpydata")
329 bpydatadir = os.listdir(bpydatapath)
330 for bpydataitem in bpydatadir:
331 bpydatafile = "%s\\%s" % (bpydatapath, bpydataitem)
332 if os.path.isdir(bpydatafile) == 0:
333 bpydatalist.append("File %s" % bpydatafile)
334 bpydatastring = string.join(bpydatalist, "\n ")
335 bpydatastring += "\n\n"
336 ns_cnt = string.replace(ns_cnt, "[SCRIPTDATACONTS]", bpydatastring)
340 plugincludepath = "%s%s" % (inst_dir, "\\plugins\\include")
341 plugincludedir = os.listdir(plugincludepath)
342 for plugincludeitem in plugincludedir:
343 plugincludefile = "%s\\%s" % (plugincludepath, plugincludeitem)
344 if os.path.isdir(plugincludefile) == 0:
345 if plugincludefile.find('.h') or plugincludefile.find('.DEF'):
346 plugincludelist.append("File %s" % plugincludefile)
347 plugincludestring = string.join(plugincludelist, "\n ")
348 plugincludestring += "\n\n"
349 ns_cnt = string.replace(ns_cnt, "[PLUGINCONTS]", plugincludestring)
351 # do scripts\bpydata\config
353 cfgpath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpydata\\config")
354 cfgdir = os.listdir(cfgpath)
355 for cfgitem in cfgdir:
356 cfgfile = "%s\\%s" % (cfgpath, cfgitem)
357 if os.path.isdir(cfgfile) == 0:
358 cfglist.append("File %s" % cfgfile)
359 cfgstring = string.join(cfglist, "\n ")
361 ns_cnt = string.replace(ns_cnt, "[SCRIPTDATACFGCONTS]", cfgstring)
365 dotblenddir = os.listdir(inst_dir+"\\.blender")
366 for dotblenditem in dotblenddir:
367 if os.path.isdir(inst_dir + "\\.blender\\" + dotblenditem) == 0:
368 dotblendlist.append("File " + inst_dir + "\\.blender\\" + dotblenditem)
369 dotblendstring = string.join(dotblendlist, "\n ")
370 dotblendstring += "\n\n"
371 ns_cnt = string.replace(ns_cnt, "[DOTBLENDERCONTS]", dotblendstring)
376 langdir = os.listdir(inst_dir + "\\.blender\\locale")
377 for langitem in langdir:
378 if os.path.isdir(inst_dir + "\\.blender\\locale\\" + langitem) == 1:
379 langfiles.append("SetOutPath $BLENDERHOME\\.blender\\locale\\" + langitem + "\\LC_MESSAGES")
380 langfiles.append("File " + inst_dir + "\\.blender\\locale\\" + langitem + "\\LC_MESSAGES\\blender.mo")
381 langstring = string.join(langfiles, "\n ")
383 ns_cnt = string.replace(ns_cnt, "[LANGUAGECONTS]", langstring)
386 ns_cnt = string.replace(ns_cnt, "DISTDIR", inst_dir+"\\")
387 ns_cnt = string.replace(ns_cnt, "SHORTVER", shortver)
388 ns_cnt = string.replace(ns_cnt, "VERSION", version)
390 new_nsis = open("00.blender_tmp.nsi", 'w')
391 new_nsis.write(ns_cnt)
394 sys.stdout = os.popen("makensis 00.blender_tmp.nsi", 'w')
397 if 'nsis' in B.targets:
401 # We do a shortcut for clean when no quicklist is given: just delete
402 # builddir without reading in SConscripts
404 if 'clean' in B.targets:
407 if not quickie and do_clean:
408 print B.bc.HEADER+'Cleaning...'+B.bc.ENDC
409 dirs = os.listdir(B.root_build_dir)
411 if os.path.isdir(B.root_build_dir + dir) == 1:
412 print "clean dir %s"%(B.root_build_dir+dir)
413 shutil.rmtree(B.root_build_dir+dir)
414 print B.bc.OKGREEN+'...done'+B.bc.ENDC
417 if not os.path.isdir ( B.root_build_dir):
418 os.makedirs ( B.root_build_dir )
419 os.makedirs ( B.root_build_dir + 'source' )
420 os.makedirs ( B.root_build_dir + 'intern' )
421 os.makedirs ( B.root_build_dir + 'extern' )
422 os.makedirs ( B.root_build_dir + 'lib' )
423 os.makedirs ( B.root_build_dir + 'bin' )
425 Help(opts.GenerateHelpText(env))
427 # default is new quieter output, but if you need to see the
428 # commands, do 'scons BF_QUIET=0'
429 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
430 if bf_quietoutput=='1':
431 B.set_quiet_output(env)
436 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
437 env.SConsignFile(B.root_build_dir+'scons-signatures')
440 ##### END SETUP ##########
444 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
445 SConscript(B.root_build_dir+'/intern/SConscript')
446 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
447 SConscript(B.root_build_dir+'/extern/SConscript')
448 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
449 SConscript(B.root_build_dir+'/source/SConscript')
451 # now that we have read all SConscripts, we know what
452 # libraries will be built. Create list of
453 # libraries to give as objects to linking phase
455 for tp in B.possible_types:
456 if not tp == 'player' and not tp == 'player2':
457 mainlist += B.create_blender_liblist(env, tp)
459 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
460 B.propose_priorities()
462 dobj = B.buildinfo(env, "dynamic") + B.resources
463 thestatlibs, thelibincs = B.setup_staticlibs(env)
464 thesyslibs = B.setup_syslibs(env)
466 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
467 if env['WITH_BF_PLAYER']:
468 playerlist = B.create_blender_liblist(env, 'player')
469 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
471 ##### Now define some targets
474 #------------ INSTALL
478 if env['OURPLATFORM']=='darwin':
479 for prg in B.program_list:
480 bundle = '%s.app' % prg[0]
481 bundledir = os.path.dirname(bundle)
482 for dp, dn, df in os.walk(bundle):
487 dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
488 source=[dp+os.sep+f for f in df]
489 blenderinstall.append(env.Install(dir=dir,source=source))
491 blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
496 for dp, dn, df in os.walk('bin/.blender'):
502 dotblendlist.append(dp+os.sep+f)
503 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
505 dotblenderinstall = []
506 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
507 td, tf = os.path.split(targetdir)
508 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
512 scriptpath='release/scripts'
513 for dp, dn, df in os.walk(scriptpath):
518 dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
519 source=[dp+os.sep+f for f in df]
520 scriptinstall.append(env.Install(dir=dir,source=source))
525 for tp, tn, tf in os.walk('release/plugins'):
531 pluglist.append(tp+os.sep+f)
532 plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
535 for targetdir,srcfile in zip(plugtargetlist, pluglist):
536 td, tf = os.path.split(targetdir)
537 plugininstall.append(env.Install(dir=td, source=srcfile))
541 for tp, tn, tf in os.walk('release/text'):
547 textlist.append(tp+os.sep+f)
549 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
551 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
553 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
554 dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
555 '${LCGDIR}/png/lib/libpng.dll',
556 '#release/windows/extra/python25.zip',
557 # '#release/windows/extra/zlib.pyd',
558 '${LCGDIR}/sdl/lib/SDL.dll',
559 '${LCGDIR}/zlib/lib/zlib.dll',
560 '${LCGDIR}/tiff/lib/libtiff.dll']
562 dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}.dll')
564 dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}.dll')
565 if env['OURPLATFORM'] == 'win32-mingw':
566 dllsources += ['${LCGDIR}/pthreads/lib/pthreadGC2.dll']
568 dllsources += ['${LCGDIR}/pthreads/lib/pthreadVC2.dll']
569 if env['WITH_BF_ICONV']:
570 dllsources += ['${LCGDIR}/iconv/lib/iconv.dll']
571 if env['WITH_BF_FFMPEG']:
572 dllsources += ['${LCGDIR}/ffmpeg/lib/avcodec-51.dll',
573 '${LCGDIR}/ffmpeg/lib/avformat-51.dll',
574 '${LCGDIR}/ffmpeg/lib/avutil-49.dll']
575 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
576 allinstall += windlls
578 installtarget = env.Alias('install', allinstall)
579 bininstalltarget = env.Alias('install-bin', blenderinstall)
581 if env['WITH_BF_PLAYER']:
582 blenderplayer = env.Alias('blenderplayer', B.program_list)
583 Depends(blenderplayer,installtarget)
585 if not env['WITH_BF_GAMEENGINE']:
586 blendernogame = env.Alias('blendernogame', B.program_list)
587 Depends(blendernogame,installtarget)
589 Default(B.program_list)
590 Default(installtarget)
592 #------------ RELEASE
593 # TODO: zipup the installation
595 #------------ BLENDERPLAYER
596 # TODO: build stubs and link into blenderplayer