* use sys.exit() instead of exit()
[blender-staging.git] / SConstruct
1 import string
2 import os
3 import time
4 import sys
5 from distutils import sysconfig
6
7 if sys.hexversion < 0x2030000:
8         print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
9         print
10         print "You need at least Python 2.3 to build Blender with SCons"
11         print
12         print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
13         sys.exit()
14
15 if sys.platform != 'win32':
16         sys.stdout = os.popen("tee build.log", "w")
17         sys.stderr = sys.stdout
18
19 # Build directory.
20 root_build_dir = '..' + os.sep + 'build' + os.sep + sys.platform + os.sep
21
22 # Create the build directory. SCons does this automatically, but since we
23 # don't want to put scons-generated .sconsign files in the source tree, but in
24 # the root_build_dir, we have to create that dir ourselves before SCons tries
25 # to access/create the file containing .sconsign data.
26 if os.path.isdir (root_build_dir) == 0:
27     os.makedirs (root_build_dir)
28
29 # User configurable options file. This can be controlled by the user by running
30 # scons with the following argument: CONFIG=user_config_options_file
31 config_file = ARGUMENTS.get('CONFIG', 'config.opts')
32
33 # Blender version.
34 version='2.33a'
35 shortversion = '233a' # for wininst target -> nsis installer creation
36
37 sdl_env = Environment ()
38 freetype_env = Environment ()
39 env = Environment ()
40
41 if sys.platform == 'linux2' or sys.platform == 'linux-i386':
42     use_international = 'false'
43     use_gameengine = 'true'
44     use_openal = 'false'
45     use_fmod = 'false'
46     use_quicktime = 'false'
47     use_sumo = 'true'
48     use_ode = 'false'
49     use_buildinfo = 'true'
50     build_blender_dynamic = 'true'
51     build_blender_static = 'false'
52     build_blender_player = 'true'
53     build_blender_plugin = 'false'
54     release_flags = ['-O2']
55     debug_flags = ['-O2', '-g']
56     extra_flags = ['-pipe', '-funsigned-char']
57     cxxflags = []
58     defines = []
59     warn_flags = ['-Wall', '-W']
60     window_system = 'X11'
61     platform_libs = ['m', 'util', 'stdc++']
62     platform_libpath = []
63     platform_linkflags = ['-pthread']
64     extra_includes = []
65     # z library information
66     z_lib = ['z']
67     z_libpath = ['/usr/lib']
68     z_include = ['/usr/include']
69     # png library information
70     png_lib = ['png']
71     png_libpath = ['/usr/lib']
72     png_include = ['/usr/include']
73     # jpeg library information
74     jpeg_lib = ['jpeg']
75     jpeg_libpath = ['/usr/lib']
76     jpeg_include = ['/usr/include']
77     # OpenGL library information
78     opengl_lib = ['GL', 'GLU']
79     opengl_static = ['/usr/lib/libGL.a', '/usr/lib/libGLU.a']
80     opengl_libpath = ['/usr/lib', '/usr/X11R6/lib']
81     opengl_include = ['/usr/include']
82     # SDL library information
83     sdl_env.ParseConfig ('sdl-config --cflags --libs')
84     sdl_cflags = sdl_env.Dictionary()['CCFLAGS']
85     sdl_include = sdl_env.Dictionary()['CPPPATH']
86     sdl_libpath = sdl_env.Dictionary()['LIBPATH']
87     sdl_lib = sdl_env.Dictionary()['LIBS']
88     # SOLID library information
89     solid_lib = []                                              # TODO
90     solid_libpath = []                                          # TODO
91     solid_include = ['#extern/solid']
92     qhull_lib = []                                              # TODO
93     qhull_libpath = []                                          # TODO
94     qhull_include = ['#extern/qhull/include']
95     # ODE library information
96     ode_lib = ['ode']
97     ode_libpath = ['#../lib/linux-glibc2.2.5-i386/ode/lib']
98     ode_include = ['#../lib/linux-glibc2.2.5-i386/ode/include']
99     # Python library information
100     python_lib = ['python%d.%d' % sys.version_info[0:2]]
101     python_libpath = [sysconfig.get_python_lib (0, 1) + '/config']
102     python_include = [sysconfig.get_python_inc ()]
103     python_linkflags = Split (sysconfig.get_config_var('LINKFORSHARED'))
104     # International support information
105     ftgl_lib = ['ftgl']
106     ftgl_libpath = ['#../lib/linux-glibc2.2.5-i386/ftgl/lib']
107     ftgl_include = ['#../lib/linux-glibc2.2.5-i386/ftgl/include']
108     freetype_env.ParseConfig ('pkg-config --cflags --libs freetype2 2>/dev/null || freetype-config --cflags --libs 2>/dev/null')
109     freetype_lib = freetype_env.Dictionary()['LIBS']
110     freetype_libpath = freetype_env.Dictionary()['LIBPATH']
111     freetype_include = freetype_env.Dictionary()['CPPPATH']
112     gettext_lib = []
113     gettext_libpath = []
114     gettext_include = []
115     # OpenAL library information
116     openal_lib = ['openal']
117     openal_libpath = ['/usr/lib']
118     openal_include = ['/usr/include']
119
120 elif sys.platform == 'darwin':
121     use_international = 'true'
122     use_gameengine = 'true'
123     use_openal = 'true'
124     use_fmod = 'false'
125     use_quicktime = 'true'
126     use_precomp = 'true'
127     use_sumo = 'true'
128     use_ode = 'false'
129     use_buildinfo = 'true'
130     build_blender_dynamic = 'true'
131     build_blender_static = 'false'
132     build_blender_player = 'true'
133     build_blender_plugin = 'false'
134     # TODO: replace darwin-6.1-powerpc with the actual directiory on the
135     #       build machine
136     # darwin-6.1 is the name of cvs precomp folder
137     # a symbolic link named darwin-X.Y-powerpc must be manually done
138     #for now. X-Y is darwin kernel rev number
139     darwin_precomp = '#../lib/darwin-6.1-powerpc/'
140     fink_path = '/sw/'
141     # TODO : try -mpowerpc -mpowerpc-gopt -mpowerpc-gfxopt optims
142     #           doing actual profiling
143     extra_flags = ['-pipe', '-fPIC', '-funsigned-char', '-ffast-math']
144     cxxflags = []
145     defines = ['_THREAD_SAFE', 'MT_NDEBUG']
146     if use_quicktime == 'true':
147         defines += ['WITH_QUICKTIME']
148     warn_flags = ['-Wall', '-W']
149     release_flags = ['-O3']
150     debug_flags = ['-g']
151     window_system = 'CARBON'
152     # z library information
153     z_lib = ['z']
154     z_libpath = []
155     z_include = []
156     # TODO : add a flag to allow each lib to be build from fink or precomp
157     #        without having to have to specify the path manually in config.opts.    
158     # png library information
159     png_lib = ['libpng']
160     png_libpath = [darwin_precomp + 'png/lib']
161     png_include = [darwin_precomp + 'png/include']
162     # jpeg library information
163     jpeg_lib = ['libjpeg']
164     jpeg_libpath = [darwin_precomp + 'jpeg/lib']
165     jpeg_include = [darwin_precomp + 'jpeg/include']
166     # OpenGL library information
167     opengl_lib = ['GL', 'GLU']
168     opengl_static = []
169     opengl_libpath = []
170     opengl_include = []
171     # SDL specific stuff.
172     sdl_env.ParseConfig ('sdl-config --cflags --libs')
173     sdl_cflags = sdl_env.Dictionary()['CCFLAGS']
174     # Want to use precompiled libraries?
175     if use_precomp == 'true':
176         sdl_include = [darwin_precomp + 'sdl/include']
177         sdl_libpath = [darwin_precomp + 'sdl/lib']
178         sdl_lib = ['libSDL.a']
179     platform_libs = ['stdc++'] 
180     extra_includes = ['/sw/include']
181     platform_libpath = ['/System/Library/Frameworks/OpenGL.framework/Libraries']
182     platform_linkflags = []
183     # SOLID library information
184     solid_lib = ['libsolid']                                          
185     solid_libpath = [darwin_precomp + 'solid/lib']                                          
186     solid_include = [darwin_precomp + 'solid/include']
187     qhull_lib = ['libqhull']                                          
188     qhull_libpath = [darwin_precomp + 'qhull/lib']                                          
189     qhull_include = [darwin_precomp + 'qhull/include']
190     # ODE library information
191     ode_lib = ['libode']                                             
192     ode_libpath = [darwin_precomp + 'ode/lib']                                          
193     ode_include = [darwin_precomp + 'ode/include/ode']
194     # Python variables.
195     # TODO : fill vars differently if we are on 10.2 or 10.3
196     # python_lib = ['python%d.%d' % sys.version_info[0:2]]
197     # python_libpath = [sysconfig.get_python_lib (0, 1) + '/config']
198     # python_include = [sysconfig.get_python_inc ()]
199     # python_linkflags = Split (sysconfig.get_config_var('LINKFORSHARED'))
200     python_lib = []
201     python_libpath = ['/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config']
202     python_include = ['/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3']
203     python_linkflags = ['-u', '__dummy', '-u', '_PyMac_Error', 
204                         '-framework', 'System',
205                         '-framework', 'Python',
206                         '-framework', 'CoreServices',
207                         '-framework', 'Foundation']
208     # International stuff
209     ftgl_lib = ['ftgl']
210     ftgl_libpath = [darwin_precomp + 'ftgl/lib']
211     ftgl_include = [darwin_precomp + 'ftgl/include']
212     freetype_lib = ['libfreetype']
213     freetype_libpath = [darwin_precomp + 'freetype/lib']
214     freetype_include = [darwin_precomp + 'freetype/include']
215     gettext_lib = ['libintl']
216     gettext_libpath = [darwin_precomp + 'gettext/lib']
217     gettext_include = [darwin_precomp + 'gettext/include']
218     # OpenAL library information
219     openal_lib = ['libopenal']
220     openal_libpath = [darwin_precomp + 'openal/lib']
221     openal_include = [darwin_precomp + 'openal/include']
222
223 elif sys.platform == 'cygwin':
224     use_international = 'false'
225     use_gameengine = 'false'
226     use_openal = 'false'
227     use_fmod = 'false'
228     use_quicktime = 'false'
229     use_sumo = 'false'
230     use_ode = 'false'
231     use_buildinfo = 'false'
232     build_blender_dynamic = 'true'
233     build_blender_static = 'false'
234     build_blender_player = 'false'
235     build_blender_plugin = 'false'
236     release_flags = ['-O2']
237     debug_flags = ['-O2', '-g']
238     extra_flags = ['-pipe', '-mno-cygwin', '-mwindows', '-funsigned-char']
239     cxxflags = []
240     defines = ['FREE_WINDOWS', 'NDEBUG']
241     warn_flags = ['-Wall', '-Wno-char-subscripts']
242     platform_libs = ['png', 'jpeg', 'netapi32',
243                      'opengl32', 'glu32', 'winmm',
244                      'mingw32']
245     platform_libpath = ['/usr/lib/w32api', '/lib/w32api']
246     platform_linkflags = ['-mwindows', '-mno-cygwin', '-mconsole']
247     window_system = 'WIN32'
248     extra_includes = []
249     # z library information
250     z_lib = ['z']
251     z_libpath = ['#../lib/windows/zlib/lib']
252     z_include = ['#../lib/windows/zlib/include']
253     # png library information
254     png_lib = ['png']
255     png_libpath = ['#../lib/windows/png/lib']
256     png_include = ['#../lib/windows/png/include']
257     # jpeg library information
258     jpeg_lib = ['jpeg']
259     jpeg_libpath = ['#../lib/windows/jpeg/lib']
260     jpeg_include = ['#../lib/windows/jpeg/include']
261     # OpenGL library information
262     opengl_lib = ['opengl32', 'glu32']
263     opengl_static = []
264     opengl_libpath = []
265     opengl_include = []
266     # SDL specific stuff.
267     sdl_include = ['#../lib/windows/sdl/include']
268     sdl_libpath = ['#../lib/windows/sdl/lib']
269     sdl_lib = ['SDL']
270     sdl_cflags = []
271     #sdl_cflags = '-DWIN32'
272     # SOLID library information
273     solid_lib = []                                              # TODO
274     solid_libpath = []                                          # TODO
275     solid_include = ['#extern/solid']
276     qhull_lib = []                                              # TODO
277     qhull_libpath = []                                          # TODO
278     qhull_include = ['#extern/qhull/include']
279     # ODE library information
280     ode_lib = ['ode']
281     ode_libpath = ['#../lib/windows/gcc/ode/lib']
282     ode_include = ['#../lib/windows/gcc/ode/include']
283     # Python library information
284     python_include = ['#../lib/windows/python/include/python2.2']
285     python_libpath = ['#../lib/windows/python/lib']
286     python_lib = ['python22']
287     python_linkflags = []
288     # International stuff
289     ftgl_lib = ['ftgl']
290     ftgl_libpath = ['#../lib/windows/gcc/ftgl/lib']
291     ftgl_include = ['#../lib/windows/gcc/ftgl/include']
292     freetype_lib = ['freetype']
293     freetype_libpath = ['#../lib/windows/gcc/freetype/lib']
294     freetype_include = ['#../lib/windows/gcc/freetype/include']
295     gettext_lib = []
296     gettext_libpath = []
297     gettext_include = []
298     # OpenAL library information
299     openal_lib = []
300     openal_libpath = []
301     openal_include = []
302
303 elif sys.platform == 'win32':
304     use_international = 'true'
305     use_gameengine = 'true'
306     use_openal = 'true'
307     use_fmod = 'false'
308     use_quicktime = 'true'
309     use_sumo = 'true'
310     use_ode = 'false'
311     use_buildinfo = 'true'
312     build_blender_dynamic = 'true'
313     build_blender_static = 'false'
314     build_blender_player = 'true'
315     build_blender_plugin = 'false'
316     release_flags = ['/Og', '/Ot', '/Ob1', '/Op', '/G6']
317     debug_flags = ['/Zi', '/Fr${TARGET.base}.sbr']
318     extra_flags = ['/EHsc', '/J', '/W3', '/Gd', '/MT']
319     cxxflags = []
320     defines = ['WIN32', '_CONSOLE']
321     defines += ['WITH_QUICKTIME']
322     defines += ['_LIB', 'USE_OPENAL']
323     defines += ['FTGL_LIBRARY_STATIC']
324     warn_flags = []
325     platform_libs = [ 'qtmlClient', 'soundsystem',
326                      'ws2_32', 'dxguid', 'vfw32', 'winmm',
327                      'iconv', 'kernel32', 'user32', 'gdi32',
328                      'winspool', 'comdlg32', 'advapi32', 'shell32',
329                      'ole32', 'oleaut32', 'uuid', 'odbc32', 'odbccp32',
330                      'libcmt', 'libc']
331     platform_libpath = ['#../lib/windows/iconv/lib',
332                         '#../lib/windows/QTDevWin/Libraries']
333     platform_linkflags = [
334                         '/SUBSYSTEM:CONSOLE',
335                         '/MACHINE:IX86',
336                         '/ENTRY:mainCRTStartup',
337                         '/INCREMENTAL:NO',
338                         '/NODEFAULTLIB:"msvcprt.lib"',
339                         '/NODEFAULTLIB:"glut32.lib"',
340                         '/NODEFAULTLIB:"libcd.lib"',
341                         #'/NODEFAULTLIB:"libc.lib"',
342                         '/NODEFAULTLIB:"libcpd.lib"',
343                         '/NODEFAULTLIB:"libcp.lib"',
344                         '/NODEFAULTLIB:"libcmtd.lib"',
345                         ]
346     window_system = 'WIN32'
347     extra_includes = []
348     if use_quicktime == 'true':
349         extra_includes += ['#../lib/windows/QTDevWin/CIncludes']
350     # z library information
351     z_lib = ['libz_st']
352     z_libpath = ['#../lib/windows/zlib/lib']
353     z_include = ['#../lib/windows/zlib/include']
354     # png library information
355     png_lib = ['libpng_st']
356     png_libpath = ['#../lib/windows/png/lib']
357     png_include = ['#../lib/windows/png/include']
358     # jpeg library information
359     jpeg_lib = ['libjpeg']
360     jpeg_libpath = ['#../lib/windows/jpeg/lib']
361     jpeg_include = ['#../lib/windows/jpeg/include']
362     # OpenGL library information
363     opengl_lib = ['opengl32', 'glu32']
364     opengl_static = []
365     opengl_libpath = []
366     opengl_include = ['/usr/include']
367     # SDL library information
368     sdl_include = ['#../lib/windows/sdl/include']
369     sdl_libpath = ['#../lib/windows/sdl/lib']
370     sdl_lib = ['SDL']
371     sdl_cflags = []
372     window_system = 'WIN32'
373     # SOLID library information
374     solid_lib = ['extern/solid']
375     solid_libpath = ['#../lib/windows/solid/lib']
376     solid_include = ['#extern/solid']
377     qhull_lib = ['qhull']
378     qhull_libpath = ['#../lib/windows/qhull/lib']
379     qhull_include = ['#extern/qhull/include']
380     # ODE library information
381     ode_lib = []                                                # TODO
382     ode_libpath = ['#../lib/windows/ode/lib']
383     ode_include = ['#../lib/windows/ode/include']
384     # Python lib name
385     python_include = ['#../lib/windows/python/include/python2.3']
386     python_libpath = ['#../lib/windows/python/lib']
387     python_lib = ['python23']
388     python_linkflags = []
389     # International stuff
390     ftgl_lib = ['ftgl_static_ST']
391     ftgl_libpath = ['#../lib/windows/ftgl/lib']
392     ftgl_include = ['#../lib/windows/ftgl/include']
393     freetype_lib = ['freetype2ST']
394     freetype_libpath = ['#../lib/windows/freetype/lib']
395     freetype_include = ['#../lib/windows/freetype/include']
396     gettext_lib = ['gnu_gettext']
397     gettext_libpath = ['#../lib/windows/gettext/lib']
398     gettext_include = ['#../lib/windows/gettext/include']
399     # OpenAL library information
400     openal_lib = ['openal_static']
401     openal_libpath = ['#../lib/windows/openal/lib']
402     openal_include = ['#../lib/windows/openal/include']
403
404 elif string.find (sys.platform, 'sunos') != -1:
405     use_international = 'true'
406     use_gameengine = 'false'
407     use_openal = 'false'
408     use_fmod = 'false'
409     use_quicktime = 'false'
410     use_sumo = 'false'
411     use_ode = 'false'
412     use_buildinfo = 'false'
413     build_blender_dynamic = 'true'
414     build_blender_static = 'false'
415     build_blender_player = 'false'
416     build_blender_plugin = 'false'
417     release_flags = ['-O2']
418     debug_flags = ['-O2', '-g']
419     extra_flags = ['-pipe', '-fPIC', '-funsigned-char', '-DSUN_OGL_NO_VERTEX_MACROS']
420     cxxflags = []
421     defines = []
422     warn_flags = ['-Wall', '-W']
423     window_system = 'X11'
424     platform_libs = ['stdc++', 'dl', 'm']
425     platform_libpath = []
426     platform_linkflags = []
427     extra_includes = []
428     # z library information
429     z_lib = ['z']
430     z_libpath = []
431     z_include = []
432     # png library information
433     png_lib = ['png']
434     png_libpath = []
435     png_include = []
436     # jpeg library information
437     jpeg_lib = ['jpeg']
438     jpeg_libpath = []
439     jpeg_include = []
440     # OpenGL library information
441     opengl_lib = ['GL', 'GLU', 'X11']
442     opengl_static = []
443     opengl_libpath = ['/usr/openwin/include']
444     opengl_include = ['/usr/openwin/lib']
445     # SDL library information
446     sdl_env.ParseConfig ('sdl-config --cflags --libs')
447     sdl_cflags = sdl_env.Dictionary()['CCFLAGS']
448     sdl_include = sdl_env.Dictionary()['CPPPATH']
449     sdl_libpath = sdl_env.Dictionary()['LIBPATH']
450     sdl_lib = sdl_env.Dictionary()['LIBS']
451     # SOLID library information
452     solid_lib = []                                              # TODO
453     solid_libpath = []                                          # TODO
454     solid_include = ['#extern/solid']
455     qhull_lib = []                                              # TODO
456     qhull_libpath = []                                          # TODO
457     qhull_include = ['#extern/qhull/include']
458     # ODE library information
459     ode_lib = []                                                # TODO
460     ode_libpath = []                                            # TODO
461     ode_include = ['#extern/ode/dist/include/ode']
462     # Python variables.
463     python_lib = ['python%d.%d' % sys.version_info[0:2]]
464     python_libpath = [sysconfig.get_python_lib (0, 1) + '/config']
465     python_include = [sysconfig.get_python_inc ()]
466     python_linkflags = []
467     # International support information
468     ftgl_lib = ['ftgl']
469     ftgl_libpath = ['#../lib/solaris-2.8-sparc/ftgl/lib']
470     ftgl_include = ['#../lib/solaris-2.8-sparc/ftgl/include']
471     freetype_lib = ['freetype']
472     freetype_libpath = ['#../lib/solaris-2.8-sparc/freetype/lib']
473     freetype_include = ['#../lib/solaris-2.8-sparc/freetype/include']
474     gettext_lib = []
475     gettext_libpath = []
476     gettext_include = []
477     # OpenAL library information
478     openal_lib = []
479     openal_libpath = []
480     openal_include = []
481
482 elif string.find (sys.platform, 'irix') != -1:
483     use_international = 'false'
484     use_gameengine = 'false'
485     use_openal = 'false'
486     use_fmod = 'false'
487     use_quicktime = 'false'
488     use_sumo = 'false'
489     use_ode = 'false'
490     use_buildinfo = 'false'
491     build_blender_dynamic = 'true'
492     build_blender_static = 'false'
493     build_blender_player = 'false'
494     build_blender_plugin = 'false'
495     irix_precomp = '#../lib/irix-6.5-mips'
496     extra_flags = ['-n32', '-mips3', '-Xcpluscomm']
497     cxxflags = ['-n32', '-mips3', '-Xcpluscomm', '-LANG:std']
498     cxxflags += ['-LANG:libc_in_namespace_std=off']
499     
500     window_system = 'X11'
501     release_flags = ['-O2', '-OPT:Olimit=0']
502     debug_flags = ['-O2', '-g']
503     defines = []
504     warn_flags = ['-fullwarn', '-woff', '1001,1110,1201,1209,1355,1424,1681,3201']
505     platform_libs = ['movieGL', 'Xmu', 'Xext', 'X11',
506                      'c', 'm', 'dmedia', 'cl', 'audio',
507                      'Cio', 'pthread']
508     platform_libpath = ['/usr/lib32/mips3',
509                         '/lib/freeware/lib32',
510                         '/usr/lib32']
511     platform_linkflags = ['-mips3', '-n32']
512     extra_includes = ['/usr/freeware/include',
513                       '/usr/include']
514     # z library information
515     z_lib = ['z']
516     z_libpath = []
517     z_include = []
518     # png library information
519     png_lib = ['png']
520     png_libpath = [irix_precomp + '/png/lib']
521     png_include = [irix_precomp + '/png/include']
522     # jpeg library information
523     jpeg_lib = ['jpeg']
524     jpeg_libpath = [irix_precomp + '/jpeg/lib']
525     jpeg_include = [irix_precomp + '/jpeg/include']
526     # OpenGL library information
527     opengl_lib = ['GL', 'GLU']
528     opengl_static = []
529     opengl_libpath = []
530     opengl_include = []
531     # SDL library information
532     sdl_cflags = []
533     sdl_include = [irix_precomp + '/sdl/include/SDL']
534     sdl_libpath = [irix_precomp + '/sdl/lib']
535     sdl_lib = ['SDL', 'libSDL.a']
536     # SOLID library information
537     solid_lib = []                                              # TODO
538     solid_libpath = []                                          # TODO
539     solid_include = [irix_precomp + '/solid/include']
540     qhull_lib = []                                              # TODO
541     qhull_libpath = []                                          # TODO
542     qhull_include = ['#extern/qhull/include']
543     # ODE library information
544     ode_lib = []                                                # TODO
545     ode_libpath = []                                            # TODO
546     ode_include = [irix_precomp + '/ode/include']
547     # Python library information
548     python_libpath = [irix_precomp + '/python/lib/python2.2/config']
549     python_include = [irix_precomp + '/python/include/python2.2']
550     python_lib = ['python2.2']
551     python_linkflags = []
552     # International support information
553     ftgl_lib = ['ftgl']
554     ftgl_libpath = [irix_precomp + '/ftgl/lib']
555     ftgl_include = [irix_precomp + '/ftgl/include']
556     freetype_lib = ['freetype']
557     freetype_libpath = [irix_precomp + '/freetype/lib']
558     freetype_include = [irix_precomp + '/freetype/include']
559     gettext_lib = []
560     gettext_libpath = []
561     gettext_include = []
562     # OpenAL library information
563     openal_lib = []
564     openal_libpath = []
565     openal_include = []
566
567 elif string.find (sys.platform, 'hp-ux') != -1:
568     window_system = 'X11'
569     defines = []
570
571 elif sys.platform=='openbsd3':
572     print "Building for OpenBSD 3.x"
573     use_international = 'false'
574     use_gameengine = 'false'
575     use_openal = 'false'
576     use_fmod = 'false'
577     use_quicktime = 'false'
578     use_sumo = 'false'
579     use_ode = 'false'
580     use_buildinfo = 'true'
581     build_blender_dynamic = 'true'
582     build_blender_static = 'false'
583     build_blender_player = 'false'
584     build_blender_plugin = 'false'
585     release_flags = ['-O2']
586     debug_flags = ['-O2', '-g']
587     extra_flags = ['-pipe', '-fPIC', '-funsigned-char']
588     cxxflags = []
589     defines = []
590     warn_flags = ['-Wall','-W']
591     window_system = 'X11'
592     platform_libs = ['m', 'stdc++', 'pthread', 'util']
593     platform_libpath = []
594     platform_linkflags = []
595     extra_includes = []
596     z_lib = ['z']
597     z_libpath = ['/usr/lib']
598     z_include = ['/usr/include']
599     # png library information
600     png_lib = ['png']
601     png_libpath = ['/usr/local/lib']
602     png_include = ['/usr/local/include']
603     # jpeg library information
604     jpeg_lib = ['jpeg']
605     jpeg_libpath = ['/usr/local/lib']
606     jpeg_include = ['/usr/local/include']
607     # OpenGL library information
608     opengl_lib = ['GL', 'GLU']
609     opengl_static = ['/usr/lib/libGL.a', '/usr/lib/libGLU.a']
610     opengl_libpath = ['/usr/lib', '/usr/X11R6/lib']
611     opengl_include = ['/usr/X11R6/include/']
612     # SDL library information
613     sdl_env.ParseConfig ('sdl-config --cflags --libs')
614     sdl_cflags = sdl_env.Dictionary()['CCFLAGS']
615     sdl_include = sdl_env.Dictionary()['CPPPATH']
616     sdl_libpath = sdl_env.Dictionary()['LIBPATH']
617     sdl_lib = sdl_env.Dictionary()['LIBS']
618     # SOLID library information
619     solid_lib = []                     # TODO
620     solid_libpath = []        # TODO
621     solid_include = ['#extern/solid']
622     qhull_lib = []       # TODO
623     qhull_libpath = []  # TODO
624     qhull_include = ['#extern/qhull/include']
625     # ODE library information
626     ode_lib = ['ode']
627     ode_libpath = ['#../lib/linux-glibc2.2.5-i386/ode/lib']
628     ode_include = ['#../lib/linux-glibc2.2.5-i386/ode/include']
629     # Python library information
630     python_lib = ['python%d.%d' % sys.version_info[0:2]]
631     python_libpath = [sysconfig.get_python_lib (0, 1) + '/config']
632     python_include = [sysconfig.get_python_inc ()]
633     python_linkflags = []
634     # International support information
635     ftgl_lib = ['ftgl']
636     ftgl_libpath = ['#../lib/linux-glibc2.2.5-i386/ftgl/lib']
637     ftgl_include = ['#../lib/linux-glibc2.2.5-i386/ftgl/include']
638     freetype_env.ParseConfig('pkg-config --cflags --libs freetype2')
639     freetype_lib = freetype_env.Dictionary()['LIBS']
640     freetype_libpath = freetype_env.Dictionary()['LIBPATH']
641     freetype_include = freetype_env.Dictionary()['CPPPATH']
642     gettext_lib = []
643     gettext_libpath = []
644     gettext_include = []
645     # OpenAL library information
646     openal_lib = ['openal']
647     openal_libpath = ['/usr/lib']
648     openal_include = ['/usr/include']
649
650 else:
651     print "Unknown platform %s"%sys.platform
652     exit
653
654 #-----------------------------------------------------------------------------
655 # End of platform specific section
656 #-----------------------------------------------------------------------------
657
658 #-----------------------------------------------------------------------------
659 # User configurable options to be saved in a config file.
660 #-----------------------------------------------------------------------------
661 # Checking for an existing config file - use that one if it exists,
662 # otherwise create one.
663 my_defines = []
664 my_ccflags = []
665 my_cxxflags = []
666 my_ldflags = []
667 if os.path.exists (config_file):
668     print "Using config file: " + config_file
669 else:
670     print "Creating new config file: " + config_file
671     env_dict = env.Dictionary()
672     config=open (config_file, 'w')
673     config.write ("# Configuration file containing user definable options.\n")
674     config.write ("VERSION = '2.33-cvs'\n")
675     config.write ("BUILD_BINARY = 'release'\n")
676     config.write ("USE_BUILDINFO = %r\n"%(use_buildinfo))
677     config.write ("BUILD_BLENDER_DYNAMIC = %r\n"%(build_blender_dynamic))
678     config.write ("BUILD_BLENDER_STATIC = %r\n"%(build_blender_static))
679     config.write ("BUILD_BLENDER_PLAYER = %r\n"%(build_blender_player))
680     config.write ("BUILD_BLENDER_PLUGIN = %r\n"%(build_blender_plugin))
681     config.write ("BUILD_DIR = %r\n"%(root_build_dir))
682     
683     config.write ("\n# Extra compiler flags can be defined here.\n")
684     config.write ("DEFINES = %s\n"%(my_defines))
685     config.write ("CCFLAGS = %s\n"%(my_ccflags))
686     config.write ("CXXFLAGS = %s\n"%(my_cxxflags))
687     config.write ("LDFLAGS = %s\n"%(my_ldflags))
688
689     config.write ("USE_INTERNATIONAL = %r\n"%(use_international))
690     config.write ("BUILD_GAMEENGINE = %r\n"%(use_gameengine))
691     if use_ode == 'true':
692         config.write ("USE_PHYSICS = 'ode'\n")
693     else:
694         config.write ("USE_PHYSICS = 'solid'\n")
695     config.write ("USE_OPENAL = %r\n"%(use_openal))
696     config.write ("USE_FMOD = %r\n"%(use_fmod))
697     config.write ("USE_QUICKTIME = %r\n"%(use_quicktime))
698     config.write ("\n# Compiler information.\n")
699     config.write ("HOST_CC = %r\n"%(env_dict['CC']))
700     config.write ("HOST_CXX = %r\n"%(env_dict['CXX']))
701     config.write ("TARGET_CC = %r\n"%(env_dict['CC']))
702     config.write ("TARGET_CXX = %r\n"%(env_dict['CXX']))
703     config.write ("TARGET_AR = %r\n"%(env_dict['AR']))
704     config.write ("PATH = %r\n"%(os.environ['PATH']))
705     config.write ("\n# External library information.\n")
706     config.write ("PLATFORM_LIBS = %r\n"%(platform_libs))
707     config.write ("PLATFORM_LIBPATH = %r\n"%(platform_libpath))
708     config.write ("PLATFORM_LINKFLAGS = %r\n"%(platform_linkflags))
709     config.write ("PYTHON_INCLUDE = %r\n"%(python_include))
710     config.write ("PYTHON_LIBPATH = %r\n"%(python_libpath))
711     config.write ("PYTHON_LIBRARY = %r\n"%(python_lib))
712     config.write ("PYTHON_LINKFLAGS = %r\n"%(python_linkflags))
713     config.write ("SDL_CFLAGS = %r\n"%(sdl_cflags))
714     config.write ("SDL_INCLUDE = %r\n"%(sdl_include))
715     config.write ("SDL_LIBPATH = %r\n"%(sdl_libpath))
716     config.write ("SDL_LIBRARY = %r\n"%(sdl_lib))
717     config.write ("Z_INCLUDE = %r\n"%(z_include))
718     config.write ("Z_LIBPATH = %r\n"%(z_libpath))
719     config.write ("Z_LIBRARY = %r\n"%(z_lib))
720     config.write ("PNG_INCLUDE = %r\n"%(png_include))
721     config.write ("PNG_LIBPATH = %r\n"%(png_libpath))
722     config.write ("PNG_LIBRARY = %r\n"%(png_lib))
723     config.write ("JPEG_INCLUDE = %r\n"%(jpeg_include))
724     config.write ("JPEG_LIBPATH = %r\n"%(jpeg_libpath))
725     config.write ("JPEG_LIBRARY = %r\n"%(jpeg_lib))
726     config.write ("OPENGL_INCLUDE = %r\n"%(opengl_include))
727     config.write ("OPENGL_LIBPATH = %r\n"%(opengl_libpath))
728     config.write ("OPENGL_LIBRARY = %r\n"%(opengl_lib))
729     config.write ("OPENGL_STATIC = %r\n"%(opengl_static))
730     config.write ("\n# The following information is only necessary when you've enabled support for\n")
731     config.write ("# the game engine.\n")
732     config.write ("SOLID_INCLUDE = %r\n"%(solid_include))
733     config.write ("SOLID_LIBPATH = %r\n"%(solid_libpath))
734     config.write ("SOLID_LIBRARY = %r\n"%(solid_lib))
735     config.write ("QHULL_INCLUDE = %r\n"%(qhull_include))
736     config.write ("QHULL_LIBPATH = %r\n"%(qhull_libpath))
737     config.write ("QHULL_LIBRARY = %r\n"%(qhull_lib))
738     config.write ("ODE_INCLUDE = %r\n"%(ode_include))
739     config.write ("ODE_LIBPATH = %r\n"%(ode_libpath))
740     config.write ("ODE_LIBRARY = %r\n"%(ode_lib))
741     config.write ("OPENAL_INCLUDE = %r\n"%(openal_include))
742     config.write ("OPENAL_LIBPATH = %r\n"%(openal_libpath))
743     config.write ("OPENAL_LIBRARY = %r\n"%(openal_lib))
744     config.write ("\n# The following information is only necessary when building with\n")
745     config.write ("# internationalization support.\n");
746     config.write ("FTGL_INCLUDE = %r\n"%(ftgl_include))
747     config.write ("FTGL_LIBPATH = %r\n"%(ftgl_libpath))
748     config.write ("FTGL_LIBRARY = %r\n"%(ftgl_lib))
749     config.write ("FREETYPE_INCLUDE = %r\n"%(freetype_include))
750     config.write ("FREETYPE_LIBPATH = %r\n"%(freetype_libpath))
751     config.write ("FREETYPE_LIBRARY = %r\n"%(freetype_lib))
752     config.write ("GETTEXT_INCLUDE = %r\n"%(gettext_include))
753     config.write ("GETTEXT_LIBPATH = %r\n"%(gettext_libpath))
754     config.write ("GETTEXT_LIBRARY = %r\n"%(gettext_lib))
755     config.close ()
756
757 #-----------------------------------------------------------------------------
758 # Read the options from the config file and update the various necessary flags
759 #-----------------------------------------------------------------------------
760 list_opts = []
761 user_options_env = Environment ()
762 user_options = Options (config_file)
763 user_options.AddOptions (
764         ('VERSION', 'Blender version', version),
765         (EnumOption ('BUILD_BINARY', 'release',
766                      'Select a release or debug binary.',
767                      allowed_values = ('release', 'debug'))),
768         (BoolOption ('USE_BUILDINFO',
769                      'Set to 1 if you want to add build information.',
770                      'false')),
771         (BoolOption ('BUILD_BLENDER_DYNAMIC',
772                      'Set to 1 if you want to build blender with hardware accellerated OpenGL support.',
773                      'true')),
774         (BoolOption ('BUILD_BLENDER_STATIC',
775                      'Set to 1 if you want to build blender with software OpenGL support.',
776                      'false')),
777         (BoolOption ('BUILD_BLENDER_PLAYER',
778                      'Set to 1 if you want to build the blender player.',
779                      'false')),
780         (BoolOption ('BUILD_BLENDER_PLUGIN',
781                      'Set to 1 if you want to build the blender plugin.',
782                      'false')),
783         ('BUILD_DIR', 'Target directory for intermediate files.',
784                      root_build_dir),
785         (BoolOption ('USE_INTERNATIONAL',
786                      'Set to 1 to have international support.',
787                      'false')),
788         (EnumOption ('USE_PHYSICS', 'solid',
789                      'Select which physics engine to use.',
790                      allowed_values = ('ode', 'solid'))),
791         (BoolOption ('BUILD_GAMEENGINE',
792                      'Set to 1 to build blender with game engine support.',
793                      'false')),
794         (BoolOption ('USE_OPENAL',
795                      'Set to 1 to build the game engine with OpenAL support.',
796                      'false')),
797         (BoolOption ('USE_FMOD',
798                      'Set to 1 to build the game engine with FMod support.',
799                      'false')),
800         (BoolOption ('USE_QUICKTIME',
801                      'Set to 1 to add support for QuickTime.',
802                      'false')),
803         ('HOST_CC', 'C compiler for the host platfor. This is the same as target platform when not cross compiling.'),
804         ('HOST_CXX', 'C++ compiler for the host platform. This is the same as target platform when not cross compiling.'),
805         ('TARGET_CC', 'C compiler for the target platform.'),
806         ('TARGET_CXX', 'C++ compiler for the target platform.'),
807         ('TARGET_AR', 'Linker command for linking libraries.'),
808         ('PATH', 'Standard search path'),
809         ('PLATFORM_LIBS', 'Platform specific libraries.'),
810         ('PLATFORM_LIBPATH', 'Platform specific library link path.'),
811         ('PLATFORM_LINKFLAGS', 'Platform specific linkflags'),
812         ('PYTHON_INCLUDE', 'Include directory for Python header files.'),
813         ('PYTHON_LIBPATH', 'Library path where the Python lib is located.'),
814         ('PYTHON_LIBRARY', 'Python library name.'),
815         ('PYTHON_LINKFLAGS', 'Python specific linkflags.'),
816         ('SDL_CFLAGS', 'Necessary CFLAGS when using sdl functionality.'),
817         ('SDL_INCLUDE', 'Include directory for SDL header files.'),
818         ('SDL_LIBPATH', 'Library path where the SDL library is located.'),
819         ('SDL_LIBRARY', 'SDL library name.'),
820         ('Z_INCLUDE', 'Include directory for zlib header files.'),
821         ('Z_LIBPATH', 'Library path where the zlib library is located.'),
822         ('Z_LIBRARY', 'Z library name.'),
823         ('PNG_INCLUDE', 'Include directory for png header files.'),
824         ('PNG_LIBPATH', 'Library path where the png library is located.'),
825         ('PNG_LIBRARY', 'png library name.'),
826         ('JPEG_INCLUDE', 'Include directory for jpeg header files.'),
827         ('JPEG_LIBPATH', 'Library path where the jpeg library is located.'),
828         ('JPEG_LIBRARY', 'jpeg library name.'),
829         ('OPENGL_INCLUDE', 'Include directory for OpenGL header files.'),
830         ('OPENGL_LIBPATH', 'Library path where the OpenGL libraries are located.'),
831         ('OPENGL_LIBRARY', 'OpenGL library names.'),
832         ('OPENGL_STATIC', 'Linker flags for static linking of Open GL.'),
833         ('SOLID_INCLUDE', 'Include directory for SOLID header files.'),
834         ('SOLID_LIBPATH', 'Library path where the SOLID library is located.'),
835         ('SOLID_LIBRARY', 'SOLID library name.'),
836         ('QHULL_INCLUDE', 'Include directory for QHULL header files.'),
837         ('QHULL_LIBPATH', 'Library path where the QHULL library is located.'),
838         ('QHULL_LIBRARY', 'QHULL library name.'),
839         ('ODE_INCLUDE', 'Include directory for ODE header files.'),
840         ('ODE_LIBPATH', 'Library path where the ODE library is located.'),
841         ('ODE_LIBRARY', 'ODE library name.'),
842         ('OPENAL_INCLUDE', 'Include directory for OpenAL header files.'),
843         ('OPENAL_LIBPATH', 'Library path where the OpenAL library is located.'),
844         ('OPENAL_LIBRARY', 'OpenAL library name.'),
845         ('FTGL_INCLUDE', 'Include directory for ftgl header files.'),
846         ('FTGL_LIBPATH', 'Library path where the ftgl library is located.'),
847         ('FTGL_LIBRARY', 'ftgl library name.'),
848         ('FREETYPE_INCLUDE', 'Include directory for freetype2 header files.'),
849         ('FREETYPE_LIBPATH', 'Library path where the freetype2 library is located.'),
850         ('FREETYPE_LIBRARY', 'Freetype2 library name.'),
851         ('GETTEXT_INCLUDE', 'Include directory for gettext header files.'),
852         ('GETTEXT_LIBPATH', 'Library path where the gettext library is located.'),
853         ('GETTEXT_LIBRARY', 'gettext library name.'),
854
855         ('DEFINES', 'Extra Preprocessor defines.'),
856         ('CCFLAGS', 'Extra C Compiler flags.'),
857         ('CXXFLAGS','Extra C++ Compiler flags.'),
858         ('LDFLAGS', 'Extra Linker flags.')
859     )
860 user_options.Update (user_options_env)
861 user_options_dict = user_options_env.Dictionary()
862
863 root_build_dir = user_options_dict['BUILD_DIR']
864     
865 if user_options_dict['BUILD_GAMEENGINE'] == 1:
866     defines += ['GAMEBLENDER=1']
867     if user_options_dict['USE_PHYSICS'] == 'ode':
868         defines += ['USE_ODE']
869     else:
870         defines += ['USE_SUMO_SOLID']
871 else:
872     defines += ['GAMEBLENDER=0']
873
874 if user_options_dict['BUILD_BINARY'] == 'release':
875     cflags = extra_flags + release_flags + warn_flags
876     if sys.platform == 'win32':
877         defines += ['NDEBUG']
878 else:
879     cflags = extra_flags + debug_flags + warn_flags
880     if sys.platform == 'win32':
881         #defines += ['_DEBUG'] specifying this makes msvc want to link to python22_d.lib??
882         platform_linkflags += ['/DEBUG','/PDB:blender.pdb']
883
884 defines += user_options_dict['DEFINES']
885 cflags += user_options_dict['CCFLAGS']
886 cxxflags += user_options_dict['CXXFLAGS']
887 platform_linkflags += user_options_dict['LDFLAGS']
888
889 #-----------------------------------------------------------------------------
890 # Generic library generation environment. This one is the basis for each
891 # library.
892 #-----------------------------------------------------------------------------
893 library_env = env.Copy ()
894 library_env.Replace (CC = user_options_dict['TARGET_CC'])
895 library_env.Replace (CXX = user_options_dict['TARGET_CXX'])
896 library_env.Replace (PATH = user_options_dict['PATH'])
897 library_env.Replace (AR = user_options_dict['TARGET_AR'])
898 library_env.Append (CCFLAGS = cflags)
899 library_env.Append (CXXFLAGS = cxxflags)
900 library_env.Append (CPPDEFINES = defines)
901 library_env.SConsignFile (root_build_dir+'scons-signatures')
902
903 #-----------------------------------------------------------------------------
904 # Settings to be exported to other SConscript files
905 #-----------------------------------------------------------------------------
906
907 Export ('cflags')
908 Export ('defines')
909 Export ('window_system')
910 Export ('extra_includes')
911 Export ('user_options_dict')
912 Export ('library_env')
913
914 BuildDir (root_build_dir+'/extern', 'extern', duplicate=0)
915 SConscript (root_build_dir+'extern/SConscript')
916 BuildDir (root_build_dir+'/intern', 'intern', duplicate=0)
917 SConscript (root_build_dir+'intern/SConscript')
918 BuildDir (root_build_dir+'/source', 'source', duplicate=0)
919 SConscript (root_build_dir+'source/SConscript')
920
921 libpath = (['#'+root_build_dir+'/lib'])
922
923 link_env = library_env.Copy ()
924 link_env.Append (LIBPATH=libpath)
925
926 def common_libs(env):
927         """
928         Append to env all libraries that are common to Blender and Blenderplayer
929         """
930         env.Append (LIBS=[
931                 'blender_blenloader',
932                 'blender_readblenfile',
933                 'blender_img',
934                 'blender_blenkernel',
935                 'blender_blenpluginapi',
936                 'blender_imbuf',
937                 'blender_avi',
938                 'blender_blenlib',
939                 'blender_makesdna',
940                 'blender_kernel',
941                 'blender_GHOST',
942                 'blender_STR',
943                 'blender_guardedalloc',
944                 'blender_CTR',
945                 'blender_MEM',
946                 'blender_MT',
947                 'blender_BMF',
948                 'soundsystem'])
949         if user_options_dict['USE_QUICKTIME'] == 1:
950                 env.Append (LIBS=['blender_quicktime'])
951
952
953 def international_libs(env):
954         """
955         Append international font support libraries
956         """
957         if user_options_dict['USE_INTERNATIONAL'] == 1:
958                 env.Append (LIBS=user_options_dict['FREETYPE_LIBRARY'])
959                 env.Append (LIBPATH=user_options_dict['FREETYPE_LIBPATH'])
960                 env.Append (LIBS=['blender_FTF'])
961                 env.Append (LIBS=user_options_dict['FTGL_LIBRARY'])
962                 env.Append (LIBPATH=user_options_dict['FTGL_LIBPATH'])
963                 env.Append (LIBS=user_options_dict['FREETYPE_LIBRARY'])
964
965 def blender_libs(env):
966         """
967         Blender only libs (not in player)
968         """
969         env.Append( LIBS=['blender_creator',
970                 'blender_blendersrc',
971                 'blender_render',
972                 'blender_yafray',
973                 'blender_renderconverter',
974                 'blender_radiosity',
975                 'blender_LOD',
976                 'blender_BSP',
977                 'blender_blenkernel',
978                 'blender_IK',
979                 'blender_ONL'])
980
981 def ketsji_libs(env):
982         """
983         Game Engine libs
984         """
985         if user_options_dict['BUILD_GAMEENGINE'] == 1:
986                 env.Append (LIBS=['KX_blenderhook',
987                                 'KX_converter',
988                                 'PHY_Dummy',
989                                 'PHY_Physics',
990                                 'KX_ketsji',
991                                 'SCA_GameLogic',
992                                 'RAS_rasterizer',
993                                 'RAS_OpenGLRasterizer',
994                                 'blender_expressions',
995                                 'SG_SceneGraph',
996                                 'blender_MT',
997                                 'KX_blenderhook',
998                                 'KX_network',
999                                 'blender_kernel',
1000                                 'NG_network',
1001                                 'NG_loopbacknetwork'])
1002                 if user_options_dict['USE_PHYSICS'] == 'solid':
1003                         env.Append (LIBS=['PHY_Sumo', 'PHY_Physics', 'blender_MT', 'extern_solid', 'extern_qhull'])
1004                 else:
1005                         env.Append (LIBS=['PHY_Ode',
1006                                         'PHY_Physics'])
1007                         env.Append (LIBS=user_options_dict['ODE_LIBRARY'])
1008                         env.Append (LIBPATH=user_options_dict['ODE_LIBPATH'])
1009
1010 def player_libs(env):
1011         """
1012         Player libraries
1013         """
1014         env.Append (LIBS=['GPG_ghost',
1015                         'GPC_common'])
1016
1017 def player_libs2(env):
1018         """
1019         Link order shenannigans: these libs are added after common_libs
1020         """
1021         env.Append (LIBS=['blender_blenkernel_blc',
1022                         'soundsystem'])
1023
1024 def winblenderres(env):
1025         """
1026         build the windows icon resource file
1027         """
1028         if sys.platform == 'win32':
1029                 env.RES(['source/icons/winblender.rc'])
1030
1031 def system_libs(env):
1032         """
1033         System libraries: Python, SDL, PNG, JPEG, Gettext, OpenAL, Carbon
1034         """
1035         env.Append (LIBS=['blender_python'])
1036         env.Append (LIBS=user_options_dict['PYTHON_LIBRARY'])
1037         env.Append (LIBPATH=user_options_dict['PYTHON_LIBPATH'])
1038         env.Append (LINKFLAGS=user_options_dict['PYTHON_LINKFLAGS'])
1039         env.Append (LIBS=user_options_dict['SDL_LIBRARY'])
1040         env.Append (LIBPATH=user_options_dict['SDL_LIBPATH'])
1041         env.Append (LIBS=user_options_dict['PNG_LIBRARY'])
1042         env.Append (LIBPATH=user_options_dict['PNG_LIBPATH'])
1043         env.Append (LIBS=user_options_dict['JPEG_LIBRARY'])
1044         env.Append (LIBPATH=user_options_dict['JPEG_LIBPATH'])
1045         env.Append (LIBS=user_options_dict['GETTEXT_LIBRARY'])
1046         env.Append (LIBPATH=user_options_dict['GETTEXT_LIBPATH'])
1047         env.Append (LIBS=user_options_dict['Z_LIBRARY'])
1048         env.Append (LIBPATH=user_options_dict['Z_LIBPATH'])
1049         if user_options_dict['USE_OPENAL'] == 1:
1050                 env.Append (LIBS=user_options_dict['OPENAL_LIBRARY'])
1051                 env.Append (LIBPATH=user_options_dict['OPENAL_LIBPATH'])
1052         env.Append (LIBS=user_options_dict['PLATFORM_LIBS'])
1053         env.Append (LIBPATH=user_options_dict['PLATFORM_LIBPATH'])
1054         if sys.platform == 'darwin':
1055                 env.Append (LINKFLAGS='-framework')
1056                 env.Append (LINKFLAGS='Carbon')
1057                 env.Append (LINKFLAGS='-framework')
1058                 env.Append (LINKFLAGS='AGL')
1059                 env.Append (LINKFLAGS='-framework')
1060                 env.Append (LINKFLAGS='AudioUnit')
1061                 env.Append (LINKFLAGS='-framework')
1062                 env.Append (LINKFLAGS='AudioToolbox')
1063                 env.Append (LINKFLAGS='-framework')
1064                 env.Append (LINKFLAGS='CoreAudio')
1065                 if user_options_dict['USE_QUICKTIME'] == 1:
1066                         env.Append (LINKFLAGS='-framework')
1067                         env.Append (LINKFLAGS='QuickTime')
1068         else:
1069                 env.Append (LINKFLAGS=user_options_dict['PLATFORM_LINKFLAGS'])
1070         env.BuildDir (root_build_dir, '.', duplicate=0)
1071
1072 def buildinfo(env, build_type):
1073         """
1074         Generate a buildinfo object
1075         """
1076         build_date = time.strftime ("%Y-%m-%d")
1077         build_time = time.strftime ("%H:%M:%S")
1078         obj = []
1079         if user_options_dict['USE_BUILDINFO'] == 1:
1080                 if sys.platform=='win32':
1081                         build_info_file = open("source/creator/winbuildinfo.h", 'w')
1082                         build_info_file.write("char *build_date=\"%s\";\n"%build_date)
1083                         build_info_file.write("char *build_time=\"%s\";\n"%build_time)
1084                         build_info_file.write("char *build_platform=\"win32\";\n")
1085                         build_info_file.write("char *build_type=\"%s\";\n"%build_type)
1086                         build_info_file.close()
1087                         env.Append (CPPDEFINES = ['NAN_BUILDINFO', 'BUILD_DATE'])
1088                 else:
1089                         env.Append (CPPDEFINES = ['BUILD_TIME=\'"%s"\''%(build_time),
1090                                                         'BUILD_DATE=\'"%s"\''%(build_date),
1091                                                         'BUILD_TYPE=\'"dynamic"\'',
1092                                                         'NAN_BUILDINFO',
1093                                                         'BUILD_PLATFORM=\'"%s"\''%(sys.platform)])
1094                 obj = [env.Object (root_build_dir+'source/creator/%s_buildinfo'%build_type,
1095                                                 [root_build_dir+'source/creator/buildinfo.c'])]
1096         return obj
1097         
1098 def cleanCVS():
1099         """
1100         walks the dist dir and removes all CVS dirs
1101         """
1102         
1103         try:
1104                 import shutil
1105         except:
1106                 print "no shutil available"
1107                 print "make sure you use python 2.3"
1108                 print
1109                 return 0
1110         
1111         startdir = os.getcwd()
1112         
1113         for root, dirs, files in os.walk("dist", topdown=False):
1114                 for name in dirs:
1115                         if name in ['CVS']:
1116                                 if os.path.isdir(root + "/" + name):
1117                                         shutil.rmtree(root + "/" + name)
1118         
1119         os.chdir(startdir)
1120         
1121         return 1
1122
1123 def preparedist():
1124         """
1125         Prepare a directory for creating either archives or the installer
1126         """
1127         
1128         try:
1129                 import shutil
1130         except:
1131                 print "no shutil available"
1132                 print "make sure you use python 2.3"
1133                 print
1134                 return 0
1135         
1136         startdir = os.getcwd()
1137         
1138         if os.path.isdir("dist") == 0:
1139                 os.makedirs("dist")
1140         else:
1141                 shutil.rmtree("dist") # make sure we don't get old cruft
1142                 os.makedirs("dist")
1143         
1144         # first copy binaries
1145         
1146         if sys.platform == 'win32':
1147                 shutil.copy("blender.exe", "dist/blender.exe")
1148                 if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
1149                         shutil.copy("blenderplayer.exe", "dist/blenderplayer.exe")
1150                 shutil.copy("../lib/windows/python/lib/python23.dll", "dist/python23.dll")
1151                 shutil.copy("../lib/windows/sdl/lib/SDL.dll", "dist/SDL.dll")
1152                 shutil.copy("../lib/windows/gettext/lib/gnu_gettext.dll", "dist/gnu_gettext.dll")
1153         elif sys.platform in ['linux2', 'linux-i386']:
1154                 shutil.copy("blender", "dist/blender")
1155                 if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
1156                         shutil.copy("blenderplayer", "dist/blenderplayer")
1157         else:
1158                 print "update preparedist() for your platform!"
1159                 return 0
1160         
1161         # now copy .blender and necessary extras for it
1162         if os.path.isdir("dist/.blender"):
1163                 shutil.rmtree("dist/.blender")
1164         os.chdir("bin")
1165         shutil.copytree(".blender/", "../dist/.blender")
1166         os.chdir(startdir)
1167         if os.path.isdir("dist/.blender/scripts"):
1168                 shutil.rmtree("dist/.blender/scripts")
1169         if os.path.isdir("dist/.blender/bpydata"):
1170                 shutil.rmtree("dist/.blender/bpydata")
1171                 
1172         os.makedirs("dist/.blender/bpydata")
1173         shutil.copy("release/bpydata/readme.txt", "dist/.blender/bpydata/readme.txt")
1174         
1175         os.chdir("release")
1176         shutil.copytree("scripts/", "../dist/.blender/scripts")
1177         
1178         # finally copy auxiliaries (readme, license, etc.)
1179         if sys.platform == 'win32':
1180                 shutil.copy("windows/extra/Help.url", "../dist/Help.url")
1181         shutil.copy("text/copyright.txt", "../dist/copyright.txt")
1182         shutil.copy("text/blender.html", "../dist/blender.html")
1183         shutil.copy("text/GPL-license.txt", "../dist/GPL-license.txt")
1184         shutil.copy("text/Python-license.txt", "../dist/Python-lisence.txt")
1185         
1186         reltext = "release_" + string.join(version.split("."), '') + ".txt"
1187         shutil.copy("text/" + reltext, "../dist/" + reltext)
1188         
1189         os.chdir(startdir)
1190         
1191         if cleanCVS()==0:
1192                 return 0
1193
1194         return 1
1195
1196 def finalisedist(zipname):
1197         """
1198         Fetch the package created and remove temp dir
1199         """
1200         
1201         try:
1202                 import shutil
1203         except:
1204                 print "no shutil available"
1205                 print "make sure you use python 2.3"
1206                 print
1207                 return 0
1208         
1209         shutil.copy("dist/" + zipname, zipname)
1210         shutil.rmtree("dist")
1211         
1212         return 1
1213
1214 def add2arc(arc, file):
1215         if sys.platform == 'win32':
1216                 arc.write(file)
1217         else:
1218                 arc.add(file)
1219
1220 def zipit(env, target, source):
1221         try:
1222                 if sys.platform == 'win32':
1223                         import zipfile
1224                 else:
1225                         import tarfile
1226         except:
1227                 if sys.platform == 'win32':
1228                         print "no zipfile module found"
1229                 else:
1230                         print "no tarfile module found"
1231                         print "make sure you use python 2.3"
1232                 print
1233                 return
1234         
1235         import glob
1236         import time
1237         
1238         startdir = os.getcwd()
1239         pf=""
1240         zipext = ""
1241         zipname = ""
1242         
1243         today = time.strftime("%Y%m%d", time.gmtime()) # get time in the form 20040714
1244         
1245         if preparedist()==0:
1246                 print "check output for error"
1247                 return
1248         
1249         os.chdir(startdir + "/dist")
1250         
1251         if sys.platform == 'win32':
1252                 zipext += ".zip"
1253                 pf = "windows"
1254         elif sys.platform == 'linux2' or sys.platform == 'linux-i386':
1255                 zipext += ".tar.gz"
1256                 pf = "linux"
1257         
1258         zipname = "bf_blender_" + pf+ "_" + today + zipext
1259         
1260         print
1261         if sys.platform == 'win32':
1262                 print "Create the zip!"
1263         elif sys.platform == 'linux2' or sys.platform == 'linux-i386':
1264                 print "Create the tarball!"
1265         print
1266         
1267         if sys.platform == 'win32':
1268                 thezip = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
1269         else:
1270                 thezip = tarfile.open(zipname, 'w:gz')
1271         
1272         for root, dirs, files in os.walk(".", topdown=False):
1273                 for name in files:
1274                         if name in [zipname]:
1275                                 print "skipping self"
1276                         else:
1277                                 file = root + "/" + name
1278                                 print "adding: " + file
1279                                 add2arc(thezip, file)
1280         
1281         thezip.close()
1282         
1283         os.chdir(startdir)
1284         
1285         if finalisedist(zipname)==0:
1286                 print "encountered an error in finalisedist"
1287                 print
1288                 return
1289         
1290         print
1291         print "Blender has been successfully packaged"
1292         print "You can find the file %s in the root source directory"%zipname
1293         print
1294         
1295
1296 def printadd(env, target, source):
1297         """
1298         Print warning message if platform hasn't been added to zipit() yet
1299         """
1300         
1301         print
1302         print "############"
1303         print 
1304         print "Make sure zipit() works for your platform:"
1305         print "  - binaries to copy (naming?)"
1306         print "  - possible libraries?"
1307         print "  - archive format?"
1308         print
1309         print "After you've corrected zipit() for your"
1310         print "platform, be sure to add a proper elif"
1311         print "at the end of BlenderRelease"
1312         print
1313         print "Blender is now ready and can be found in"
1314         print "root of the source distribution, but it"
1315         print "hasn't been packaged neatly. Make sure you"
1316         print "get the right files"
1317         print
1318         print "/jesterKing"
1319         print
1320         
1321
1322 def noaction(env, target, source):
1323         print "Empty action"
1324
1325 def DoClean(dir2clean):
1326         """
1327         Do a removal of the root_build_dir the fast way
1328         """
1329         import shutil
1330
1331         print "distcleaning... %s"%dir2clean
1332         dirs = os.listdir(dir2clean)
1333         for dir in dirs:
1334                 if os.path.isdir(dir2clean + "/" + dir) == 1:
1335                         print "clean dir %s"%(dir2clean+"/" + dir)
1336                         shutil.rmtree(dir2clean+"/" + dir)
1337                 else:
1338                         print "clean file %s"%(dir2clean+"/" + dir)
1339                         os.remove(dir2clean+"/" + dir)
1340         print "done"
1341
1342 def BlenderDefault(target):
1343         """
1344         The default Blender build.
1345         """
1346         def_env = Environment()
1347         default = def_env.Command('nozip', 'blender$PROGSUFFIX', noaction)
1348         if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
1349                 def_env.Depends(default, 'blenderplayer$PROGSUFFIX')
1350         def_env.Alias(".", default)
1351
1352 def donsis(env, target, source):
1353         """
1354         Create a Windows installer with NSIS
1355         """
1356         print
1357         print "Creating the Windows installer"
1358         print
1359         
1360         startdir = os.getcwd()
1361         
1362         if preparedist()==0:
1363                 print "check output for error"
1364                 return
1365         
1366         os.chdir("release/windows/installer")
1367         
1368         nsis = open("00.sconsblender.nsi", 'r')
1369         nsis_cnt = str(nsis.read())
1370         nsis.close()
1371         
1372         # do root
1373         rootlist = []
1374         rootdir = os.listdir(startdir + "\\dist")
1375         for rootitem in rootdir:
1376                 if os.path.isdir(startdir + "\\dist\\" + rootitem) == 0:
1377                         rootlist.append("File " + startdir + "\\dist\\" + rootitem)
1378         rootstring = string.join(rootlist, "\n  ")
1379         rootstring += "\n\n"
1380         nsis_cnt = string.replace(nsis_cnt, "[ROOTDIRCONTS]", rootstring)
1381         
1382         # do scripts
1383         scriptlist = []
1384         scriptdir = os.listdir(startdir + "\\dist\\.blender\\scripts")
1385         for scriptitem in scriptdir:
1386                 if os.path.isdir(startdir + "\\dist\\.blender\\scripts\\" + scriptitem) == 0:
1387                         scriptlist.append("File " + startdir + "\\dist\\.blender\\scripts\\" + scriptitem)
1388         scriptstring = string.join(scriptlist, "\n  ")
1389         scriptstring += "\n\n"
1390         nsis_cnt = string.replace(nsis_cnt, "[SCRIPTCONTS]", scriptstring)
1391         
1392         # do dotblender
1393         dotblendlist = []
1394         dotblenddir = os.listdir(startdir+"\\dist\\.blender")
1395         for dotblenditem in dotblenddir:
1396                 if os.path.isdir(startdir + "\\dist\\.blender\\" + dotblenditem) == 0:
1397                         dotblendlist.append("File " + startdir + "\\dist\\.blender\\" + dotblenditem)
1398         dotblendstring = string.join(dotblendlist, "\n  ")
1399         dotblendstring += "\n\n"
1400         nsis_cnt = string.replace(nsis_cnt, "[DOTBLENDERCONTS]", dotblendstring)
1401         
1402         # do language files
1403         langlist = []
1404         langdir = os.listdir(startdir + "\\dist\\.blender\\locale")
1405         for langitem in langdir:
1406                 if os.path.isdir(startdir + "\\dist\\.blender\\locale\\" + langitem) == 1:
1407                         langlist.append("File " + startdir + "\\dist\\.blender\\locale\\" + langitem + "\\LC_MESSAGES\\blender.mo")
1408         langstring = string.join(langlist, "\n  ")
1409         langstring += "\n\n"
1410         nsis_cnt = string.replace(nsis_cnt, "[LANGUAGECONTS]", langstring)
1411         
1412         # var replacements
1413         nsis_cnt = string.replace(nsis_cnt, "DISTDIR", startdir + "\\dist")
1414         nsis_cnt = string.replace(nsis_cnt, "SHORTVER", shortversion)
1415         nsis_cnt = string.replace(nsis_cnt, "VERSION", version)
1416         
1417         new_nsis = open("00.blender_tmp.nsi", 'w')
1418         new_nsis.write(nsis_cnt)
1419         new_nsis.close()
1420         
1421         sys.stdout = os.popen("makensis 00.blender_tmp.nsi", 'w')
1422         
1423         os.chdir(startdir)
1424         
1425         
1426 def BlenderNSIS(target):
1427         """
1428         Entry for creating Windows installer
1429         """
1430         if sys.platform == 'win32':
1431                 inst_env = Environment()
1432                 nsis_inst = inst_env.Command('nsisinstaller', 'blender$PROGSUFFIX', donsis)
1433                 if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
1434                         inst_env.Depends(nsis_inst, 'blenderplayer$PROGSUFFIX')
1435                 inst_env.Alias("wininst", nsis_inst)
1436         else:
1437                 print "This target is for the win32 platform only"
1438
1439 def BlenderRelease(target):
1440         """
1441         Make a Release package (tarball, zip, bundle).
1442         
1443         target = Name of package to make (string)
1444         eg: BlenderRelease('blender')
1445         """
1446         if sys.platform == 'darwin':
1447                 bundle = Environment ()
1448                 blender_app = target
1449                 bundle.Depends ('#/%s.app/Contents/Info.plist'%target, blender_app)
1450                 bundle.Command ('#/%s.app/Contents/Info.plist'%target,
1451                                 '#/source/darwin/%s.app/Contents/Info.plist'%target,
1452                                 "rm -rf %s.app && "%target + \
1453                                 "cp -R source/darwin/%s.app . && "%target +
1454                                 "cat $SOURCE | sed s/VERSION/`cat release/VERSION`/ | \
1455                                                 sed s/DATE/`date +'%Y-%b-%d'`/ \
1456                                                 > $TARGET && " + \
1457                                 'cp -p %s %s.app/Contents/MacOS/%s && '%(target, target, target) + \
1458                                 'strip -u -r %s.app/Contents/MacOS/%s && '%(target, target) + \
1459                                 'cp bin/.blender/.bfont.ttf %s.app/Contents/Resources/ && '%target + \
1460                                 'cp bin/.blender/.Blanguages %s.app/Contents/Resources/ && '%target + \
1461                                 'cp -R bin/.blender/locale %s.app/Contents/Resources/ && '%target + \
1462                                 'cp -R release/bpydata %s.app/Contents/Resources/ && '%target + \
1463                                 'cp -R release/scripts %s.app/Contents/Resources/ && '%target + \
1464                                 'cp -R release/plugins %s.app/Contents/Resources/ && '%target + \
1465                                 'chmod +x $TARGET && ' + \
1466                                 'find %s.app -name CVS -prune -exec rm -rf {} \; && '%target +
1467                                 'find %s.app -name .DS_Store -exec rm -rf {} \;'%target)
1468         elif sys.platform in ['win32', 'linux2', 'linux-i386']:
1469                 release_env = Environment()
1470                 releaseit = release_env.Command('blenderrelease', 'blender$PROGSUFFIX', zipit)
1471                 if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
1472                         release_env.Depends(releaseit, 'blenderplayer$PROGSUFFIX')
1473                 release_env.Alias("release", releaseit)
1474         else:
1475                 release_env = Environment()
1476                 releaseit = release_env.Command('blender.tar.gz', 'blender$PROGSUFFIX', printadd)
1477                 if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
1478                         release_env.Depends(releaseit, 'blenderplayer$PROGSUFFIX')
1479                 release_env.Alias("release", releaseit)
1480
1481 if user_options_dict['BUILD_BLENDER_DYNAMIC'] == 1:
1482         dy_blender = link_env.Copy ()
1483         if sys.platform=='win32':
1484                 winblenderres(dy_blender)
1485         blender_libs(dy_blender)
1486         common_libs(dy_blender)
1487         international_libs(dy_blender)
1488         ketsji_libs(dy_blender)
1489         system_libs(dy_blender)
1490         dy_blender.Append (LIBS=user_options_dict['OPENGL_LIBRARY'])
1491         dy_blender.Append (LIBPATH=user_options_dict['OPENGL_LIBPATH'])
1492         dy_blender.Append (CPPPATH=user_options_dict['OPENGL_INCLUDE'])
1493         d_obj = buildinfo(dy_blender, "dynamic")
1494         if sys.platform == 'win32':
1495                 dy_blender.Program (target='blender',
1496                                         source=d_obj + ['source/icons/winblender.res'])
1497         else:
1498                 if sys.platform == 'cygwin':
1499                         dy_blender.Replace (CC='g++')
1500                 dy_blender.Program (target='blender', source=d_obj)
1501
1502 if user_options_dict['BUILD_BLENDER_STATIC'] == 1:
1503         st_blender = link_env.Copy ()
1504         if sys.platform=='win32':
1505                 winblenderres(st_blender)
1506         blender_libs(st_blender)
1507         common_libs(st_blender)
1508         international_libs(st_blender)
1509         ketsji_libs(st_blender)
1510         system_libs(st_blender)
1511         # The next line is to make sure that the LINKFLAGS are appended at the end
1512         # of the link command. This 'trick' is needed because the GL and GLU static
1513         # libraries need to be at the end of the command.
1514         st_blender.Replace(LINKCOM="$LINK -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $LINKFLAGS")
1515         s_obj = buildinfo(st_blender, "static")
1516         st_blender.Append (LINKFLAGS=user_options_dict['OPENGL_STATIC'])
1517         st_blender.Append (CPPPATH=user_options_dict['OPENGL_INCLUDE'])
1518         st_blender.Prepend (LIBPATH=['/usr/lib/opengl/xfree/lib'])
1519         st_blender.Program (target='blenderstatic', source=s_obj)
1520
1521 if sys.platform=='win32':
1522     if user_options_dict['BUILD_BINARY']=='debug':
1523         browser = Environment()
1524         browser_tmp = root_build_dir+'bscmake.tmp'
1525         browser.Command ('blender.bsc', 'blender$PROGSUFFIX',
1526             ['dir /b/s '+root_build_dir+'*.sbr >'+browser_tmp,
1527              'bscmake /nologo /n /oblender.bsc @'+browser_tmp,
1528              'del '+browser_tmp])
1529
1530 if user_options_dict['BUILD_BLENDER_PLAYER'] == 1 and user_options_dict['BUILD_GAMEENGINE'] == 1:
1531         player_blender = link_env.Copy()
1532         player_libs(player_blender)
1533         common_libs(player_blender)
1534         international_libs(player_blender)
1535         ketsji_libs(player_blender)
1536         player_libs2(player_blender)
1537         system_libs(player_blender)
1538         player_blender.Append (LIBS=user_options_dict['OPENGL_LIBRARY'])
1539         player_blender.Append (LIBPATH=user_options_dict['OPENGL_LIBPATH'])
1540         player_blender.Append (CPPPATH=user_options_dict['OPENGL_INCLUDE'])
1541         d_obj = buildinfo(player_blender, "player")
1542         if sys.platform == 'win32':
1543                 player_blender.Program (target='blenderplayer',
1544                                         source=d_obj + ['source/icons/winblender.res'])
1545         else:
1546                 if sys.platform == 'cygwin':
1547                         player_blender.Replace (CC='g++')
1548                 player_blender.Program (target='blenderplayer', source=d_obj)
1549         if sys.platform=='win32':
1550                 if user_options_dict['BUILD_BINARY']=='debug':
1551                         browser = Environment()
1552                         browser_tmp = root_build_dir+'bscmake.tmp'
1553                         browser.Command ('blenderplayer.bsc', 'blenderplayer$PROGSUFFIX',
1554                         ['dir /b/s '+root_build_dir+'*.sbr >'+browser_tmp,
1555                         'bscmake /nologo /n /oblenderplayer.bsc @'+browser_tmp,
1556                         'del '+browser_tmp])
1557
1558 release_target = env.Alias("release", BlenderRelease('blender$PROGSUFFIX'))
1559 default_target = env.Alias("default", BlenderDefault('blender$PROGSUFFIX'))
1560 wininst_target = env.Alias("winist", BlenderNSIS('blender$PROGSUFFIX'))
1561 distclean_target = env.Alias("clean", DoClean(root_build_dir))
1562
1563 Default("default")
1564
1565 if sys.platform == 'win32':
1566         if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
1567                 env.Depends(wininst_target, 'blenderplayer$PROGSUFFIX')
1568         env.Depends(wininst_target, 'blender$PROGSUFFIX')
1569
1570 if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
1571         env.Depends(release_target, 'blenderplayer$PROGSUFFIX')
1572 env.Depends(release_target, 'blender$PROGSUFFIX')
1573
1574 if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
1575         env.Depends(default_target, 'blenderplayer$PROGSUFFIX')
1576 env.Depends(default_target, 'blender$PROGSUFFIX')