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