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