SCons: cleaner determination of 32-bit/64-bit builds
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 sys
37 import os
38 import os.path
39 import string
40 import shutil
41 import re
42
43 # store path to tools
44 toolpath=os.path.join(".", "build_files", "scons", "tools")
45
46 # needed for importing tools
47 sys.path.append(toolpath)
48
49 import Blender
50 import btools
51
52 EnsureSConsVersion(1,0,0)
53
54 # Before we do anything, let's check if we have a sane os.environ
55 if not btools.check_environ():
56     Exit()
57
58 BlenderEnvironment = Blender.BlenderEnvironment
59 B = Blender
60
61 VERSION = btools.VERSION # This is used in creating the local config directories
62 VERSION_RELEASE_CYCLE = btools.VERSION_RELEASE_CYCLE
63
64 ### globals ###
65 platform = sys.platform
66 quickie = None
67 quickdebug = None
68
69 ##### BEGIN SETUP #####
70
71 B.possible_types = ['core', 'player', 'player2', 'intern', 'extern']
72
73 B.binarykind = ['blender' , 'blenderplayer']
74 ##################################
75 # target and argument validation #
76 ##################################
77 # XX cheating for BF_FANCY, we check for BF_FANCY before args are validated
78 use_color = ARGUMENTS.get('BF_FANCY', '1')
79 if platform=='win32':
80     use_color = None
81
82 if not use_color=='1':
83     B.bc.disable()
84
85  #on defaut white Os X terminal, some colors are totally unlegible
86 if platform=='darwin':
87     B.bc.OKGREEN = '\033[34m'
88     B.bc.WARNING = '\033[36m'
89
90 # arguments
91 print B.bc.HEADER+'Command-line arguments'+B.bc.ENDC
92 B.arguments = btools.validate_arguments(ARGUMENTS, B.bc)
93 btools.print_arguments(B.arguments, B.bc)
94
95 # targets
96 print B.bc.HEADER+'Command-line targets'+B.bc.ENDC
97 B.targets = btools.validate_targets(COMMAND_LINE_TARGETS, B.bc)
98 btools.print_targets(B.targets, B.bc)
99
100 ##########################
101 # setting up environment #
102 ##########################
103
104 # handling cmd line arguments & config file
105
106 # bitness stuff
107 tempbitness = int(B.arguments.get('BF_BITNESS', B.bitness)) # default to bitness found as per starting python
108 if tempbitness in B.allowed_bitnesses.values() :
109     B.bitness = tempbitness
110
111 # first check cmdline for toolset and we create env to work on
112 quickie = B.arguments.get('BF_QUICK', None)
113 quickdebug = B.arguments.get('BF_QUICKDEBUG', None)
114
115 if quickdebug:
116     B.quickdebug=string.split(quickdebug, ',')
117 else:
118     B.quickdebug=[]
119
120 if quickie:
121     B.quickie=string.split(quickie,',')
122 else:
123     B.quickie=[]
124
125 toolset = B.arguments.get('BF_TOOLSET', None)
126 vcver = B.arguments.get('MSVS_VERSION', '9.0')
127
128 if toolset:
129     print "Using " + toolset
130     if toolset=='mstoolkit':
131         env = BlenderEnvironment(ENV = os.environ)
132         env.Tool('mstoolkit', [toolpath])
133     else:
134         env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
135         if env:
136             btools.SetupSpawn(env)
137 else:
138     if B.bitness==64 and platform=='win32':
139         env = BlenderEnvironment(ENV = os.environ, MSVS_ARCH='amd64', TARGET_ARCH='x86_64', MSVC_VERSION=vcver)
140     else:
141         env = BlenderEnvironment(ENV = os.environ, TARGET_ARCH='x86', MSVC_VERSION=vcver)
142
143 if not env:
144     print "Could not create a build environment"
145     Exit()
146
147 cc = B.arguments.get('CC', None)
148 cxx = B.arguments.get('CXX', None)
149 if cc:
150     env['CC'] = cc
151 if cxx:
152     env['CXX'] = cxx
153
154 if sys.platform=='win32':
155     if env['CC'] in ['cl', 'cl.exe']:
156         platform = 'win64-vc' if B.bitness == 64 else 'win32-vc'
157     elif env['CC'] in ['gcc']:
158         platform = 'win64-mingw' if B.bitness == 64 else 'win32-mingw'
159
160 if 'mingw' in platform:
161     print "Setting custom spawn function"
162     btools.SetupSpawn(env)
163
164 env.SConscriptChdir(0)
165
166 # Remove major kernel version from linux platform.
167 # After Linus switched kernel to new version model this major version
168 # shouldn't take much sense for building rules.
169
170 if re.match('linux[0-9]+', platform):
171     platform = 'linux'
172
173 crossbuild = B.arguments.get('BF_CROSS', None)
174 if crossbuild and platform not in ('win32-vc', 'win64-vc'):
175     platform = 'linuxcross'
176
177 env['OURPLATFORM'] = platform
178
179 configfile = os.path.join("build_files", "scons", "config", platform + "-config.py")
180
181 if os.path.exists(configfile):
182     print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
183 else:
184     print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
185
186 if crossbuild and env['PLATFORM'] != 'win32':
187     print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
188     env.Tool('crossmingw', [toolpath])
189     # todo: determine proper libs/includes etc.
190     # Needed for gui programs, console programs should do without it
191
192     # Now we don't need this option to have console window
193     # env.Append(LINKFLAGS=['-mwindows'])
194
195 userconfig = B.arguments.get('BF_CONFIG', 'user-config.py')
196 # first read platform config. B.arguments will override
197 optfiles = [configfile]
198 if os.path.exists(userconfig):
199     print B.bc.OKGREEN + "Using user-config file: " + B.bc.ENDC + userconfig
200     optfiles += [userconfig]
201 else:
202     print B.bc.WARNING + userconfig + " not found, no user overrides" + B.bc.ENDC
203
204 opts = btools.read_opts(env, optfiles, B.arguments)
205 opts.Update(env)
206
207 if sys.platform=='win32':
208     if B.bitness==64:
209         env.Append(CPPFLAGS=['-DWIN64']) # -DWIN32 needed too, as it's used all over to target Windows generally
210
211 if not env['BF_FANCY']:
212     B.bc.disable()
213
214
215 # remove install dir so old and new files are not mixed.
216 # NOTE: only do the scripts directory for now, otherwise is too disruptive for developers
217 # TODO: perhaps we need an option (off by default) to not do this altogether...
218 if not env['WITHOUT_BF_INSTALL'] and not env['WITHOUT_BF_OVERWRITE_INSTALL']:
219     scriptsDir = os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts')
220     if os.path.isdir(scriptsDir):
221         print B.bc.OKGREEN + "Clearing installation directory%s: %s" % (B.bc.ENDC, os.path.abspath(scriptsDir))
222         shutil.rmtree(scriptsDir)
223
224
225 SetOption('num_jobs', int(env['BF_NUMJOBS']))
226 print B.bc.OKGREEN + "Build with parallel jobs%s: %s" % (B.bc.ENDC, GetOption('num_jobs'))
227 print B.bc.OKGREEN + "Build with debug symbols%s: %s" % (B.bc.ENDC, env['BF_DEBUG'])
228
229 if 'blenderlite' in B.targets:
230     target_env_defs = {}
231     target_env_defs['WITH_BF_GAMEENGINE'] = False
232     target_env_defs['WITH_BF_CYCLES'] = False
233     target_env_defs['WITH_BF_OPENAL'] = False
234     target_env_defs['WITH_BF_OPENEXR'] = False
235     target_env_defs['WITH_BF_PSD'] = False
236     target_env_defs['WITH_BF_OPENMP'] = False
237     target_env_defs['WITH_BF_ICONV'] = False
238     target_env_defs['WITH_BF_INTERNATIONAL'] = False
239     target_env_defs['WITH_BF_OPENJPEG'] = False
240     target_env_defs['WITH_BF_FFMPEG'] = False
241     target_env_defs['WITH_BF_QUICKTIME'] = False
242     target_env_defs['WITH_BF_REDCODE'] = False
243     target_env_defs['WITH_BF_DDS'] = False
244     target_env_defs['WITH_BF_CINEON'] = False
245     target_env_defs['WITH_BF_FRAMESERVER'] = False
246     target_env_defs['WITH_BF_HDR'] = False
247     target_env_defs['WITH_BF_ZLIB'] = False
248     target_env_defs['WITH_BF_SDL'] = False
249     target_env_defs['WITH_BF_JPEG'] = False
250     target_env_defs['WITH_BF_PNG'] = False
251     target_env_defs['WITH_BF_BULLET'] = False
252     target_env_defs['WITH_BF_BINRELOC'] = False
253     target_env_defs['BF_BUILDINFO'] = False
254     target_env_defs['WITH_BF_FLUID'] = False
255     target_env_defs['WITH_BF_OCEANSIM'] = False
256     target_env_defs['WITH_BF_SMOKE'] = False
257     target_env_defs['WITH_BF_BOOLEAN'] = False
258     target_env_defs['WITH_BF_REMESH'] = False
259     target_env_defs['WITH_BF_PYTHON'] = False
260     target_env_defs['WITH_BF_3DMOUSE'] = False
261     target_env_defs['WITH_BF_LIBMV'] = False
262     target_env_defs['WITH_BF_FREESTYLE'] = 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 if 'cudakernels' in B.targets:
270     env['WITH_BF_CYCLES'] = True
271     env['WITH_BF_CYCLES_CUDA_BINARIES'] = True
272     env['WITH_BF_PYTHON'] = False
273
274 # Configure paths for automated configuration test programs
275 env['CONFIGUREDIR'] = os.path.abspath(os.path.normpath(os.path.join(env['BF_BUILDDIR'], "sconf_temp")))
276 env['CONFIGURELOG'] = os.path.abspath(os.path.normpath(os.path.join(env['BF_BUILDDIR'], "config.log")))
277
278 #############################################################################
279 ###################    Automatic configuration for OSX     ##################
280 #############################################################################
281
282 if env['OURPLATFORM']=='darwin':
283
284     import commands
285     import subprocess
286
287     command = ["%s"%env['CC'], "--version"]
288     process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, shell=False)
289     line = process.communicate()[0]
290     ver = re.search(r'[0-9]+(\.[0-9]+)+', line)
291     if ver:
292         env['CCVERSION'] = ver.group(0)
293     frontend = re.search(r'gcc', line) or re.search(r'clang', line) or re.search(r'llvm-gcc', line)  or re.search(r'icc', line)
294     if frontend:
295         env['C_COMPILER_ID'] = frontend.group(0)
296
297     print B.bc.OKGREEN + "Using Compiler: " + B.bc.ENDC + env['C_COMPILER_ID'] + '-' + env['CCVERSION']
298
299     cmd = 'sw_vers -productVersion'
300     MAC_CUR_VER=cmd_res=commands.getoutput(cmd)
301     cmd = 'xcodebuild -version'
302     cmd_xcode=commands.getoutput(cmd)
303     env['XCODE_CUR_VER']=cmd_xcode[6:][:3] # truncate output to major.minor version
304     cmd = 'xcodebuild -showsdks'
305     cmd_sdk=commands.getoutput(cmd)
306     MACOSX_SDK_CHECK=cmd_sdk
307     cmd = 'xcode-select --print-path'
308     XCODE_SELECT_PATH=commands.getoutput(cmd)
309     if XCODE_SELECT_PATH.endswith("/Contents/Developer"):
310         XCODE_BUNDLE=XCODE_SELECT_PATH[:-19]
311     else:
312         XCODE_BUNDLE=XCODE_SELECT_PATH
313
314     print B.bc.OKGREEN + "Detected Xcode version: -- " + B.bc.ENDC + env['XCODE_CUR_VER'] + " --"
315     print B.bc.OKGREEN + "Available SDK's: \n" + B.bc.ENDC + MACOSX_SDK_CHECK.replace('\t', '')
316
317     if env['MACOSX_SDK'] == '': # no set sdk, choosing best one found
318         if 'OS X 10.9' in MACOSX_SDK_CHECK:
319             env['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
320             env['MACOSX_SDK']='/Developer/SDKs/MacOSX10.9.sdk'
321         elif 'OS X 10.8' in MACOSX_SDK_CHECK:
322             env['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
323             env['MACOSX_SDK']='/Developer/SDKs/MacOSX10.8.sdk'
324         elif 'OS X 10.7' in MACOSX_SDK_CHECK:
325             env['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
326             env['MACOSX_SDK']='/Developer/SDKs/MacOSX10.7.sdk'
327         elif 'OS X 10.6' in MACOSX_SDK_CHECK:
328             env['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
329             env['MACOSX_SDK']='/Developer/SDKs/MacOSX10.6.sdk'
330         elif 'OS X 10.5' in MACOSX_SDK_CHECK:
331             env['MACOSX_DEPLOYMENT_TARGET'] = '10.5'
332             env['MACOSX_SDK']='/Developer/SDKs/MacOSX10.5.sdk'
333     else:
334         env['MACOSX_SDK']='/Developer/SDKs/MacOSX' + env['MACOSX_SDK'] + '.sdk'
335
336     if env['XCODE_CUR_VER'] >= '4.3':  ## since version 4.3, XCode and developer dir are bundled ##
337          env['MACOSX_SDK'] = XCODE_BUNDLE + '/Contents/Developer/Platforms/MacOSX.platform' +  env['MACOSX_SDK']
338
339     print B.bc.OKGREEN + "Using OSX SDK :" + B.bc.ENDC + env['MACOSX_SDK']
340                 
341     if not env['WITH_OSX_STATICPYTHON'] == 1:
342         # python 3.3 uses Python-framework additionally installed in /Library/Frameworks
343         env['BF_PYTHON'] = '/Library/Frameworks/Python.framework/Versions/'
344         env['BF_PYTHON_INC'] = env['BF_PYTHON'] + env['BF_PYTHON_VERSION'] + '/include/python' + env['BF_PYTHON_VERSION'] + 'm'
345         env['BF_PYTHON_BINARY'] = env['BF_PYTHON'] + env['BF_PYTHON_VERSION'] + '/bin/python' + env['BF_PYTHON_VERSION']
346         env['BF_PYTHON_LIB'] = ''
347         env['BF_PYTHON_LIBPATH'] = env['BF_PYTHON'] + env['BF_PYTHON_VERSION'] + '/lib/python' + env['BF_PYTHON_VERSION'] + '/config-' + env['BF_PYTHON_VERSION'] +'m'
348         env['PLATFORM_LINKFLAGS'] = env['PLATFORM_LINKFLAGS']+['-framework','Python'] # link to python framework
349
350     #Ray trace optimization
351     if env['WITH_BF_RAYOPTIMIZATION'] == 1:
352         if env['MACOSX_ARCHITECTURE'] == 'x86_64' or env['MACOSX_ARCHITECTURE'] == 'i386':
353             env['WITH_BF_RAYOPTIMIZATION'] = 1
354         else:
355             env['WITH_BF_RAYOPTIMIZATION'] = 0
356         if env['MACOSX_ARCHITECTURE'] == 'i386':
357             env['BF_RAYOPTIMIZATION_SSE_FLAGS'] = env['BF_RAYOPTIMIZATION_SSE_FLAGS']+['-msse']
358         elif env['MACOSX_ARCHITECTURE'] == 'x86_64':
359             env['BF_RAYOPTIMIZATION_SSE_FLAGS'] = env['BF_RAYOPTIMIZATION_SSE_FLAGS']+['-msse','-msse2']
360
361     if env['MACOSX_ARCHITECTURE'] == 'x86_64' or env['MACOSX_ARCHITECTURE'] == 'ppc64':
362         ARCH_FLAGS = ['-m64']
363     else:
364         ARCH_FLAGS = ['-m32']
365
366     env.Append(CPPFLAGS=ARCH_FLAGS)
367
368     SDK_FLAGS=['-isysroot',  env['MACOSX_SDK'],'-mmacosx-version-min='+ env['MACOSX_DEPLOYMENT_TARGET'],'-arch',env['MACOSX_ARCHITECTURE']] # always used
369     env['PLATFORM_LINKFLAGS'] = ['-mmacosx-version-min='+ env['MACOSX_DEPLOYMENT_TARGET'],'-isysroot', env['MACOSX_SDK'],'-arch',env['MACOSX_ARCHITECTURE']]+ARCH_FLAGS+env['PLATFORM_LINKFLAGS']
370     env['CCFLAGS']=SDK_FLAGS+env['CCFLAGS']
371     env['CXXFLAGS']=SDK_FLAGS+env['CXXFLAGS']
372
373     #Intel Macs are CoreDuo and Up
374     if env['MACOSX_ARCHITECTURE'] == 'i386' or env['MACOSX_ARCHITECTURE'] == 'x86_64':
375         env['REL_CCFLAGS'] = env['REL_CCFLAGS']+['-msse','-msse2','-msse3']
376         if env['C_COMPILER_ID'] != 'clang' or (env['C_COMPILER_ID'] == 'clang' and env['CCVERSION'] >= '5.0'):
377             env['REL_CCFLAGS'] = env['REL_CCFLAGS']+['-ftree-vectorize'] # clang xcode 4 does not accept flag
378     else:
379         env['CCFLAGS'] =  env['CCFLAGS']+['-fno-strict-aliasing']
380
381     # Intel 64bit Macs are Core2Duo and up
382     if env['MACOSX_ARCHITECTURE'] == 'x86_64':
383         env['REL_CCFLAGS'] = env['REL_CCFLAGS']+['-mssse3']
384
385     if env['C_COMPILER_ID'] == 'clang' and env['CCVERSION'] >= '5.0':
386         env['CCFLAGS'].append('-ftemplate-depth=1024') # only valid for clang bundled with xcode 5
387
388     # 3DconnexionClient.framework, optionally install
389     if env['WITH_BF_3DMOUSE'] == 1:
390         if not os.path.exists('/Library/Frameworks/3DconnexionClient.framework'):
391             env['WITH_BF_3DMOUSE'] = 0
392             print B.bc.OKGREEN + "3DconnexionClient install not found, disabling WITH_BF_3DMOUSE" # avoid build errors !
393         else:
394             env.Append(LINKFLAGS=['-F/Library/Frameworks','-Xlinker','-weak_framework','-Xlinker','3DconnexionClient'])
395             env['BF_3DMOUSE_INC'] = '/Library/Frameworks/3DconnexionClient.framework/Headers'
396             print B.bc.OKGREEN + "Using 3Dconnexion"
397
398     # Jackmp.framework, optionally install
399     if env['WITH_BF_JACK'] == 1:
400         if not os.path.exists('/Library/Frameworks/Jackmp.framework'):
401             env['WITH_BF_JACK'] = 0
402             print B.bc.OKGREEN + "JackOSX install not found, disabling WITH_BF_JACK" # avoid build errors !
403         else:
404             env.Append(LINKFLAGS=['-F/Library/Frameworks','-Xlinker','-weak_framework','-Xlinker','Jackmp'])
405             print B.bc.OKGREEN + "Using Jack"
406
407     if env['WITH_BF_QUICKTIME'] == 1:
408         env['PLATFORM_LINKFLAGS'] = env['PLATFORM_LINKFLAGS']+['-framework','QTKit']
409
410     #Defaults openMP to true if compiler handles it ( only gcc 4.6.1 and newer )
411     # if your compiler does not have accurate suffix you may have to enable it by hand !
412     if env['WITH_BF_OPENMP'] == 1:
413         if env['C_COMPILER_ID'] == 'gcc' and env['CCVERSION'] >= '4.6.1': # strip down to version string if any
414             env['WITH_BF_OPENMP'] = 1  # multithreading for fluids, cloth, sculpt and smoke
415             print B.bc.OKGREEN + "Using OpenMP"
416         else:
417             env['WITH_BF_OPENMP'] = 0
418             print B.bc.OKGREEN + "Disabled OpenMP, not supported by compiler"
419
420     if env['WITH_BF_CYCLES_OSL'] == 1:
421         OSX_OSL_LIBPATH = Dir(env.subst(env['BF_OSL_LIBPATH'])).abspath
422         # we need 2 variants of passing the oslexec with the force_load option, string and list type atm
423         if env['C_COMPILER_ID'] == 'gcc' and env['CCVERSION'] >= '4.8': # strip down to version string if any
424             env.Append(LINKFLAGS=['-L'+OSX_OSL_LIBPATH,'-loslcomp','-loslexec','-loslquery'])
425         else:
426             env.Append(LINKFLAGS=['-L'+OSX_OSL_LIBPATH,'-loslcomp','-force_load '+ OSX_OSL_LIBPATH +'/liboslexec.a','-loslquery'])
427         env.Append(BF_PROGRAM_LINKFLAGS=['-Xlinker','-force_load','-Xlinker',OSX_OSL_LIBPATH +'/liboslexec.a'])
428
429     # Trying to get rid of eventually clashes, we export some symbols explicite as local
430     env.Append(LINKFLAGS=['-Xlinker','-unexported_symbols_list','-Xlinker','./source/creator/osx_locals.map'])
431     
432     #for < 10.7.sdk, SystemStubs needs to be linked
433     if  env['MACOSX_SDK'].endswith("10.6.sdk") or  env['MACOSX_SDK'].endswith("10.5.sdk"):
434         env['LLIBS'].append('SystemStubs')
435
436 #############################################################################
437 ###################  End Automatic configuration for OSX   ##################
438 #############################################################################
439
440 if env['WITH_BF_OPENMP'] == 1:
441         if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
442                 env['CCFLAGS'].append('/openmp')
443         else:
444             if env['CC'].endswith('icc'): # to be able to handle CC=/opt/bla/icc case
445                 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
446                 env['CCFLAGS'].append('-openmp')
447             else:
448                 env.Append(CCFLAGS=['-fopenmp'])
449
450 #check for additional debug libnames
451
452 if env.has_key('BF_DEBUG_LIBS'):
453     B.quickdebug += env['BF_DEBUG_LIBS']
454
455 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
456
457 if len(B.quickdebug) > 0 and printdebug != 0:
458     print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
459     for l in B.quickdebug:
460         print "\t" + l
461
462 # remove stdc++ from LLIBS if we are building a statc linked CXXFLAGS
463 if env['WITH_BF_STATICCXX']:
464     if 'stdc++' in env['LLIBS']:
465         env['LLIBS'].remove('stdc++')
466     else:
467         print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
468
469 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
470 if 'blenderplayer' in B.targets:
471     env['WITH_BF_PLAYER'] = True
472
473 if 'blendernogame' in B.targets:
474     env['WITH_BF_GAMEENGINE'] = False
475
476 if not env['WITH_BF_GAMEENGINE']:
477     env['WITH_BF_PLAYER'] = False
478
479 # build without elbeem (fluidsim)?
480 if env['WITH_BF_FLUID'] == 1:
481     env['CPPFLAGS'].append('-DWITH_MOD_FLUID')
482
483 # build with ocean sim?
484 if env['WITH_BF_OCEANSIM'] == 1:
485     env['WITH_BF_FFTW3']  = 1  # ocean needs fftw3 so enable it
486     env['CPPFLAGS'].append('-DWITH_MOD_OCEANSIM')
487
488
489 if btools.ENDIAN == "big":
490     env['CPPFLAGS'].append('-D__BIG_ENDIAN__')
491 else:
492     env['CPPFLAGS'].append('-D__LITTLE_ENDIAN__')
493
494 # TODO, make optional (as with CMake)
495 env['CPPFLAGS'].append('-DWITH_AUDASPACE')
496 env['CPPFLAGS'].append('-DWITH_AVI')
497 env['CPPFLAGS'].append('-DWITH_OPENNL')
498 env['CPPFLAGS'].append('-DWITH_BOOL_COMPAT')
499 if env['OURPLATFORM'] in ('win32-vc', 'win64-vc') and env['MSVC_VERSION'] == '11.0':
500     env['CPPFLAGS'].append('-D_ALLOW_KEYWORD_MACROS')
501
502 if env['OURPLATFORM'] not in ('win32-vc', 'win64-vc'):
503     env['CPPFLAGS'].append('-DHAVE_STDBOOL_H')
504
505 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
506 B.root_build_dir = env['BF_BUILDDIR']
507 B.doc_build_dir = os.path.join(env['BF_INSTALLDIR'], 'doc')
508 if not B.root_build_dir[-1]==os.sep:
509     B.root_build_dir += os.sep
510 if not B.doc_build_dir[-1]==os.sep:
511     B.doc_build_dir += os.sep
512
513 # We do a shortcut for clean when no quicklist is given: just delete
514 # builddir without reading in SConscripts
515 do_clean = None
516 if 'clean' in B.targets:
517     do_clean = True
518
519 if not quickie and do_clean:
520     if os.path.exists(B.doc_build_dir):
521         print B.bc.HEADER+'Cleaning doc dir...'+B.bc.ENDC
522         dirs = os.listdir(B.doc_build_dir)
523         for entry in dirs:
524             if os.path.isdir(B.doc_build_dir + entry) == 1:
525                 print "clean dir %s"%(B.doc_build_dir+entry)
526                 shutil.rmtree(B.doc_build_dir+entry)
527             else: # remove file
528                 print "remove file %s"%(B.doc_build_dir+entry)
529                 os.remove(B.root_build_dir+entry)
530     if os.path.exists(B.root_build_dir):
531         print B.bc.HEADER+'Cleaning build dir...'+B.bc.ENDC
532         dirs = os.listdir(B.root_build_dir)
533         for entry in dirs:
534             if os.path.isdir(B.root_build_dir + entry) == 1:
535                 print "clean dir %s"%(B.root_build_dir+entry)
536                 shutil.rmtree(B.root_build_dir+entry)
537             else: # remove file
538                 print "remove file %s"%(B.root_build_dir+entry)
539                 os.remove(B.root_build_dir+entry)
540         for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
541                 'extern/xvidcore/build/generic/platform.inc', 'extern/ffmpeg/include']:
542             if os.path.exists(confile):
543                 print "clean file %s"%confile
544                 if os.path.isdir(confile):
545                     for root, dirs, files in os.walk(confile):
546                         for name in files:
547                             os.remove(os.path.join(root, name))
548                 else:
549                     os.remove(confile)
550         print B.bc.OKGREEN+'...done'+B.bc.ENDC
551     else:
552         print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
553     Exit()
554
555
556 # ensure python header is found since detection can fail, this could happen
557 # with _any_ library but since we used a fixed python version this tends to
558 # be most problematic.
559 if env['WITH_BF_PYTHON']:
560     found_python_h = found_pyconfig_h = False
561     for bf_python_inc in env.subst('${BF_PYTHON_INC}').split():
562         py_h = os.path.join(Dir(bf_python_inc).abspath, "Python.h")
563         if os.path.exists(py_h):
564             found_python_h = True
565         py_h = os.path.join(Dir(bf_python_inc).abspath, "pyconfig.h")
566         if os.path.exists(py_h):
567             found_pyconfig_h = True
568
569     if not (found_python_h and found_pyconfig_h):
570         print("""\nMissing: Python.h and/or pyconfig.h in "%s"
571          Set 'BF_PYTHON_INC' to point to valid include path(s),
572          containing Python.h and pyconfig.h for Python version "%s".
573
574          Example: python scons/scons.py BF_PYTHON_INC=../Python/include
575               """ % (env.subst('${BF_PYTHON_INC}'), env.subst('${BF_PYTHON_VERSION}')))
576         Exit()
577
578
579 if not os.path.isdir ( B.root_build_dir):
580     os.makedirs ( B.root_build_dir )
581     os.makedirs ( B.root_build_dir + 'source' )
582     os.makedirs ( B.root_build_dir + 'intern' )
583     os.makedirs ( B.root_build_dir + 'extern' )
584     os.makedirs ( B.root_build_dir + 'lib' )
585     os.makedirs ( B.root_build_dir + 'bin' )
586 # # Docs not working with epy anymore
587 # if not os.path.isdir(B.doc_build_dir) and env['WITH_BF_DOCS']:
588 #     os.makedirs ( B.doc_build_dir )
589
590 ###################################
591 # Ensure all data files are valid #
592 ###################################
593 if not os.path.isdir ( B.root_build_dir + 'data_headers'):
594     os.makedirs ( B.root_build_dir + 'data_headers' )
595 if not os.path.isdir ( B.root_build_dir + 'data_sources'):
596     os.makedirs ( B.root_build_dir + 'data_sources' )
597 # use for includes
598 env['DATA_HEADERS'] = os.path.join(os.path.abspath(env['BF_BUILDDIR']), "data_headers")
599 env['DATA_SOURCES'] = os.path.join(os.path.abspath(env['BF_BUILDDIR']), "data_sources")
600 def data_to_c(FILE_FROM, FILE_TO, VAR_NAME):
601     if os.sep == "\\":
602         FILE_FROM = FILE_FROM.replace("/", "\\")
603         FILE_TO   = FILE_TO.replace("/", "\\")
604
605     # first check if we need to bother.
606     if os.path.exists(FILE_TO):
607         if os.path.getmtime(FILE_FROM) < os.path.getmtime(FILE_TO):
608             return
609
610     print(B.bc.HEADER + "Generating: " + B.bc.ENDC + "%r" % os.path.basename(FILE_TO))
611     fpin = open(FILE_FROM, "rb")
612     fpin.seek(0, os.SEEK_END)
613     size = fpin.tell()
614     fpin.seek(0)
615
616     fpout = open(FILE_TO, "w")
617     fpout.write("int  %s_size = %d;\n" % (VAR_NAME, size))
618     fpout.write("char %s[] = {\n" % VAR_NAME)
619
620     while size > 0:
621         size -= 1
622         if size % 32 == 31:
623             fpout.write("\n")
624
625         fpout.write("%3d," % ord(fpin.read(1)))
626     fpout.write("\n  0};\n\n")
627
628     fpin.close()
629     fpout.close()
630
631 def data_to_c_simple(FILE_FROM):
632         filename_only = os.path.basename(FILE_FROM)
633         FILE_TO = os.path.join(env['DATA_SOURCES'], filename_only + ".c")
634         VAR_NAME = "datatoc_" + filename_only.replace(".", "_")
635
636         data_to_c(FILE_FROM, FILE_TO, VAR_NAME)
637
638
639 def data_to_c_simple_icon(PATH_FROM):
640
641     # first handle import
642     import sys
643     path = "source/blender/datatoc"
644     if path not in sys.path:
645         sys.path.append(path)
646
647     # convert the pixmaps to a png
648     import datatoc_icon
649
650     filename_only = os.path.basename(PATH_FROM)
651     FILE_TO_PNG = os.path.join(env['DATA_SOURCES'], filename_only + ".png")
652     FILE_TO = FILE_TO_PNG + ".c"
653     argv = [PATH_FROM, FILE_TO_PNG]
654     datatoc_icon.main_ex(argv)
655
656     # then the png to a c file
657     data_to_c_simple(FILE_TO_PNG)
658
659
660 if B.targets != ['cudakernels']:
661     data_to_c("source/blender/compositor/operations/COM_OpenCLKernels.cl",
662               B.root_build_dir + "data_headers/COM_OpenCLKernels.cl.h",
663               "datatoc_COM_OpenCLKernels_cl")
664
665     data_to_c_simple("release/datafiles/startup.blend")
666     data_to_c_simple("release/datafiles/preview.blend")
667     data_to_c_simple("release/datafiles/preview_cycles.blend")
668
669     # --- glsl ---
670     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_simple_frag.glsl")
671     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_simple_vert.glsl")
672     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_material.glsl")
673     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_material.glsl")
674     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl")
675     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl")
676     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vertex.glsl")
677     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl")
678     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl")
679     data_to_c_simple("intern/opencolorio/gpu_shader_display_transform.glsl")
680
681     # --- blender ---
682     data_to_c_simple("release/datafiles/bfont.pfb")
683     data_to_c_simple("release/datafiles/bfont.ttf")
684     data_to_c_simple("release/datafiles/bmonofont.ttf")
685
686     data_to_c_simple("release/datafiles/splash.png")
687
688     # data_to_c_simple("release/datafiles/blender_icons16.png")
689     # data_to_c_simple("release/datafiles/blender_icons32.png")
690     data_to_c_simple_icon("release/datafiles/blender_icons16")
691     data_to_c_simple_icon("release/datafiles/blender_icons32")
692
693     data_to_c_simple("release/datafiles/prvicons.png")
694
695     data_to_c_simple("release/datafiles/brushicons/add.png")
696     data_to_c_simple("release/datafiles/brushicons/blob.png")
697     data_to_c_simple("release/datafiles/brushicons/blur.png")
698     data_to_c_simple("release/datafiles/brushicons/clay.png")
699     data_to_c_simple("release/datafiles/brushicons/claystrips.png")
700     data_to_c_simple("release/datafiles/brushicons/clone.png")
701     data_to_c_simple("release/datafiles/brushicons/crease.png")
702     data_to_c_simple("release/datafiles/brushicons/darken.png")
703     data_to_c_simple("release/datafiles/brushicons/draw.png")
704     data_to_c_simple("release/datafiles/brushicons/fill.png")
705     data_to_c_simple("release/datafiles/brushicons/flatten.png")
706     data_to_c_simple("release/datafiles/brushicons/grab.png")
707     data_to_c_simple("release/datafiles/brushicons/inflate.png")
708     data_to_c_simple("release/datafiles/brushicons/layer.png")
709     data_to_c_simple("release/datafiles/brushicons/lighten.png")
710     data_to_c_simple("release/datafiles/brushicons/mask.png")
711     data_to_c_simple("release/datafiles/brushicons/mix.png")
712     data_to_c_simple("release/datafiles/brushicons/multiply.png")
713     data_to_c_simple("release/datafiles/brushicons/nudge.png")
714     data_to_c_simple("release/datafiles/brushicons/pinch.png")
715     data_to_c_simple("release/datafiles/brushicons/scrape.png")
716     data_to_c_simple("release/datafiles/brushicons/smear.png")
717     data_to_c_simple("release/datafiles/brushicons/smooth.png")
718     data_to_c_simple("release/datafiles/brushicons/snake_hook.png")
719     data_to_c_simple("release/datafiles/brushicons/soften.png")
720     data_to_c_simple("release/datafiles/brushicons/subtract.png")
721     data_to_c_simple("release/datafiles/brushicons/texdraw.png")
722     data_to_c_simple("release/datafiles/brushicons/thumb.png")
723     data_to_c_simple("release/datafiles/brushicons/twist.png")
724     data_to_c_simple("release/datafiles/brushicons/vertexdraw.png")
725
726     data_to_c_simple("release/datafiles/matcaps/mc01.jpg")
727     data_to_c_simple("release/datafiles/matcaps/mc02.jpg")
728     data_to_c_simple("release/datafiles/matcaps/mc03.jpg")
729     data_to_c_simple("release/datafiles/matcaps/mc04.jpg")
730     data_to_c_simple("release/datafiles/matcaps/mc05.jpg")
731     data_to_c_simple("release/datafiles/matcaps/mc06.jpg")
732     data_to_c_simple("release/datafiles/matcaps/mc07.jpg")
733     data_to_c_simple("release/datafiles/matcaps/mc08.jpg")
734     data_to_c_simple("release/datafiles/matcaps/mc09.jpg")
735     data_to_c_simple("release/datafiles/matcaps/mc10.jpg")
736     data_to_c_simple("release/datafiles/matcaps/mc11.jpg")
737     data_to_c_simple("release/datafiles/matcaps/mc12.jpg")
738     data_to_c_simple("release/datafiles/matcaps/mc13.jpg")
739     data_to_c_simple("release/datafiles/matcaps/mc14.jpg")
740     data_to_c_simple("release/datafiles/matcaps/mc15.jpg")
741     data_to_c_simple("release/datafiles/matcaps/mc16.jpg")
742     data_to_c_simple("release/datafiles/matcaps/mc17.jpg")
743     data_to_c_simple("release/datafiles/matcaps/mc18.jpg")
744     data_to_c_simple("release/datafiles/matcaps/mc19.jpg")
745     data_to_c_simple("release/datafiles/matcaps/mc20.jpg")
746     data_to_c_simple("release/datafiles/matcaps/mc21.jpg")
747     data_to_c_simple("release/datafiles/matcaps/mc22.jpg")
748     data_to_c_simple("release/datafiles/matcaps/mc23.jpg")
749     data_to_c_simple("release/datafiles/matcaps/mc24.jpg")
750
751 ##### END DATAFILES ##########
752
753 Help(opts.GenerateHelpText(env))
754
755 # default is new quieter output, but if you need to see the
756 # commands, do 'scons BF_QUIET=0'
757 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
758 if env['BF_QUIET']:
759     B.set_quiet_output(env)
760 else:
761     if toolset=='msvc':
762         B.msvc_hack(env)
763
764 print B.bc.HEADER+'Building in: ' + B.bc.ENDC + os.path.abspath(B.root_build_dir)
765 env.SConsignFile(B.root_build_dir+'scons-signatures')
766 B.init_lib_dict()
767
768 ##### END SETUP ##########
769
770 Export('env')
771
772 VariantDir(B.root_build_dir+'/source', 'source', duplicate=0)
773 SConscript(B.root_build_dir+'/source/SConscript')
774 VariantDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
775 SConscript(B.root_build_dir+'/intern/SConscript')
776 VariantDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
777 SConscript(B.root_build_dir+'/extern/SConscript')
778
779 # now that we have read all SConscripts, we know what
780 # libraries will be built. Create list of
781 # libraries to give as objects to linking phase
782 mainlist = []
783 for tp in B.possible_types:
784     if (not tp == 'player') and (not tp == 'player2'):
785         mainlist += B.create_blender_liblist(env, tp)
786
787 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
788     B.propose_priorities()
789
790 dobj = B.buildinfo(env, "dynamic") + B.resources
791 creob = B.creator(env)
792 thestatlibs, thelibincs = B.setup_staticlibs(env)
793 thesyslibs = B.setup_syslibs(env)
794
795 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
796     env.BlenderProg(B.root_build_dir, "blender", creob + mainlist + thestatlibs + dobj, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
797 if env['WITH_BF_PLAYER']:
798     playerlist = B.create_blender_liblist(env, 'player')
799     playerlist += B.create_blender_liblist(env, 'player2')
800     playerlist += B.create_blender_liblist(env, 'intern')
801     playerlist += B.create_blender_liblist(env, 'extern')
802     env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
803
804 ##### Now define some targets
805
806
807 #------------ INSTALL
808
809 #-- binaries
810 blenderinstall = []
811 if  env['OURPLATFORM']=='darwin':
812     for prg in B.program_list:
813         bundle = '%s.app' % prg[0]
814         bundledir = os.path.dirname(bundle)
815         for dp, dn, df in os.walk(bundle):
816             if '.svn' in dn:
817                 dn.remove('.svn')
818             if '_svn' in dn:
819                 dn.remove('_svn')
820             if '.git' in df:
821                 df.remove('.git')
822             dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
823             source=[dp+os.sep+f for f in df]
824             blenderinstall.append(env.Install(dir=dir,source=source))
825 else:
826     blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
827
828 #-- local path = config files in install dir: installdir\VERSION
829 #- dont do config and scripts for darwin, it is already in the bundle
830 dotblendlist = []
831 datafileslist = []
832 datafilestargetlist = []
833 dottargetlist = []
834 scriptinstall = []
835 cubininstall = []
836
837 if env['OURPLATFORM']!='darwin':
838     dotblenderinstall = []
839     for targetdir,srcfile in zip(dottargetlist, dotblendlist):
840         td, tf = os.path.split(targetdir)
841         dotblenderinstall.append(env.Install(dir=td, source=srcfile))
842     for targetdir,srcfile in zip(datafilestargetlist, datafileslist):
843         td, tf = os.path.split(targetdir)
844         dotblenderinstall.append(env.Install(dir=td, source=srcfile))
845
846     if env['WITH_BF_PYTHON']:
847         #-- local/VERSION/scripts
848         scriptpaths=['release/scripts']
849         for scriptpath in scriptpaths:
850             for dp, dn, df in os.walk(scriptpath):
851                 if '.git' in df:
852                     df.remove('.git')
853                 if '__pycache__' in dn:  # py3.2 cache dir
854                     dn.remove('__pycache__')
855
856                 # only for testing builds
857                 if VERSION_RELEASE_CYCLE == "release" and "addons_contrib" in dn:
858                     dn.remove('addons_contrib')
859
860                 # do not install freestyle if disabled
861                 if not env['WITH_BF_FREESTYLE'] and "freestyle" in dn:
862                     dn.remove("freestyle")
863
864                 dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
865                 dir += os.sep + os.path.basename(scriptpath) + dp[len(scriptpath):]
866
867                 source=[os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
868                 # To ensure empty dirs are created too
869                 if len(source)==0 and not os.path.exists(dir):
870                     env.Execute(Mkdir(dir))
871                 scriptinstall.append(env.Install(dir=dir,source=source))
872         if env['WITH_BF_CYCLES']:
873             # cycles python code
874             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles')
875             source=os.listdir('intern/cycles/blender/addon')
876             if '__pycache__' in source: source.remove('__pycache__')
877             source=['intern/cycles/blender/addon/'+s for s in source]
878             scriptinstall.append(env.Install(dir=dir,source=source))
879
880             # cycles kernel code
881             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel')
882             source=os.listdir('intern/cycles/kernel')
883             if '__pycache__' in source: source.remove('__pycache__')
884             source.remove('kernel.cpp')
885             source.remove('CMakeLists.txt')
886             source.remove('svm')
887             source.remove('closure')
888             source.remove('shaders')
889             source.remove('osl')
890             source=['intern/cycles/kernel/'+s for s in source]
891             source.append('intern/cycles/util/util_color.h')
892             source.append('intern/cycles/util/util_half.h')
893             source.append('intern/cycles/util/util_math.h')
894             source.append('intern/cycles/util/util_transform.h')
895             source.append('intern/cycles/util/util_types.h')
896             scriptinstall.append(env.Install(dir=dir,source=source))
897             # svm
898             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel', 'svm')
899             source=os.listdir('intern/cycles/kernel/svm')
900             if '__pycache__' in source: source.remove('__pycache__')
901             source=['intern/cycles/kernel/svm/'+s for s in source]
902             scriptinstall.append(env.Install(dir=dir,source=source))
903             # closure
904             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel', 'closure')
905             source=os.listdir('intern/cycles/kernel/closure')
906             if '__pycache__' in source: source.remove('__pycache__')
907             source=['intern/cycles/kernel/closure/'+s for s in source]
908             scriptinstall.append(env.Install(dir=dir,source=source))
909
910             # licenses
911             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'license')
912             source=os.listdir('intern/cycles/doc/license')
913             if '__pycache__' in source: source.remove('__pycache__')
914             source.remove('CMakeLists.txt')
915             source=['intern/cycles/doc/license/'+s for s in source]
916             scriptinstall.append(env.Install(dir=dir,source=source))
917
918     if env['WITH_BF_CYCLES']:
919         # cuda binaries
920         if env['WITH_BF_CYCLES_CUDA_BINARIES']:
921             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'lib')
922             for arch in env['BF_CYCLES_CUDA_BINARIES_ARCH']:
923                 kernel_build_dir = os.path.join(B.root_build_dir, 'intern/cycles/kernel')
924                 cubin_file = os.path.join(kernel_build_dir, "kernel_%s.cubin" % arch)
925                 cubininstall.append(env.Install(dir=dir,source=cubin_file))
926
927         # osl shaders
928         if env['WITH_BF_CYCLES_OSL']:
929             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'shader')
930
931             osl_source_dir = Dir('./intern/cycles/kernel/shaders').srcnode().path
932             oso_build_dir = os.path.join(B.root_build_dir, 'intern/cycles/kernel/shaders')
933
934             headers='node_color.h node_fresnel.h node_texture.h oslutil.h stdosl.h'.split()
935             source=['intern/cycles/kernel/shaders/'+s for s in headers]
936             scriptinstall.append(env.Install(dir=dir,source=source))
937
938             for f in os.listdir(osl_source_dir):
939                 if f.endswith('.osl'):
940                     oso_file = os.path.join(oso_build_dir, f.replace('.osl', '.oso'))
941                     scriptinstall.append(env.Install(dir=dir,source=oso_file))
942
943     if env['WITH_BF_OCIO']:
944         colormanagement = os.path.join('release', 'datafiles', 'colormanagement')
945
946         for dp, dn, df in os.walk(colormanagement):
947             dir = os.path.join(env['BF_INSTALLDIR'], VERSION, 'datafiles')
948             dir += os.sep + os.path.basename(colormanagement) + dp[len(colormanagement):]
949
950             source = [os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
951
952             # To ensure empty dirs are created too
953             if len(source) == 0:
954                 env.Execute(Mkdir(dir))
955
956             scriptinstall.append(env.Install(dir=dir,source=source))
957
958     if env['WITH_BF_INTERNATIONAL']:
959         internationalpaths=['release' + os.sep + 'datafiles']
960
961         def check_path(path, member):
962             return (member in path.split(os.sep))
963
964         po_dir = os.path.join("release", "datafiles", "locale", "po")
965
966         # font files
967         for intpath in internationalpaths:
968             for dp, dn, df in os.walk(intpath):
969                 if '.git' in df:
970                     df.remove('.git')
971
972                 # we only care about release/datafiles/fonts, release/datafiles/locales
973                 if check_path(dp, "fonts"):
974                     pass
975                 else:
976                     continue
977
978                 dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
979                 dir += os.sep + os.path.basename(intpath) + dp[len(intpath):]
980
981                 source=[os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
982                 # To ensure empty dirs are created too
983                 if len(source)==0:
984                     env.Execute(Mkdir(dir))
985                 scriptinstall.append(env.Install(dir=dir,source=source))
986
987         # .mo files
988         for f in os.listdir(po_dir):
989             if not f.endswith(".po"):
990                 continue
991
992             locale_name = os.path.splitext(f)[0]
993
994             mo_file = os.path.join(B.root_build_dir, "locale", locale_name + ".mo")
995
996             dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
997             dir = os.path.join(dir, "datafiles", "locale", locale_name, "LC_MESSAGES")
998             scriptinstall.append(env.InstallAs(os.path.join(dir, "blender.mo"), mo_file))
999
1000         # languages file
1001         dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
1002         dir = os.path.join(dir, "datafiles", "locale")
1003         languages_file = os.path.join("release", "datafiles", "locale", "languages")
1004         scriptinstall.append(env.InstallAs(os.path.join(dir, "languages"), languages_file))
1005
1006 #-- icons
1007 if env['OURPLATFORM']=='linux':
1008     iconlist = []
1009     icontargetlist = []
1010
1011     for tp, tn, tf in os.walk('release/freedesktop/icons'):
1012         for f in tf:
1013             iconlist.append(os.path.join(tp, f))
1014             icontargetlist.append( os.path.join(*([env['BF_INSTALLDIR']] + tp.split(os.sep)[2:] + [f])) )
1015
1016     iconinstall = []
1017     for targetdir,srcfile in zip(icontargetlist, iconlist):
1018         td, tf = os.path.split(targetdir)
1019         iconinstall.append(env.Install(dir=td, source=srcfile))
1020
1021     scriptinstall.append(env.Install(dir=env['BF_INSTALLDIR'], source='release/bin/blender-thumbnailer.py'))
1022
1023 # dlls for linuxcross
1024 # TODO - add more libs, for now this lets blenderlite run
1025 if env['OURPLATFORM']=='linuxcross':
1026     dir=env['BF_INSTALLDIR']
1027     source = []
1028
1029     if env['WITH_BF_OPENMP']:
1030         source += ['../lib/windows/pthreads/lib/pthreadGC2.dll']
1031
1032     scriptinstall.append(env.Install(dir=dir, source=source))
1033
1034 textlist = []
1035 texttargetlist = []
1036 for tp, tn, tf in os.walk('release/text'):
1037     for f in tf:
1038         textlist.append(tp+os.sep+f)
1039
1040 # Font licenses
1041 textlist.append('release/datafiles/LICENSE-bfont.ttf.txt')
1042 if env['WITH_BF_INTERNATIONAL']:
1043     textlist += ['release/datafiles/LICENSE-droidsans.ttf.txt', 'release/datafiles/LICENSE-bmonofont-i18n.ttf.txt']
1044
1045 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
1046
1047 if  env['OURPLATFORM']=='darwin':
1048         allinstall = [blenderinstall, textinstall]
1049 elif env['OURPLATFORM']=='linux':
1050         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, textinstall, iconinstall, cubininstall]
1051 else:
1052         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, textinstall, cubininstall]
1053
1054 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'):
1055     dllsources = []
1056
1057     # Used when linking to libtiff was dynamic
1058     # keep it here until compilation on all platform would be ok
1059     # dllsources += ['${BF_TIFF_LIBPATH}/${BF_TIFF_LIB}.dll']
1060
1061     if env['OURPLATFORM'] != 'linuxcross':
1062         # pthreads library is already added
1063         dllsources += ['${BF_PTHREADS_LIBPATH}/${BF_PTHREADS_LIB}.dll']
1064
1065     if env['WITH_BF_SDL']:
1066         if env['OURPLATFORM'] == 'win64-vc':
1067             pass # we link statically already to SDL on win64
1068         else:
1069             dllsources.append('${BF_SDL_LIBPATH}/SDL.dll')
1070
1071     if env['WITH_BF_PYTHON']:
1072         if env['BF_DEBUG']:
1073             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
1074         else:
1075             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
1076
1077     if env['WITH_BF_ICONV']:
1078         if env['OURPLATFORM'] == 'win64-vc':
1079             pass # we link statically to iconv on win64
1080         elif not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
1081             #gettext for MinGW and cross-compilation is compiled staticly
1082             dllsources += ['${BF_ICONV_LIBPATH}/iconv.dll']
1083
1084     if env['WITH_BF_OPENAL']:
1085         dllsources.append('${LCGDIR}/openal/lib/OpenAL32.dll')
1086         if env['OURPLATFORM'] in ('win32-vc', 'win64-vc') and env['MSVC_VERSION'] == '11.0':
1087             pass
1088         else:
1089             dllsources.append('${LCGDIR}/openal/lib/wrap_oal.dll')
1090
1091     if env['WITH_BF_SNDFILE']:
1092         dllsources.append('${LCGDIR}/sndfile/lib/libsndfile-1.dll')
1093
1094     if env['WITH_BF_FFMPEG']:
1095         dllsources += env['BF_FFMPEG_DLL'].split()
1096
1097     # Since the thumb handler is loaded by Explorer, architecture is
1098     # strict: the x86 build fails on x64 Windows. We need to ship
1099     # both builds in x86 packages.
1100     if B.bitness == 32:
1101         dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb.dll')
1102     dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll')
1103
1104     if env['WITH_BF_OCIO']:
1105         if not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
1106             dllsources.append('${LCGDIR}/opencolorio/bin/OpenColorIO.dll')
1107
1108         else:
1109             dllsources.append('${LCGDIR}/opencolorio/bin/libOpenColorIO.dll')
1110
1111     dllsources.append('#source/icons/blender.exe.manifest')
1112
1113     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
1114     allinstall += windlls
1115
1116 if env['OURPLATFORM'] == 'win64-mingw':
1117     dllsources = []
1118
1119     if env['WITH_BF_PYTHON']:
1120         if env['BF_DEBUG']:
1121             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
1122         else:
1123             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
1124
1125     if env['WITH_BF_FFMPEG']:
1126         dllsources += env['BF_FFMPEG_DLL'].split()
1127
1128     if env['WITH_BF_OPENAL']:
1129         dllsources.append('${LCGDIR}/openal/lib/OpenAL32.dll')
1130         dllsources.append('${LCGDIR}/openal/lib/wrap_oal.dll')
1131
1132     if env['WITH_BF_SNDFILE']:
1133         dllsources.append('${LCGDIR}/sndfile/lib/libsndfile-1.dll')
1134
1135     if env['WITH_BF_SDL']:
1136         dllsources.append('${LCGDIR}/sdl/lib/SDL.dll')
1137
1138     if(env['WITH_BF_OPENMP']):
1139         dllsources.append('${LCGDIR}/binaries/libgomp-1.dll')
1140
1141     if env['WITH_BF_OCIO']:
1142         dllsources.append('${LCGDIR}/opencolorio/bin/libOpenColorIO.dll')
1143
1144     dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll')
1145     dllsources.append('${LCGDIR}/binaries/libgcc_s_sjlj-1.dll')
1146     dllsources.append('${LCGDIR}/binaries/libwinpthread-1.dll')
1147     dllsources.append('${LCGDIR}/binaries/libstdc++-6.dll')
1148     dllsources.append('#source/icons/blender.exe.manifest')
1149
1150     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
1151     allinstall += windlls
1152
1153 installtarget = env.Alias('install', allinstall)
1154 bininstalltarget = env.Alias('install-bin', blenderinstall)
1155
1156 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
1157 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
1158 nsisalias = env.Alias('nsis', nsiscmd)
1159
1160 if 'blender' in B.targets:
1161     blenderexe= env.Alias('blender', B.program_list)
1162     Depends(blenderexe,installtarget)
1163
1164 if env['WITH_BF_PLAYER']:
1165     blenderplayer = env.Alias('blenderplayer', B.program_list)
1166     Depends(blenderplayer,installtarget)
1167
1168 if not env['WITH_BF_GAMEENGINE']:
1169     blendernogame = env.Alias('blendernogame', B.program_list)
1170     Depends(blendernogame,installtarget)
1171
1172 if 'blenderlite' in B.targets:
1173     blenderlite = env.Alias('blenderlite', B.program_list)
1174     Depends(blenderlite,installtarget)
1175
1176 Depends(nsiscmd, allinstall)
1177
1178 buildslave_action = env.Action(btools.buildslave, btools.buildslave_print)
1179 buildslave_cmd = env.Command('buildslave_exec', None, buildslave_action)
1180 buildslave_alias = env.Alias('buildslave', buildslave_cmd)
1181
1182 Depends(buildslave_cmd, allinstall)
1183
1184 cudakernels_action = env.Action(btools.cudakernels, btools.cudakernels_print)
1185 cudakernels_cmd = env.Command('cudakernels_exec', None, cudakernels_action)
1186 cudakernels_alias = env.Alias('cudakernels', cudakernels_cmd)
1187
1188 cudakernel_dir = os.path.join(os.path.abspath(os.path.normpath(B.root_build_dir)), 'intern/cycles/kernel')
1189 cuda_kernels = []
1190
1191 for x in env['BF_CYCLES_CUDA_BINARIES_ARCH']:
1192     cubin = os.path.join(cudakernel_dir, 'kernel_' + x + '.cubin')
1193     cuda_kernels.append(cubin)
1194
1195 Depends(cudakernels_cmd, cuda_kernels)
1196 Depends(cudakernels_cmd, cubininstall)
1197
1198 Default(B.program_list)
1199
1200 if not env['WITHOUT_BF_INSTALL']:
1201         Default(installtarget)
1202