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