SConscript revision 34472a0d8713c4eb300c9d1de0844c8b78bcf1ab
1#######################################################################
2# SConscript for Mesa
3
4
5Import('*')
6import filecmp
7import os
8import subprocess
9from sys import executable as python_cmd
10
11env = env.Clone()
12
13env.Append(CPPPATH = [
14    '#/src/mapi',
15    '#/src/glsl',
16    '#/src/mesa',
17])
18
19env.Append(CPPDEFINES = [
20    'FEATURE_GL=1',
21])
22
23if env['platform'] == 'windows':
24    env.Append(CPPDEFINES = [
25        '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
26        'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
27    ])
28    if not env['gles']:
29        # prevent _glapi_* from being declared __declspec(dllimport)
30        env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
31else:
32    env.Append(CPPDEFINES = [
33        'IN_DRI_DRIVER', # enable the remap table (for DRI drivers)
34    ])
35
36#
37# Source files
38#
39
40main_sources = [
41    'main/api_arrayelt.c',
42    'main/api_exec.c',
43    'main/api_loopback.c',
44    'main/api_validate.c',
45    'main/accum.c',
46    'main/arbprogram.c',
47    'main/atifragshader.c',
48    'main/attrib.c',
49    'main/arrayobj.c',
50    'main/blend.c',
51    'main/bufferobj.c',
52    'main/buffers.c',
53    'main/clear.c',
54    'main/clip.c',
55    'main/colortab.c',
56    'main/condrender.c',
57    'main/context.c',
58    'main/convolve.c',
59    'main/cpuinfo.c',
60    'main/debug.c',
61    'main/depth.c',
62    'main/dlist.c',
63    'main/dlopen.c',
64    'main/drawpix.c',
65    'main/drawtex.c',
66    'main/enable.c',
67    'main/enums.c',
68    'main/errors.c',
69    'main/eval.c',
70    'main/execmem.c',
71    'main/extensions.c',
72    'main/fbobject.c',
73    'main/feedback.c',
74    'main/ff_fragment_shader.cpp',
75    'main/ffvertex_prog.c',
76    'main/fog.c',
77    'main/formats.c',
78    'main/format_pack.c',
79    'main/format_unpack.c',
80    'main/framebuffer.c',
81    'main/get.c',
82    'main/getstring.c',
83    'main/glformats.c',
84    'main/hash.c',
85    'main/hint.c',
86    'main/histogram.c',
87    'main/image.c',
88    'main/imports.c',
89    'main/light.c',
90    'main/lines.c',
91    'main/matrix.c',
92    'main/mipmap.c',
93    'main/mm.c',
94    'main/multisample.c',
95    'main/nvprogram.c',
96    'main/pack.c',
97    'main/pbo.c',
98    'main/pixel.c',
99    'main/pixelstore.c',
100    'main/pixeltransfer.c',
101    'main/points.c',
102    'main/polygon.c',
103    'main/querymatrix.c',
104    'main/queryobj.c',
105    'main/rastpos.c',
106    'main/readpix.c',
107    'main/remap.c',
108    'main/renderbuffer.c',
109    'main/samplerobj.c',
110    'main/scissor.c',
111    'main/shaderapi.c',
112    'main/shaderobj.c',
113    'main/shader_query.cpp',
114    'main/shared.c',
115    'main/state.c',
116    'main/stencil.c',
117    'main/syncobj.c',
118    'main/texcompress.c',
119    'main/texcompress_rgtc.c',
120    'main/texcompress_s3tc.c',
121    'main/texcompress_fxt1.c',
122    'main/texcompress_etc.c',
123    'main/texenv.c',
124    'main/texformat.c',
125    'main/texgen.c',
126    'main/texgetimage.c',
127    'main/teximage.c',
128    'main/texobj.c',
129    'main/texpal.c',
130    'main/texparam.c',
131    'main/texstate.c',
132    'main/texstorage.c',
133    'main/texstore.c',
134    'main/texturebarrier.c',
135    'main/transformfeedback.c',
136    'main/uniform_query.cpp',
137    'main/uniforms.c',
138    'main/varray.c',
139    'main/version.c',
140    'main/viewport.c',
141    'main/vtxfmt.c',
142]
143
144math_sources = [
145    'math/m_debug_clip.c',
146    'math/m_debug_norm.c',
147    'math/m_debug_xform.c',
148    'math/m_eval.c',
149    'math/m_matrix.c',
150    'math/m_translate.c',
151    'math/m_vector.c',
152    'math/m_xform.c',
153]
154
155swrast_sources = [
156    'swrast/s_aaline.c',
157    'swrast/s_aatriangle.c',
158    'swrast/s_alpha.c',
159    'swrast/s_atifragshader.c',
160    'swrast/s_bitmap.c',
161    'swrast/s_blend.c',
162    'swrast/s_blit.c',
163    'swrast/s_clear.c',
164    'swrast/s_copypix.c',
165    'swrast/s_context.c',
166    'swrast/s_depth.c',
167    'swrast/s_drawpix.c',
168    'swrast/s_feedback.c',
169    'swrast/s_fog.c',
170    'swrast/s_fragprog.c',
171    'swrast/s_lines.c',
172    'swrast/s_logic.c',
173    'swrast/s_masking.c',
174    'swrast/s_points.c',
175    'swrast/s_renderbuffer.c',
176    'swrast/s_span.c',
177    'swrast/s_stencil.c',
178    'swrast/s_texcombine.c',
179    'swrast/s_texfetch.c',
180    'swrast/s_texfilter.c',
181    'swrast/s_texrender.c',
182    'swrast/s_texture.c',
183    'swrast/s_triangle.c',
184    'swrast/s_zoom.c',
185]
186
187swrast_setup_sources = [
188    'swrast_setup/ss_context.c',
189    'swrast_setup/ss_triangle.c',
190]
191
192tnl_sources = [
193    'tnl/t_context.c',
194    'tnl/t_pipeline.c',
195    'tnl/t_draw.c',
196    'tnl/t_rasterpos.c',
197    'tnl/t_vb_program.c',
198    'tnl/t_vb_render.c',
199    'tnl/t_vb_texgen.c',
200    'tnl/t_vb_texmat.c',
201    'tnl/t_vb_vertex.c',
202    'tnl/t_vb_fog.c',
203    'tnl/t_vb_light.c',
204    'tnl/t_vb_normals.c',
205    'tnl/t_vb_points.c',
206    'tnl/t_vp_build.c',
207    'tnl/t_vertex.c',
208    'tnl/t_vertex_sse.c',
209    'tnl/t_vertex_generic.c',
210]
211
212vbo_sources = [
213    'vbo/vbo_context.c',
214    'vbo/vbo_exec.c',
215    'vbo/vbo_exec_api.c',
216    'vbo/vbo_exec_array.c',
217    'vbo/vbo_exec_draw.c',
218    'vbo/vbo_exec_eval.c',
219    'vbo/vbo_noop.c',
220    'vbo/vbo_primitive_restart.c',
221    'vbo/vbo_rebase.c',
222    'vbo/vbo_split.c',
223    'vbo/vbo_split_copy.c',
224    'vbo/vbo_split_inplace.c',
225    'vbo/vbo_save.c',
226    'vbo/vbo_save_api.c',
227    'vbo/vbo_save_draw.c',
228    'vbo/vbo_save_loopback.c',
229]
230
231statetracker_sources = [
232    'state_tracker/st_atom.c',
233    'state_tracker/st_atom_array.c',
234    'state_tracker/st_atom_blend.c',
235    'state_tracker/st_atom_clip.c',
236    'state_tracker/st_atom_constbuf.c',
237    'state_tracker/st_atom_depth.c',
238    'state_tracker/st_atom_framebuffer.c',
239    'state_tracker/st_atom_msaa.c',
240    'state_tracker/st_atom_pixeltransfer.c',
241    'state_tracker/st_atom_sampler.c',
242    'state_tracker/st_atom_scissor.c',
243    'state_tracker/st_atom_shader.c',
244    'state_tracker/st_atom_rasterizer.c',
245    'state_tracker/st_atom_stipple.c',
246    'state_tracker/st_atom_texture.c',
247    'state_tracker/st_atom_viewport.c',
248    'state_tracker/st_cb_bitmap.c',
249    'state_tracker/st_cb_blit.c',
250    'state_tracker/st_cb_bufferobjects.c',
251    'state_tracker/st_cb_clear.c',
252    'state_tracker/st_cb_condrender.c',
253    'state_tracker/st_cb_flush.c',
254    'state_tracker/st_cb_drawpixels.c',
255    'state_tracker/st_cb_drawtex.c',
256    'state_tracker/st_cb_eglimage.c',
257    'state_tracker/st_cb_fbo.c',
258    'state_tracker/st_cb_feedback.c',
259    'state_tracker/st_cb_program.c',
260    'state_tracker/st_cb_queryobj.c',
261    'state_tracker/st_cb_rasterpos.c',
262    'state_tracker/st_cb_readpixels.c',
263    'state_tracker/st_cb_syncobj.c',
264    'state_tracker/st_cb_strings.c',
265    'state_tracker/st_cb_texture.c',
266    'state_tracker/st_cb_texturebarrier.c',
267    'state_tracker/st_cb_viewport.c',
268    'state_tracker/st_cb_xformfb.c',
269    'state_tracker/st_context.c',
270    'state_tracker/st_debug.c',
271    'state_tracker/st_draw.c',
272    'state_tracker/st_draw_feedback.c',
273    'state_tracker/st_extensions.c',
274    'state_tracker/st_format.c',
275    'state_tracker/st_glsl_to_tgsi.cpp',
276    'state_tracker/st_gen_mipmap.c',
277    'state_tracker/st_manager.c',
278    'state_tracker/st_mesa_to_tgsi.c',
279    'state_tracker/st_program.c',
280    'state_tracker/st_texture.c',
281]
282
283env.Append(YACCFLAGS = '-d')
284program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
285program_parse = env.CFile('program/program_parse.tab.c',
286                          'program/program_parse.y')
287
288# Make program/program_parse.tab.h reacheable from the include path
289env.Append(CPPPATH = [Dir('.').abspath])
290
291program_sources = [
292    'program/arbprogparse.c',
293    'program/hash_table.c',
294    'program/ir_to_mesa.cpp',
295    'program/nvfragparse.c',
296    'program/nvvertparse.c',
297    'program/program.c',
298    'program/program_parse_extra.c',
299    'program/prog_cache.c',
300    'program/prog_execute.c',
301    'program/prog_instruction.c',
302    'program/prog_noise.c',
303    'program/prog_optimize.c',
304    'program/prog_opt_constant_fold.c',
305    'program/prog_parameter.c',
306    'program/prog_parameter_layout.c',
307    'program/prog_print.c',
308    'program/prog_statevars.c',
309    'program/programopt.c',
310    'program/sampler.cpp',
311    'program/symbol_table.c',
312    'program/string_to_uint_map.cpp',
313    program_lex,
314    program_parse[0],
315]
316
317common_driver_sources =	[
318    'drivers/common/driverfuncs.c',
319    'drivers/common/meta.c',
320]
321
322mesa_sources = (
323    main_sources +
324    math_sources +
325    program_sources +
326    vbo_sources +
327    tnl_sources +
328    swrast_sources +
329    swrast_setup_sources +
330    common_driver_sources +
331    statetracker_sources
332)
333
334GLAPI = '#src/mapi/glapi/'
335
336if env['gles']:
337
338    env.Append(CPPDEFINES = ['FEATURE_ES1=1', 'FEATURE_ES2=1'])
339
340    # generate GLES sources
341    gles_sources = ['main/es1_conversion.c',]
342    gles_sources += env.CodeGenerate(
343        target = 'main/api_exec_es1.c',
344        script = 'main/es_generator.py',
345        source = 'main/APIspec.xml',
346        command = python_cmd + ' $SCRIPT -S $SOURCE -V GLES1.1 > $TARGET'
347    )
348    gles_sources += env.CodeGenerate(
349        target = 'main/api_exec_es2.c',
350        script = 'main/es_generator.py',
351        source = 'main/APIspec.xml',
352        command = python_cmd + ' $SCRIPT -S $SOURCE -V GLES2.0 > $TARGET'
353    )
354
355    # generate GLES headers
356    gles_headers = []
357    gles_headers += env.CodeGenerate(
358        target = 'main/api_exec_es1_dispatch.h',
359        script = GLAPI + 'gen/gl_table.py',
360        source = GLAPI + 'gen/gl_and_es_API.xml',
361        command = python_cmd + ' $SCRIPT -c es1 -m remap_table -f $SOURCE > $TARGET',
362    )
363    gles_headers += env.CodeGenerate(
364        target = 'main/api_exec_es1_remap_helper.h',
365        script = GLAPI + 'gen/remap_helper.py',
366        source = GLAPI + 'gen/gl_and_es_API.xml',
367        command = python_cmd + ' $SCRIPT -c es1 -f $SOURCE > $TARGET',
368    )
369    gles_headers += env.CodeGenerate(
370        target = 'main/api_exec_es2_dispatch.h',
371        script = GLAPI + 'gen/gl_table.py',
372        source = GLAPI + 'gen/gl_and_es_API.xml',
373        command = python_cmd + ' $SCRIPT -c es2 -m remap_table -f $SOURCE > $TARGET',
374    )
375    gles_headers += env.CodeGenerate(
376        target = 'main/api_exec_es2_remap_helper.h',
377        script = GLAPI + 'gen/remap_helper.py',
378        source = GLAPI + 'gen/gl_and_es_API.xml',
379        command = python_cmd + ' $SCRIPT -c es2 -f $SOURCE > $TARGET',
380    )
381
382    env.Depends(gles_sources, gles_headers)
383
384    # gles_sources #include gles_headers with full path
385    env.Append(CPPPATH = [gles_headers[0].dir.up().up()])
386
387    mesa_sources += gles_sources
388
389#
390# Assembly sources
391#
392if env['gcc'] and env['platform'] not in ('darwin', 'windows'):
393    if env['machine'] == 'x86':
394        env.Append(CPPDEFINES = [
395            'USE_X86_ASM',
396            'USE_MMX_ASM',
397            'USE_3DNOW_ASM',
398            'USE_SSE_ASM',
399        ])
400        mesa_sources += [
401            'x86/common_x86.c',
402            'x86/x86_xform.c',
403            'x86/3dnow.c',
404            'x86/sse.c',
405            'x86/common_x86_asm.S',
406            'x86/x86_xform2.S',
407            'x86/x86_xform3.S',
408            'x86/x86_xform4.S',
409            'x86/x86_cliptest.S',
410            'x86/mmx_blend.S',
411            'x86/3dnow_xform1.S',
412            'x86/3dnow_xform2.S',
413            'x86/3dnow_xform3.S',
414            'x86/3dnow_xform4.S',
415            'x86/3dnow_normal.S',
416            'x86/sse_xform1.S',
417            'x86/sse_xform2.S',
418            'x86/sse_xform3.S',
419            'x86/sse_xform4.S',
420            'x86/sse_normal.S',
421            'x86/read_rgba_span_x86.S',
422        ]
423    elif env['machine'] == 'x86_64':
424        env.Append(CPPDEFINES = [
425            'USE_X86_64_ASM',
426        ])
427        mesa_sources += [
428            'x86-64/x86-64.c',
429            'x86-64/xform4.S',
430        ]
431    elif env['machine'] == 'sparc':
432        mesa_sources += [
433            'sparc/sparc.c',
434            'sparc/sparc_clip.S',
435            'sparc/norm.S',
436            'sparc/xform.S',
437        ]
438    else:
439        pass
440
441    # Generate matypes.h
442    if env['machine'] in ('x86', 'x86_64'):
443        # See http://www.scons.org/wiki/UsingCodeGenerators
444        gen_matypes = env.Program(
445            target = 'gen_matypes',
446            source = 'x86/gen_matypes.c',
447        )
448        matypes = env.Command(
449            'matypes.h',
450            gen_matypes,
451            gen_matypes[0].abspath + ' > $TARGET',
452        )
453        # Add the dir containing the generated header (somewhere inside  the
454        # build dir) to the include path
455        env.Append(CPPPATH = [matypes[0].dir])
456
457
458# The enums.c file is generated from the GL/ES API.xml file
459env.CodeGenerate(
460    target = 'main/enums.c',
461    script = GLAPI + 'gen/gl_enums.py',
462    source = GLAPI + 'gen/gl_and_es_API.xml',
463    command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET'
464    )
465
466# We also depend on the auto-generated GL API headers
467env.Depends(mesa_sources, glapi_headers)
468
469
470def write_git_sha1_h_file(filename):
471    """Mesa looks for a git_sha1.h file at compile time in order to display
472    the current git hash id in the GL_VERSION string.  This function tries
473    to retrieve the git hashid and write the header file.  An empty file
474    will be created if anything goes wrong."""
475
476    args = [ 'git', 'log', '-n', '1', '--oneline' ]
477    try:
478        (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
479    except:
480        # git log command didn't work
481        if not os.path.exists(filename):
482            # create an empty file if none already exists
483            f = open(filename, "w")
484            f.close()
485        return
486
487    commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
488    tempfile = "git_sha1.h.tmp"
489    f = open(tempfile, "w")
490    f.write(commit)
491    f.close()
492    if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
493        # The filename does not exist or it's different from the new file,
494        # so replace old file with new.
495        if os.path.exists(filename):
496            os.remove(filename)
497        os.rename(tempfile, filename)
498    return
499
500
501# Create the git_sha1.h header file
502write_git_sha1_h_file("main/git_sha1.h")
503# and update CPPPATH so the git_sha1.h header can be found
504env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
505
506
507#
508# Libraries
509#
510
511mesa = env.ConvenienceLibrary(
512    target = 'mesa',
513    source = mesa_sources,
514)
515
516env.Alias('mesa', mesa)
517
518Export('mesa')
519
520SConscript('drivers/SConscript')
521