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