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
55 ##### BEGIN SETUP #####
57 B.possible_types = ['core', 'common', 'blender', 'intern',
58 'international', 'game', 'game2',
59 'player', 'player2', 'system']
61 B.binarykind = ['blender' , 'blenderplayer']
62 ##################################
63 # target and argument validation #
64 ##################################
65 # XX cheating for BF_FANCY, we check for BF_FANCY before args are validated
66 use_color = ARGUMENTS.get('BF_FANCY', '1')
70 if not use_color=='1':
74 print B.bc.HEADER+'Command-line arguments'+B.bc.ENDC
75 B.arguments = btools.validate_arguments(ARGUMENTS, B.bc)
76 btools.print_arguments(B.arguments, B.bc)
79 print B.bc.HEADER+'Command-line targets'+B.bc.ENDC
80 B.targets = btools.validate_targets(COMMAND_LINE_TARGETS, B.bc)
81 btools.print_targets(B.targets, B.bc)
83 ##########################
84 # setting up environment #
85 ##########################
87 # handling cmd line arguments & config file
89 # first check cmdline for toolset and we create env to work on
90 quickie = B.arguments.get('BF_QUICK', None)
92 B.quickie=string.split(quickie,',')
96 toolset = B.arguments.get('BF_TOOLSET', None)
98 print "Using " + toolset
99 if toolset=='mstoolkit':
100 env = BlenderEnvironment(ENV = os.environ)
101 env.Tool('mstoolkit', ['tools'])
103 env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
105 env = BlenderEnvironment(ENV = os.environ)
108 print "Could not create a build environment"
111 cc = B.arguments.get('CC', None)
112 cxx = B.arguments.get('CXX', None)
118 if env['CC'] in ['cl', 'cl.exe'] and sys.platform=='win32':
119 platform = 'win32-vc'
120 elif env['CC'] in ['gcc'] and sys.platform=='win32':
121 platform = 'win32-mingw'
123 crossbuild = B.arguments.get('BF_CROSS', None)
124 if crossbuild and platform!='win32':
125 platform = 'linuxcross'
127 env['OURPLATFORM'] = platform
129 configfile = B.arguments.get('BF_CONFIG', 'config'+os.sep+platform+'-config.py')
131 if os.path.exists(configfile):
132 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
134 print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
136 if crossbuild and env['PLATFORM'] != 'win32':
137 print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
138 env.Tool('crossmingw', ['tools'])
139 # todo: determine proper libs/includes etc.
140 # Needed for gui programs, console programs should do without it
141 env.Append(LINKFLAGS=['-mwindows'])
143 # first read platform config. B.arguments will override
144 optfiles = [configfile]
145 if os.path.exists('user-config.py'):
146 print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + 'user-config.py'
147 optfiles += ['user-config.py']
149 print B.bc.WARNING + 'user-config.py' + " not found, no user overrides" + B.bc.ENDC
151 opts = btools.read_opts(optfiles, B.arguments)
154 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
155 if 'blenderplayer' in B.targets:
156 env['WITH_BF_PLAYER'] = True
158 if 'blendernogame' in B.targets:
159 env['WITH_BF_GAMEENGINE'] = False
161 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
162 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
163 B.root_build_dir = env['BF_BUILDDIR']
164 env['BUILDDIR'] = B.root_build_dir
165 if not B.root_build_dir[-1]==os.sep:
166 B.root_build_dir += os.sep
168 # We do a shortcut for clean when no quicklist is given: just delete
169 # builddir without reading in SConscripts
171 if 'clean' in B.targets:
174 if not quickie and do_clean:
175 print B.bc.HEADER+'Cleaning...'+B.bc.ENDC
176 dirs = os.listdir(B.root_build_dir)
178 if os.path.isdir(B.root_build_dir + dir) == 1:
179 print "clean dir %s"%(B.root_build_dir+dir)
180 shutil.rmtree(B.root_build_dir+dir)
181 print B.bc.OKGREEN+'...done'+B.bc.ENDC
184 if not os.path.isdir ( B.root_build_dir):
185 os.makedirs ( B.root_build_dir )
186 os.makedirs ( B.root_build_dir + 'source' )
187 os.makedirs ( B.root_build_dir + 'intern' )
188 os.makedirs ( B.root_build_dir + 'extern' )
189 os.makedirs ( B.root_build_dir + 'lib' )
190 os.makedirs ( B.root_build_dir + 'bin' )
192 Help(opts.GenerateHelpText(env))
194 # default is new quieter output, but if you need to see the
195 # commands, do 'scons BF_QUIET=0'
196 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
197 if bf_quietoutput=='1':
198 B.set_quiet_output(env)
203 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
204 env.SConsignFile(B.root_build_dir+'scons-signatures')
207 ##### END SETUP ##########
210 #Export('root_build_dir') # this one is still needed for makesdna
211 ##TODO: improve makesdna usage
213 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
214 SConscript(B.root_build_dir+'/intern/SConscript')
215 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
216 SConscript(B.root_build_dir+'/extern/SConscript')
217 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
218 SConscript(B.root_build_dir+'/source/SConscript')
220 # now that we have read all SConscripts, we know what
221 # libraries will be built. Create list of
222 # libraries to give as objects to linking phase
224 for tp in B.possible_types:
225 if not tp == 'player' and not tp == 'player2':
226 mainlist += B.create_blender_liblist(env, tp)
228 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
229 B.propose_priorities()
231 dobj = B.buildinfo(env, "dynamic")
232 thestatlibs, thelibincs = B.setup_staticlibs(env)
233 thesyslibs = B.setup_syslibs(env)
235 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
236 if env['WITH_BF_PLAYER']:
237 playerlist = B.create_blender_liblist(env, 'player')
238 env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
240 ##### Now define some targets
243 #------------ INSTALL
245 blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
250 for dp, dn, df in os.walk('bin/.blender'):
254 dotblendlist.append(dp+os.sep+f)
255 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
257 dotblenderinstall = []
258 for targetdir,srcfile in zip(dottargetlist, dotblendlist):
259 td, tf = os.path.split(targetdir)
260 dotblenderinstall.append(env.Install(dir=td, source=srcfile))
263 scriptlist = glob.glob('release/scripts/*.py')
264 scriptinstall = env.Install(dir=env['BF_INSTALLDIR']+'/.blender/scripts', source=scriptlist)
269 for tp, tn, tf in os.walk('release/plugins'):
273 pluglist.append(tp+os.sep+f)
274 plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
277 for targetdir,srcfile in zip(plugtargetlist, pluglist):
278 td, tf = os.path.split(targetdir)
279 plugininstall.append(env.Install(dir=td, source=srcfile))
283 for tp, tn, tf in os.walk('release/text'):
287 textlist.append(tp+os.sep+f)
289 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
291 allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
293 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
294 dllsources = ['#../lib/windows/gettext/lib/gnu_gettext.dll',
295 '#../lib/windows/png/lib/libpng.dll',
296 '#../lib/windows/python/lib/python24.dll',
297 '#../lib/windows/sdl/lib/SDL.dll',
298 '#../lib/windows/zlib/lib/zlib.dll']
299 if env['OURPLATFORM'] == 'win32-mingw':
300 dllsources += ['#../lib/windows/pthreads/lib/pthreadGC2.dll']
302 dllsources += ['#../lib/windows/pthreads/lib/pthreadVC2.dll']
303 windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
304 allinstall += windlls
306 installtarget = env.Alias('install', allinstall)
307 bininstalltarget = env.Alias('install-bin', blenderinstall)
309 if env['WITH_BF_PLAYER']:
310 blenderplayer = env.Alias('blenderplayer', B.program_list)
311 Depends(blenderplayer,installtarget)
313 if not env['WITH_BF_GAMEENGINE']:
314 blendernogame = env.Alias('blendernogame', B.program_list)
315 Depends(blendernogame,installtarget)
318 Default(B.program_list)
319 Default(installtarget)
321 #------------ RELEASE
322 # TODO: zipup the installation
324 #------------ BLENDERPLAYER
325 # TODO: build stubs and link into blenderplayer