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