svn merge ^/trunk/blender -r49929:49933
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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_DECIMATE'] = False
268     target_env_defs['WITH_BF_BOOLEAN'] = False
269     target_env_defs['WITH_BF_REMESH'] = False
270     target_env_defs['WITH_BF_PYTHON'] = False
271     target_env_defs['WITH_BF_3DMOUSE'] = False
272     target_env_defs['WITH_BF_LIBMV'] = False
273
274     # Merge blenderlite, let command line to override
275     for k,v in target_env_defs.iteritems():
276         if k not in B.arguments:
277             env[k] = v
278
279 # Extended OSX_SDK and 3D_CONNEXION_CLIENT_LIBRARY and JAckOSX detection for OSX
280 if env['OURPLATFORM']=='darwin':
281     print B.bc.OKGREEN + "Detected Xcode version: -- " + B.bc.ENDC + env['XCODE_CUR_VER'] + " --"
282     print "Available " + env['MACOSX_SDK_CHECK']
283     if not 'Mac OS X 10.6' in env['MACOSX_SDK_CHECK']:
284         print  B.bc.OKGREEN + "Auto-setting available MacOSX SDK -> " + B.bc.ENDC + "MacOSX10.7.sdk"
285     elif not 'Mac OS X 10.5' in env['MACOSX_SDK_CHECK']:
286         print  B.bc.OKGREEN + "Auto-setting available MacOSX SDK -> " + B.bc.ENDC + "MacOSX10.6.sdk"
287     else:
288         print B.bc.OKGREEN + "Found recommended sdk :" + B.bc.ENDC + " using MacOSX10.5.sdk"
289
290     # for now, Mac builders must download and install the 3DxWare 10 Beta 4 driver framework from 3Dconnexion
291     # necessary header file lives here when installed:
292     # /Library/Frameworks/3DconnexionClient.framework/Versions/Current/Headers/ConnexionClientAPI.h
293     if env['WITH_BF_3DMOUSE'] == 1:
294         if not os.path.exists('/Library/Frameworks/3DconnexionClient.framework'):
295             print "3D_CONNEXION_CLIENT_LIBRARY not found, disabling WITH_BF_3DMOUSE" # avoid build errors !
296             env['WITH_BF_3DMOUSE'] = 0
297         else:
298             env.Append(LINKFLAGS=['-Xlinker','-weak_framework','-Xlinker','3DconnexionClient'])
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=['-Xlinker','-weak_framework','-Xlinker','Jackmp'])
309
310 if env['WITH_BF_OPENMP'] == 1:
311         if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
312                 env['CCFLAGS'].append('/openmp')
313         else:
314             if env['CC'].endswith('icc'): # to be able to handle CC=/opt/bla/icc case
315                 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
316                 env['CCFLAGS'].append('-openmp')
317             else:
318                 env.Append(CCFLAGS=['-fopenmp']) 
319
320 if env['WITH_GHOST_COCOA'] == True:
321     env.Append(CPPFLAGS=['-DGHOST_COCOA']) 
322
323 if env['USE_QTKIT'] == True:
324     env.Append(CPPFLAGS=['-DUSE_QTKIT'])
325
326 #check for additional debug libnames
327
328 if env.has_key('BF_DEBUG_LIBS'):
329     B.quickdebug += env['BF_DEBUG_LIBS']
330
331 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
332
333 if len(B.quickdebug) > 0 and printdebug != 0:
334     print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
335     for l in B.quickdebug:
336         print "\t" + l
337
338 # remove stdc++ from LLIBS if we are building a statc linked CXXFLAGS
339 if env['WITH_BF_STATICCXX']:
340     if 'stdc++' in env['LLIBS']:
341         env['LLIBS'].remove('stdc++')
342     else:
343         print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
344
345 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
346 if 'blenderplayer' in B.targets:
347     env['WITH_BF_PLAYER'] = True
348
349 if 'blendernogame' in B.targets:
350     env['WITH_BF_GAMEENGINE'] = False
351
352 # build without elbeem (fluidsim)?
353 if env['WITH_BF_FLUID'] == 1:
354     env['CPPFLAGS'].append('-DWITH_MOD_FLUID')
355
356 # build with ocean sim?
357 if env['WITH_BF_OCEANSIM'] == 1:
358     env['WITH_BF_FFTW3']  = 1  # ocean needs fftw3 so enable it 
359     env['CPPFLAGS'].append('-DWITH_MOD_OCEANSIM')
360
361
362 if btools.ENDIAN == "big":
363     env['CPPFLAGS'].append('-D__BIG_ENDIAN__')
364 else:
365     env['CPPFLAGS'].append('-D__LITTLE_ENDIAN__')
366
367 # TODO, make optional
368 env['CPPFLAGS'].append('-DWITH_AUDASPACE')
369
370 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
371 B.root_build_dir = env['BF_BUILDDIR']
372 B.doc_build_dir = os.path.join(env['BF_INSTALLDIR'], 'doc')
373 if not B.root_build_dir[-1]==os.sep:
374     B.root_build_dir += os.sep
375 if not B.doc_build_dir[-1]==os.sep:
376     B.doc_build_dir += os.sep
377
378 # We do a shortcut for clean when no quicklist is given: just delete
379 # builddir without reading in SConscripts
380 do_clean = None
381 if 'clean' in B.targets:
382     do_clean = True
383
384 if not quickie and do_clean:
385     if os.path.exists(B.doc_build_dir):
386         print B.bc.HEADER+'Cleaning doc dir...'+B.bc.ENDC
387         dirs = os.listdir(B.doc_build_dir)
388         for entry in dirs:
389             if os.path.isdir(B.doc_build_dir + entry) == 1:
390                 print "clean dir %s"%(B.doc_build_dir+entry)
391                 shutil.rmtree(B.doc_build_dir+entry)
392             else: # remove file
393                 print "remove file %s"%(B.doc_build_dir+entry)
394                 os.remove(B.root_build_dir+entry)
395     if os.path.exists(B.root_build_dir):
396         print B.bc.HEADER+'Cleaning build dir...'+B.bc.ENDC
397         dirs = os.listdir(B.root_build_dir)
398         for entry in dirs:
399             if os.path.isdir(B.root_build_dir + entry) == 1:
400                 print "clean dir %s"%(B.root_build_dir+entry)
401                 shutil.rmtree(B.root_build_dir+entry)
402             else: # remove file
403                 print "remove file %s"%(B.root_build_dir+entry)
404                 os.remove(B.root_build_dir+entry)
405         for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
406                 'extern/xvidcore/build/generic/platform.inc', 'extern/ffmpeg/include']:
407             if os.path.exists(confile):
408                 print "clean file %s"%confile
409                 if os.path.isdir(confile):
410                     for root, dirs, files in os.walk(confile):
411                         for name in files:
412                             os.remove(os.path.join(root, name))
413                 else:
414                     os.remove(confile)
415         print B.bc.OKGREEN+'...done'+B.bc.ENDC
416     else:
417         print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
418     Exit()
419
420
421 # ensure python header is found since detection can fail, this could happen
422 # with _any_ library but since we used a fixed python version this tends to
423 # be most problematic.
424 if env['WITH_BF_PYTHON']:
425     py_h = os.path.join(Dir(env.subst('${BF_PYTHON_INC}')).abspath, "Python.h")
426
427     if not os.path.exists(py_h):
428         print("\nMissing: \"" + env.subst('${BF_PYTHON_INC}') + os.sep + "Python.h\",\n"
429               "  Set 'BF_PYTHON_INC' to point "
430               "to a valid python include path.\n  Containing "
431               "Python.h for python version \"" + env.subst('${BF_PYTHON_VERSION}') + "\"")
432
433         Exit()
434     del py_h
435
436
437 if not os.path.isdir ( B.root_build_dir):
438     os.makedirs ( B.root_build_dir )
439     os.makedirs ( B.root_build_dir + 'source' )
440     os.makedirs ( B.root_build_dir + 'intern' )
441     os.makedirs ( B.root_build_dir + 'extern' )
442     os.makedirs ( B.root_build_dir + 'lib' )
443     os.makedirs ( B.root_build_dir + 'bin' )
444 # # Docs not working with epy anymore
445 # if not os.path.isdir(B.doc_build_dir) and env['WITH_BF_DOCS']:
446 #     os.makedirs ( B.doc_build_dir )
447
448 ###################################
449 # Ensure all data files are valid #
450 ###################################
451 if not os.path.isdir ( B.root_build_dir + 'data_headers'):
452     os.makedirs ( B.root_build_dir + 'data_headers' )
453 if not os.path.isdir ( B.root_build_dir + 'data_sources'):
454     os.makedirs ( B.root_build_dir + 'data_sources' )
455 # use for includes
456 env['DATA_HEADERS'] = os.path.join(os.path.abspath(env['BF_BUILDDIR']), "data_headers")
457 env['DATA_SOURCES'] = os.path.join(os.path.abspath(env['BF_BUILDDIR']), "data_sources")
458 def data_to_c(FILE_FROM, FILE_TO, VAR_NAME):
459     if os.sep == "\\":
460         FILE_FROM = FILE_FROM.replace("/", "\\")
461         FILE_TO   = FILE_TO.replace("/", "\\")
462
463     # first check if we need to bother.
464     if os.path.exists(FILE_TO):
465         if os.path.getmtime(FILE_FROM) < os.path.getmtime(FILE_TO):
466             return
467
468     print(B.bc.HEADER + "Generating: " + B.bc.ENDC + "%r" % os.path.basename(FILE_TO))
469     fpin = open(FILE_FROM, "rb")
470     fpin.seek(0, os.SEEK_END)
471     size = fpin.tell()
472     fpin.seek(0)
473
474     fpout = open(FILE_TO, "w")
475     fpout.write("int  %s_size = %d;\n" % (VAR_NAME, size))
476     fpout.write("char %s[] = {\n" % VAR_NAME)
477
478     while size > 0:
479         size -= 1
480         if size % 32 == 31:
481             fpout.write("\n")
482
483         fpout.write("%3d," % ord(fpin.read(1)))
484     fpout.write("\n  0};\n\n")
485
486     fpin.close()
487     fpout.close()
488
489 def data_to_c_simple(FILE_FROM):
490         filename_only = os.path.basename(FILE_FROM)
491         FILE_TO = os.path.join(env['DATA_SOURCES'], filename_only + ".c")
492         VAR_NAME = "datatoc_" + filename_only.replace(".", "_")
493         
494         data_to_c(FILE_FROM, FILE_TO, VAR_NAME)
495         
496
497 data_to_c("source/blender/compositor/operations/COM_OpenCLKernels.cl",
498           B.root_build_dir + "data_headers/COM_OpenCLKernels.cl.h",
499           "datatoc_COM_OpenCLKernels_cl")
500
501 data_to_c_simple("release/datafiles/startup.blend")
502 data_to_c_simple("release/datafiles/preview.blend")
503
504 # --- glsl ---
505 data_to_c_simple("source/blender/gpu/shaders/gpu_shader_material.glsl")
506 data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vertex.glsl")
507 data_to_c_simple("source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl")
508 data_to_c_simple("source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl")
509 data_to_c_simple("source/blender/gpu/shaders/gpu_shader_material.glsl")
510 data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl")
511 data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl")
512
513 # --- blender ---
514 data_to_c_simple("release/datafiles/bfont.pfb")
515 data_to_c_simple("release/datafiles/bfont.ttf")
516 data_to_c_simple("release/datafiles/bmonofont.ttf")
517
518 data_to_c_simple("release/datafiles/splash.png")
519 data_to_c_simple("release/datafiles/blender_icons.png")
520 data_to_c_simple("release/datafiles/prvicons.png")
521
522 data_to_c_simple("release/datafiles/brushicons/add.png")
523 data_to_c_simple("release/datafiles/brushicons/blob.png")
524 data_to_c_simple("release/datafiles/brushicons/blur.png")
525 data_to_c_simple("release/datafiles/brushicons/clay.png")
526 data_to_c_simple("release/datafiles/brushicons/claystrips.png")
527 data_to_c_simple("release/datafiles/brushicons/clone.png")
528 data_to_c_simple("release/datafiles/brushicons/crease.png")
529 data_to_c_simple("release/datafiles/brushicons/darken.png")
530 data_to_c_simple("release/datafiles/brushicons/draw.png")
531 data_to_c_simple("release/datafiles/brushicons/fill.png")
532 data_to_c_simple("release/datafiles/brushicons/flatten.png")
533 data_to_c_simple("release/datafiles/brushicons/grab.png")
534 data_to_c_simple("release/datafiles/brushicons/inflate.png")
535 data_to_c_simple("release/datafiles/brushicons/layer.png")
536 data_to_c_simple("release/datafiles/brushicons/lighten.png")
537 data_to_c_simple("release/datafiles/brushicons/mask.png")
538 data_to_c_simple("release/datafiles/brushicons/mix.png")
539 data_to_c_simple("release/datafiles/brushicons/multiply.png")
540 data_to_c_simple("release/datafiles/brushicons/nudge.png")
541 data_to_c_simple("release/datafiles/brushicons/pinch.png")
542 data_to_c_simple("release/datafiles/brushicons/scrape.png")
543 data_to_c_simple("release/datafiles/brushicons/smear.png")
544 data_to_c_simple("release/datafiles/brushicons/smooth.png")
545 data_to_c_simple("release/datafiles/brushicons/snake_hook.png")
546 data_to_c_simple("release/datafiles/brushicons/soften.png")
547 data_to_c_simple("release/datafiles/brushicons/subtract.png")
548 data_to_c_simple("release/datafiles/brushicons/texdraw.png")
549 data_to_c_simple("release/datafiles/brushicons/thumb.png")
550 data_to_c_simple("release/datafiles/brushicons/twist.png")
551 data_to_c_simple("release/datafiles/brushicons/vertexdraw.png")
552
553 ##### END DATAFILES ##########
554
555 Help(opts.GenerateHelpText(env))
556
557 # default is new quieter output, but if you need to see the
558 # commands, do 'scons BF_QUIET=0'
559 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
560 if env['BF_QUIET']:
561     B.set_quiet_output(env)
562 else:
563     if toolset=='msvc':
564         B.msvc_hack(env)
565
566 print B.bc.HEADER+'Building in: ' + B.bc.ENDC + os.path.abspath(B.root_build_dir)
567 env.SConsignFile(B.root_build_dir+'scons-signatures')
568 B.init_lib_dict()
569
570 ##### END SETUP ##########
571
572 Export('env')
573
574 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
575 SConscript(B.root_build_dir+'/source/SConscript')
576 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
577 SConscript(B.root_build_dir+'/intern/SConscript')
578 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
579 SConscript(B.root_build_dir+'/extern/SConscript')
580
581 # now that we have read all SConscripts, we know what
582 # libraries will be built. Create list of
583 # libraries to give as objects to linking phase
584 mainlist = []
585 for tp in B.possible_types:
586     if (not tp == 'player') and (not tp == 'player2'):
587         mainlist += B.create_blender_liblist(env, tp)
588
589 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
590     B.propose_priorities()
591
592 dobj = B.buildinfo(env, "dynamic") + B.resources
593 creob = B.creator(env)
594 thestatlibs, thelibincs = B.setup_staticlibs(env)
595 thesyslibs = B.setup_syslibs(env)
596
597 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
598     env.BlenderProg(B.root_build_dir, "blender", creob + mainlist + thestatlibs + dobj, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
599 if env['WITH_BF_PLAYER']:
600     playerlist = B.create_blender_liblist(env, 'player')
601     playerlist += B.create_blender_liblist(env, 'player2')
602     playerlist += B.create_blender_liblist(env, 'intern')
603     playerlist += B.create_blender_liblist(env, 'extern')
604     env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
605
606 ##### Now define some targets
607
608
609 #------------ INSTALL
610
611 #-- binaries
612 blenderinstall = []
613 if  env['OURPLATFORM']=='darwin':
614     for prg in B.program_list:
615         bundle = '%s.app' % prg[0]
616         bundledir = os.path.dirname(bundle)
617         for dp, dn, df in os.walk(bundle):
618             if '.svn' in dn:
619                 dn.remove('.svn')
620             if '_svn' in dn:
621                 dn.remove('_svn')
622             dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
623             source=[dp+os.sep+f for f in df]
624             blenderinstall.append(env.Install(dir=dir,source=source))
625 else:
626     blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
627
628 #-- local path = config files in install dir: installdir\VERSION
629 #- dont do config and scripts for darwin, it is already in the bundle
630 dotblendlist = []
631 datafileslist = []
632 datafilestargetlist = []
633 dottargetlist = []
634 scriptinstall = []
635
636 if env['OURPLATFORM']!='darwin':
637     dotblenderinstall = []
638     for targetdir,srcfile in zip(dottargetlist, dotblendlist):
639         td, tf = os.path.split(targetdir)
640         dotblenderinstall.append(env.Install(dir=td, source=srcfile))
641     for targetdir,srcfile in zip(datafilestargetlist, datafileslist):
642         td, tf = os.path.split(targetdir)
643         dotblenderinstall.append(env.Install(dir=td, source=srcfile))
644
645     if env['WITH_BF_PYTHON']:
646         #-- local/VERSION/scripts
647         scriptpaths=['release/scripts']
648         for scriptpath in scriptpaths:
649             for dp, dn, df in os.walk(scriptpath):
650                 if '.svn' in dn:
651                     dn.remove('.svn')
652                 if '_svn' in dn:
653                     dn.remove('_svn')
654                 if '__pycache__' in dn:  # py3.2 cache dir
655                     dn.remove('__pycache__')
656
657                 # only for testing builds
658                 if VERSION_RELEASE_CYCLE == "release" and "addons_contrib" in dn:
659                     dn.remove('addons_contrib')
660
661                 dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
662                 dir += os.sep + os.path.basename(scriptpath) + dp[len(scriptpath):]
663
664                 source=[os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
665                 # To ensure empty dirs are created too
666                 if len(source)==0 and not os.path.exists(dir):
667                     env.Execute(Mkdir(dir))
668                 scriptinstall.append(env.Install(dir=dir,source=source))
669         if env['WITH_BF_CYCLES']:
670             # cycles python code
671             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles')
672             source=os.listdir('intern/cycles/blender/addon')
673             if '.svn' in source: source.remove('.svn')
674             if '_svn' in source: source.remove('_svn')
675             if '__pycache__' in source: source.remove('__pycache__')
676             source=['intern/cycles/blender/addon/'+s for s in source]
677             scriptinstall.append(env.Install(dir=dir,source=source))
678
679             # cycles kernel code
680             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel')
681             source=os.listdir('intern/cycles/kernel')
682             if '.svn' in source: source.remove('.svn')
683             if '_svn' in source: source.remove('_svn')
684             if '__pycache__' in source: source.remove('__pycache__')
685             source.remove('kernel.cpp')
686             source.remove('CMakeLists.txt')
687             source.remove('svm')
688             source.remove('osl')
689             source=['intern/cycles/kernel/'+s for s in source]
690             source.append('intern/cycles/util/util_color.h')
691             source.append('intern/cycles/util/util_math.h')
692             source.append('intern/cycles/util/util_transform.h')
693             source.append('intern/cycles/util/util_types.h')
694             scriptinstall.append(env.Install(dir=dir,source=source))
695             # svm
696             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'kernel', 'svm')
697             source=os.listdir('intern/cycles/kernel/svm')
698             if '.svn' in source: source.remove('.svn')
699             if '_svn' in source: source.remove('_svn')
700             if '__pycache__' in source: source.remove('__pycache__')
701             source=['intern/cycles/kernel/svm/'+s for s in source]
702             scriptinstall.append(env.Install(dir=dir,source=source))
703
704             # licenses
705             dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'license')
706             source=os.listdir('intern/cycles/doc/license')
707             if '.svn' in source: source.remove('.svn')
708             if '_svn' in source: source.remove('_svn')
709             if '__pycache__' in source: source.remove('__pycache__')
710             source.remove('CMakeLists.txt')
711             source=['intern/cycles/doc/license/'+s for s in source]
712             scriptinstall.append(env.Install(dir=dir,source=source))
713
714             # cuda binaries
715             if env['WITH_BF_CYCLES_CUDA_BINARIES']:
716                 dir=os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts', 'addons','cycles', 'lib')
717                 for arch in env['BF_CYCLES_CUDA_BINARIES_ARCH']:
718                     kernel_build_dir = os.path.join(B.root_build_dir, 'intern/cycles/kernel')
719                     cubin_file = os.path.join(kernel_build_dir, "kernel_%s.cubin" % arch)
720                     scriptinstall.append(env.Install(dir=dir,source=cubin_file))
721
722     if env['WITH_BF_OCIO']:
723         colormanagement = os.path.join('release', 'datafiles', 'colormanagement')
724
725         for dp, dn, df in os.walk(colormanagement):
726             if '.svn' in dn:
727                 dn.remove('.svn')
728             if '_svn' in dn:
729                 dn.remove('_svn')
730
731             dir = os.path.join(env['BF_INSTALLDIR'], VERSION, 'datafiles')
732             dir += os.sep + os.path.basename(colormanagement) + dp[len(colormanagement):]
733
734             source = [os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
735
736             # To ensure empty dirs are created too
737             if len(source) == 0:
738                 env.Execute(Mkdir(dir))
739
740             scriptinstall.append(env.Install(dir=dir,source=source))
741
742     if env['WITH_BF_INTERNATIONAL']:
743         internationalpaths=['release' + os.sep + 'datafiles']
744
745         def check_path(path, member):
746             return (member in path.split(os.sep))
747
748         for intpath in internationalpaths:
749             for dp, dn, df in os.walk(intpath):
750                 if '.svn' in dn:
751                     dn.remove('.svn')
752                 if '_svn' in dn:
753                     dn.remove('_svn')
754
755                 # we only care about release/datafiles/fonts, release/datafiles/locales
756                 if check_path(dp, "fonts") or check_path(dp, "locale"):
757                     pass
758                 else:
759                     continue
760
761                 dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
762                 dir += os.sep + os.path.basename(intpath) + dp[len(intpath):]
763
764                 source=[os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
765                 # To ensure empty dirs are created too
766                 if len(source)==0:
767                     env.Execute(Mkdir(dir))
768                 scriptinstall.append(env.Install(dir=dir,source=source))
769
770 #-- icons
771 if env['OURPLATFORM']=='linux':
772     iconlist = []
773     icontargetlist = []
774
775     for tp, tn, tf in os.walk('release/freedesktop/icons'):
776         if '.svn' in tn:
777             tn.remove('.svn')
778         if '_svn' in tn:
779             tn.remove('_svn')
780         for f in tf:
781             iconlist.append(os.path.join(tp, f))
782             icontargetlist.append( os.path.join(*([env['BF_INSTALLDIR']] + tp.split(os.sep)[2:] + [f])) )
783
784     iconinstall = []
785     for targetdir,srcfile in zip(icontargetlist, iconlist):
786         td, tf = os.path.split(targetdir)
787         iconinstall.append(env.Install(dir=td, source=srcfile))
788
789 # dlls for linuxcross
790 # TODO - add more libs, for now this lets blenderlite run
791 if env['OURPLATFORM']=='linuxcross':
792     dir=env['BF_INSTALLDIR']
793     source = []
794
795     if env['WITH_BF_OPENMP']:
796         source += ['../lib/windows/pthreads/lib/pthreadGC2.dll']
797
798     scriptinstall.append(env.Install(dir=dir, source=source))
799
800 textlist = []
801 texttargetlist = []
802 for tp, tn, tf in os.walk('release/text'):
803     if '.svn' in tn:
804         tn.remove('.svn')
805     if '_svn' in tn:
806         tn.remove('_svn')
807     for f in tf:
808         textlist.append(tp+os.sep+f)
809
810 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
811
812 if  env['OURPLATFORM']=='darwin':
813         allinstall = [blenderinstall, textinstall]
814 elif env['OURPLATFORM']=='linux':
815         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, textinstall, iconinstall]
816 else:
817         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, textinstall]
818
819 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'):
820     dllsources = []
821
822     if not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
823         # For MinGW and linuxcross static linking will be used
824         dllsources += ['${LCGDIR}/gettext/lib/gnu_gettext.dll']
825
826     dllsources += ['${BF_ZLIB_LIBPATH}/zlib.dll']
827     # Used when linking to libtiff was dynamic
828     # keep it here until compilation on all platform would be ok
829     # dllsources += ['${BF_TIFF_LIBPATH}/${BF_TIFF_LIB}.dll']
830
831     if env['OURPLATFORM'] != 'linuxcross':
832         # pthreads library is already added
833         dllsources += ['${BF_PTHREADS_LIBPATH}/${BF_PTHREADS_LIB}.dll']
834
835     if env['WITH_BF_SDL']:
836         if env['OURPLATFORM'] == 'win64-vc':
837             pass # we link statically already to SDL on win64
838         else:
839             dllsources.append('${BF_SDL_LIBPATH}/SDL.dll')
840
841     if env['WITH_BF_PYTHON']:
842         if env['BF_DEBUG']:
843             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
844         else:
845             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
846
847     if env['WITH_BF_ICONV']:
848         if env['OURPLATFORM'] == 'win64-vc':
849             pass # we link statically to iconv on win64
850         elif not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
851             #gettext for MinGW and cross-compilation is compiled staticly
852             dllsources += ['${BF_ICONV_LIBPATH}/iconv.dll']
853
854     if env['WITH_BF_OPENAL']:
855         dllsources.append('${LCGDIR}/openal/lib/OpenAL32.dll')
856         dllsources.append('${LCGDIR}/openal/lib/wrap_oal.dll')
857
858     if env['WITH_BF_SNDFILE']:
859         dllsources.append('${LCGDIR}/sndfile/lib/libsndfile-1.dll')
860
861     if env['WITH_BF_FFMPEG']:
862         dllsources += env['BF_FFMPEG_DLL'].split()
863
864     # Since the thumb handler is loaded by Explorer, architecture is
865     # strict: the x86 build fails on x64 Windows. We need to ship
866     # both builds in x86 packages.
867     if bitness == 32:
868         dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb.dll')
869     dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll')
870
871     if env['WITH_BF_OIIO'] and env['OURPLATFORM'] != 'win32-mingw':
872         dllsources.append('${LCGDIR}/openimageio/bin/OpenImageIO.dll')
873
874     if env['WITH_BF_OCIO'] and env['OURPLATFORM'] != 'win32-mingw':
875         dllsources.append('${LCGDIR}/opencolorio/bin/OpenColorIO.dll')
876
877     dllsources.append('#source/icons/blender.exe.manifest')
878
879     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
880     allinstall += windlls
881
882 if env['OURPLATFORM'] == 'win64-mingw':
883     dllsources = []
884
885     if env['WITH_BF_PYTHON']:
886         if env['BF_DEBUG']:
887             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
888         else:
889             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
890
891     if env['WITH_BF_FFMPEG']:
892         dllsources += env['BF_FFMPEG_DLL'].split()
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_SDL']:
902         dllsources.append('${LCGDIR}/sdl/lib/SDL.dll')
903
904     if(env['WITH_BF_OPENMP']):
905         dllsources.append('${LCGDIR}/binaries/libgomp-1.dll')
906
907     dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll')
908     dllsources.append('${LCGDIR}/binaries/libgcc_s_sjlj-1.dll')
909     dllsources.append('${LCGDIR}/binaries/libwinpthread-1.dll')
910     dllsources.append('${LCGDIR}/binaries/libstdc++-6.dll')
911     dllsources.append('#source/icons/blender.exe.manifest')
912
913     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
914     allinstall += windlls
915
916 installtarget = env.Alias('install', allinstall)
917 bininstalltarget = env.Alias('install-bin', blenderinstall)
918
919 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
920 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
921 nsisalias = env.Alias('nsis', nsiscmd)
922
923 if 'blender' in B.targets:
924     blenderexe= env.Alias('blender', B.program_list)
925     Depends(blenderexe,installtarget)
926
927 if env['WITH_BF_PLAYER']:
928     blenderplayer = env.Alias('blenderplayer', B.program_list)
929     Depends(blenderplayer,installtarget)
930
931 if not env['WITH_BF_GAMEENGINE']:
932     blendernogame = env.Alias('blendernogame', B.program_list)
933     Depends(blendernogame,installtarget)
934
935 if 'blenderlite' in B.targets:
936     blenderlite = env.Alias('blenderlite', B.program_list)
937     Depends(blenderlite,installtarget)
938
939 Depends(nsiscmd, allinstall)
940
941 buildslave_action = env.Action(btools.buildslave, btools.buildslave_print)
942 buildslave_cmd = env.Command('buildslave_exec', None, buildslave_action)
943 buildslave_alias = env.Alias('buildslave', buildslave_cmd)
944
945 Depends(buildslave_cmd, allinstall)
946
947 Default(B.program_list)
948
949 if not env['WITHOUT_BF_INSTALL']:
950         Default(installtarget)
951