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