svn merge ^/trunk/blender -r40394:40395
[blender.git] / SConstruct
1 #!/usr/bin/env python
2 # $Id$
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
34 import platform as pltfrm
35
36 # Need a better way to do this. Automagical maybe is not the best thing, maybe it is.
37 if pltfrm.architecture()[0] == '64bit':
38     bitness = 64
39 else:
40     bitness = 32
41
42 import sys
43 import os
44 import os.path
45 import string
46 import shutil
47 import glob
48 import re
49 from tempfile import mkdtemp
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 import bcolors
60
61 EnsureSConsVersion(1,0,0)
62
63 # Before we do anything, let's check if we have a sane os.environ
64 if not btools.check_environ():
65     Exit()
66
67 BlenderEnvironment = Blender.BlenderEnvironment
68 B = Blender
69
70 VERSION = btools.VERSION # This is used in creating the local config directories
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 # first check cmdline for toolset and we create env to work on
120 quickie = B.arguments.get('BF_QUICK', None)
121 quickdebug = B.arguments.get('BF_QUICKDEBUG', None)
122
123 if quickdebug:
124     B.quickdebug=string.split(quickdebug, ',')
125 else:
126     B.quickdebug=[]
127
128 if quickie:
129     B.quickie=string.split(quickie,',')
130 else:
131     B.quickie=[]
132     
133 toolset = B.arguments.get('BF_TOOLSET', None)
134 if toolset:
135     print "Using " + toolset
136     if toolset=='mstoolkit':
137         env = BlenderEnvironment(ENV = os.environ)
138         env.Tool('mstoolkit', [toolpath])
139     else:
140         env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
141         # xxx commented out, as was supressing warnings under mingw..
142         #if env:
143         #    btools.SetupSpawn(env)
144 else:
145     if bitness==64 and platform=='win32':
146         env = BlenderEnvironment(ENV = os.environ, MSVS_ARCH='amd64')
147     else:
148         env = BlenderEnvironment(ENV = os.environ)
149
150 if not env:
151     print "Could not create a build environment"
152     Exit()
153
154 cc = B.arguments.get('CC', None)
155 cxx = B.arguments.get('CXX', None)
156 if cc:
157     env['CC'] = cc
158 if cxx:
159     env['CXX'] = cxx
160
161 if sys.platform=='win32':
162     if env['CC'] in ['cl', 'cl.exe']:
163          platform = 'win64-vc' if bitness == 64 else 'win32-vc'
164     elif env['CC'] in ['gcc']:
165         platform = 'win32-mingw'
166
167 env.SConscriptChdir(0)
168
169 # Remove major kernel version from linux platform.
170 # After Linus switched kernel to new version model this major version
171 # shouldn't take much sense for building rules.
172
173 if re.match('linux[0-9]+', platform):
174     platform = 'linux'
175
176 crossbuild = B.arguments.get('BF_CROSS', None)
177 if crossbuild and platform not in ('win32-vc', 'win64-vc'):
178     platform = 'linuxcross'
179
180 env['OURPLATFORM'] = platform
181
182 configfile = os.path.join("build_files", "scons", "config", platform + "-config.py")
183
184 if os.path.exists(configfile):
185     print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
186 else:
187     print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
188
189 if crossbuild and env['PLATFORM'] != 'win32':
190     print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
191     env.Tool('crossmingw', [toolpath])
192     # todo: determine proper libs/includes etc.
193     # Needed for gui programs, console programs should do without it
194
195     # Now we don't need this option to have console window
196     # env.Append(LINKFLAGS=['-mwindows'])
197
198 userconfig = B.arguments.get('BF_CONFIG', 'user-config.py')
199 # first read platform config. B.arguments will override
200 optfiles = [configfile]
201 if os.path.exists(userconfig):
202     print B.bc.OKGREEN + "Using user-config file: " + B.bc.ENDC + userconfig
203     optfiles += [userconfig]
204 else:
205     print B.bc.WARNING + userconfig + " not found, no user overrides" + B.bc.ENDC
206
207 opts = btools.read_opts(env, optfiles, B.arguments)
208 opts.Update(env)
209
210 if sys.platform=='win32':
211     if bitness==64:
212         env.Append(CFLAGS=['-DWIN64']) # -DWIN32 needed too, as it's used all over to target Windows generally
213
214 if not env['BF_FANCY']:
215     B.bc.disable()
216
217
218 # remove install dir so old and new files are not mixed.
219 # NOTE: only do the scripts directory for now, otherwise is too disruptive for developers
220 # TODO: perhaps we need an option (off by default) to not do this altogether...
221 if not env['WITHOUT_BF_INSTALL'] and not env['WITHOUT_BF_OVERWRITE_INSTALL']:
222     scriptsDir = os.path.join(env['BF_INSTALLDIR'], VERSION, 'scripts')
223     if os.path.isdir(scriptsDir):
224         print B.bc.OKGREEN + "Clearing installation directory%s: %s" % (B.bc.ENDC, os.path.abspath(scriptsDir))
225         shutil.rmtree(scriptsDir)
226
227
228 SetOption('num_jobs', int(env['BF_NUMJOBS']))
229 print B.bc.OKGREEN + "Build with parallel jobs%s: %s" % (B.bc.ENDC, GetOption('num_jobs'))
230 print B.bc.OKGREEN + "Build with debug symbols%s: %s" % (B.bc.ENDC, env['BF_DEBUG'])
231
232 if 'blenderlite' in B.targets:
233     target_env_defs = {}
234     target_env_defs['WITH_BF_GAMEENGINE'] = False
235     target_env_defs['WITH_BF_OPENAL'] = False
236     target_env_defs['WITH_BF_OPENEXR'] = False
237     target_env_defs['WITH_BF_OPENMP'] = False
238     target_env_defs['WITH_BF_ICONV'] = False
239     target_env_defs['WITH_BF_INTERNATIONAL'] = False
240     target_env_defs['WITH_BF_OPENJPEG'] = False
241     target_env_defs['WITH_BF_FFMPEG'] = False
242     target_env_defs['WITH_BF_QUICKTIME'] = False
243     target_env_defs['WITH_BF_REDCODE'] = False
244     target_env_defs['WITH_BF_DDS'] = False
245     target_env_defs['WITH_BF_CINEON'] = False
246     target_env_defs['WITH_BF_HDR'] = False
247     target_env_defs['WITH_BF_ZLIB'] = False
248     target_env_defs['WITH_BF_SDL'] = False
249     target_env_defs['WITH_BF_JPEG'] = False
250     target_env_defs['WITH_BF_PNG'] = False
251     target_env_defs['WITH_BF_BULLET'] = False
252     target_env_defs['WITH_BF_BINRELOC'] = False
253     target_env_defs['BF_BUILDINFO'] = False
254     target_env_defs['BF_NO_ELBEEM'] = True
255     target_env_defs['WITH_BF_PYTHON'] = False
256     target_env_defs['WITH_BF_3DMOUSE'] = False
257     
258     # Merge blenderlite, let command line to override
259     for k,v in target_env_defs.iteritems():
260         if k not in B.arguments:
261             env[k] = v
262
263 # Extended OSX_SDK and 3D_CONNEXION_CLIENT_LIBRARY detection for OSX
264 if env['OURPLATFORM']=='darwin':
265     print B.bc.OKGREEN + "Detected Xcode version: -- " + B.bc.ENDC + env['XCODE_CUR_VER'][:9] + " --"
266     print "Available " + env['MACOSX_SDK_CHECK']
267     if not 'Mac OS X 10.5' in env['MACOSX_SDK_CHECK']:
268         print  B.bc.OKGREEN + "MacOSX10.5.sdk not available:" + B.bc.ENDC + " using MacOSX10.6.sdk"
269     else:
270         print B.bc.OKGREEN + "Found recommended sdk :" + B.bc.ENDC + " using MacOSX10.5.sdk"
271
272     # for now, Mac builders must download and install the 3DxWare 10 Beta 4 driver framework from 3Dconnexion
273     # necessary header file lives here when installed:
274     # /Library/Frameworks/3DconnexionClient.framework/Versions/Current/Headers/ConnexionClientAPI.h
275     if env['WITH_BF_3DMOUSE'] == 1:
276         if not os.path.exists('/Library/Frameworks/3DconnexionClient.framework'):
277             print "3D_CONNEXION_CLIENT_LIBRARY not found, disabling WITH_BF_3DMOUSE" # avoid build errors !
278             env['WITH_BF_3DMOUSE'] = 0
279         else:
280             env.Append(LINKFLAGS=['-weak_framework','3DconnexionClient'])
281
282 if env['WITH_BF_OPENMP'] == 1:
283         if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
284                 env['CCFLAGS'].append('/openmp')
285                 env['CPPFLAGS'].append('/openmp')
286                 env['CXXFLAGS'].append('/openmp')
287         else:
288             if env['CC'].endswith('icc'): # to be able to handle CC=/opt/bla/icc case
289                 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
290                 env['CCFLAGS'].append('-openmp')
291                 env['CPPFLAGS'].append('-openmp')
292                 env['CXXFLAGS'].append('-openmp')
293             else:
294                 env.Append(CCFLAGS=['-fopenmp']) 
295                 env.Append(CPPFLAGS=['-fopenmp'])
296                 env.Append(CXXFLAGS=['-fopenmp'])
297
298 if env['WITH_GHOST_COCOA'] == True:
299     env.Append(CFLAGS=['-DGHOST_COCOA']) 
300     env.Append(CXXFLAGS=['-DGHOST_COCOA'])
301     env.Append(CPPFLAGS=['-DGHOST_COCOA'])
302     
303 if env['USE_QTKIT'] == True:
304     env.Append(CFLAGS=['-DUSE_QTKIT']) 
305     env.Append(CXXFLAGS=['-DUSE_QTKIT'])
306     env.Append(CPPFLAGS=['-DUSE_QTKIT'])
307
308 #check for additional debug libnames
309
310 if env.has_key('BF_DEBUG_LIBS'):
311     B.quickdebug += env['BF_DEBUG_LIBS']
312
313 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
314
315 if len(B.quickdebug) > 0 and printdebug != 0:
316     print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
317     for l in B.quickdebug:
318         print "\t" + l
319
320 # remove stdc++ from LLIBS if we are building a statc linked CXXFLAGS
321 if env['WITH_BF_STATICCXX']:
322     if 'stdc++' in env['LLIBS']:
323         env['LLIBS'].remove('stdc++')
324     else:
325         print '\tcould not remove stdc++ library from LLIBS, WITH_BF_STATICCXX may not work for your platform'
326
327 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
328 if 'blenderplayer' in B.targets:
329     env['WITH_BF_PLAYER'] = True
330
331 if 'blendernogame' in B.targets:
332     env['WITH_BF_GAMEENGINE'] = False
333
334 # disable elbeem (fluidsim) compilation?
335 if env['BF_NO_ELBEEM'] == 1:
336     env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
337     env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
338     env['CCFLAGS'].append('-DDISABLE_ELBEEM')
339
340
341 if btools.ENDIAN == "big":
342     env['CPPFLAGS'].append('-D__BIG_ENDIAN__')
343     env['CXXFLAGS'].append('-D__BIG_ENDIAN__')
344     env['CCFLAGS'].append('-D__BIG_ENDIAN__')
345 else:
346     env['CPPFLAGS'].append('-D__LITTLE_ENDIAN__')
347     env['CXXFLAGS'].append('-D__LITTLE_ENDIAN__')
348     env['CCFLAGS'].append('-D__LITTLE_ENDIAN__')        
349
350
351 # TODO, make optional
352 env['CPPFLAGS'].append('-DWITH_AUDASPACE')
353 env['CXXFLAGS'].append('-DWITH_AUDASPACE')
354 env['CCFLAGS'].append('-DWITH_AUDASPACE')
355
356 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
357 B.root_build_dir = env['BF_BUILDDIR']
358 B.doc_build_dir = os.path.join(env['BF_INSTALLDIR'], 'doc')
359 if not B.root_build_dir[-1]==os.sep:
360     B.root_build_dir += os.sep
361 if not B.doc_build_dir[-1]==os.sep:
362     B.doc_build_dir += os.sep
363     
364 # We do a shortcut for clean when no quicklist is given: just delete
365 # builddir without reading in SConscripts
366 do_clean = None
367 if 'clean' in B.targets:
368     do_clean = True
369
370 if not quickie and do_clean:
371     if os.path.exists(B.doc_build_dir):
372         print B.bc.HEADER+'Cleaning doc dir...'+B.bc.ENDC
373         dirs = os.listdir(B.doc_build_dir)
374         for entry in dirs:
375             if os.path.isdir(B.doc_build_dir + entry) == 1:
376                 print "clean dir %s"%(B.doc_build_dir+entry)
377                 shutil.rmtree(B.doc_build_dir+entry)
378             else: # remove file
379                 print "remove file %s"%(B.doc_build_dir+entry)
380                 os.remove(B.root_build_dir+entry)
381     if os.path.exists(B.root_build_dir):
382         print B.bc.HEADER+'Cleaning build dir...'+B.bc.ENDC
383         dirs = os.listdir(B.root_build_dir)
384         for entry in dirs:
385             if os.path.isdir(B.root_build_dir + entry) == 1:
386                 print "clean dir %s"%(B.root_build_dir+entry)
387                 shutil.rmtree(B.root_build_dir+entry)
388             else: # remove file
389                 print "remove file %s"%(B.root_build_dir+entry)
390                 os.remove(B.root_build_dir+entry)
391         for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
392                 'extern/xvidcore/build/generic/platform.inc', 'extern/ffmpeg/include']:
393             if os.path.exists(confile):
394                 print "clean file %s"%confile
395                 if os.path.isdir(confile):
396                     for root, dirs, files in os.walk(confile):
397                         for name in files:
398                             os.remove(os.path.join(root, name))
399                 else:
400                     os.remove(confile)
401         print B.bc.OKGREEN+'...done'+B.bc.ENDC
402     else:
403         print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
404     Exit()
405
406
407 # ensure python header is found since detection can fail, this could happen
408 # with _any_ library but since we used a fixed python version this tends to
409 # be most problematic.
410 if env['WITH_BF_PYTHON']:
411         py_h = os.path.join(Dir(env.subst('${BF_PYTHON_INC}')).abspath, "Python.h")
412
413         if not os.path.exists(py_h):
414                 print("\nMissing: \"" + env.subst('${BF_PYTHON_INC}') + os.sep + "Python.h\",\n"
415                           "  Set 'BF_PYTHON_INC' to point "
416                           "to a valid python include path.\n  Containing "
417                           "Python.h for python version \"" + env.subst('${BF_PYTHON_VERSION}') + "\"")
418
419                 Exit()
420         del py_h
421
422
423 if not os.path.isdir ( B.root_build_dir):
424     os.makedirs ( B.root_build_dir )
425     os.makedirs ( B.root_build_dir + 'source' )
426     os.makedirs ( B.root_build_dir + 'intern' )
427     os.makedirs ( B.root_build_dir + 'extern' )
428     os.makedirs ( B.root_build_dir + 'lib' )
429     os.makedirs ( B.root_build_dir + 'bin' )
430 # # Docs not working with epy anymore
431 # if not os.path.isdir(B.doc_build_dir) and env['WITH_BF_DOCS']:
432 #     os.makedirs ( B.doc_build_dir )
433
434 Help(opts.GenerateHelpText(env))
435
436 # default is new quieter output, but if you need to see the 
437 # commands, do 'scons BF_QUIET=0'
438 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
439 if env['BF_QUIET']:
440     B.set_quiet_output(env)
441 else:
442     if toolset=='msvc':
443         B.msvc_hack(env)
444
445 print B.bc.HEADER+'Building in: ' + B.bc.ENDC + os.path.abspath(B.root_build_dir)
446 env.SConsignFile(B.root_build_dir+'scons-signatures')
447 B.init_lib_dict()
448
449 ##### END SETUP ##########
450
451 Export('env')
452
453 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
454 SConscript(B.root_build_dir+'/intern/SConscript')
455 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
456 SConscript(B.root_build_dir+'/extern/SConscript')
457 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
458 SConscript(B.root_build_dir+'/source/SConscript')
459
460 # now that we have read all SConscripts, we know what
461 # libraries will be built. Create list of
462 # libraries to give as objects to linking phase
463 mainlist = []
464 for tp in B.possible_types:
465     if (not tp == 'player') and (not tp == 'player2'):
466         mainlist += B.create_blender_liblist(env, tp)
467
468 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
469     B.propose_priorities()
470
471 dobj = B.buildinfo(env, "dynamic") + B.resources
472 creob = B.creator(env)
473 thestatlibs, thelibincs = B.setup_staticlibs(env)
474 thesyslibs = B.setup_syslibs(env)
475
476 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
477     env.BlenderProg(B.root_build_dir, "blender", creob + mainlist + thestatlibs + dobj, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
478 if env['WITH_BF_PLAYER']:
479     playerlist = B.create_blender_liblist(env, 'player')
480     playerlist += B.create_blender_liblist(env, 'player2')
481     playerlist += B.create_blender_liblist(env, 'intern')
482     playerlist += B.create_blender_liblist(env, 'extern')
483     env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
484
485 ##### Now define some targets
486
487
488 #------------ INSTALL
489
490 #-- binaries
491 blenderinstall = []
492 if  env['OURPLATFORM']=='darwin':
493     for prg in B.program_list:
494         bundle = '%s.app' % prg[0]
495         bundledir = os.path.dirname(bundle)
496         for dp, dn, df in os.walk(bundle):
497             if '.svn' in dn:
498                 dn.remove('.svn')
499             if '_svn' in dn:
500                 dn.remove('_svn')
501             dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
502             source=[dp+os.sep+f for f in df]
503             blenderinstall.append(env.Install(dir=dir,source=source))
504 else:
505     blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
506
507 #-- local path = config files in install dir: installdir\VERSION
508 #- dont do config and scripts for darwin, it is already in the bundle
509 dotblendlist = []
510 datafileslist = []
511 datafilestargetlist = []
512 dottargetlist = []
513 scriptinstall = []
514
515 if env['OURPLATFORM']!='darwin':
516         for dp, dn, df in os.walk('release/bin/.blender'):
517             dp = os.path.normpath(dp)
518
519             if '.svn' in dn:
520                 dn.remove('.svn')
521             if '_svn' in dn:
522                 dn.remove('_svn')
523             
524             for f in df:
525                 if not env['WITH_BF_INTERNATIONAL']:
526                     if 'locale' in dp:
527                         continue
528                     if f == '.Blanguages':
529                         continue
530                 if not env['WITH_BF_FREETYPE']:
531                     if f.endswith('.ttf'):
532                         continue
533                 
534                 if 'locale' in dp or 'fonts' in dp:
535                     datafileslist.append(os.path.join(dp,f))
536                     dir= os.path.join(*([env['BF_INSTALLDIR']] + [VERSION] + ['datafiles'] + dp.split(os.sep)[3:]))    # skip bin
537                     datafilestargetlist.append(dir + os.sep + f)
538
539                 else:
540                     dotblendlist.append(os.path.join(dp, f))
541                     dir= os.path.join(*([env['BF_INSTALLDIR']] + [VERSION] + ['config'] + dp.split(os.sep)[3:]))    # skip bin
542                     dottargetlist.append(dir + os.sep + f)
543                     
544         dotblenderinstall = []
545         for targetdir,srcfile in zip(dottargetlist, dotblendlist):
546             td, tf = os.path.split(targetdir)
547             dotblenderinstall.append(env.Install(dir=td, source=srcfile))
548         for targetdir,srcfile in zip(datafilestargetlist, datafileslist):
549             td, tf = os.path.split(targetdir)
550             dotblenderinstall.append(env.Install(dir=td, source=srcfile))
551         
552         if env['WITH_BF_PYTHON']:
553             #-- local/VERSION/scripts
554             scriptpaths=['release/scripts']
555             for scriptpath in scriptpaths:
556                 for dp, dn, df in os.walk(scriptpath):
557                     if '.svn' in dn:
558                         dn.remove('.svn')
559                     if '_svn' in dn:
560                         dn.remove('_svn')
561                     if '__pycache__' in dn:  # py3.2 cache dir
562                         dn.remove('__pycache__')
563
564                     dir = os.path.join(env['BF_INSTALLDIR'], VERSION)
565                     dir += os.sep + os.path.basename(scriptpath) + dp[len(scriptpath):]
566
567                     source=[os.path.join(dp, f) for f in df if not f.endswith(".pyc")]
568                     # To ensure empty dirs are created too
569                     if len(source)==0:
570                         env.Execute(Mkdir(dir))
571                     scriptinstall.append(env.Install(dir=dir,source=source))
572
573 #-- icons
574 if env['OURPLATFORM']=='linux':
575     iconlist = []
576     icontargetlist = []
577
578     for tp, tn, tf in os.walk('release/freedesktop/icons'):
579         if '.svn' in tn:
580             tn.remove('.svn')
581         if '_svn' in tn:
582             tn.remove('_svn')
583         for f in tf:
584             iconlist.append(os.path.join(tp, f))
585             icontargetlist.append( os.path.join(*([env['BF_INSTALLDIR']] + tp.split(os.sep)[2:] + [f])) )
586
587     iconinstall = []
588     for targetdir,srcfile in zip(icontargetlist, iconlist):
589         td, tf = os.path.split(targetdir)
590         iconinstall.append(env.Install(dir=td, source=srcfile))
591
592 # dlls for linuxcross
593 # TODO - add more libs, for now this lets blenderlite run
594 if env['OURPLATFORM']=='linuxcross':
595     dir=env['BF_INSTALLDIR']
596     source = []
597
598     if env['WITH_BF_OPENMP']:
599         source += ['../lib/windows/pthreads/lib/pthreadGC2.dll']
600
601     scriptinstall.append(env.Install(dir=dir, source=source))
602
603 #-- plugins
604 pluglist = []
605 plugtargetlist = []
606 for tp, tn, tf in os.walk('release/plugins'):
607     if '.svn' in tn:
608         tn.remove('.svn')
609     if '_svn' in tn:
610         tn.remove('_svn')
611     df = tp[8:] # remove 'release/'
612     for f in tf:
613         pluglist.append(os.path.join(tp, f))
614         plugtargetlist.append( os.path.join(env['BF_INSTALLDIR'], VERSION, df, f) )
615
616
617 # header files for plugins
618 pluglist.append('source/blender/blenpluginapi/documentation.h')
619 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'documentation.h'))
620 pluglist.append('source/blender/blenpluginapi/externdef.h')
621 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'externdef.h'))
622 pluglist.append('source/blender/blenpluginapi/floatpatch.h')
623 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'floatpatch.h'))
624 pluglist.append('source/blender/blenpluginapi/iff.h')
625 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'iff.h'))
626 pluglist.append('source/blender/blenpluginapi/plugin.h')
627 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'plugin.h'))
628 pluglist.append('source/blender/blenpluginapi/util.h')
629 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'util.h'))
630 pluglist.append('source/blender/blenpluginapi/plugin.DEF')
631 plugtargetlist.append(os.path.join(env['BF_INSTALLDIR'], VERSION, 'plugins', 'include', 'plugin.def'))
632
633 plugininstall = []
634 # plugins in blender 2.5 don't work at the moment.
635 #for targetdir,srcfile in zip(plugtargetlist, pluglist):
636 #    td, tf = os.path.split(targetdir)
637 #    plugininstall.append(env.Install(dir=td, source=srcfile))
638
639 textlist = []
640 texttargetlist = []
641 for tp, tn, tf in os.walk('release/text'):
642     if '.svn' in tn:
643         tn.remove('.svn')
644     if '_svn' in tn:
645         tn.remove('_svn')
646     for f in tf:
647         textlist.append(tp+os.sep+f)
648
649 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
650
651 if  env['OURPLATFORM']=='darwin':
652         allinstall = [blenderinstall, plugininstall, textinstall]
653 elif env['OURPLATFORM']=='linux':
654         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall, iconinstall]
655 else:
656         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
657
658 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'):
659     dllsources = []
660
661     if not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
662         # For MinGW and linuxcross static linking will be used
663         dllsources += ['${LCGDIR}/gettext/lib/gnu_gettext.dll']
664
665     #currently win64-vc doesn't appear to have libpng.dll
666     if env['OURPLATFORM'] != 'win64-vc':
667         dllsources += ['${BF_PNG_LIBPATH}/libpng.dll']
668
669     dllsources += ['${BF_ZLIB_LIBPATH}/zlib.dll']
670     # Used when linking to libtiff was dynamic
671     # keep it here until compilation on all platform would be ok
672     # dllsources += ['${BF_TIFF_LIBPATH}/${BF_TIFF_LIB}.dll']
673
674     if env['OURPLATFORM'] != 'linuxcross':
675         # pthreads library is already added
676         dllsources += ['${BF_PTHREADS_LIBPATH}/${BF_PTHREADS_LIB}.dll']
677
678     if env['WITH_BF_SDL']:
679         if env['OURPLATFORM'] == 'win64-vc':
680             pass # we link statically already to SDL on win64
681         else:
682             dllsources.append('${BF_SDL_LIBPATH}/SDL.dll')
683
684     if env['WITH_BF_PYTHON']:
685         if env['BF_DEBUG']:
686             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll')
687         else:
688             dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}.dll')
689
690     if env['WITH_BF_ICONV']:
691         if env['OURPLATFORM'] == 'win64-vc':
692             pass # we link statically to iconv on win64
693         elif not env['OURPLATFORM'] in ('win32-mingw', 'linuxcross'):
694             #gettext for MinGW and cross-compilation is compiled staticly
695             dllsources += ['${BF_ICONV_LIBPATH}/iconv.dll']
696
697     if env['WITH_BF_OPENAL']:
698         dllsources.append('${LCGDIR}/openal/lib/OpenAL32.dll')
699         dllsources.append('${LCGDIR}/openal/lib/wrap_oal.dll')
700
701     if env['WITH_BF_SNDFILE']:
702         dllsources.append('${LCGDIR}/sndfile/lib/libsndfile-1.dll')
703
704     if env['WITH_BF_FFMPEG']:
705         dllsources += env['BF_FFMPEG_DLL'].split()
706
707     # Since the thumb handler is loaded by Explorer, architecture is
708     # strict: the x86 build fails on x64 Windows. We need to ship
709     # both builds in x86 packages.
710     if bitness == 32:
711         dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb.dll')  
712     dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll')
713
714     dllsources.append('#source/icons/blender.exe.manifest')
715
716     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
717     allinstall += windlls
718
719 installtarget = env.Alias('install', allinstall)
720 bininstalltarget = env.Alias('install-bin', blenderinstall)
721
722 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
723 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
724 nsisalias = env.Alias('nsis', nsiscmd)
725
726 if 'blender' in B.targets:
727     blenderexe= env.Alias('blender', B.program_list)
728     Depends(blenderexe,installtarget)
729
730 if env['WITH_BF_PLAYER']:
731     blenderplayer = env.Alias('blenderplayer', B.program_list)
732     Depends(blenderplayer,installtarget)
733
734 if not env['WITH_BF_GAMEENGINE']:
735     blendernogame = env.Alias('blendernogame', B.program_list)
736     Depends(blendernogame,installtarget)
737
738 if 'blenderlite' in B.targets:
739     blenderlite = env.Alias('blenderlite', B.program_list)
740     Depends(blenderlite,installtarget)
741
742 Depends(nsiscmd, allinstall)
743
744 buildslave_action = env.Action(btools.buildslave, btools.buildslave_print)
745 buildslave_cmd = env.Command('buildslave_exec', None, buildslave_action)
746 buildslave_alias = env.Alias('buildslave', buildslave_cmd)
747
748 Depends(buildslave_cmd, allinstall)
749
750 Default(B.program_list)
751
752 if not env['WITHOUT_BF_INSTALL']:
753         Default(installtarget)
754