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
56 ##### BEGIN SETUP #####
58 B.possible_types = ['core', 'common', 'blender', 'intern',
59 'international', 'game', 'game2',
60 'player', 'player2', 'system']
62 B.binarykind = ['blender' , 'blenderplayer']
63 ##################################
64 # target and argument validation #
65 ##################################
66 # XX cheating for BF_FANCY, we check for BF_FANCY before args are validated
67 use_color = ARGUMENTS.get('BF_FANCY', '1')
71 if not use_color=='1':
75 print B.bc.HEADER+'Command-line arguments'+B.bc.ENDC
76 B.arguments = btools.validate_arguments(ARGUMENTS, B.bc)
77 btools.print_arguments(B.arguments, B.bc)
80 print B.bc.HEADER+'Command-line targets'+B.bc.ENDC
81 B.targets = btools.validate_targets(COMMAND_LINE_TARGETS, B.bc)
82 btools.print_targets(B.targets, B.bc)
84 ##########################
85 # setting up environment #
86 ##########################
88 # handling cmd line arguments & config file
90 # first check cmdline for toolset and we create env to work on
91 quickie = B.arguments.get('BF_QUICK', None)
92 quickdebug = B.arguments.get('BF_QUICKDEBUG', None)
95 B.quickdebug=string.split(quickdebug, ',')
100 B.quickie=string.split(quickie,',')
104 toolset = B.arguments.get('BF_TOOLSET', None)
106 print "Using " + toolset
107 if toolset=='mstoolkit':
108 env = BlenderEnvironment(ENV = os.environ)
109 env.Tool('mstoolkit', ['tools'])
111 env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
113 env = BlenderEnvironment(ENV = os.environ)
116 print "Could not create a build environment"
119 env.SConscriptChdir(0)
120 cc = B.arguments.get('CC', None)
121 cxx = B.arguments.get('CXX', None)
127 if env['CC'] in ['cl', 'cl.exe'] and sys.platform=='win32':
128 platform = 'win32-vc'
129 elif env['CC'] in ['gcc'] and sys.platform=='win32':
130 platform = 'win32-mingw'
132 crossbuild = B.arguments.get('BF_CROSS', None)
133 if crossbuild and platform!='win32':
134 platform = 'linuxcross'
136 env['OURPLATFORM'] = platform
138 configfile = B.arguments.get('BF_CONFIG', 'config'+os.sep+platform+'-config.py')
140 if os.path.exists(configfile):
141 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
143 print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
145 if crossbuild and env['PLATFORM'] != 'win32':
146 print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
147 env.Tool('crossmingw', ['tools'])
148 # todo: determine proper libs/includes etc.
149 # Needed for gui programs, console programs should do without it
150 env.Append(LINKFLAGS=['-mwindows'])
152 # first read platform config. B.arguments will override
153 optfiles = [configfile]
154 if os.path.exists('user-config.py'):
155 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + 'user-config.py'
156 optfiles += ['user-config.py']
158 print B.bc.WARNING + 'user-config.py' + " not found, no user overrides" + B.bc.ENDC
160 opts = btools.read_opts(optfiles, B.arguments)
163 # disable elbeem (fluidsim) compilation?
164 if env['BF_NO_ELBEEM'] == 'true':
165 env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
166 env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
167 env['CCFLAGS'].append('-DDISABLE_ELBEEM')
169 #check for additional debug libnames
171 if env.has_key('BF_DEBUG_LIBS'):
172 B.quickdebug += env['BF_DEBUG_LIBS']
174 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
176 # see if this linux distro has libalut
178 if env['OURPLATFORM'] == 'linux2' :
179 if env['WITH_BF_OPENAL']:
180 mylib_test_source_file = """
182 int main(int argc, char **argv)
184 alutGetMajorVersion();
189 def CheckFreeAlut(context,env):
190 context.Message( B.bc.OKGREEN + "Linux platform detected:\n checking for FreeAlut... " + B.bc.ENDC )
192 result = context.TryLink(mylib_test_source_file, '.c')
193 context.Result(result)
196 env2 = env.Copy( LIBPATH = env['BF_OPENAL'] )
197 conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, '.sconf_temp', '/dev/null' )
198 if conf.CheckFreeAlut( env2 ):
199 env['BF_OPENAL_LIB'] += ' alut'
201 for root, dirs, files in os.walk('.sconf_temp', topdown=False):
203 os.remove(os.path.join(root, name))
205 os.rmdir(os.path.join(root, name))
208 if len(B.quickdebug) > 0 and printdebug != 0:
209 print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
210 for l in B.quickdebug:
213 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
214 if 'blenderplayer' in B.targets:
215 env['WITH_BF_PLAYER'] = True
217 if 'blendernogame' in B.targets:
218 env['WITH_BF_GAMEENGINE'] = False
220 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
221 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
222 B.root_build_dir = env['BF_BUILDDIR']
223 env['BUILDDIR'] = B.root_build_dir
224 if not B.root_build_dir[-1]==os.sep:
225 B.root_build_dir += os.sep
227 # We do a shortcut for clean when no quicklist is given: just delete
228 # builddir without reading in SConscripts
230 if 'clean' in B.targets:
233 if not quickie and do_clean:
234 print B.bc.HEADER+'Cleaning...'+B.bc.ENDC
235 dirs = os.listdir(B.root_build_dir)
237 if os.path.isdir(B.root_build_dir + dir) == 1:
238 print "clean dir %s"%(B.root_build_dir+dir)
239 shutil.rmtree(B.root_build_dir+dir)
240 print B.bc.OKGREEN+'...done'+B.bc.ENDC
243 if not os.path.isdir ( B.root_build_dir):
244 os.makedirs ( B.root_build_dir )
245 os.makedirs ( B.root_build_dir + 'source' )
246 os.makedirs ( B.root_build_dir + 'intern' )
247 os.makedirs ( B.root_build_dir + 'extern' )
248 os.makedirs ( B.root_build_dir + 'lib' )
249 os.makedirs ( B.root_build_dir + 'bin' )
251 Help(opts.GenerateHelpText(env))
253 # default is new quieter output, but if you need to see the
254 # commands, do 'scons BF_QUIET=0'
255 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
256 if bf_quietoutput=='1':
257 B.set_quiet_output(env)
262 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
263 env.SConsignFile(B.root_build_dir+'scons-signatures')
266 ##### END SETUP ##########
269 #Export('root_build_dir') # this one is still needed for makesdna
270 ##TODO: improve makesdna usage
272 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
273 SConscript(B.root_build_dir+'/intern/SConscript')
274 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
275 SConscript(B.root_build_dir+'/extern/SConscript')
276 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
277 SConscript(B.root_build_dir+'/source/SConscript')
279 # now that we have read all SConscripts, we know what
280 # libraries will be built. Create list of
281 # libraries to give as objects to linking phase
283 for tp in B.possible_types:
284 if not tp == 'player' and not tp == 'player2':
285 mainlist += B.create_blender_liblist(env, tp)
287 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
288 B.propose_priorities()
290 dobj = B.buildinfo(env, "dynamic") + B.resources
291 thestatlibs, thelibincs = B.setup_staticlibs(env)
292 thesyslibs = B.setup_syslibs(env)
294 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
295 if env['WITH_BF_PLAYER']:
296 playerlist = B.create_blender_liblist(env, 'player')
297 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
299 ##### Now define some targets
302 #------------ INSTALL
304 blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
309 for dp, dn, df in os.walk('bin/.blender'):
313 dotblendlist.append(dp+os.sep+f)
314 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
316 dotblenderinstall = []
317 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
318 td, tf = os.path.split(targetdir)
319 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
323 scriptpath='release/scripts'
324 for dp, dn, df in os.walk(scriptpath):
327 dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
328 source=[dp+os.sep+f for f in df]
329 scriptinstall.append(env.Install(dir=dir,source=source))
334 for tp, tn, tf in os.walk('release/plugins'):
338 pluglist.append(tp+os.sep+f)
339 plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
342 for targetdir,srcfile in zip(plugtargetlist, pluglist):
343 td, tf = os.path.split(targetdir)
344 plugininstall.append(env.Install(dir=td, source=srcfile))
348 for tp, tn, tf in os.walk('release/text'):
352 textlist.append(tp+os.sep+f)
354 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
356 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
358 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
359 dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
360 '${LCGDIR}/png/lib/libpng.dll',
361 '${LCGDIR}/python/lib/python24.dll',
362 '#release/windows/extra/python24.zip',
363 '#release/windows/extra/zlib.pyd',
364 '${LCGDIR}/sdl/lib/SDL.dll',
365 '${LCGDIR}/zlib/lib/zlib.dll',
366 '${LCGDIR}/tiff/lib/libtiff.dll']
367 if env['OURPLATFORM'] == 'win32-mingw':
368 dllsources += ['${LCGDIR}/pthreads/lib/pthreadGC2.dll']
370 dllsources += ['${LCGDIR}/pthreads/lib/pthreadVC2.dll']
371 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
372 allinstall += windlls
374 installtarget = env.Alias('install', allinstall)
375 bininstalltarget = env.Alias('install-bin', blenderinstall)
377 if env['WITH_BF_PLAYER']:
378 blenderplayer = env.Alias('blenderplayer', B.program_list)
379 Depends(blenderplayer,installtarget)
381 if not env['WITH_BF_GAMEENGINE']:
382 blendernogame = env.Alias('blendernogame', B.program_list)
383 Depends(blendernogame,installtarget)
385 Default(B.program_list)
386 Default(installtarget)
388 #------------ RELEASE
389 # TODO: zipup the installation
391 #------------ BLENDERPLAYER
392 # TODO: build stubs and link into blenderplayer