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