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 if not env['BF_FANCY']:
176 # disable elbeem (fluidsim) compilation?
177 if env['BF_NO_ELBEEM'] == 1:
178 env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
179 env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
180 env['CCFLAGS'].append('-DDISABLE_ELBEEM')
182 if env['WITH_BF_OPENMP'] == 1:
183 if env['OURPLATFORM']=='win32-vc':
184 env['CCFLAGS'].append('/openmp')
185 env['CPPFLAGS'].append('/openmp')
186 env['CXXFLAGS'].append('/openmp')
188 env.Append(LINKFLAGS=['-lgomp'])
189 env['CCFLAGS'].append('-fopenmp')
190 env['CPPFLAGS'].append('-fopenmp')
191 env['CXXFLAGS'].append('-fopenmp')
193 #check for additional debug libnames
195 if env.has_key('BF_DEBUG_LIBS'):
196 B.quickdebug += env['BF_DEBUG_LIBS']
198 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
200 # see if this linux distro has libalut
202 if env['OURPLATFORM'] == 'linux2' :
203 if env['WITH_BF_OPENAL']:
204 mylib_test_source_file = """
206 int main(int argc, char **argv)
208 alutGetMajorVersion();
213 def CheckFreeAlut(context,env):
214 context.Message( B.bc.OKGREEN + "Linux platform detected:\n checking for FreeAlut... " + B.bc.ENDC )
216 result = context.TryLink(mylib_test_source_file, '.c')
217 context.Result(result)
220 env2 = env.Copy( LIBPATH = env['BF_OPENAL'] )
221 conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, '.sconf_temp', '/dev/null' )
222 if conf.CheckFreeAlut( env2 ):
223 env['BF_OPENAL_LIB'] += ' alut'
225 for root, dirs, files in os.walk('.sconf_temp', topdown=False):
227 os.remove(os.path.join(root, name))
229 os.rmdir(os.path.join(root, name))
232 if len(B.quickdebug) > 0 and printdebug != 0:
233 print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
234 for l in B.quickdebug:
237 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
238 if 'blenderplayer' in B.targets:
239 env['WITH_BF_PLAYER'] = True
241 if 'blendernogame' in B.targets:
242 env['WITH_BF_GAMEENGINE'] = False
244 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
245 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
246 B.root_build_dir = env['BF_BUILDDIR']
247 env['BUILDDIR'] = B.root_build_dir
248 if not B.root_build_dir[-1]==os.sep:
249 B.root_build_dir += os.sep
251 # We do a shortcut for clean when no quicklist is given: just delete
252 # builddir without reading in SConscripts
254 if 'clean' in B.targets:
257 if not quickie and do_clean:
258 if os.path.exists(B.root_build_dir):
259 print B.bc.HEADER+'Cleaning...'+B.bc.ENDC
260 dirs = os.listdir(B.root_build_dir)
262 if os.path.isdir(B.root_build_dir + dir) == 1:
263 print "clean dir %s"%(B.root_build_dir+dir)
264 shutil.rmtree(B.root_build_dir+dir)
265 print B.bc.OKGREEN+'...done'+B.bc.ENDC
267 print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
270 if not os.path.isdir ( B.root_build_dir):
271 os.makedirs ( B.root_build_dir )
272 os.makedirs ( B.root_build_dir + 'source' )
273 os.makedirs ( B.root_build_dir + 'intern' )
274 os.makedirs ( B.root_build_dir + 'extern' )
275 os.makedirs ( B.root_build_dir + 'lib' )
276 os.makedirs ( B.root_build_dir + 'bin' )
278 Help(opts.GenerateHelpText(env))
280 # default is new quieter output, but if you need to see the
281 # commands, do 'scons BF_QUIET=0'
282 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
283 if bf_quietoutput=='1':
284 B.set_quiet_output(env)
289 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
290 env.SConsignFile(B.root_build_dir+'scons-signatures')
293 ##### END SETUP ##########
297 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
298 SConscript(B.root_build_dir+'/intern/SConscript')
299 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
300 SConscript(B.root_build_dir+'/extern/SConscript')
301 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
302 SConscript(B.root_build_dir+'/source/SConscript')
304 # now that we have read all SConscripts, we know what
305 # libraries will be built. Create list of
306 # libraries to give as objects to linking phase
308 for tp in B.possible_types:
309 if not tp == 'player' and not tp == 'player2':
310 mainlist += B.create_blender_liblist(env, tp)
312 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
313 B.propose_priorities()
315 dobj = B.buildinfo(env, "dynamic") + B.resources
316 thestatlibs, thelibincs = B.setup_staticlibs(env)
317 thesyslibs = B.setup_syslibs(env)
319 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
320 if env['WITH_BF_PLAYER']:
321 playerlist = B.create_blender_liblist(env, 'player')
322 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
324 ##### Now define some targets
327 #------------ INSTALL
331 if env['OURPLATFORM']=='darwin':
332 for prg in B.program_list:
333 bundle = '%s.app' % prg[0]
334 bundledir = os.path.dirname(bundle)
335 for dp, dn, df in os.walk(bundle):
340 dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
341 source=[dp+os.sep+f for f in df]
342 blenderinstall.append(env.Install(dir=dir,source=source))
344 blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
349 for dp, dn, df in os.walk('bin/.blender'):
355 dotblendlist.append(dp+os.sep+f)
356 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
358 dotblenderinstall = []
359 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
360 td, tf = os.path.split(targetdir)
361 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
365 scriptpath='release/scripts'
366 for dp, dn, df in os.walk(scriptpath):
371 dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
372 source=[dp+os.sep+f for f in df]
373 scriptinstall.append(env.Install(dir=dir,source=source))
378 for tp, tn, tf in os.walk('release/plugins'):
384 pluglist.append(tp+os.sep+f)
385 plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
388 for targetdir,srcfile in zip(plugtargetlist, pluglist):
389 td, tf = os.path.split(targetdir)
390 plugininstall.append(env.Install(dir=td, source=srcfile))
394 for tp, tn, tf in os.walk('release/text'):
400 textlist.append(tp+os.sep+f)
402 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
404 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
406 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
407 dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
408 '${LCGDIR}/png/lib/libpng.dll',
409 '#release/windows/extra/python25.zip',
410 '#release/windows/extra/zlib.pyd',
411 '${LCGDIR}/sdl/lib/SDL.dll',
412 '${LCGDIR}/zlib/lib/zlib.dll',
413 '${LCGDIR}/tiff/lib/libtiff.dll']
415 dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}_d.dll')
417 dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}.dll')
418 if env['OURPLATFORM'] == 'win32-mingw':
419 dllsources += ['${LCGDIR}/pthreads/lib/pthreadGC2.dll']
421 dllsources += ['${LCGDIR}/pthreads/lib/pthreadVC2.dll']
422 if env['WITH_BF_ICONV']:
423 dllsources += ['${LCGDIR}/iconv/lib/iconv.dll']
424 # if env['WITH_BF_FFMPEG']:
425 # dllsources += ['${LCGDIR}/ffmpeg/lib/avcodec-51.dll',
426 # '${LCGDIR}/ffmpeg/lib/avformat-51.dll',
427 # '${LCGDIR}/ffmpeg/lib/avutil-49.dll']
428 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
429 allinstall += windlls
431 installtarget = env.Alias('install', allinstall)
432 bininstalltarget = env.Alias('install-bin', blenderinstall)
434 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
435 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
436 nsisalias = env.Alias('nsis', nsiscmd)
438 if env['WITH_BF_PLAYER']:
439 blenderplayer = env.Alias('blenderplayer', B.program_list)
440 Depends(blenderplayer,installtarget)
442 if not env['WITH_BF_GAMEENGINE']:
443 blendernogame = env.Alias('blendernogame', B.program_list)
444 Depends(blendernogame,installtarget)
446 Depends(nsiscmd, allinstall)
448 Default(B.program_list)
450 if not env['WITHOUT_BF_INSTALL']:
451 Default(installtarget)
453 #------------ RELEASE
454 # TODO: zipup the installation
456 #------------ BLENDERPLAYER
457 # TODO: build stubs and link into blenderplayer