svn merge ^/trunk/blender -r48288:48302
[blender.git] / SConstruct
1 #!/usr/bin/env python
2 #
3 # ***** BEGIN GPL LICENSE BLOCK *****
4 #
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.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 #
19 # The Original Code is Copyright (C) 2006, Blender Foundation
20 # All rights reserved.
21 #
22 # The Original Code is: all of this file.
23 #
24 # Contributor(s): Nathan Letwory.
25 #
26 # ***** END GPL LICENSE BLOCK *****
27 #
28 # Main entry-point for the SCons building system
29 # Set up some custom actions and target/argument handling
30 # Then read all SConscripts and build
31 #
32 # TODO: fix /FORCE:MULTIPLE on windows to get proper debug builds.
33 # TODO: directory copy functions are far too complicated, see:
34 #       http://wiki.blender.org/index.php/User:Ideasman42/SConsNotSimpleInstallingFiles
35
36 import platform as pltfrm
37
38 # Need a better way to do this. Automagical maybe is not the best thing, maybe it is.
39 if pltfrm.architecture()[0] == '64bit':
40     bitness = 64
41 else:
42     bitness = 32
43
44 import sys
45 import os
46 import os.path
47 import string
48 import shutil
49 import glob
50 import re
51 from tempfile import mkdtemp
52
53 # store path to tools
54 toolpath=os.path.join(".", "build_files", "scons", "tools")
55
56 # needed for importing tools
57 sys.path.append(toolpath)
58
59 import Blender
60 import btools
61 import bcolors
62
63 EnsureSConsVersion(1,0,0)
64
65 # Before we do anything, let's check if we have a sane os.environ
66 if not btools.check_environ():
67     Exit()
68
69 BlenderEnvironment = Blender.BlenderEnvironment
70 B = Blender
71
72 VERSION = btools.VERSION # This is used in creating the local config directories
73 VERSION_RELEASE_CYCLE = btools.VERSION_RELEASE_CYCLE
74
75 ### globals ###
76 platform = sys.platform
77 quickie = None
78 quickdebug = None
79
80 ##### BEGIN SETUP #####
81
82 B.possible_types = ['core', 'player', 'player2', 'intern', 'extern']
83
84 B.binarykind = ['blender' , 'blenderplayer']
85 ##################################
86 # target and argument validation #
87 ##################################
88 # XX cheating for BF_FANCY, we check for BF_FANCY before args are validated
89 use_color = ARGUMENTS.get('BF_FANCY', '1')
90 if platform=='win32':
91     use_color = None
92
93 if not use_color=='1':
94     B.bc.disable()
95     
96  #on defaut white Os X terminal, some colors are totally unlegible
97 if platform=='darwin':
98     B.bc.OKGREEN = '\033[34m'
99     B.bc.WARNING = '\033[36m'
100
101 # arguments
102 print B.bc.HEADER+'Command-line arguments'+B.bc.ENDC
103 B.arguments = btools.validate_arguments(ARGUMENTS, B.bc)
104 btools.print_arguments(B.arguments, B.bc)
105
106 # targets
107 print B.bc.HEADER+'Command-line targets'+B.bc.ENDC
108 B.targets = btools.validate_targets(COMMAND_LINE_TARGETS, B.bc)
109 btools.print_targets(B.targets, B.bc)
110
111 ##########################
112 # setting up environment #
113 ##########################
114
115 # handling cmd line arguments & config file
116
117 # bitness stuff
118 tempbitness = int(B.arguments.get('BF_BITNESS', bitness)) # default to bitness found as per starting python
119 if tempbitness in (32, 64): # only set if 32 or 64 has been given
120     bitness = int(tempbitness)
121
122 if bitness:
123     B.bitness = bitness
124 else: 
125     B.bitness = tempbitness
126     
127
128 # first check cmdline for toolset and we create env to work on
129 quickie = B.arguments.get('BF_QUICK', None)
130 quickdebug = B.arguments.get('BF_QUICKDEBUG', None)
131
132 if quickdebug:
133     B.quickdebug=string.split(quickdebug, ',')
134 else:
135     B.quickdebug=[]
136
137 if quickie:
138     B.quickie=string.split(quickie,',')
139 else:
140     B.quickie=[]
141     
142 toolset = B.arguments.get('BF_TOOLSET', None)
143 if toolset:
144     print "Using " + toolset
145     if toolset=='mstoolkit':
146         env = BlenderEnvironment(ENV = os.environ)
147         env.Tool('mstoolkit', [toolpath])
148     else:
149         env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
150         if env:
151             btools.SetupSpawn(env)
152 else:
153     if bitness==64 and platform=='win32':
154         env = BlenderEnvironment(ENV = os.environ, MSVS_ARCH='amd64')
155     else:
156         env = BlenderEnvironment(ENV = os.environ)
157
158 if not env:
159     print "Could not create a build environment"
160     Exit()
161
162 cc = B.arguments.get('CC', None)
163 cxx = B.arguments.get('CXX', None)
164 if cc:
165     env['CC'] = cc
166 if cxx:
167     env['CXX'] = cxx
168
169 if sys.platform=='win32':
170     if env['CC'] in ['cl', 'cl.exe']:
171         platform = 'win64-vc' if bitness == 64 else 'win32-vc'
172     elif env['CC'] in ['gcc']:
173         platform = 'win64-mingw' if bitness == 64 else 'win32-mingw'
174
175 env.SConscriptChdir(0)
176
177 # Remove major kernel version from linux platform.
178 # After Linus switched kernel to new version model this major version
179 # shouldn't take much sense for building rules.
180
181 if re.match('linux[0-9]+', platform):
182     platform = 'linux'
183
184 crossbuild = B.arguments.get('BF_CROSS', None)
185 if crossbuild and platform not in ('win32-vc', 'win64-vc'):
186     platform = 'linuxcross'
187
188 env['OURPLATFORM'] = platform
189
190 configfile = os.path.join("build_files", "scons", "config", platform + "-config.py")
191
192 if os.path.exists(configfile):
193     print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
194 else:
195     print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
196
197 if crossbuild and env['PLATFORM'] != 'win32':
198     print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
199     env.Tool('crossmingw', [toolpath])
200     # todo: determine proper libs/includes etc.
201     # Needed for gui programs, console programs should do without it
202
203     # Now we don't need this option to have console window
204     # env.Append(LINKFLAGS=['-mwindows'])
205
206 userconfig = B.arguments.get('BF_CONFIG', 'user-config.py')
207 # first read platform config. B.arguments will override
208 optfiles = [configfile]
209 if os.path.exists(userconfig):
210     print B.bc.OKGREEN + "Using user-config file: " + B.bc.ENDC + userconfig
211     optfiles += [userconfig]
212 else:
213     print B.bc.WARNING + userconfig + " not found, no user overrides" + B.bc.ENDC
214
215 opts = btools.read_opts(env, optfiles, B.arguments)
216 opts.Update(env)
217
218 if sys.platform=='win32':
219     if bitness==64:
220         env.Append(CPPFLAGS=['-DWIN64']) # -DWIN32 needed too, as it's used all over to target Windows generally
221
222 if not env['BF_FANCY']:
223     B.bc.disable()
224
225
226 # remove install dir so old and new files are not mixed.
227 # NOTE: only do the scripts directory for now, otherwise is too disruptive for developers
228 # TODO: perhaps we need an option (off by default) to not do this altogether...
229 if not env['WITHOUT_BF_INSTALL'] and not env['WITHOUT_BF_OVERWRITE_INSTALL']:
230     scriptsDir = os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts')
231     if os.path.isdir(scriptsDir):
232         print B.bc.OKGREEN + "Clearing installation directory%s: %s" % (B.bc.ENDC, os.path.abspath(scriptsDir))
233         shutil.rmtree(scriptsDir)
234
235
236 SetOption('num_jobs', int(env['BF_NUMJOBS']))
237 print B.bc.OKGREEN + "Build with parallel jobs%s: %s" % (B.bc.ENDC, GetOption('num_jobs'))
238 print B.bc.OKGREEN + "Build with debug symbols%s: %s" % (B.bc.ENDC, env['BF_DEBUG'])
239
240 if 'blenderlite' in B.targets:
241     target_env_defs = {}
242     target_env_defs['WITH_BF_GAMEENGINE'] = False
243     target_env_defs['WITH_BF_CYCLES'] = False
244     target_env_defs['WITH_BF_OPENAL'] = False
245     target_env_defs['WITH_BF_OPENEXR'] = False
246     target_env_defs['WITH_BF_OPENMP'] = False
247     target_env_defs['WITH_BF_ICONV'] = False
248     target_env_defs['WITH_BF_INTERNATIONAL'] = False
249     target_env_defs['WITH_BF_OPENJPEG'] = False
250     target_env_defs['WITH_BF_FFMPEG'] = False
251     target_env_defs['WITH_BF_QUICKTIME'] = False
252     target_env_defs['WITH_BF_REDCODE'] = False
253     target_env_defs['WITH_BF_DDS'] = False
254     target_env_defs['WITH_BF_CINEON'] = False
255     target_env_defs['WITH_BF_FRAMESERVER'] = False
256     target_env_defs['WITH_BF_HDR'] = False
257     target_env_defs['WITH_BF_ZLIB'] = False
258     target_env_defs['WITH_BF_SDL'] = False
259     target_env_defs['WITH_BF_JPEG'] = False
260     target_env_defs['WITH_BF_PNG'] = False
261     target_env_defs['WITH_BF_BULLET'] = False
262     target_env_defs['WITH_BF_BINRELOC'] = False
263     target_env_defs['BF_BUILDINFO'] = False
264     target_env_defs['WITH_BF_FLUID'] = False
265     target_env_defs['WITH_BF_OCEANSIM'] = False
266     target_env_defs['WITH_BF_SMOKE'] = False
267     target_env_defs['WITH_BF_DECIMATE'] = False
268     target_env_defs['WITH_BF_BOOLEAN'] = False
269     target_env_defs['WITH_BF_REMESH'] = False
270     target_env_defs['WITH_BF_PYTHON'] = False
271     target_env_defs['WITH_BF_3DMOUSE'] = False
272     target_env_defs['WITH_BF_LIBMV'] = False
273     
274     # Merge blenderlite, let command line to override
275     for k,v in target_env_defs.iteritems():
276         if k not in B.arguments:
277             env[k] = v
278
279 # Extended OSX_SDK and 3D_CONNEXION_CLIENT_LIBRARY and JAckOSX detection for OSX
280 if env['OURPLATFORM']=='darwin':
281     print B.bc.OKGREEN + "Detected Xcode version: -- " + B.bc.ENDC + env['XCODE_CUR_VER'] + " --"
282     print "Available " + env['MACOSX_SDK_CHECK']
283     if not 'Mac OS X 10.5' in env['MACOSX_SDK_CHECK']:
284         print  B.bc.OKGREEN + "MacOSX10.5.sdk not available:" + B.bc.ENDC + " using MacOSX10.6.sdk"
285     else:
286         print B.bc.OKGREEN + "Found recommended sdk :" + B.bc.ENDC + " using MacOSX10.5.sdk"
287
288     # for now, Mac builders must download and install the 3DxWare 10 Beta 4 driver framework from 3Dconnexion
289     # necessary header file lives here when installed:
290     # /Library/Frameworks/3DconnexionClient.framework/Versions/Current/Headers/ConnexionClientAPI.h
291     if env['WITH_BF_3DMOUSE'] == 1:
292         if not os.path.exists('/Library/Frameworks/3DconnexionClient.framework'):
293             print "3D_CONNEXION_CLIENT_LIBRARY not found, disabling WITH_BF_3DMOUSE" # avoid build errors !
294             env['WITH_BF_3DMOUSE'] = 0
295         else:
296             env.Append(LINKFLAGS=['-Xlinker','-weak_framework','-Xlinker','3DconnexionClient'])
297
298     # for now, Mac builders must download and install the JackOSX framework 
299     # necessary header file lives here when installed:
300     # /Library/Frameworks/Jackmp.framework/Versions/A/Headers/jack.h
301     if env['WITH_BF_JACK'] == 1:
302         if not os.path.exists('/Library/Frameworks/Jackmp.framework'):
303             print "JackOSX install not found, disabling WITH_BF_JACK" # avoid build errors !
304             env['WITH_BF_JACK'] = 0
305         else:
306             env.Append(LINKFLAGS=['-Xlinker','-weak_framework','-Xlinker','Jackmp'])
307
308 if env['WITH_BF_OPENMP'] == 1:
309         if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
310                 env['CCFLAGS'].append('/openmp')
311         else:
312             if env['CC'].endswith('icc'): # to be able to handle CC=/opt/bla/icc case
313                 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
314                 env['CCFLAGS'].append('-openmp')
315             else:
316                 env.Append(CCFLAGS=['-fopenmp']) 
317
318 if env['WITH_GHOST_COCOA'] == True:
319     env.Append(CPPFLAGS=['-DGHOST_COCOA']) 
320     
321 if env['USE_QTKIT'] == True:
322     env.Append(CPPFLAGS=['-DUSE_QTKIT'])
323
324 #check for additional debug libnames
325
326 if env.has_key('BF_DEBUG_LIBS'):
327     B.quickdebug += env['BF_DEBUG_LIBS']
328
329 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
330
331 if len(B.quickdebug) > 0 and printdebug != 0:
332     print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
333     for l in B.quickdebug:
334         print "\t" + l
335
336 # remove stdc++ from LLIBS if we are building a statc linked CXXFLAGS
337 if env['WITH_BF_STATICCXX']:
338     if 'stdc++' in env['LLIBS']:
339         env['LLIBS'].remove('stdc++')
340     else:
341         print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
342
343 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
344 if 'blenderplayer' in B.targets:
345     env['WITH_BF_PLAYER'] = True
346
347 if 'blendernogame' in B.targets:
348     env['WITH_BF_GAMEENGINE'] = False
349
350 # build without elbeem (fluidsim)?
351 if env['WITH_BF_FLUID'] == 1:
352     env['CPPFLAGS'].append('-DWITH_MOD_FLUID')
353
354 # build with ocean sim?
355 if env['WITH_BF_OCEANSIM'] == 1:
356     env['WITH_BF_FFTW3']  = 1  # ocean needs fftw3 so enable it 
357     env['CPPFLAGS'].append('-DWITH_MOD_OCEANSIM')
358
359
360 if btools.ENDIAN == "big":
361     env['CPPFLAGS'].append('-D__BIG_ENDIAN__')
362 else:
363     env['CPPFLAGS'].append('-D__LITTLE_ENDIAN__')
364
365 # TODO, make optional
366 env['CPPFLAGS'].append('-DWITH_AUDASPACE')
367
368 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
369 B.root_build_dir = env['BF_BUILDDIR']
370 B.doc_build_dir = os.path.join(env['BF_INSTALLDIR'], 'doc')
371 if not B.root_build_dir[-1]==os.sep:
372     B.root_build_dir += os.sep
373 if not B.doc_build_dir[-1]==os.sep:
374     B.doc_build_dir += os.sep
375     
376 # We do a shortcut for clean when no quicklist is given: just delete
377 # builddir without reading in SConscripts
378 do_clean = None
379 if 'clean' in B.targets:
380     do_clean = True
381
382 if not quickie and do_clean:
383     if os.path.exists(B.doc_build_dir):
384         print B.bc.HEADER+'Cleaning doc dir...'+B.bc.ENDC
385         dirs = os.listdir(B.doc_build_dir)
386         for entry in dirs:
387             if os.path.isdir(B.doc_build_dir + entry) == 1:
388                 print "clean dir %s"%(B.doc_build_dir+entry)
389                 shutil.rmtree(B.doc_build_dir+entry)
390             else: # remove file
391                 print "remove file %s"%(B.doc_build_dir+entry)
392                 os.remove(B.root_build_dir+entry)
393     if os.path.exists(B.root_build_dir):
394         print B.bc.HEADER+'Cleaning build dir...'+B.bc.ENDC
395         dirs = os.listdir(B.root_build_dir)
396         for entry in dirs:
397             if os.path.isdir(B.root_build_dir + entry) == 1:
398                 print "clean dir %s"%(B.root_build_dir+entry)
399                 shutil.rmtree(B.root_build_dir+entry)
400             else: # remove file
401                 print "remove file %s"%(B.root_build_dir+entry)
402                 os.remove(B.root_build_dir+entry)
403         for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
404                 'extern/xvidcore/build/generic/platform.inc', 'extern/ffmpeg/include']:
405             if os.path.exists(confile):
406                 print "clean file %s"%confile
407                 if os.path.isdir(confile):
408                     for root, dirs, files in os.walk(confile):
409                         for name in files:
410                             os.remove(os.path.join(root, name))
411                 else:
412                     os.remove(confile)
413         print B.bc.OKGREEN+'...done'+B.bc.ENDC
414     else:
415         print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
416     Exit()
417
418
419 # ensure python header is found since detection can fail, this could happen
420 # with _any_ library but since we used a fixed python version this tends to
421 # be most problematic.
422 if env['WITH_BF_PYTHON']:
423         py_h = os.path.join(Dir(env.subst('${BF_PYTHON_INC}')).abspath, "Python.h")
424
425         if not os.path.exists(py_h):
426                 print("\nMissing: \"" + env.subst('${BF_PYTHON_INC}') + os.sep + "Python.h\",\n"
427                           "  Set 'BF_PYTHON_INC' to point "
428                           "to a valid python include path.\n  Containing "
429                           "Python.h for python version \"" + env.subst('${BF_PYTHON_VERSION}') + "\"")
430
431                 Exit()
432         del py_h
433
434
435 if not os.path.isdir ( B.root_build_dir):
436     os.makedirs ( B.root_build_dir )
437     os.makedirs ( B.root_build_dir + 'source' )
438     os.makedirs ( B.root_build_dir + 'intern' )
439     os.makedirs ( B.root_build_dir + 'extern' )
440     os.makedirs ( B.root_build_dir + 'lib' )
441     os.makedirs ( B.root_build_dir + 'bin' )
442 # # Docs not working with epy anymore
443 # if not os.path.isdir(B.doc_build_dir) and env['WITH_BF_DOCS']:
444 #     os.makedirs ( B.doc_build_dir )
445
446 Help(opts.GenerateHelpText(env))
447
448 # default is new quieter output, but if you need to see the 
449 # commands, do 'scons BF_QUIET=0'
450 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
451 if env['BF_QUIET']:
452     B.set_quiet_output(env)
453 else:
454     if toolset=='msvc':
455         B.msvc_hack(env)
456
457 print B.bc.HEADER+'Building in: ' + B.bc.ENDC + os.path.abspath(B.root_build_dir)
458 env.SConsignFile(B.root_build_dir+'scons-signatures')
459 B.init_lib_dict()
460
461 ##### END SETUP ##########
462
463 Export('env')
464
465 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
466 SConscript(B.root_build_dir+'/source/SConscript')
467 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
468 SConscript(B.root_build_dir+'/intern/SConscript')
469 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
470 SConscript(B.root_build_dir+'/extern/SConscript')
471
472 # now that we have read all SConscripts, we know what
473 # libraries will be built. Create list of
474 # libraries to give as objects to linking phase
475 mainlist = []
476 for tp in B.possible_types:
477     if (not tp == 'player') and (not tp == 'player2'):
478         mainlist += B.create_blender_liblist(env, tp)
479
480 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
481     B.propose_priorities()
482
483 dobj = B.buildinfo(env, "dynamic") + B.resources
484 creob = B.creator(env)
485 thestatlibs, thelibincs = B.setup_staticlibs(env)
486 thesyslibs = B.setup_syslibs(env)
487
488 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
489     env.BlenderProg(B.root_build_dir, "blender", creob + mainlist + thestatlibs + dobj, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
490 if env['WITH_BF_PLAYER']:
491     playerlist = B.create_blender_liblist(env, 'player')
492     playerlist += B.create_blender_liblist(env, 'player2')
493     playerlist += B.create_blender_liblist(env, 'intern')
494     playerlist += B.create_blender_liblist(env, 'extern')
495     env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
496
497 ##### Now define some targets
498
499
500 #------------ INSTALL
501
502 #-- binaries
503 blenderinstall = []
504 if  env['OURPLATFORM']=='darwin':
505     for prg in B.program_list:
506         bundle = '%s.app' % prg[0]
507         bundledir = os.path.dirname(bundle)
508         for dp, dn, df in os.walk(bundle):
509             if '.svn' in dn:
510                 dn.remove('.svn')
511             if '_svn' in dn:
512                 dn.remove('_svn')
513             dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
514             source=[dp+os.sep+f for f in df]
515             blenderinstall.append(env.Install(dir=dir,source=source))
516 else:
517     blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
518
519 #-- local path = config files in install dir: installdir\VERSION
520 #- dont do config and scripts for darwin, it is already in the bundle
521 dotblendlist = []
522 datafileslist = []
523 datafilestargetlist = []
524 dottargetlist = []
525 scriptinstall = []
526
527 if env['OURPLATFORM']!='darwin':
528     dotblenderinstall = []
529     for targetdir,srcfile in zip(dottargetlist, dotblendlist):
530         td, tf = os.path.split(targetdir)
531         dotblenderinstall.append(env.Install(dir=td, source=srcfile))
532     for targetdir,srcfile in zip(datafilestargetlist, datafileslist):
533         td, tf = os.path.split(targetdir)
534         dotblenderinstall.append(env.Install(dir=td, source=srcfile))
535     
536     if env['WITH_BF_PYTHON']:
537         #-- local/VERSION/scripts
538         scriptpaths=['release/scripts']
539         for scriptpath in scriptpaths:
540             for dp, dn, df in os.walk(scriptpath):
541                 if '.svn' in dn:
542                     dn.remove('.svn')
543                 if '_svn' in dn:
544                     dn.remove('_svn')
545                 if '__pycache__' in dn:  # py3.2 cache dir
546                     dn.remove('__pycache__')
547
548                 # only for testing builds
549                 if VERSION_RELEASE_CYCLE == "release" and "addons_contrib" in dn:
550                     dn.remove('addons_contrib')
551
552                 dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
553                 dir += os.sep + os.path.basename(scriptpath) + dp[len(scriptpath):]
554
555                 source=[os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
556                 # To ensure empty dirs are created too
557                 if len(source)==0 and not os.path.exists(dir):
558                     env.Execute(Mkdir(dir))
559                 scriptinstall.append(env.Install(dir=dir,source=source))
560         if env['WITH_BF_CYCLES']:
561             # cycles python code
562             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles')
563             source=os.listdir('intern/cycles/blender/addon')
564             if '.svn' in source: source.remove('.svn')
565             if '_svn' in source: source.remove('_svn')
566             if '__pycache__' in source: source.remove('__pycache__')
567             source=['intern/cycles/blender/addon/'+s for s in source]
568             scriptinstall.append(env.Install(dir=dir,source=source))
569
570             # cycles kernel code
571             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel')
572             source=os.listdir('intern/cycles/kernel')
573             if '.svn' in source: source.remove('.svn')
574             if '_svn' in source: source.remove('_svn')
575             if '__pycache__' in source: source.remove('__pycache__')
576             source.remove('kernel.cpp')
577             source.remove('CMakeLists.txt')
578             source.remove('svm')
579             source.remove('osl')
580             source=['intern/cycles/kernel/'+s for s in source]
581             source.append('intern/cycles/util/util_color.h')
582             source.append('intern/cycles/util/util_math.h')
583             source.append('intern/cycles/util/util_transform.h')
584             source.append('intern/cycles/util/util_types.h')
585             scriptinstall.append(env.Install(dir=dir,source=source))
586             # svm
587             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel', 'svm')
588             source=os.listdir('intern/cycles/kernel/svm')
589             if '.svn' in source: source.remove('.svn')
590             if '_svn' in source: source.remove('_svn')
591             if '__pycache__' in source: source.remove('__pycache__')
592             source=['intern/cycles/kernel/svm/'+s for s in source]
593             scriptinstall.append(env.Install(dir=dir,source=source))
594
595             # licenses
596             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'license')
597             source=os.listdir('intern/cycles/doc/license')
598             if '.svn' in source: source.remove('.svn')
599             if '_svn' in source: source.remove('_svn')
600             if '__pycache__' in source: source.remove('__pycache__')
601             source.remove('CMakeLists.txt')
602             source=['intern/cycles/doc/license/'+s for s in source]
603             scriptinstall.append(env.Install(dir=dir,source=source))
604
605             # cuda binaries
606             if env['WITH_BF_CYCLES_CUDA_BINARIES']:
607                 dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'lib')
608                 for arch in env['BF_CYCLES_CUDA_BINARIES_ARCH']:
609                     kernel_build_dir = os.path.join(B.root_build_dir, 'intern/cycles/kernel')
610                     cubin_file = os.path.join(kernel_build_dir, "kernel_%s.cubin" % arch)
611                     scriptinstall.append(env.Install(dir=dir,source=cubin_file))
612
613     if env['WITH_BF_OCIO']:
614         dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'datafiles', 'colormanagement')
615         source=os.listdir('release/datafiles/colormanagement')
616         if '.svn' in source: source.remove('.svn')
617         if '_svn' in source: source.remove('_svn')
618         source=['release/datafiles/colormanagement/'+s for s in source]
619         scriptinstall.append(env.Install(dir=dir,source=source))
620
621     if env['WITH_BF_INTERNATIONAL']:
622         internationalpaths=['release' + os.sep + 'datafiles']
623         
624         def check_path(path, member):
625             return (member in path.split(os.sep))
626         
627         for intpath in internationalpaths:
628             for dp, dn, df in os.walk(intpath):
629                 if '.svn' in dn:
630                     dn.remove('.svn')
631                 if '_svn' in dn:
632                     dn.remove('_svn')
633
634                 # we only care about release/datafiles/fonts, release/datafiles/locales
635                 if check_path(dp, "fonts") or check_path(dp, "locale"):
636                     pass
637                 else:
638                     continue
639                 
640                 dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
641                 dir += os.sep + os.path.basename(intpath) + dp[len(intpath):]
642
643                 source=[os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
644                 # To ensure empty dirs are created too
645                 if len(source)==0:
646                     env.Execute(Mkdir(dir))
647                 scriptinstall.append(env.Install(dir=dir,source=source))
648
649 #-- icons
650 if env['OURPLATFORM']=='linux':
651     iconlist = []
652     icontargetlist = []
653
654     for tp, tn, tf in os.walk('release/freedesktop/icons'):
655         if '.svn' in tn:
656             tn.remove('.svn')
657         if '_svn' in tn:
658             tn.remove('_svn')
659         for f in tf:
660             iconlist.append(os.path.join(tp, f))
661             icontargetlist.append( os.path.join(*([env['BF_INSTALLDIR']] + tp.split(os.sep)[2:] + [f])) )
662
663     iconinstall = []
664     for targetdir,srcfile in zip(icontargetlist, iconlist):
665         td, tf = os.path.split(targetdir)
666         iconinstall.append(env.Install(dir=td, source=srcfile))
667
668 # dlls for linuxcross
669 # TODO - add more libs, for now this lets blenderlite run
670 if env['OURPLATFORM']=='linuxcross':
671     dir=env['BF_INSTALLDIR']
672     source = []
673
674     if env['WITH_BF_OPENMP']:
675         source += ['../lib/windows/pthreads/lib/pthreadGC2.dll']
676
677     scriptinstall.append(env.Install(dir=dir, source=source))
678
679 textlist = []
680 texttargetlist = []
681 for tp, tn, tf in os.walk('release/text'):
682     if '.svn' in tn:
683         tn.remove('.svn')
684     if '_svn' in tn:
685         tn.remove('_svn')
686     for f in tf:
687         textlist.append(tp+os.sep+f)
688
689 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
690
691 if  env['OURPLATFORM']=='darwin':
692         allinstall = [blenderinstall, textinstall]
693 elif env['OURPLATFORM']=='linux':
694         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, textinstall, iconinstall]
695 else:
696         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, textinstall]
697
698 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'):
699     dllsources = []
700
701     if not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
702         # For MinGW and linuxcross static linking will be used
703         dllsources += ['${LCGDIR}/gettext/lib/gnu_gettext.dll']
704
705     dllsources += ['${BF_ZLIB_LIBPATH}/zlib.dll']
706     # Used when linking to libtiff was dynamic
707     # keep it here until compilation on all platform would be ok
708     # dllsources += ['${BF_TIFF_LIBPATH}/${BF_TIFF_LIB}.dll']
709
710     if env['OURPLATFORM'] != 'linuxcross':
711         # pthreads library is already added
712         dllsources += ['${BF_PTHREADS_LIBPATH}/${BF_PTHREADS_LIB}.dll']
713
714     if env['WITH_BF_SDL']:
715         if env['OURPLATFORM'] == 'win64-vc':
716             pass # we link statically already to SDL on win64
717         else:
718             dllsources.append('${BF_SDL_LIBPATH}/SDL.dll')
719
720     if env['WITH_BF_PYTHON']:
721         if env['BF_DEBUG']:
722             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
723         else:
724             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
725
726     if env['WITH_BF_ICONV']:
727         if env['OURPLATFORM'] == 'win64-vc':
728             pass # we link statically to iconv on win64
729         elif not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
730             #gettext for MinGW and cross-compilation is compiled staticly
731             dllsources += ['${BF_ICONV_LIBPATH}/iconv.dll']
732
733     if env['WITH_BF_OPENAL']:
734         dllsources.append('${LCGDIR}/openal/lib/OpenAL32.dll')
735         dllsources.append('${LCGDIR}/openal/lib/wrap_oal.dll')
736
737     if env['WITH_BF_SNDFILE']:
738         dllsources.append('${LCGDIR}/sndfile/lib/libsndfile-1.dll')
739
740     if env['WITH_BF_FFMPEG']:
741         dllsources += env['BF_FFMPEG_DLL'].split()
742
743     # Since the thumb handler is loaded by Explorer, architecture is
744     # strict: the x86 build fails on x64 Windows. We need to ship
745     # both builds in x86 packages.
746     if bitness == 32:
747         dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb.dll')  
748     dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll')
749
750     if env['WITH_BF_OIIO'] and env['OURPLATFORM'] != 'win32-mingw':
751         dllsources.append('${LCGDIR}/openimageio/bin/OpenImageIO.dll')
752
753     if env['WITH_BF_OCIO'] and env['OURPLATFORM'] != 'win32-mingw':
754         dllsources.append('${LCGDIR}/opencolorio/bin/OpenColorIO.dll')
755
756     dllsources.append('#source/icons/blender.exe.manifest')
757
758     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
759     allinstall += windlls
760
761 if env['OURPLATFORM'] == 'win64-mingw':
762     dllsources = []
763     
764     if env['WITH_BF_PYTHON']:
765         if env['BF_DEBUG']:
766             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
767         else:
768             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
769
770     if env['WITH_BF_FFMPEG']:
771         dllsources += env['BF_FFMPEG_DLL'].split()
772
773     if env['WITH_BF_OPENAL']:
774         dllsources.append('${LCGDIR}/openal/lib/OpenAL32.dll')
775         dllsources.append('${LCGDIR}/openal/lib/wrap_oal.dll')
776
777     if env['WITH_BF_SNDFILE']:
778         dllsources.append('${LCGDIR}/sndfile/lib/libsndfile-1.dll')
779
780     if env['WITH_BF_SDL']:
781         dllsources.append('${LCGDIR}/sdl/lib/SDL.dll')
782         
783     dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll')
784     dllsources.append('${LCGDIR}/binaries/pthreadGC2-w64.dll')
785     dllsources.append('#source/icons/blender.exe.manifest')
786
787     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
788     allinstall += windlls
789
790 installtarget = env.Alias('install', allinstall)
791 bininstalltarget = env.Alias('install-bin', blenderinstall)
792
793 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
794 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
795 nsisalias = env.Alias('nsis', nsiscmd)
796
797 if 'blender' in B.targets:
798     blenderexe= env.Alias('blender', B.program_list)
799     Depends(blenderexe,installtarget)
800
801 if env['WITH_BF_PLAYER']:
802     blenderplayer = env.Alias('blenderplayer', B.program_list)
803     Depends(blenderplayer,installtarget)
804
805 if not env['WITH_BF_GAMEENGINE']:
806     blendernogame = env.Alias('blendernogame', B.program_list)
807     Depends(blendernogame,installtarget)
808
809 if 'blenderlite' in B.targets:
810     blenderlite = env.Alias('blenderlite', B.program_list)
811     Depends(blenderlite,installtarget)
812
813 Depends(nsiscmd, allinstall)
814
815 buildslave_action = env.Action(btools.buildslave, btools.buildslave_print)
816 buildslave_cmd = env.Command('buildslave_exec', None, buildslave_action)
817 buildslave_alias = env.Alias('buildslave', buildslave_cmd)
818
819 Depends(buildslave_cmd, allinstall)
820
821 Default(B.program_list)
822
823 if not env['WITHOUT_BF_INSTALL']:
824         Default(installtarget)
825