1 ####################################################################### 2 # SConscript for Mesa 3 4 5 Import('*') 6 import filecmp 7 import os 8 import subprocess 9 from sys import executable as python_cmd 10 11 env = env.Clone() 12 13 env.Append(CPPPATH = [ 14 '#/src/mapi', 15 '#/src/glsl', 16 '#/src/mesa', 17 ]) 18 19 env.Append(CPPDEFINES = [ 20 'FEATURE_GL=1', 21 ]) 22 23 if 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']) 31 else: 32 env.Append(CPPDEFINES = [ 33 'IN_DRI_DRIVER', # enable the remap table (for DRI drivers) 34 ('HAVE_DLOPEN', '1'), 35 ]) 36 37 # 38 # Source files 39 # 40 41 main_sources = [ 42 'main/api_arrayelt.c', 43 'main/api_exec.c', 44 'main/api_loopback.c', 45 'main/api_validate.c', 46 'main/accum.c', 47 'main/arbprogram.c', 48 'main/atifragshader.c', 49 'main/attrib.c', 50 'main/arrayobj.c', 51 'main/blend.c', 52 'main/bufferobj.c', 53 'main/buffers.c', 54 'main/clear.c', 55 'main/clip.c', 56 'main/colortab.c', 57 'main/condrender.c', 58 'main/context.c', 59 'main/convolve.c', 60 'main/cpuinfo.c', 61 'main/debug.c', 62 'main/depth.c', 63 'main/dlist.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_cpal.c', 120 'main/texcompress_rgtc.c', 121 'main/texcompress_s3tc.c', 122 'main/texcompress_fxt1.c', 123 'main/texcompress_etc.c', 124 'main/texenv.c', 125 'main/texformat.c', 126 'main/texgen.c', 127 'main/texgetimage.c', 128 'main/teximage.c', 129 'main/texobj.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 144 math_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 155 swrast_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 187 swrast_setup_sources = [ 188 'swrast_setup/ss_context.c', 189 'swrast_setup/ss_triangle.c', 190 ] 191 192 tnl_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 212 vbo_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 231 statetracker_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 283 env.Append(YACCFLAGS = '-d -p "_mesa_program_"') 284 program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l') 285 program_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 289 env.Append(CPPPATH = [Dir('.').abspath]) 290 291 program_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 317 common_driver_sources = [ 318 'drivers/common/driverfuncs.c', 319 'drivers/common/meta.c', 320 ] 321 322 mesa_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 334 GLAPI = '#src/mapi/glapi/' 335 336 if 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 349 # generate GLES headers 350 gles_headers = [] 351 gles_headers += env.CodeGenerate( 352 target = 'main/api_exec_es1_dispatch.h', 353 script = GLAPI + 'gen/gl_table.py', 354 source = GLAPI + 'gen/gl_and_es_API.xml', 355 command = python_cmd + ' $SCRIPT -c es1 -m remap_table -f $SOURCE > $TARGET', 356 ) 357 gles_headers += env.CodeGenerate( 358 target = 'main/api_exec_es1_remap_helper.h', 359 script = GLAPI + 'gen/remap_helper.py', 360 source = GLAPI + 'gen/gl_and_es_API.xml', 361 command = python_cmd + ' $SCRIPT -c es1 -f $SOURCE > $TARGET', 362 ) 363 364 env.Depends(gles_sources, gles_headers) 365 366 # gles_sources #include gles_headers with full path 367 env.Append(CPPPATH = [gles_headers[0].dir.up().up()]) 368 369 mesa_sources += gles_sources 370 371 # 372 # Assembly sources 373 # 374 if env['gcc'] and env['platform'] not in ('darwin', 'windows'): 375 if env['machine'] == 'x86': 376 env.Append(CPPDEFINES = [ 377 'USE_X86_ASM', 378 'USE_MMX_ASM', 379 'USE_3DNOW_ASM', 380 'USE_SSE_ASM', 381 ]) 382 mesa_sources += [ 383 'x86/common_x86.c', 384 'x86/x86_xform.c', 385 'x86/3dnow.c', 386 'x86/sse.c', 387 'x86/common_x86_asm.S', 388 'x86/x86_xform2.S', 389 'x86/x86_xform3.S', 390 'x86/x86_xform4.S', 391 'x86/x86_cliptest.S', 392 'x86/mmx_blend.S', 393 'x86/3dnow_xform1.S', 394 'x86/3dnow_xform2.S', 395 'x86/3dnow_xform3.S', 396 'x86/3dnow_xform4.S', 397 'x86/3dnow_normal.S', 398 'x86/sse_xform1.S', 399 'x86/sse_xform2.S', 400 'x86/sse_xform3.S', 401 'x86/sse_xform4.S', 402 'x86/sse_normal.S', 403 'x86/read_rgba_span_x86.S', 404 ] 405 elif env['machine'] == 'x86_64': 406 env.Append(CPPDEFINES = [ 407 'USE_X86_64_ASM', 408 ]) 409 mesa_sources += [ 410 'x86-64/x86-64.c', 411 'x86-64/xform4.S', 412 ] 413 elif env['machine'] == 'sparc': 414 mesa_sources += [ 415 'sparc/sparc.c', 416 'sparc/sparc_clip.S', 417 'sparc/norm.S', 418 'sparc/xform.S', 419 ] 420 else: 421 pass 422 423 # Generate matypes.h 424 if env['machine'] in ('x86', 'x86_64'): 425 # See http://www.scons.org/wiki/UsingCodeGenerators 426 gen_matypes = env.Program( 427 target = 'gen_matypes', 428 source = 'x86/gen_matypes.c', 429 ) 430 matypes = env.Command( 431 'matypes.h', 432 gen_matypes, 433 gen_matypes[0].abspath + ' > $TARGET', 434 ) 435 # Add the dir containing the generated header (somewhere inside the 436 # build dir) to the include path 437 env.Append(CPPPATH = [matypes[0].dir]) 438 439 440 # The enums.c file is generated from the GL/ES API.xml file 441 env.CodeGenerate( 442 target = 'main/enums.c', 443 script = GLAPI + 'gen/gl_enums.py', 444 source = GLAPI + 'gen/gl_and_es_API.xml', 445 command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET' 446 ) 447 448 # We also depend on the auto-generated GL API headers 449 env.Depends(mesa_sources, glapi_headers) 450 451 452 def write_git_sha1_h_file(filename): 453 """Mesa looks for a git_sha1.h file at compile time in order to display 454 the current git hash id in the GL_VERSION string. This function tries 455 to retrieve the git hashid and write the header file. An empty file 456 will be created if anything goes wrong.""" 457 458 args = [ 'git', 'log', '-n', '1', '--oneline' ] 459 try: 460 (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate() 461 except: 462 # git log command didn't work 463 if not os.path.exists(filename): 464 # create an empty file if none already exists 465 f = open(filename, "w") 466 f.close() 467 return 468 469 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7] 470 tempfile = "git_sha1.h.tmp" 471 f = open(tempfile, "w") 472 f.write(commit) 473 f.close() 474 if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename): 475 # The filename does not exist or it's different from the new file, 476 # so replace old file with new. 477 if os.path.exists(filename): 478 os.remove(filename) 479 os.rename(tempfile, filename) 480 return 481 482 483 # Create the git_sha1.h header file 484 write_git_sha1_h_file("main/git_sha1.h") 485 # and update CPPPATH so the git_sha1.h header can be found 486 env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"]) 487 488 489 # 490 # Libraries 491 # 492 493 mesa = env.ConvenienceLibrary( 494 target = 'mesa', 495 source = mesa_sources, 496 ) 497 498 env.Alias('mesa', mesa) 499 500 Export('mesa') 501 502 SConscript('drivers/SConscript') 503