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