Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / tools / Blender.py
1 #!/usr/bin/env python
2
3 """
4 tools.BlenderEnvironment
5
6 This environment builds on SCons.Script.SConscript.SConsEnvironment
7
8 * library repository
9 * custom printout
10 * wrapper functions
11
12 TODO: clean up and sanitise code - crosscheck with btools and SConstruct
13 to kill any code duplication
14
15 """
16
17 import os
18 import os.path
19 import string
20 import glob
21 import time
22 import sys
23
24 from SCons.Script.SConscript import SConsEnvironment
25 import SCons.Action
26 import SCons.Util
27 import SCons.Builder
28 import SCons.Tool
29 import bcolors
30 bc = bcolors.bcolors()
31
32 Split = SCons.Util.Split
33 Action = SCons.Action.Action
34 Builder = SCons.Builder.Builder
35 GetBuildPath = SConsEnvironment.GetBuildPath
36
37 # a few globals
38 root_build_dir = ''
39 doc_build_dir = ''
40 quickie = None # Anything else than None if BF_QUICK has been passed
41 quicklist = [] # The list of libraries/programs to compile during a quickie
42 program_list = [] # A list holding Nodes to final binaries, used to create installs
43 arguments = None
44 targets = None
45 resources = []
46
47 #some internals
48 blenderdeps = [] # don't manipulate this one outside this module!
49
50 ##### LIB STUFF ##########
51
52 possible_types = ['core'] # can be set in ie. SConstruct
53 libs = {}
54 vcp = []
55
56 def getresources():
57         return resources
58
59 def init_lib_dict():
60         for pt in possible_types:
61                 libs[pt] = {}
62
63 # helper func for add_lib_to_dict
64 def internal_lib_to_dict(dict = None, libtype = None, libname = None, priority = 100):
65         if not libname in dict[libtype]:
66                 done = None
67                 while not done:
68                         if dict[libtype].has_key(priority):
69                                 priority = priority + 1
70                         else:
71                                 done = True
72                 dict[libtype][priority] = libname
73
74 # libtype and priority can both be lists, for defining lib in multiple places
75 def add_lib_to_dict(env, dict = None, libtype = None, libname = None, priority = 100):
76         if not dict or not libtype or not libname:
77                 print "Passed wrong arg"
78                 env.Exit()
79
80         if type(libtype) is str and type(priority) is int:
81                 internal_lib_to_dict(dict, libtype, libname, priority)
82         elif type(libtype) is list and type(priority) is list:
83                 if len(libtype)==len(priority):
84                         for lt, p in zip(libtype, priority):
85                                 internal_lib_to_dict(dict, lt, libname, p)
86                 else:
87                         print "libtype and priority lists are unequal in length"
88                         env.Exit()
89         else:
90                 print "Wrong type combinations for libtype and priority. Only str and int or list and list"
91                 env.Exit()
92
93 def create_blender_liblist(lenv = None, libtype = None):
94         if not lenv or not libtype:
95                 print "missing arg"
96
97         lst = []
98         if libtype in possible_types:
99                 curlib = libs[libtype]
100                 sortlist = curlib.keys()
101                 sortlist.sort()
102                 for sk in sortlist:
103                         v = curlib[sk]
104                         target = os.path.abspath(os.getcwd() + os.sep + root_build_dir + 'lib' + os.sep +lenv['LIBPREFIX'] + v + lenv['LIBSUFFIX'])
105                         lst.append(target)
106
107         return lst
108
109 ## TODO: static linking
110 def setup_staticlibs(lenv):
111         statlibs = [
112                 #here libs for static linking
113         ]
114         libincs = [
115                 lenv['BF_OPENGL_LIBPATH'],
116                 lenv['BF_JPEG_LIBPATH'],
117                 lenv['BF_PNG_LIBPATH'],
118                 lenv['BF_ZLIB_LIBPATH'],
119                 lenv['BF_LIBSAMPLERATE_LIBPATH'],
120                 lenv['BF_ICONV_LIBPATH']
121                 ]
122
123         if lenv['OURPLATFORM'] != 'linuxcross':
124                 libincs = ['/usr/lib'] + libincs
125
126         libincs += Split(lenv['BF_FREETYPE_LIBPATH'])
127         if lenv['WITH_BF_PYTHON']:
128                 libincs += Split(lenv['BF_PYTHON_LIBPATH'])
129         if lenv['WITH_BF_SDL']:
130                 libincs += Split(lenv['BF_SDL_LIBPATH'])
131         if lenv['WITH_BF_FFMPEG']:
132                 libincs += Split(lenv['BF_FFMPEG_LIBPATH'])
133         if lenv['WITH_BF_JACK']:
134                 libincs += Split(lenv['BF_JACK_LIBPATH'])
135         if lenv['WITH_BF_OPENEXR']:
136                 libincs += Split(lenv['BF_OPENEXR_LIBPATH'])
137                 if lenv['WITH_BF_STATICOPENEXR']:
138                         statlibs += Split(lenv['BF_OPENEXR_LIB_STATIC'])
139         if lenv['WITH_BF_FFTW3']:
140                 libincs += Split(lenv['BF_FFTW3_LIBPATH'])
141         if lenv['WITH_BF_INTERNATIONAL']:
142                 libincs += Split(lenv['BF_GETTEXT_LIBPATH'])
143         if lenv['WITH_BF_OPENAL']:
144                 libincs += Split(lenv['BF_OPENAL_LIBPATH'])
145                 if lenv['WITH_BF_STATICOPENAL']:
146                         statlibs += Split(lenv['BF_OPENAL_LIB_STATIC'])
147         if lenv['WITH_BF_STATICOPENGL']:
148                 statlibs += Split(lenv['BF_OPENGL_LIB_STATIC'])
149         if lenv['WITH_BF_STATICCXX']:
150                 statlibs += Split(lenv['BF_CXX_LIB_STATIC'])
151
152         if lenv['WITH_BF_PYTHON'] and lenv['WITH_BF_STATICPYTHON']:
153                 statlibs += Split(lenv['BF_PYTHON_LIB_STATIC'])
154
155         if lenv['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
156                 libincs += Split(lenv['BF_PTHREADS_LIBPATH'])
157
158         return statlibs, libincs
159
160 def setup_syslibs(lenv):
161         syslibs = [
162                 
163                 lenv['BF_JPEG_LIB'],
164                 lenv['BF_PNG_LIB'],
165                 lenv['BF_ZLIB_LIB'],
166                 lenv['BF_LIBSAMPLERATE_LIB']
167                 ]
168
169         syslibs += Split(lenv['BF_FREETYPE_LIB'])
170         if lenv['WITH_BF_UNIT_TEST']:
171                 syslibs.append(lenv['BF_CHECK_LIB'])
172         if lenv['WITH_BF_PYTHON'] and not lenv['WITH_BF_STATICPYTHON']:
173                 if lenv['BF_DEBUG'] and lenv['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
174                         syslibs.append(lenv['BF_PYTHON_LIB']+'_d')
175                 else:
176                         syslibs.append(lenv['BF_PYTHON_LIB'])
177         if lenv['WITH_BF_INTERNATIONAL']:
178                 syslibs += Split(lenv['BF_GETTEXT_LIB'])
179         if lenv['WITH_BF_OPENAL']:
180                 if not lenv['WITH_BF_STATICOPENAL']:
181                         syslibs += Split(lenv['BF_OPENAL_LIB'])
182         if lenv['WITH_BF_OPENMP'] and lenv['CC'] != 'icc':
183                 if lenv['CC'] == 'cl.exe':
184                         syslibs += ['vcomp']
185                 else:
186                         syslibs += ['gomp']
187         if lenv['WITH_BF_ICONV']:
188                 syslibs += Split(lenv['BF_ICONV_LIB'])
189         if lenv['WITH_BF_OPENEXR']:
190                 if not lenv['WITH_BF_STATICOPENEXR']:
191                         syslibs += Split(lenv['BF_OPENEXR_LIB'])
192         if lenv['WITH_BF_FFMPEG']:
193                 syslibs += Split(lenv['BF_FFMPEG_LIB'])
194                 if lenv['WITH_BF_OGG']:
195                         syslibs += Split(lenv['BF_OGG_LIB'])
196         if lenv['WITH_BF_JACK']:
197                         syslibs += Split(lenv['BF_JACK_LIB'])
198         if lenv['WITH_BF_FFTW3']:
199                 syslibs += Split(lenv['BF_FFTW3_LIB'])
200         if lenv['WITH_BF_SDL']:
201                 syslibs += Split(lenv['BF_SDL_LIB'])
202         if not lenv['WITH_BF_STATICOPENGL']:
203                 syslibs += Split(lenv['BF_OPENGL_LIB'])
204         if lenv['OURPLATFORM'] in ('win32-vc', 'win32-mingw','linuxcross', 'win64-vc'):
205                 syslibs += Split(lenv['BF_PTHREADS_LIB'])
206         if lenv['WITH_BF_LCMS']:
207                 syslibs.append(lenv['BF_LCMS_LIB'])
208
209
210         syslibs += lenv['LLIBS']
211
212         return syslibs
213
214 def propose_priorities():
215         print bc.OKBLUE+"Priorities:"+bc.ENDC
216         for t in possible_types:
217                 print bc.OKGREEN+"\t"+t+bc.ENDC
218                 new_priority = 0
219                 curlib = libs[t]
220                 sortlist = curlib.keys()
221                 sortlist.sort()
222
223                 for sk in sortlist:
224                         v = curlib[sk]
225                         #for p,v in sorted(libs[t].iteritems()):
226                         print "\t\t",new_priority, v
227                         new_priority += 5
228
229 ## TODO: see if this can be made in an emitter
230 def buildinfo(lenv, build_type):
231         """
232         Generate a buildinfo object
233         """
234         build_date = time.strftime ("%Y-%m-%d")
235         build_time = time.strftime ("%H:%M:%S")
236         build_rev = os.popen('svnversion').read()[:-1] # remove \n
237
238         obj = []
239         if lenv['BF_BUILDINFO']:
240                 if sys.platform=='win32' or lenv['OURPLATFORM']=='linuxcross':
241                         build_info_file = open("source/creator/winbuildinfo.h", 'w')
242                         build_info_file.write("char *build_date=\"%s\";\n"%build_date)
243                         build_info_file.write("char *build_time=\"%s\";\n"%build_time)
244                         build_info_file.write("char *build_rev=\"%s\";\n"%build_rev)
245                         build_info_file.write("char *build_platform=\"win32\";\n")
246                         build_info_file.write("char *build_type=\"dynamic\";\n")
247                         build_info_file.close()
248                         lenv.Append (CPPDEFINES = ['NAN_BUILDINFO', 'BUILD_DATE'])
249                 else:
250                         lenv.Append (CPPDEFINES = ['BUILD_TIME=\'"%s"\''%(build_time),
251                                                                                 'BUILD_DATE=\'"%s"\''%(build_date),
252                                                                                 'BUILD_TYPE=\'"dynamic"\'',
253                                                                                 'BUILD_REV=\'"%s"\''%(build_rev),
254                                                                                 'NAN_BUILDINFO',
255                                                                                 'BUILD_PLATFORM=\'"%s"\''%(sys.platform)])
256                 obj = [lenv.Object (root_build_dir+'source/creator/%s_buildinfo'%build_type,
257                                                 [root_build_dir+'source/creator/buildinfo.c'])]
258         return obj
259
260 ##### END LIB STUFF ############
261
262 ##### ACTION STUFF #############
263
264 def my_compile_print(target, source, env):
265         a = '%s' % (source[0])
266         d, f = os.path.split(a)
267         return bc.OKBLUE+"Compiling"+bc.ENDC +" ==> '"+bc.OKGREEN+"%s" % (f) + "'"+bc.ENDC
268
269 def my_moc_print(target, source, env):
270         a = '%s' % (source[0])
271         d, f = os.path.split(a)
272         return bc.OKBLUE+"Creating MOC"+bc.ENDC+ " ==> '"+bc.OKGREEN+"%s" %(f) + "'"+bc.ENDC
273
274 def my_linking_print(target, source, env):
275         t = '%s' % (target[0])
276         d, f = os.path.split(t)
277         return bc.OKBLUE+"Linking library"+bc.ENDC +" ==> '"+bc.OKGREEN+"%s" % (f) + "'"+bc.ENDC
278
279 def my_program_print(target, source, env):
280         t = '%s' % (target[0])
281         d, f = os.path.split(t)
282         return bc.OKBLUE+"Linking program"+bc.ENDC +" ==> '"+bc.OKGREEN+"%s" % (f) + "'"+bc.ENDC
283
284 def msvc_hack(env):
285         static_lib = SCons.Tool.createStaticLibBuilder(env)
286         program = SCons.Tool.createProgBuilder(env)
287         
288         env['BUILDERS']['Library'] = static_lib
289         env['BUILDERS']['StaticLibrary'] = static_lib
290         env['BUILDERS']['Program'] = program
291                 
292 def set_quiet_output(env):
293         mycaction = Action("$CCCOM", strfunction=my_compile_print)
294         myshcaction = Action("$SHCCCOM", strfunction=my_compile_print)
295         mycppaction = Action("$CXXCOM", strfunction=my_compile_print)
296         myshcppaction = Action("$SHCXXCOM", strfunction=my_compile_print)
297         mylibaction = Action("$ARCOM", strfunction=my_linking_print)
298         mylinkaction = Action("$LINKCOM", strfunction=my_program_print)
299
300         static_ob, shared_ob = SCons.Tool.createObjBuilders(env)
301         static_ob.add_action('.c', mycaction)
302         static_ob.add_action('.cpp', mycppaction)
303         shared_ob.add_action('.c', myshcaction)
304         shared_ob.add_action('.cpp', myshcppaction)
305
306         static_lib = SCons.Builder.Builder(action = mylibaction,
307                                                                            emitter = '$LIBEMITTER',
308                                                                            prefix = '$LIBPREFIX',
309                                                                            suffix = '$LIBSUFFIX',
310                                                                            src_suffix = '$OBJSUFFIX',
311                                                                            src_builder = 'StaticObject')
312
313         program = SCons.Builder.Builder(action = mylinkaction,
314                                                                         emitter = '$PROGEMITTER',
315                                                                         prefix = '$PROGPREFIX',
316                                                                         suffix = '$PROGSUFFIX',
317                                                                         src_suffix = '$OBJSUFFIX',
318                                                                         src_builder = 'Object',
319                                                                         target_scanner = SCons.Defaults.ProgScan)
320
321         env['BUILDERS']['Object'] = static_ob
322         env['BUILDERS']['StaticObject'] = static_ob
323         env['BUILDERS']['StaticLibrary'] = static_lib
324         env['BUILDERS']['Library'] = static_lib
325         env['BUILDERS']['Program'] = program
326
327 def  my_appit_print(target, source, env):
328         a = '%s' % (target[0])
329         d, f = os.path.split(a)
330         return "making bundle for " + f
331
332 def AppIt(target=None, source=None, env=None):
333         import shutil
334         import commands
335         import os.path
336         
337         
338         a = '%s' % (target[0])
339         builddir, b = os.path.split(a)
340         libdir = env['LCGDIR'][1:]
341
342         bldroot = env.Dir('.').abspath
343         binary = env['BINARYKIND']
344          
345         if b=='verse':
346                 print bc.OKBLUE+"no bundle for verse"+bc.ENDC 
347                 return 0
348         
349         sourcedir = bldroot + '/source/darwin/%s.app'%binary
350         sourceinfo = bldroot + "/source/darwin/%s.app/Contents/Info.plist"%binary
351         targetinfo = builddir +'/' + "%s.app/Contents/Info.plist"%binary
352         cmd = builddir + '/' +'%s.app'%binary
353         
354         if os.path.isdir(cmd):
355                 shutil.rmtree(cmd)
356         shutil.copytree(sourcedir, cmd)
357         cmd = "cat %s | sed s/VERSION/`cat release/VERSION`/ | sed s/DATE/`date +'%%Y-%%b-%%d'`/ > %s"%(sourceinfo,targetinfo)
358         commands.getoutput(cmd)
359         cmd = 'cp %s/%s %s/%s.app/Contents/MacOS/%s'%(builddir, binary,builddir, binary, binary)
360         commands.getoutput(cmd)
361         cmd = 'mkdir %s/%s.app/Contents/MacOS/.blender/'%(builddir, binary)
362         print cmd
363         commands.getoutput(cmd)
364         cmd = builddir + '/%s.app/Contents/MacOS/.blender'%binary
365         shutil.copy(bldroot + '/bin/.blender/.bfont.ttf', cmd)
366         shutil.copy(bldroot + '/bin/.blender/.Blanguages', cmd)
367         cmd = 'cp -R %s/bin/.blender/locale %s/%s.app/Contents/Resources/'%(bldroot,builddir,binary)
368         commands.getoutput(cmd) 
369         cmd = 'cp -R %s/bin/.blender/locale %s/%s.app/Contents/MacOS/.blender/'%(bldroot,builddir,binary)
370         commands.getoutput(cmd) 
371         cmd = 'cp %s/bin/.blender/.Blanguages %s/%s.app/Contents/Resources/'%(bldroot,builddir,binary)
372         commands.getoutput(cmd) 
373         cmd = 'mkdir %s/%s.app/Contents/MacOS/.blender/python/'%(builddir,binary)
374         commands.getoutput(cmd) 
375         cmd = 'unzip -q %s/release/python.zip -d %s/%s.app/Contents/MacOS/.blender/python/'%(libdir,builddir,binary)
376         commands.getoutput(cmd) 
377         cmd = 'cp -R %s/release/scripts %s/%s.app/Contents/MacOS/.blender/'%(bldroot,builddir,binary)
378         commands.getoutput(cmd)
379         cmd = 'cp -R %s/release/ui %s/%s.app/Contents/MacOS/.blender/'%(bldroot,builddir,binary)
380         commands.getoutput(cmd)
381         cmd = 'cp -R %s/release/io %s/%s.app/Contents/MacOS/.blender/'%(bldroot,builddir,binary)
382         commands.getoutput(cmd)
383         cmd = 'chmod +x  %s/%s.app/Contents/MacOS/%s'%(builddir,binary, binary)
384         commands.getoutput(cmd)
385         cmd = 'find %s/%s.app -name .svn -prune -exec rm -rf {} \;'%(builddir, binary)
386         commands.getoutput(cmd)
387         cmd = 'find %s/%s.app -name .DS_Store -exec rm -rf {} \;'%(builddir, binary)
388         commands.getoutput(cmd)
389
390 # extract copy system python, be sure to update other build systems
391 # when making changes to the files that are copied.
392 def my_pyinst_print(target, source, env):
393         pass
394
395 def PyInstall(target=None, source=None, env=None):
396         # Any Unix except osx
397         #-- .blender/python/lib/python3.1
398         
399         import commands
400         
401         def run(cmd):
402                 print 'Install command:', cmd
403                 commands.getoutput(cmd)
404         
405         py_src =        env.subst( env['BF_PYTHON_LIBPATH'] + '/python'+env['BF_PYTHON_VERSION'] )
406         py_target =     env.subst( env['BF_INSTALLDIR'] + '/.blender/python/lib/python'+env['BF_PYTHON_VERSION'] )
407         
408         # Copied from source/creator/CMakeLists.txt, keep in sync.
409         print 'Install python from:'
410         print '\t"%s" into...' %        py_src
411         print '\t"%s"\n' %                      py_target
412         
413         run('rm -rf "%s"' % py_target)
414         try:    os.makedirs(os.path.dirname(py_target)) # the final part is copied
415         except:pass
416         
417         run('cp -R "%s" "%s"' % (py_src, os.path.dirname(py_target)))
418         run('rm -rf "%s/distutils"' % py_target)
419         run('rm -rf "%s/lib2to3"' % py_target)
420         run('rm -rf "%s/idlelib"' % py_target)
421         run('rm -rf "%s/tkinter"' % py_target)
422         run('rm -rf "%s/config"' % py_target)
423
424         run('rm -rf "%s/site-packages"' % py_target)
425         run('mkdir "%s/site-packages"' % py_target)    # python needs it.'
426
427         run('rm "%s/lib-dynload/_tkinter.so"' % py_target)
428         run('find "%s" -name "test" -prune -exec rm -rf {} \;' % py_target)
429         run('find "%s" -name "*.py?" -exec rm -rf {} \;' % py_target)
430         run('find "%s" -name "*.so"-exec strip -s {} \;' % py_target)
431
432 #### END ACTION STUFF #########
433
434 def bsc(env, target, source):
435         
436         bd = os.path.dirname(target[0].abspath)
437         bscfile = '\"'+target[0].abspath+'\"'
438         bscpathcollect = '\"'+bd + os.sep + '*.sbr\"'
439         bscpathtmp = '\"'+bd + os.sep + 'bscmake.tmp\"'
440
441         os.system('dir /b/s '+bscpathcollect+' >'+bscpathtmp)
442
443         myfile = open(bscpathtmp[1:-1], 'r')
444         lines = myfile.readlines()
445         myfile.close()
446
447         newfile = open(bscpathtmp[1:-1], 'w')
448         for l in lines:
449                 newfile.write('\"'+l[:-1]+'\"\n')
450         newfile.close()
451                                 
452         os.system('bscmake /nologo /n /o'+bscfile+' @'+bscpathtmp)
453         os.system('del '+bscpathtmp)
454
455 class BlenderEnvironment(SConsEnvironment):
456
457         def BlenderRes(self=None, libname=None, source=None, libtype=['core'], priority=[100]):
458                 global libs
459                 if not self or not libname or not source:
460                         print bc.FAIL+'Cannot continue.  Missing argument for BlenderRes '+libname+bc.ENDC
461                         self.Exit()
462                 if self['OURPLATFORM'] not in ('win32-vc','win32-mingw','linuxcross', 'win64-vc'):
463                         print bc.FAIL+'BlenderRes is for windows only!'+bc.END
464                         self.Exit()
465                 
466                 print bc.HEADER+'Configuring resource '+bc.ENDC+bc.OKGREEN+libname+bc.ENDC
467                 lenv = self.Clone()
468                 res = lenv.RES('#'+root_build_dir+'lib/'+libname, source)
469                 
470                 SConsEnvironment.Default(self, res)
471                 resources.append(res)
472
473         def BlenderLib(self=None, libname=None, sources=None, includes=[], defines=[], libtype='common', priority = 100, compileflags=None, cc_compileflags=None, cxx_compileflags=None):
474                 global vcp
475                 if not self or not libname or not sources:
476                         print bc.FAIL+'Cannot continue. Missing argument for BuildBlenderLib '+libname+bc.ENDC
477                         self.Exit()
478
479                 def list_substring(quickie, libname):
480                         for q in quickie:
481                                 if libname.find(q) != -1:
482                                         return True
483                         return False
484
485                 if list_substring(quickie, libname) or len(quickie)==0:
486                         if list_substring(quickdebug, libname):
487                                 print bc.HEADER+'Configuring library '+bc.ENDC+bc.OKGREEN+libname +bc.ENDC+bc.OKBLUE+ " (debug mode)" + bc.ENDC
488                         else:
489                                 print bc.HEADER+'Configuring library '+bc.ENDC+bc.OKGREEN+libname + bc.ENDC
490                         lenv = self.Clone()
491                         lenv.Append(CPPPATH=includes)
492                         lenv.Append(CPPDEFINES=defines)
493                         if lenv['BF_DEBUG'] or (libname in quickdebug):
494                                         lenv.Append(CFLAGS = lenv['BF_DEBUG_CFLAGS'])
495                                         lenv.Append(CCFLAGS = lenv['BF_DEBUG_CCFLAGS'])
496                                         lenv.Append(CXXFLAGS = lenv['BF_DEBUG_CXXFLAGS'])
497                         else:
498                                         lenv.Append(CFLAGS = lenv['REL_CFLAGS'])
499                                         lenv.Append(CCFLAGS = lenv['REL_CCFLAGS'])
500                                         lenv.Append(CXXFLAGS = lenv['REL_CXXFLAGS'])
501                         if lenv['BF_PROFILE']:
502                                         lenv.Append(CFLAGS = lenv['BF_PROFILE_CFLAGS'])
503                                         lenv.Append(CCFLAGS = lenv['BF_PROFILE_CCFLAGS'])
504                                         lenv.Append(CXXFLAGS = lenv['BF_PROFILE_CXXFLAGS'])
505                         if compileflags:
506                                 lenv.Replace(CFLAGS = compileflags)
507                         if cc_compileflags:
508                                 lenv.Replace(CCFLAGS = cc_compileflags)
509                         if cxx_compileflags:
510                                 lenv.Replace(CXXFLAGS = cxx_compileflags)
511                         lenv.Append(CFLAGS = lenv['C_WARN'])
512                         lenv.Append(CCFLAGS = lenv['CC_WARN'])
513                         lenv.Append(CXXFLAGS = lenv['CXX_WARN'])
514
515                         if lenv['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
516                                 if lenv['BF_DEBUG']:
517                                         lenv.Append(CCFLAGS = ['/MTd'])
518                                 else:
519                                         lenv.Append(CCFLAGS = ['/MT'])
520                         
521                         targetdir = root_build_dir+'lib/' + libname
522                         if not (root_build_dir[0]==os.sep or root_build_dir[1]==':'):
523                                 targetdir = '#'+targetdir
524                         lib = lenv.Library(target= targetdir, source=sources)
525                         SConsEnvironment.Default(self, lib) # we add to default target, because this way we get some kind of progress info during build
526                         if self['BF_MSVS'] and self['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
527                                 #if targetdir[0] == '#':
528                                 #       targetdir = targetdir[1:-1]
529                                 print "! ",targetdir+ '.vcproj' # + self['MSVSPROJECTSUFFIX']
530                                 vcproject = self.MSVSProject(target = targetdir + '.vcproj', # + self['MSVSPROJECTSUFFIX'],
531                                                  srcs = sources,
532                                                  buildtarget = lib,
533                                                  variant = 'Release',
534                                                  auto_build_solution=0)
535                                 vcp.append(vcproject)
536                                 SConsEnvironment.Default(self, vcproject)
537                 else:
538                         print bc.WARNING+'Not building '+bc.ENDC+bc.OKGREEN+libname+bc.ENDC+' for '+bc.OKBLUE+'BF_QUICK'+bc.ENDC
539                 # note: libs is a global
540                 add_lib_to_dict(self, libs, libtype, libname, priority)
541
542         def BlenderProg(self=None, builddir=None, progname=None, sources=None, includes=None, libs=None, libpath=None, binarykind=''):
543                 global vcp
544                 print bc.HEADER+'Configuring program '+bc.ENDC+bc.OKGREEN+progname+bc.ENDC
545                 lenv = self.Clone()
546                 if lenv['OURPLATFORM'] in ('win32-vc', 'cygwin', 'win64-vc'):
547                         lenv.Append(LINKFLAGS = lenv['PLATFORM_LINKFLAGS'])
548                         lenv.Append(LINKFLAGS = ['/FORCE:MULTIPLE'])
549                         if lenv['BF_DEBUG']:
550                                 lenv.Prepend(LINKFLAGS = ['/DEBUG','/PDB:'+progname+'.pdb'])
551                 if  lenv['OURPLATFORM']=='linux2':
552                         lenv.Append(LINKFLAGS = lenv['PLATFORM_LINKFLAGS'])
553                         if lenv['WITH_BF_PYTHON']:
554                                 lenv.Append(LINKFLAGS = lenv['BF_PYTHON_LINKFLAGS'])
555                 if  lenv['OURPLATFORM']=='sunos5':
556                         lenv.Append(LINKFLAGS = lenv['PLATFORM_LINKFLAGS'])
557                         if lenv['WITH_BF_PYTHON']:
558                                 lenv.Append(LINKFLAGS = lenv['BF_PYTHON_LINKFLAGS'])
559                         if lenv['CXX'].endswith('CC'):
560                                  lenv.Replace(LINK = '$CXX')
561                 if  lenv['OURPLATFORM']=='darwin':
562                         lenv.Append(LINKFLAGS = lenv['PLATFORM_LINKFLAGS'])
563                         if lenv['WITH_BF_PYTHON']:
564                                 lenv.Append(LINKFLAGS = lenv['BF_PYTHON_LINKFLAGS'])
565                         lenv.Append(LINKFLAGS = lenv['BF_OPENGL_LINKFLAGS'])
566                 if lenv['BF_PROFILE']:
567                         lenv.Append(LINKFLAGS = lenv['BF_PROFILE_LINKFLAGS'])
568                 lenv.Append(CPPPATH=includes)
569                 if root_build_dir[0]==os.sep or root_build_dir[1]==':':
570                         lenv.Append(LIBPATH=root_build_dir + '/lib')
571                 lenv.Append(LIBPATH=libpath)
572                 lenv.Append(LIBS=libs)
573                 if lenv['WITH_BF_QUICKTIME']:
574                          lenv.Append(LIBS = lenv['BF_QUICKTIME_LIB'])
575                          lenv.Append(LIBPATH = lenv['BF_QUICKTIME_LIBPATH'])
576                 prog = lenv.Program(target=builddir+'bin/'+progname, source=sources)
577                 if lenv['BF_DEBUG'] and lenv['OURPLATFORM'] in ('win32-vc', 'win64-vc') and lenv['BF_BSC']:
578                         f = lenv.File(progname + '.bsc', builddir)
579                         brs = lenv.Command(f, prog, [bsc])
580                         SConsEnvironment.Default(self, brs)
581                 SConsEnvironment.Default(self, prog)
582                 if self['BF_MSVS'] and self['OURPLATFORM'] in ('win32-vc', 'win64-vc') and progname == 'blender':
583                         print "! ",builddir + "/" + progname + '.sln'
584                         sln = self.MSVSProject(target = builddir + "/" + progname + '.sln',
585                                          projects= vcp,
586                                          variant = 'Release')
587                         SConsEnvironment.Default(self, sln)
588                 program_list.append(prog)
589                 if  lenv['OURPLATFORM']=='darwin':
590                         lenv['BINARYKIND'] = binarykind
591                         lenv.AddPostAction(prog,Action(AppIt,strfunction=my_appit_print))
592                 elif os.sep == '/': # any unix
593                         if lenv['WITH_BF_PYTHON']:
594                                 if not lenv['WITHOUT_BF_INSTALL'] and not lenv['WITHOUT_BF_PYTHON_INSTALL']:
595                                         lenv.AddPostAction(prog,Action(PyInstall,strfunction=my_pyinst_print))
596                 
597                 return prog
598
599         def Glob(lenv, pattern):
600                 path = string.replace(GetBuildPath(lenv,'SConscript'),'SConscript', '')
601                 files = []
602                 for i in glob.glob(path + pattern):
603                         files.append(string.replace(i, path, ''))
604                 return files