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