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