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