Fix for bug #12463: hair didn't draw z-buffered in wireframe mode.
[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 import sys
33 import os
34 import os.path
35 import string
36 import shutil
37 import glob
38 import re
39 from tempfile import mkdtemp
40
41 import tools.Blender
42 import tools.btools
43 import tools.bcolors
44
45 BlenderEnvironment = tools.Blender.BlenderEnvironment
46 btools = tools.btools
47 B = tools.Blender
48
49 ### globals ###
50 platform = sys.platform
51 quickie = None
52 quickdebug = None
53 nsis_build = None
54
55 ##### BEGIN SETUP #####
56
57 B.possible_types = ['core', 'common', 'blender', 'intern',
58                     'international', 'game', 'game2',
59                     'player', 'player2', 'system']
60
61 B.binarykind = ['blender' , 'blenderplayer']
62 ##################################
63 # target and argument validation #
64 ##################################
65 # XX cheating for BF_FANCY, we check for BF_FANCY before args are validated
66 use_color = ARGUMENTS.get('BF_FANCY', '1')
67 if platform=='win32':
68     use_color = None
69
70 if not use_color=='1':
71     B.bc.disable()
72     
73  #on defaut white Os X terminal, some colors are totally unlegible
74 if platform=='darwin':
75     B.bc.OKGREEN = '\033[34m'
76     B.bc.WARNING = '\033[36m'
77
78 # arguments
79 print B.bc.HEADER+'Command-line arguments'+B.bc.ENDC
80 B.arguments = btools.validate_arguments(ARGUMENTS, B.bc)
81 btools.print_arguments(B.arguments, B.bc)
82
83 # targets
84 print B.bc.HEADER+'Command-line targets'+B.bc.ENDC
85 B.targets = btools.validate_targets(COMMAND_LINE_TARGETS, B.bc)
86 btools.print_targets(B.targets, B.bc)
87
88 ##########################
89 # setting up environment #
90 ##########################
91
92 # handling cmd line arguments & config file
93
94 # first check cmdline for toolset and we create env to work on
95 quickie = B.arguments.get('BF_QUICK', None)
96 quickdebug = B.arguments.get('BF_QUICKDEBUG', None)
97
98 if quickdebug:
99     B.quickdebug=string.split(quickdebug, ',')
100 else:
101     B.quickdebug=[]
102
103 if quickie:
104     B.quickie=string.split(quickie,',')
105 else:
106     B.quickie=[]
107     
108 toolset = B.arguments.get('BF_TOOLSET', None)
109 if toolset:
110     print "Using " + toolset
111     if toolset=='mstoolkit':
112         env = BlenderEnvironment(ENV = os.environ)
113         env.Tool('mstoolkit', ['tools'])
114     else:
115         env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
116         if env:
117             btools.SetupSpawn(env)
118 else:
119     env = BlenderEnvironment(ENV = os.environ)
120
121 if not env:
122     print "Could not create a build environment"
123     Exit()
124
125
126 cc = B.arguments.get('CC', None)
127 cxx = B.arguments.get('CXX', None)
128 if cc:
129     env['CC'] = cc
130 if cxx:
131     env['CXX'] = cxx
132
133 if env['CC'] in ['cl', 'cl.exe'] and sys.platform=='win32':
134     platform = 'win32-vc'
135 elif env['CC'] in ['gcc'] and sys.platform=='win32':
136     platform = 'win32-mingw'
137
138 env.SConscriptChdir(0)
139
140 crossbuild = B.arguments.get('BF_CROSS', None)
141 if crossbuild and platform!='win32':
142     platform = 'linuxcross'
143
144 env['OURPLATFORM'] = platform
145
146 configfile = 'config'+os.sep+platform+'-config.py'
147
148 if os.path.exists(configfile):
149     print B.bc.OKGREEN + "Using config file: " + B.bc.ENDC + configfile
150 else:
151     print B.bc.FAIL + configfile + " doesn't exist" + B.bc.ENDC
152
153 if crossbuild and env['PLATFORM'] != 'win32':
154     print B.bc.HEADER+"Preparing for crossbuild"+B.bc.ENDC
155     env.Tool('crossmingw', ['tools'])
156     # todo: determine proper libs/includes etc.
157     # Needed for gui programs, console programs should do without it
158     env.Append(LINKFLAGS=['-mwindows'])
159
160 userconfig = B.arguments.get('BF_CONFIG', 'user-config.py')
161 # first read platform config. B.arguments will override
162 optfiles = [configfile]
163 if os.path.exists(userconfig):
164     print B.bc.OKGREEN + "Using user-config file: " + B.bc.ENDC + userconfig
165     optfiles += [userconfig]
166 else:
167     print B.bc.WARNING + userconfig + " not found, no user overrides" + B.bc.ENDC
168
169 opts = btools.read_opts(optfiles, B.arguments)
170 opts.Update(env)
171
172 if not env['BF_FANCY']:
173     B.bc.disable()
174
175 # disable elbeem (fluidsim) compilation?
176 if env['BF_NO_ELBEEM'] == 1:
177     env['CPPFLAGS'].append('-DDISABLE_ELBEEM')
178     env['CXXFLAGS'].append('-DDISABLE_ELBEEM')
179     env['CCFLAGS'].append('-DDISABLE_ELBEEM')
180
181 if env['WITH_BF_OPENMP'] == 1:
182         if env['OURPLATFORM']=='win32-vc':
183                 env['CCFLAGS'].append('/openmp')
184                 env['CPPFLAGS'].append('/openmp')
185                 env['CXXFLAGS'].append('/openmp')
186         else:
187             if env['CC'] == 'icc':
188                 env.Append(LINKFLAGS=['-openmp', '-static-intel'])
189                 env['CCFLAGS'].append('-openmp')
190                 env['CPPFLAGS'].append('-openmp')
191                 env['CXXFLAGS'].append('-openmp')
192             else:
193                 env['CCFLAGS'].append('-fopenmp')
194                 env['CPPFLAGS'].append('-fopenmp')
195                 env['CXXFLAGS'].append('-fopenmp')
196
197 #check for additional debug libnames
198
199 if env.has_key('BF_DEBUG_LIBS'):
200     B.quickdebug += env['BF_DEBUG_LIBS']
201
202 printdebug = B.arguments.get('BF_LISTDEBUG', 0)
203
204 # see if this linux distro has libalut
205
206 if env['OURPLATFORM'] == 'linux2' :
207     if env['WITH_BF_OPENAL']:
208         mylib_test_source_file = """
209         #include "AL/alut.h"
210         int main(int argc, char **argv)
211         {
212             alutGetMajorVersion();
213             return 0;
214         }
215         """
216
217         def CheckFreeAlut(context,env):
218             context.Message( B.bc.OKGREEN + "Linux platform detected:\n  checking for FreeAlut... " + B.bc.ENDC )
219             env['LIBS'] = 'alut'
220             result = context.TryLink(mylib_test_source_file, '.c')
221             context.Result(result)
222             return result
223
224         env2 = env.Copy( LIBPATH = env['BF_OPENAL'] ) 
225         sconf_temp = mkdtemp()
226         conf = Configure( env2, {'CheckFreeAlut' : CheckFreeAlut}, sconf_temp, '/dev/null' )
227         if conf.CheckFreeAlut( env2 ):
228             env['BF_OPENAL_LIB'] += ' alut'
229         del env2
230         root = ''
231         for root, dirs, files in os.walk(sconf_temp, topdown=False):
232             for name in files:
233                 os.remove(os.path.join(root, name))
234             for name in dirs:
235                 os.rmdir(os.path.join(root, name))
236         if root: os.rmdir(root)
237
238 if len(B.quickdebug) > 0 and printdebug != 0:
239     print B.bc.OKGREEN + "Buildings these libs with debug symbols:" + B.bc.ENDC
240     for l in B.quickdebug:
241         print "\t" + l
242
243 # check target for blenderplayer. Set WITH_BF_PLAYER if found on cmdline
244 if 'blenderplayer' in B.targets:
245     env['WITH_BF_PLAYER'] = True
246
247 if 'blendernogame' in B.targets:
248     env['WITH_BF_GAMEENGINE'] = False
249
250 # lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
251 #B.root_build_dir = B.arguments.get('BF_BUILDDIR', '..'+os.sep+'build'+os.sep+platform+os.sep)
252 B.root_build_dir = env['BF_BUILDDIR']
253 env['BUILDDIR'] = B.root_build_dir
254 if not B.root_build_dir[-1]==os.sep:
255     B.root_build_dir += os.sep
256     
257 # We do a shortcut for clean when no quicklist is given: just delete
258 # builddir without reading in SConscripts
259 do_clean = None
260 if 'clean' in B.targets:
261     do_clean = True
262
263 if not quickie and do_clean:
264     if os.path.exists(B.root_build_dir):
265         print B.bc.HEADER+'Cleaning...'+B.bc.ENDC
266         dirs = os.listdir(B.root_build_dir)
267         for entry in dirs:
268             if os.path.isdir(B.root_build_dir + entry) == 1:
269                 print "clean dir %s"%(B.root_build_dir+entry)
270                 shutil.rmtree(B.root_build_dir+entry)
271             else: # remove file
272                 print "remove file %s"%(B.root_build_dir+entry)
273                 os.remove(B.root_build_dir+entry)
274         for confile in ['extern/ffmpeg/config.mak', 'extern/x264/config.mak',
275                 'extern/xvidcore/build/generic/platform.inc']:
276             if os.path.exists(confile):
277                 print "clean file %s"%confile
278                 os.remove(confile)
279         print B.bc.OKGREEN+'...done'+B.bc.ENDC
280     else:
281         print B.bc.HEADER+'Already Clean, nothing to do.'+B.bc.ENDC
282     Exit()
283
284 if not os.path.isdir ( B.root_build_dir):
285     os.makedirs ( B.root_build_dir )
286     os.makedirs ( B.root_build_dir + 'source' )
287     os.makedirs ( B.root_build_dir + 'intern' )
288     os.makedirs ( B.root_build_dir + 'extern' )
289     os.makedirs ( B.root_build_dir + 'lib' )
290     os.makedirs ( B.root_build_dir + 'bin' )
291
292 Help(opts.GenerateHelpText(env))
293
294 # default is new quieter output, but if you need to see the 
295 # commands, do 'scons BF_QUIET=0'
296 bf_quietoutput = B.arguments.get('BF_QUIET', '1')
297 if env['BF_QUIET']:
298     B.set_quiet_output(env)
299 else:
300     if toolset=='msvc':
301         B.msvc_hack(env)
302
303 print B.bc.HEADER+'Building in '+B.bc.ENDC+B.root_build_dir
304 env.SConsignFile(B.root_build_dir+'scons-signatures')
305 B.init_lib_dict()
306
307 ##### END SETUP ##########
308
309 Export('env')
310
311 BuildDir(B.root_build_dir+'/intern', 'intern', duplicate=0)
312 SConscript(B.root_build_dir+'/intern/SConscript')
313 BuildDir(B.root_build_dir+'/extern', 'extern', duplicate=0)
314 SConscript(B.root_build_dir+'/extern/SConscript')
315 BuildDir(B.root_build_dir+'/source', 'source', duplicate=0)
316 SConscript(B.root_build_dir+'/source/SConscript')
317
318 # now that we have read all SConscripts, we know what
319 # libraries will be built. Create list of
320 # libraries to give as objects to linking phase
321 mainlist = []
322 for tp in B.possible_types:
323     if not tp == 'player' and not tp == 'player2':
324         mainlist += B.create_blender_liblist(env, tp)
325
326 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
327     B.propose_priorities()
328
329 dobj = B.buildinfo(env, "dynamic") + B.resources
330 thestatlibs, thelibincs = B.setup_staticlibs(env)
331 thesyslibs = B.setup_syslibs(env)
332
333 env.BlenderProg(B.root_build_dir, "blender", dobj + mainlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
334 if env['WITH_BF_PLAYER']:
335     playerlist = B.create_blender_liblist(env, 'player')
336     env.BlenderProg(B.root_build_dir, "blenderplayer", dobj + playerlist + thestatlibs, [], thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blenderplayer')
337
338 ##### Now define some targets
339
340
341 #------------ INSTALL
342
343 #-- binaries
344 blenderinstall = []
345 if  env['OURPLATFORM']=='darwin':
346     for prg in B.program_list:
347         bundle = '%s.app' % prg[0]
348         bundledir = os.path.dirname(bundle)
349         for dp, dn, df in os.walk(bundle):
350             if 'CVS' in dn:
351                 dn.remove('CVS')
352             if '.svn' in dn:
353                 dn.remove('.svn')
354             dir=env['BF_INSTALLDIR']+dp[len(bundledir):]
355             source=[dp+os.sep+f for f in df]
356             blenderinstall.append(env.Install(dir=dir,source=source))
357 else:
358     blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
359
360 #-- .blender
361 #- dont do .blender and scripts for darwin, it is already in the bundle
362 dotblendlist = []
363 dottargetlist = []
364 scriptinstall = []
365
366 if  env['OURPLATFORM']!='darwin':
367         for dp, dn, df in os.walk('bin/.blender'):
368             if 'CVS' in dn:
369                 dn.remove('CVS')
370             if '.svn' in dn:
371                 dn.remove('.svn')
372             for f in df:
373                 dotblendlist.append(dp+os.sep+f)
374                 dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
375
376         dotblenderinstall = []
377         for targetdir,srcfile in zip(dottargetlist, dotblendlist):
378             td, tf = os.path.split(targetdir)
379             dotblenderinstall.append(env.Install(dir=td, source=srcfile))
380         
381         #-- .blender/scripts    
382         scriptpath='release/scripts'
383         for dp, dn, df in os.walk(scriptpath):
384             if 'CVS' in dn:
385                 dn.remove('CVS')
386             if '.svn' in dn:
387                 dn.remove('.svn')
388             dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
389             source=[dp+os.sep+f for f in df]
390             scriptinstall.append(env.Install(dir=dir,source=source))
391
392 #-- plugins
393 pluglist = []
394 plugtargetlist = []
395 for tp, tn, tf in os.walk('release/plugins'):
396     if 'CVS' in tn:
397         tn.remove('CVS')
398     if '.svn' in tn:
399         tn.remove('.svn')
400     for f in tf:
401         print ">>>", env['BF_INSTALLDIR'], tp, f
402         pluglist.append(tp+os.sep+f)
403         plugtargetlist.append(env['BF_INSTALLDIR']+tp[7:]+os.sep+f)
404
405 # header files for plugins
406 pluglist.append('source/blender/blenpluginapi/documentation.h')
407 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'documentation.h')
408 pluglist.append('source/blender/blenpluginapi/externdef.h')
409 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'externdef.h')
410 pluglist.append('source/blender/blenpluginapi/floatpatch.h')
411 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'floatpatch.h')
412 pluglist.append('source/blender/blenpluginapi/iff.h')
413 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'iff.h')
414 pluglist.append('source/blender/blenpluginapi/plugin.h')
415 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'plugin.h')
416 pluglist.append('source/blender/blenpluginapi/util.h')
417 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep +'util.h')
418 pluglist.append('source/blender/blenpluginapi/plugin.DEF')
419 plugtargetlist.append(env['BF_INSTALLDIR'] + os.sep + 'plugins' + os.sep + 'include' + os.sep + 'plugin.def')
420
421 plugininstall = []
422 for targetdir,srcfile in zip(plugtargetlist, pluglist):
423     td, tf = os.path.split(targetdir)
424     plugininstall.append(env.Install(dir=td, source=srcfile))
425
426 textlist = []
427 texttargetlist = []
428 for tp, tn, tf in os.walk('release/text'):
429     if 'CVS' in tn:
430         tn.remove('CVS')
431     if '.svn' in tn:
432         tn.remove('.svn')
433     for f in tf:
434         textlist.append(tp+os.sep+f)
435
436 textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
437
438 if  env['OURPLATFORM']=='darwin':
439         allinstall = [blenderinstall, plugininstall, textinstall]
440 else:
441         allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
442
443 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
444     dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',
445                         '${LCGDIR}/png/lib/libpng.dll',
446                         '#release/windows/extra/python25.zip',
447                         '#release/windows/extra/zlib.pyd',
448                         '${LCGDIR}/sdl/lib/SDL.dll',
449                         '${LCGDIR}/zlib/lib/zlib.dll',
450                         '${LCGDIR}/tiff/lib/libtiff.dll']
451     if env['BF_DEBUG']:
452         dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}_d.dll')
453     else:
454         dllsources.append('${LCGDIR}/python/lib/${BF_PYTHON_LIB}.dll')
455     if env['OURPLATFORM'] == 'win32-mingw':
456         dllsources += ['${LCGDIR}/pthreads/lib/pthreadGC2.dll']
457     else:
458         dllsources += ['${LCGDIR}/pthreads/lib/pthreadVC2.dll']
459     if env['WITH_BF_ICONV']:
460         dllsources += ['${LCGDIR}/iconv/lib/iconv.dll']
461     if env['WITH_BF_FFMPEG']:
462         dllsources += ['${LCGDIR}/ffmpeg/lib/avcodec-51.dll',
463                         '${LCGDIR}/ffmpeg/lib/avformat-52.dll',
464                         '${LCGDIR}/ffmpeg/lib/avdevice-52.dll',
465                         '${LCGDIR}/ffmpeg/lib/avutil-49.dll',
466                         '${LCGDIR}/ffmpeg/lib/libfaad-0.dll',
467                         '${LCGDIR}/ffmpeg/lib/libfaac-0.dll',
468                         '${LCGDIR}/ffmpeg/lib/libmp3lame-0.dll',
469                         '${LCGDIR}/ffmpeg/lib/libx264-59.dll',
470                         '${LCGDIR}/ffmpeg/lib/xvidcore.dll',
471                         '${LCGDIR}/ffmpeg/lib/swscale-0.dll']
472     windlls = env.Install(dir=env['BF_INSTALLDIR'], source = dllsources)
473     allinstall += windlls
474
475 installtarget = env.Alias('install', allinstall)
476 bininstalltarget = env.Alias('install-bin', blenderinstall)
477
478 nsisaction = env.Action(btools.NSIS_Installer, btools.NSIS_print)
479 nsiscmd = env.Command('nsisinstaller', None, nsisaction)
480 nsisalias = env.Alias('nsis', nsiscmd)
481
482 if env['WITH_BF_PLAYER']:
483     blenderplayer = env.Alias('blenderplayer', B.program_list)
484     Depends(blenderplayer,installtarget)
485
486 if not env['WITH_BF_GAMEENGINE']:
487     blendernogame = env.Alias('blendernogame', B.program_list)
488     Depends(blendernogame,installtarget)
489
490 Depends(nsiscmd, allinstall)
491
492 Default(B.program_list)
493
494 if not env['WITHOUT_BF_INSTALL']:
495         Default(installtarget)
496
497 #------------ RELEASE
498 # TODO: zipup the installation
499
500 #------------ BLENDERPLAYER
501 # TODO: build stubs and link into blenderplayer
502
503 #------------ EPYDOC
504 # TODO: run epydoc
505