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':
76 print B.bc.HEADER+'Command-line arguments'+B.bc.ENDC
77 B.arguments = btools.validate_arguments(ARGUMENTS, B.bc)
78 btools.print_arguments(B.arguments, B.bc)
81 print B.bc.HEADER+'Command-line targets'+B.bc.ENDC
82 B.targets = btools.validate_targets(COMMAND_LINE_TARGETS, B.bc)
83 btools.print_targets(B.targets, B.bc)
85 ##########################
86 # setting up environment #
87 ##########################
89 # handling cmd line arguments & config file
91 # first check cmdline for toolset and we create env to work on
92 quickie = B.arguments.get('BF_QUICK', None)
93 quickdebug = B.arguments.get('BF_QUICKDEBUG', None)
96 B.quickdebug=string.split(quickdebug, ',')
101 B.quickie=string.split(quickie,',')
105 toolset = B.arguments.get('BF_TOOLSET', None)
107 print "Using " + toolset
108 if toolset=='mstoolkit':
109 env = BlenderEnvironment(ENV = os.environ)
110 env.Tool('mstoolkit', ['tools'])
112 env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
114 env = BlenderEnvironment(ENV = os.environ)
117 print "Could not create a build environment"
120 env.SConscriptChdir(0)
121 cc = B.arguments.get('CC', None)
122 cxx = B.arguments.get('CXX', None)
128 if env['CC'] in ['cl', 'cl.exe'] and sys.platform=='win32':
129 platform = 'win32-vc'
130 elif env['CC'] in ['gcc'] and sys.platform=='win32':
131 platform = 'win32-mingw'
134 #if platform == 'win32-mingw':
143 slash= re.compile(r"\\")
147 b = slash.sub(r"\\\\", b[1:-1])
148 return "\"" + b + "\""
152 def my_spawn(sh, escape, cmd, args, spawnenv):
154 spawnenv[var] = spawnenv[var].encode('ascii', 'replace')
156 sAttrs = win32security.SECURITY_ATTRIBUTES()
157 StartupInfo = win32process.STARTUPINFO()
158 if cmd=='ar' and args[1]=='r':
160 newargs = string.join(map(myesc, args[1:]), ' ')
161 cmdline = cmd + " " + newargs
163 # check for any special operating system commands
166 win32file.DeleteFile(arg)
169 # otherwise execute the command.
170 hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(None, cmdline, None, None, 1, 0, spawnenv, None, StartupInfo)
171 win32event.WaitForSingleObject(hProcess, win32event.INFINITE)
172 exit_code = win32process.GetExitCodeProcess(hProcess)
173 win32file.CloseHandle(hProcess);
174 win32file.CloseHandle(hThread);
177 env['SPAWN'] = my_spawn
179 print "install win32all from http://sourceforge.net/project/showfiles.php?group_id=78018"
181 crossbuild = B.arguments.get('BF_CROSS', None)
182 if crossbuild and platform!='win32':
183 platform = 'linuxcross'
185 env['OURPLATFORM'] = platform
187 configfile = B.arguments.get('BF_CONFIG', 'config'+os.sep+platform+'-config.py')
189 if os.path.exists(configfile):
190 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
192 print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
194 if crossbuild and env['PLATFORM'] != 'win32':
195 print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
196 env.Tool('crossmingw', ['tools'])
197 # todo: determine proper libs/includes etc.
198 # Needed for gui programs, console programs should do without it
199 env.Append(LINKFLAGS=['-mwindows'])
201 # first read platform config. B.arguments will override
202 optfiles = [configfile]
203 if os.path.exists('user-config.py'):
204 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + 'user-config.py'
205 optfiles += ['user-config.py']
207 print B.bc.WARNING + 'user-config.py' + " not found, no user overrides" + B.bc.ENDC
209 opts = btools.read_opts(optfiles, B.arguments)
212 # disable elbeem (fluidsim) compilation?
213 if env['BF_NO_ELBEEM'] == 1:
214 env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
215 env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
216 env['CCFLAGS'].append('-DDISABLE_ELBEEM')
218 #check for additional debug libnames
220 if env.has_key('BF_DEBUG_LIBS'):
221 B.quickdebug += env['BF_DEBUG_LIBS']
223 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
225 # see if this linux distro has libalut
227 if env['OURPLATFORM'] == 'linux2' :
228 if env['WITH_BF_OPENAL']:
229 mylib_test_source_file = """
231 int main(int argc, char **argv)
233 alutGetMajorVersion();
238 def CheckFreeAlut(context,env):
239 context.Message( B.bc.OKGREEN + "Linux platform detected:\n checking for FreeAlut... " + B.bc.ENDC )
241 result = context.TryLink(mylib_test_source_file, '.c')
242 context.Result(result)
245 env2 = env.Copy( LIBPATH = env['BF_OPENAL'] )
246 conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, '.sconf_temp', '/dev/null' )
247 if conf.CheckFreeAlut( env2 ):
248 env['BF_OPENAL_LIB'] += ' alut'
250 for root, dirs, files in os.walk('.sconf_temp', topdown=False):
252 os.remove(os.path.join(root, name))
254 os.rmdir(os.path.join(root, name))
257 if len(B.quickdebug) > 0 and printdebug != 0:
258 print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
259 for l in B.quickdebug:
262 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
263 if 'blenderplayer' in B.targets:
264 env['WITH_BF_PLAYER'] = True
266 if 'blendernogame' in B.targets:
267 env['WITH_BF_GAMEENGINE'] = False
269 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
270 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
271 B.root_build_dir = env['BF_BUILDDIR']
272 env['BUILDDIR'] = B.root_build_dir
273 if not B.root_build_dir[-1]==os.sep:
274 B.root_build_dir += os.sep
276 def NSIS_Installer():
278 if env['OURPLATFORM'] != 'win32-vc' and env['OURPLATFORM'] != 'win32-mingw':
279 print "NSIS installer is only available on Windows."
282 install_base_dir = os.getcwd() + "\\"
286 version = v.read()[:-1]
287 shortver = version.split('.')[0] + version.split('.')[1]
290 #### change to suit install dir ####
291 inst_dir = install_base_dir + env['BF_INSTALLDIR']
293 os.chdir("windows/installer")
295 ns = open("00.sconsblender.nsi","r")
297 ns_cnt = str(ns.read())
302 rootdir = os.listdir(inst_dir+"\\")
303 for rootitem in rootdir:
304 if os.path.isdir(inst_dir+"\\"+ rootitem) == 0:
305 rootlist.append("File " + inst_dir + "\\" + rootitem)
306 rootstring = string.join(rootlist, "\n ")
308 ns_cnt = string.replace(ns_cnt, "[ROOTDIRCONTS]", rootstring)
312 for rootitem in rootdir:
313 if os.path.isdir(inst_dir + rootitem) == 0:
314 delrootlist.append("Delete $INSTDIR\\" + rootitem)
315 delrootstring = string.join(delrootlist, "\n ")
316 delrootstring += "\n"
317 ns_cnt = string.replace(ns_cnt, "[DELROOTDIRCONTS]", delrootstring)
321 scriptpath = "%s%s" % (inst_dir, "\\.blender\\scripts")
322 scriptdir = os.listdir(scriptpath)
323 for scriptitem in scriptdir:
324 scriptfile = "%s\\%s" % (scriptpath, scriptitem)
325 if os.path.isdir(scriptfile) == 0:
326 scriptlist.append("File %s" % scriptfile)
327 scriptstring = string.join(scriptlist, "\n ")
328 scriptstring += "\n\n"
329 ns_cnt = string.replace(ns_cnt, "[SCRIPTCONTS]", scriptstring)
331 # do scripts\bpymodules
333 bpymodpath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpymodules")
334 bpymoddir = os.listdir(bpymodpath)
336 for bpymoditem in bpymoddir:
337 bpymodfile = "%s\\%s" % (bpymodpath, bpymoditem)
338 if os.path.isdir(bpymodfile) == 0:
339 bpymodlist.append("File %s" % bpymodfile)
340 bpymodstring = string.join(bpymodlist, "\n ")
341 bpymodstring += "\n\n"
342 ns_cnt = string.replace(ns_cnt, "[SCRIPTMODCONTS]", bpymodstring)
344 # do scripts\bpymodules\colladaimex
346 bpymodpath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpymodules\\ColladaImEx")
347 bpymoddir = os.listdir(bpymodpath)
349 for bpymoditem in bpymoddir:
350 bpymodfile = "%s\\%s" % (bpymodpath, bpymoditem)
351 if os.path.isdir(bpymodfile) == 0:
352 colladalist.append("File %s" % bpymodfile)
353 bpymodstring = string.join(colladalist, "\n ")
354 bpymodstring += "\n\n"
355 ns_cnt = string.replace(ns_cnt, "[SCRIPTMODCOLLADACONT]", bpymodstring)
359 bpydatapath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpydata")
360 bpydatadir = os.listdir(bpydatapath)
361 for bpydataitem in bpydatadir:
362 bpydatafile = "%s\\%s" % (bpydatapath, bpydataitem)
363 if os.path.isdir(bpydatafile) == 0:
364 bpydatalist.append("File %s" % bpydatafile)
365 bpydatastring = string.join(bpydatalist, "\n ")
366 bpydatastring += "\n\n"
367 ns_cnt = string.replace(ns_cnt, "[SCRIPTDATACONTS]", bpydatastring)
371 plugincludepath = "%s%s" % (inst_dir, "\\plugins\\include")
372 plugincludedir = os.listdir(plugincludepath)
373 for plugincludeitem in plugincludedir:
374 plugincludefile = "%s\\%s" % (plugincludepath, plugincludeitem)
375 if os.path.isdir(plugincludefile) == 0:
376 if plugincludefile.find('.h') or plugincludefile.find('.DEF'):
377 plugincludelist.append("File %s" % plugincludefile)
378 plugincludestring = string.join(plugincludelist, "\n ")
379 plugincludestring += "\n\n"
380 ns_cnt = string.replace(ns_cnt, "[PLUGINCONTS]", plugincludestring)
382 # do scripts\bpydata\config
384 cfgpath = "%s%s" % (inst_dir, "\\.blender\\scripts\\bpydata\\config")
385 cfgdir = os.listdir(cfgpath)
386 for cfgitem in cfgdir:
387 cfgfile = "%s\\%s" % (cfgpath, cfgitem)
388 if os.path.isdir(cfgfile) == 0:
389 cfglist.append("File %s" % cfgfile)
390 cfgstring = string.join(cfglist, "\n ")
392 ns_cnt = string.replace(ns_cnt, "[SCRIPTDATACFGCONTS]", cfgstring)
396 dotblenddir = os.listdir(inst_dir+"\\.blender")
397 for dotblenditem in dotblenddir:
398 if os.path.isdir(inst_dir + "\\.blender\\" + dotblenditem) == 0:
399 dotblendlist.append("File " + inst_dir + "\\.blender\\" + dotblenditem)
400 dotblendstring = string.join(dotblendlist, "\n ")
401 dotblendstring += "\n\n"
402 ns_cnt = string.replace(ns_cnt, "[DOTBLENDERCONTS]", dotblendstring)
407 langdir = os.listdir(inst_dir + "\\.blender\\locale")
408 for langitem in langdir:
409 if os.path.isdir(inst_dir + "\\.blender\\locale\\" + langitem) == 1:
410 langfiles.append("SetOutPath $BLENDERHOME\\.blender\\locale\\" + langitem + "\\LC_MESSAGES")
411 langfiles.append("File " + inst_dir + "\\.blender\\locale\\" + langitem + "\\LC_MESSAGES\\blender.mo")
412 langstring = string.join(langfiles, "\n ")
414 ns_cnt = string.replace(ns_cnt, "[LANGUAGECONTS]", langstring)
417 ns_cnt = string.replace(ns_cnt, "DISTDIR", inst_dir+"\\")
418 ns_cnt = string.replace(ns_cnt, "SHORTVER", shortver)
419 ns_cnt = string.replace(ns_cnt, "VERSION", version)
421 new_nsis = open("00.blender_tmp.nsi", 'w')
422 new_nsis.write(ns_cnt)
425 sys.stdout = os.popen("makensis 00.blender_tmp.nsi", 'w')
428 if 'nsis' in B.targets:
432 # We do a shortcut for clean when no quicklist is given: just delete
433 # builddir without reading in SConscripts
435 if 'clean' in B.targets:
438 if not quickie and do_clean:
439 print B.bc.HEADER+'Cleaning...'+B.bc.ENDC
440 dirs = os.listdir(B.root_build_dir)
442 if os.path.isdir(B.root_build_dir + dir) == 1:
443 print "clean dir %s"%(B.root_build_dir+dir)
444 shutil.rmtree(B.root_build_dir+dir)
445 print B.bc.OKGREEN+'...done'+B.bc.ENDC
448 if not os.path.isdir ( B.root_build_dir):
449 os.makedirs ( B.root_build_dir )
450 os.makedirs ( B.root_build_dir + 'source' )
451 os.makedirs ( B.root_build_dir + 'intern' )
452 os.makedirs ( B.root_build_dir + 'extern' )
453 os.makedirs ( B.root_build_dir + 'lib' )
454 os.makedirs ( B.root_build_dir + 'bin' )
456 Help(opts.GenerateHelpText(env))
458 # default is new quieter output, but if you need to see the
459 # commands, do 'scons BF_QUIET=0'
460 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
461 if bf_quietoutput=='1':
462 B.set_quiet_output(env)
467 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
468 env.SConsignFile(B.root_build_dir+'scons-signatures')
471 ##### END SETUP ##########
474 #Export('root_build_dir') # this one is still needed for makesdna
475 ##TODO: improve makesdna usage
477 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
478 SConscript(B.root_build_dir+'/intern/SConscript')
479 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
480 SConscript(B.root_build_dir+'/extern/SConscript')
481 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
482 SConscript(B.root_build_dir+'/source/SConscript')
484 # now that we have read all SConscripts, we know what
485 # libraries will be built. Create list of
486 # libraries to give as objects to linking phase
488 for tp in B.possible_types:
489 if not tp == 'player' and not tp == 'player2':
490 mainlist += B.create_blender_liblist(env, tp)
492 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
493 B.propose_priorities()
495 dobj = B.buildinfo(env, "dynamic") + B.resources
496 thestatlibs, thelibincs = B.setup_staticlibs(env)
497 thesyslibs = B.setup_syslibs(env)
499 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
500 if env['WITH_BF_PLAYER']:
501 playerlist = B.create_blender_liblist(env, 'player')
502 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
504 ##### Now define some targets
507 #------------ INSTALL
509 blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
514 for dp, dn, df in os.walk('bin/.blender'):
518 dotblendlist.append(dp+os.sep+f)
519 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
521 dotblenderinstall = []
522 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
523 td, tf = os.path.split(targetdir)
524 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
528 scriptpath='release/scripts'
529 for dp, dn, df in os.walk(scriptpath):
532 dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
533 source=[dp+os.sep+f for f in df]
534 scriptinstall.append(env.Install(dir=dir,source=source))
539 for tp, tn, tf in os.walk('release/plugins'):
543 pluglist.append(tp+os.sep+f)
544 plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
547 for targetdir,srcfile in zip(plugtargetlist, pluglist):
548 td, tf = os.path.split(targetdir)
549 plugininstall.append(env.Install(dir=td, source=srcfile))
553 for tp, tn, tf in os.walk('release/text'):
557 textlist.append(tp+os.sep+f)
559 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
561 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
563 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
564 dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
565 '${LCGDIR}/png/lib/libpng.dll',
566 # '#release/windows/extra/python24.zip',
567 # '#release/windows/extra/zlib.pyd',
568 '${LCGDIR}/sdl/lib/SDL.dll',
569 '${LCGDIR}/zlib/lib/zlib.dll',
570 '${LCGDIR}/tiff/lib/libtiff.dll']
572 dllsources.append('${LCGDIR}/python/lib/python25_d.dll')
574 dllsources.append('${LCGDIR}/python/lib/python25.dll')
575 if env['OURPLATFORM'] == 'win32-mingw':
576 dllsources += ['${LCGDIR}/pthreads/lib/pthreadGC2.dll']
578 dllsources += ['${LCGDIR}/pthreads/lib/pthreadVC2.dll']
579 if env['WITH_BF_ICONV']:
580 dllsources += ['${LCGDIR}/iconv/lib/iconv.dll']
581 if env['WITH_BF_FFMPEG']:
582 dllsources += ['${LCGDIR}/ffmpeg/lib/avcodec-51.dll',
583 '${LCGDIR}/ffmpeg/lib/avformat-51.dll',
584 '${LCGDIR}/ffmpeg/lib/avutil-49.dll',
585 '${LCGDIR}/ffmpeg/lib/libdts.dll',
586 '${LCGDIR}/ffmpeg/lib/libfaac.dll',
587 '${LCGDIR}/ffmpeg/lib/libfaad.dll',
588 '${LCGDIR}/ffmpeg/lib/libgsm.dll',
589 '${LCGDIR}/ffmpeg/lib/libmp3lame-0.dll',
590 '${LCGDIR}/ffmpeg/lib/libogg-0.dll',
591 '${LCGDIR}/ffmpeg/lib/libvorbis-0.dll',
592 '${LCGDIR}/ffmpeg/lib/libvorbisenc-2.dll',
593 '${LCGDIR}/ffmpeg/lib/libx264-54.dll',
594 '${LCGDIR}/ffmpeg/lib/postproc-51.dll',
595 '${LCGDIR}/ffmpeg/lib/xvidcore.dll']
596 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
597 allinstall += windlls
599 installtarget = env.Alias('install', allinstall)
600 bininstalltarget = env.Alias('install-bin', blenderinstall)
602 if env['WITH_BF_PLAYER']:
603 blenderplayer = env.Alias('blenderplayer', B.program_list)
604 Depends(blenderplayer,installtarget)
606 if not env['WITH_BF_GAMEENGINE']:
607 blendernogame = env.Alias('blendernogame', B.program_list)
608 Depends(blendernogame,installtarget)
610 Default(B.program_list)
611 Default(installtarget)
613 #------------ RELEASE
614 # TODO: zipup the installation
616 #------------ BLENDERPLAYER
617 # TODO: build stubs and link into blenderplayer