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