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