Merging r43130 through r43500 from trunk into soc-2011-tomato
[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 = '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_OPENAL'] = False
244     target_env_defs['WITH_BF_OPENEXR'] = False
245     target_env_defs['WITH_BF_OPENMP'] = False
246     target_env_defs['WITH_BF_ICONV'] = False
247     target_env_defs['WITH_BF_INTERNATIONAL'] = False
248     target_env_defs['WITH_BF_OPENJPEG'] = False
249     target_env_defs['WITH_BF_FFMPEG'] = False
250     target_env_defs['WITH_BF_QUICKTIME'] = False
251     target_env_defs['WITH_BF_REDCODE'] = False
252     target_env_defs['WITH_BF_DDS'] = False
253     target_env_defs['WITH_BF_CINEON'] = False
254     target_env_defs['WITH_BF_HDR'] = False
255     target_env_defs['WITH_BF_ZLIB'] = False
256     target_env_defs['WITH_BF_SDL'] = False
257     target_env_defs['WITH_BF_JPEG'] = False
258     target_env_defs['WITH_BF_PNG'] = False
259     target_env_defs['WITH_BF_BULLET'] = False
260     target_env_defs['WITH_BF_BINRELOC'] = False
261     target_env_defs['BF_BUILDINFO'] = False
262     target_env_defs['WITH_BF_FLUID'] = False
263     target_env_defs['WITH_BF_OCEANSIM'] = False
264     target_env_defs['WITH_BF_DECIMATE'] = False
265     target_env_defs['WITH_BF_BOOLEAN'] = False
266     target_env_defs['WITH_BF_REMESH'] = 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 and JAckOSX 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     # for now, Mac builders must download and install the JackOSX framework 
295     # necessary header file lives here when installed:
296     # /Library/Frameworks/Jackmp.framework/Versions/A/Headers/jack.h
297     if env['WITH_BF_JACK'] == 1:
298         if not os.path.exists('/Library/Frameworks/Jackmp.framework'):
299             print "JackOSX install not found, disabling WITH_BF_JACK" # avoid build errors !
300             env['WITH_BF_JACK'] = 0
301         else:
302             env.Append(LINKFLAGS=['-Xlinker','-weak_framework','-Xlinker','Jackmp'])
303
304 if env['WITH_BF_OPENMP'] == 1:
305         if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
306                 env['CCFLAGS'].append('/openmp')
307         else:
308             if env['CC'].endswith('icc'): # to be able to handle CC=/opt/bla/icc case
309                 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
310                 env['CCFLAGS'].append('-openmp')
311             else:
312                 env.Append(CCFLAGS=['-fopenmp']) 
313
314 if env['WITH_GHOST_COCOA'] == True:
315     env.Append(CPPFLAGS=['-DGHOST_COCOA']) 
316     
317 if env['USE_QTKIT'] == True:
318     env.Append(CPPFLAGS=['-DUSE_QTKIT'])
319
320 #check for additional debug libnames
321
322 if env.has_key('BF_DEBUG_LIBS'):
323     B.quickdebug += env['BF_DEBUG_LIBS']
324
325 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
326
327 if len(B.quickdebug) > 0 and printdebug != 0:
328     print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
329     for l in B.quickdebug:
330         print "\t" + l
331
332 # remove stdc++ from LLIBS if we are building a statc linked CXXFLAGS
333 if env['WITH_BF_STATICCXX']:
334     if 'stdc++' in env['LLIBS']:
335         env['LLIBS'].remove('stdc++')
336     else:
337         print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
338
339 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
340 if 'blenderplayer' in B.targets:
341     env['WITH_BF_PLAYER'] = True
342
343 if 'blendernogame' in B.targets:
344     env['WITH_BF_GAMEENGINE'] = False
345
346 # build without elbeem (fluidsim)?
347 if env['WITH_BF_FLUID'] == 1:
348     env['CPPFLAGS'].append('-DWITH_MOD_FLUID')
349
350 # build with ocean sim?
351 if env['WITH_BF_OCEANSIM'] == 1:
352     env['WITH_BF_FFTW3']  = 1  # ocean needs fftw3 so enable it 
353     env['CPPFLAGS'].append('-DWITH_MOD_OCEANSIM')
354
355
356 if btools.ENDIAN == "big":
357     env['CPPFLAGS'].append('-D__BIG_ENDIAN__')
358 else:
359     env['CPPFLAGS'].append('-D__LITTLE_ENDIAN__')
360
361 # TODO, make optional
362 env['CPPFLAGS'].append('-DWITH_AUDASPACE')
363
364 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
365 B.root_build_dir = env['BF_BUILDDIR']
366 B.doc_build_dir = os.path.join(env['BF_INSTALLDIR'], 'doc')
367 if not B.root_build_dir[-1]==os.sep:
368     B.root_build_dir += os.sep
369 if not B.doc_build_dir[-1]==os.sep:
370     B.doc_build_dir += os.sep
371     
372 # We do a shortcut for clean when no quicklist is given: just delete
373 # builddir without reading in SConscripts
374 do_clean = None
375 if 'clean' in B.targets:
376     do_clean = True
377
378 if not quickie and do_clean:
379     if os.path.exists(B.doc_build_dir):
380         print B.bc.HEADER+'Cleaning doc dir...'+B.bc.ENDC
381         dirs = os.listdir(B.doc_build_dir)
382         for entry in dirs:
383             if os.path.isdir(B.doc_build_dir + entry) == 1:
384                 print "clean dir %s"%(B.doc_build_dir+entry)
385                 shutil.rmtree(B.doc_build_dir+entry)
386             else: # remove file
387                 print "remove file %s"%(B.doc_build_dir+entry)
388                 os.remove(B.root_build_dir+entry)
389     if os.path.exists(B.root_build_dir):
390         print B.bc.HEADER+'Cleaning build dir...'+B.bc.ENDC
391         dirs = os.listdir(B.root_build_dir)
392         for entry in dirs:
393             if os.path.isdir(B.root_build_dir + entry) == 1:
394                 print "clean dir %s"%(B.root_build_dir+entry)
395                 shutil.rmtree(B.root_build_dir+entry)
396             else: # remove file
397                 print "remove file %s"%(B.root_build_dir+entry)
398                 os.remove(B.root_build_dir+entry)
399         for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
400                 'extern/xvidcore/build/generic/platform.inc', 'extern/ffmpeg/include']:
401             if os.path.exists(confile):
402                 print "clean file %s"%confile
403                 if os.path.isdir(confile):
404                     for root, dirs, files in os.walk(confile):
405                         for name in files:
406                             os.remove(os.path.join(root, name))
407                 else:
408                     os.remove(confile)
409         print B.bc.OKGREEN+'...done'+B.bc.ENDC
410     else:
411         print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
412     Exit()
413
414
415 # ensure python header is found since detection can fail, this could happen
416 # with _any_ library but since we used a fixed python version this tends to
417 # be most problematic.
418 if env['WITH_BF_PYTHON']:
419         py_h = os.path.join(Dir(env.subst('${BF_PYTHON_INC}')).abspath, "Python.h")
420
421         if not os.path.exists(py_h):
422                 print("\nMissing: \"" + env.subst('${BF_PYTHON_INC}') + os.sep + "Python.h\",\n"
423                           "  Set 'BF_PYTHON_INC' to point "
424                           "to a valid python include path.\n  Containing "
425                           "Python.h for python version \"" + env.subst('${BF_PYTHON_VERSION}') + "\"")
426
427                 Exit()
428         del py_h
429
430
431 if not os.path.isdir ( B.root_build_dir):
432     os.makedirs ( B.root_build_dir )
433     os.makedirs ( B.root_build_dir + 'source' )
434     os.makedirs ( B.root_build_dir + 'intern' )
435     os.makedirs ( B.root_build_dir + 'extern' )
436     os.makedirs ( B.root_build_dir + 'lib' )
437     os.makedirs ( B.root_build_dir + 'bin' )
438 # # Docs not working with epy anymore
439 # if not os.path.isdir(B.doc_build_dir) and env['WITH_BF_DOCS']:
440 #     os.makedirs ( B.doc_build_dir )
441
442 Help(opts.GenerateHelpText(env))
443
444 # default is new quieter output, but if you need to see the 
445 # commands, do 'scons BF_QUIET=0'
446 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
447 if env['BF_QUIET']:
448     B.set_quiet_output(env)
449 else:
450     if toolset=='msvc':
451         B.msvc_hack(env)
452
453 print B.bc.HEADER+'Building in: ' + B.bc.ENDC + os.path.abspath(B.root_build_dir)
454 env.SConsignFile(B.root_build_dir+'scons-signatures')
455 B.init_lib_dict()
456
457 ##### END SETUP ##########
458
459 Export('env')
460
461 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
462 SConscript(B.root_build_dir+'/source/SConscript')
463 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
464 SConscript(B.root_build_dir+'/intern/SConscript')
465 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
466 SConscript(B.root_build_dir+'/extern/SConscript')
467
468 # now that we have read all SConscripts, we know what
469 # libraries will be built. Create list of
470 # libraries to give as objects to linking phase
471 mainlist = []
472 for tp in B.possible_types:
473     if (not tp == 'player') and (not tp == 'player2'):
474         mainlist += B.create_blender_liblist(env, tp)
475
476 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
477     B.propose_priorities()
478
479 dobj = B.buildinfo(env, "dynamic") + B.resources
480 creob = B.creator(env)
481 thestatlibs, thelibincs = B.setup_staticlibs(env)
482 thesyslibs = B.setup_syslibs(env)
483
484 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
485     env.BlenderProg(B.root_build_dir, "blender", creob + mainlist + thestatlibs + dobj, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
486 if env['WITH_BF_PLAYER']:
487     playerlist = B.create_blender_liblist(env, 'player')
488     playerlist += B.create_blender_liblist(env, 'player2')
489     playerlist += B.create_blender_liblist(env, 'intern')
490     playerlist += B.create_blender_liblist(env, 'extern')
491     env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
492
493 ##### Now define some targets
494
495
496 #------------ INSTALL
497
498 #-- binaries
499 blenderinstall = []
500 if  env['OURPLATFORM']=='darwin':
501     for prg in B.program_list:
502         bundle = '%s.app' % prg[0]
503         bundledir = os.path.dirname(bundle)
504         for dp, dn, df in os.walk(bundle):
505             if '.svn' in dn:
506                 dn.remove('.svn')
507             if '_svn' in dn:
508                 dn.remove('_svn')
509             dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
510             source=[dp+os.sep+f for f in df]
511             blenderinstall.append(env.Install(dir=dir,source=source))
512 else:
513     blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
514
515 #-- local path = config files in install dir: installdir\VERSION
516 #- dont do config and scripts for darwin, it is already in the bundle
517 dotblendlist = []
518 datafileslist = []
519 datafilestargetlist = []
520 dottargetlist = []
521 scriptinstall = []
522
523 if env['OURPLATFORM']!='darwin':
524     dotblenderinstall = []
525     for targetdir,srcfile in zip(dottargetlist, dotblendlist):
526         td, tf = os.path.split(targetdir)
527         dotblenderinstall.append(env.Install(dir=td, source=srcfile))
528     for targetdir,srcfile in zip(datafilestargetlist, datafileslist):
529         td, tf = os.path.split(targetdir)
530         dotblenderinstall.append(env.Install(dir=td, source=srcfile))
531     
532     if env['WITH_BF_PYTHON']:
533         #-- local/VERSION/scripts
534         scriptpaths=['release/scripts']
535         for scriptpath in scriptpaths:
536             for dp, dn, df in os.walk(scriptpath):
537                 if '.svn' in dn:
538                     dn.remove('.svn')
539                 if '_svn' in dn:
540                     dn.remove('_svn')
541                 if '__pycache__' in dn:  # py3.2 cache dir
542                     dn.remove('__pycache__')
543
544                 # only for testing builds
545                 if VERSION_RELEASE_CYCLE == "release" and "addons_contrib" in dn:
546                     dn.remove('addons_contrib')
547
548                 dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
549                 dir += os.sep + os.path.basename(scriptpath) + dp[len(scriptpath):]
550
551                 source=[os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
552                 # To ensure empty dirs are created too
553                 if len(source)==0:
554                     env.Execute(Mkdir(dir))
555                 scriptinstall.append(env.Install(dir=dir,source=source))
556         if env['WITH_BF_CYCLES']:
557             # cycles python code
558             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles')
559             source=os.listdir('intern/cycles/blender/addon')
560             if '.svn' in source: source.remove('.svn')
561             if '_svn' in source: source.remove('_svn')
562             if '__pycache__' in source: source.remove('__pycache__')
563             source=['intern/cycles/blender/addon/'+s for s in source]
564             scriptinstall.append(env.Install(dir=dir,source=source))
565
566             # cycles kernel code
567             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel')
568             source=os.listdir('intern/cycles/kernel')
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.remove('kernel.cpp')
573             source.remove('CMakeLists.txt')
574             source.remove('svm')
575             source.remove('osl')
576             source=['intern/cycles/kernel/'+s for s in source]
577             source.append('intern/cycles/util/util_color.h')
578             source.append('intern/cycles/util/util_math.h')
579             source.append('intern/cycles/util/util_transform.h')
580             source.append('intern/cycles/util/util_types.h')
581             scriptinstall.append(env.Install(dir=dir,source=source))
582             # svm
583             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel', 'svm')
584             source=os.listdir('intern/cycles/kernel/svm')
585             if '.svn' in source: source.remove('.svn')
586             if '_svn' in source: source.remove('_svn')
587             if '__pycache__' in source: source.remove('__pycache__')
588             source=['intern/cycles/kernel/svm/'+s for s in source]
589             scriptinstall.append(env.Install(dir=dir,source=source))
590
591             # licenses
592             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'license')
593             source=os.listdir('intern/cycles/doc/license')
594             if '.svn' in source: source.remove('.svn')
595             if '_svn' in source: source.remove('_svn')
596             if '__pycache__' in source: source.remove('__pycache__')
597             source.remove('CMakeLists.txt')
598             source=['intern/cycles/doc/license/'+s for s in source]
599             scriptinstall.append(env.Install(dir=dir,source=source))
600
601             # cuda binaries
602             if env['WITH_BF_CYCLES_CUDA_BINARIES']:
603                 dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'lib')
604                 for arch in env['BF_CYCLES_CUDA_BINARIES_ARCH']:
605                     kernel_build_dir = os.path.join(B.root_build_dir, 'intern/cycles/kernel')
606                     cubin_file = os.path.join(kernel_build_dir, "kernel_%s.cubin" % arch)
607                     scriptinstall.append(env.Install(dir=dir,source=cubin_file))
608     
609     if env['WITH_BF_INTERNATIONAL']:
610         internationalpaths=['release' + os.sep + 'datafiles']
611         
612         def check_path(path, member):
613             return (member in path.split(os.sep))
614         
615         for intpath in internationalpaths:
616             for dp, dn, df in os.walk(intpath):
617                 if '.svn' in dn:
618                     dn.remove('.svn')
619                 if '_svn' in dn:
620                     dn.remove('_svn')
621
622                 # we only care about release/datafiles/fonts, release/datafiles/locales
623                 if check_path(dp, "fonts") or check_path(dp, "locale"):
624                     pass
625                 else:
626                     continue
627                 
628                 dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
629                 dir += os.sep + os.path.basename(intpath) + dp[len(intpath):]
630
631                 source=[os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
632                 # To ensure empty dirs are created too
633                 if len(source)==0:
634                     env.Execute(Mkdir(dir))
635                 scriptinstall.append(env.Install(dir=dir,source=source))
636
637 #-- icons
638 if env['OURPLATFORM']=='linux':
639     iconlist = []
640     icontargetlist = []
641
642     for tp, tn, tf in os.walk('release/freedesktop/icons'):
643         if '.svn' in tn:
644             tn.remove('.svn')
645         if '_svn' in tn:
646             tn.remove('_svn')
647         for f in tf:
648             iconlist.append(os.path.join(tp, f))
649             icontargetlist.append( os.path.join(*([env['BF_INSTALLDIR']] + tp.split(os.sep)[2:] + [f])) )
650
651     iconinstall = []
652     for targetdir,srcfile in zip(icontargetlist, iconlist):
653         td, tf = os.path.split(targetdir)
654         iconinstall.append(env.Install(dir=td, source=srcfile))
655
656 # dlls for linuxcross
657 # TODO - add more libs, for now this lets blenderlite run
658 if env['OURPLATFORM']=='linuxcross':
659     dir=env['BF_INSTALLDIR']
660     source = []
661
662     if env['WITH_BF_OPENMP']:
663         source += ['../lib/windows/pthreads/lib/pthreadGC2.dll']
664
665     scriptinstall.append(env.Install(dir=dir, source=source))
666
667 #-- plugins
668 pluglist = []
669 plugtargetlist = []
670 for tp, tn, tf in os.walk('release/plugins'):
671     if '.svn' in tn:
672         tn.remove('.svn')
673     if '_svn' in tn:
674         tn.remove('_svn')
675     df = tp[8:] # remove 'release/'
676     for f in tf:
677         pluglist.append(os.path.join(tp, f))
678         plugtargetlist.append( os.path.join(env['BF_INSTALLDIR'], VERSION, df, f) )
679
680
681 # header files for plugins
682 pluglist.append('source/blender/blenpluginapi/documentation.h')
683 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'documentation.h'))
684 pluglist.append('source/blender/blenpluginapi/externdef.h')
685 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'externdef.h'))
686 pluglist.append('source/blender/blenpluginapi/floatpatch.h')
687 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'floatpatch.h'))
688 pluglist.append('source/blender/blenpluginapi/iff.h')
689 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'iff.h'))
690 pluglist.append('source/blender/blenpluginapi/plugin.h')
691 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'plugin.h'))
692 pluglist.append('source/blender/blenpluginapi/util.h')
693 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'util.h'))
694 pluglist.append('source/blender/blenpluginapi/plugin.DEF')
695 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'plugin.def'))
696
697 plugininstall = []
698 # plugins in blender 2.5 don't work at the moment.
699 #for targetdir,srcfile in zip(plugtargetlist, pluglist):
700 #    td, tf = os.path.split(targetdir)
701 #    plugininstall.append(env.Install(dir=td, source=srcfile))
702
703 textlist = []
704 texttargetlist = []
705 for tp, tn, tf in os.walk('release/text'):
706     if '.svn' in tn:
707         tn.remove('.svn')
708     if '_svn' in tn:
709         tn.remove('_svn')
710     for f in tf:
711         textlist.append(tp+os.sep+f)
712
713 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
714
715 if  env['OURPLATFORM']=='darwin':
716         allinstall = [blenderinstall, plugininstall, textinstall]
717 elif env['OURPLATFORM']=='linux':
718         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall, iconinstall]
719 else:
720         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
721
722 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'):
723     dllsources = []
724
725     if not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
726         # For MinGW and linuxcross static linking will be used
727         dllsources += ['${LCGDIR}/gettext/lib/gnu_gettext.dll']
728
729     dllsources += ['${BF_ZLIB_LIBPATH}/zlib.dll']
730     # Used when linking to libtiff was dynamic
731     # keep it here until compilation on all platform would be ok
732     # dllsources += ['${BF_TIFF_LIBPATH}/${BF_TIFF_LIB}.dll']
733
734     if env['OURPLATFORM'] != 'linuxcross':
735         # pthreads library is already added
736         dllsources += ['${BF_PTHREADS_LIBPATH}/${BF_PTHREADS_LIB}.dll']
737
738     if env['WITH_BF_SDL']:
739         if env['OURPLATFORM'] == 'win64-vc':
740             pass # we link statically already to SDL on win64
741         else:
742             dllsources.append('${BF_SDL_LIBPATH}/SDL.dll')
743
744     if env['WITH_BF_PYTHON']:
745         if env['BF_DEBUG']:
746             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
747         else:
748             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
749
750     if env['WITH_BF_ICONV']:
751         if env['OURPLATFORM'] == 'win64-vc':
752             pass # we link statically to iconv on win64
753         elif not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
754             #gettext for MinGW and cross-compilation is compiled staticly
755             dllsources += ['${BF_ICONV_LIBPATH}/iconv.dll']
756
757     if env['WITH_BF_OPENAL']:
758         dllsources.append('${LCGDIR}/openal/lib/OpenAL32.dll')
759
760     if env['WITH_BF_SNDFILE']:
761         dllsources.append('${LCGDIR}/sndfile/lib/libsndfile-1.dll')
762
763     if env['WITH_BF_FFMPEG']:
764         dllsources += env['BF_FFMPEG_DLL'].split()
765
766     # Since the thumb handler is loaded by Explorer, architecture is
767     # strict: the x86 build fails on x64 Windows. We need to ship
768     # both builds in x86 packages.
769     if bitness == 32:
770         dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb.dll')  
771     dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll')
772
773     if env['WITH_BF_OIIO']:
774         dllsources.append('${LCGDIR}/openimageio/bin/OpenImageIO.dll')
775
776     dllsources.append('#source/icons/blender.exe.manifest')
777
778     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
779     allinstall += windlls
780
781 installtarget = env.Alias('install', allinstall)
782 bininstalltarget = env.Alias('install-bin', blenderinstall)
783
784 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
785 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
786 nsisalias = env.Alias('nsis', nsiscmd)
787
788 if 'blender' in B.targets:
789     blenderexe= env.Alias('blender', B.program_list)
790     Depends(blenderexe,installtarget)
791
792 if env['WITH_BF_PLAYER']:
793     blenderplayer = env.Alias('blenderplayer', B.program_list)
794     Depends(blenderplayer,installtarget)
795
796 if not env['WITH_BF_GAMEENGINE']:
797     blendernogame = env.Alias('blendernogame', B.program_list)
798     Depends(blendernogame,installtarget)
799
800 if 'blenderlite' in B.targets:
801     blenderlite = env.Alias('blenderlite', B.program_list)
802     Depends(blenderlite,installtarget)
803
804 Depends(nsiscmd, allinstall)
805
806 buildslave_action = env.Action(btools.buildslave, btools.buildslave_print)
807 buildslave_cmd = env.Command('buildslave_exec', None, buildslave_action)
808 buildslave_alias = env.Alias('buildslave', buildslave_cmd)
809
810 Depends(buildslave_cmd, allinstall)
811
812 Default(B.program_list)
813
814 if not env['WITHOUT_BF_INSTALL']:
815         Default(installtarget)
816