Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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.MSVC2013Compat()
  14.  
  15. env.Append(CPPPATH = [
  16.     '#/src',
  17.     '#/src/mapi',
  18.     '#/src/glsl',
  19.     '#/src/mesa',
  20.     '#/src/gallium/include',
  21.     '#/src/gallium/auxiliary',
  22.     Dir('../mapi'), # src/mapi build path
  23.     Dir('.'), # src/mesa build path
  24. ])
  25.  
  26. if env['platform'] == 'windows':
  27.     env.Append(CPPDEFINES = [
  28.         '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
  29.         'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
  30.     ])
  31.     if not env['gles']:
  32.         # prevent _glapi_* from being declared __declspec(dllimport)
  33.         env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
  34. else:
  35.     env.Append(CPPDEFINES = [
  36.         ('HAVE_DLOPEN', '1'),
  37.     ])
  38.  
  39. # parse Makefile.sources
  40. source_lists = env.ParseSourceList('Makefile.sources')
  41.  
  42. env.Append(YACCFLAGS = ['-d', '-p', '_mesa_program_'])
  43. env.CFile('program/lex.yy.c', 'program/program_lexer.l')
  44. env.CFile('program/program_parse.tab.c', 'program/program_parse.y')
  45.  
  46. mesa_sources = (
  47.     source_lists['MESA_FILES'] +
  48.     source_lists['PROGRAM_FILES'] +
  49.     source_lists['STATETRACKER_FILES']
  50. )
  51.  
  52. GLAPI = '#src/mapi/glapi/'
  53.  
  54. get_hash_header = env.CodeGenerate(
  55.       target = 'main/get_hash.h',
  56.       script = 'main/get_hash_generator.py',
  57.       source = GLAPI + 'gen/gl_and_es_API.xml',
  58.       command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
  59. )
  60.  
  61. format_info = env.CodeGenerate(
  62.       target = 'main/format_info.h',
  63.       script = 'main/format_info.py',
  64.       source = 'main/formats.csv',
  65.       command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
  66. )
  67.  
  68. format_pack = env.CodeGenerate(
  69.       target = 'main/format_pack.c',
  70.       script = 'main/format_pack.py',
  71.       source = 'main/formats.csv',
  72.       command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
  73. )
  74.  
  75. format_unpack = env.CodeGenerate(
  76.       target = 'main/format_unpack.c',
  77.       script = 'main/format_unpack.py',
  78.       source = 'main/formats.csv',
  79.       command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
  80. )
  81.  
  82. #
  83. # Assembly sources
  84. #
  85. if (env['gcc'] or env['clang']) and \
  86.    env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
  87.     if env['machine'] == 'x86':
  88.         env.Append(CPPDEFINES = [
  89.             'USE_X86_ASM',
  90.             'USE_MMX_ASM',
  91.             'USE_3DNOW_ASM',
  92.             'USE_SSE_ASM',
  93.         ])
  94.         mesa_sources += source_lists['X86_FILES']
  95.     elif env['machine'] == 'x86_64':
  96.         env.Append(CPPDEFINES = [
  97.             'USE_X86_64_ASM',
  98.         ])
  99.         mesa_sources += source_lists['X86_64_FILES']
  100.     elif env['machine'] == 'sparc':
  101.         mesa_sources += source_lists['SPARC_FILES']
  102.     else:
  103.         pass
  104.  
  105.     # Generate matypes.h
  106.     if env['machine'] in ('x86', 'x86_64'):
  107.         # See http://www.scons.org/wiki/UsingCodeGenerators
  108.         gen_matypes = env.Program(
  109.             target = 'gen_matypes',
  110.             source = 'x86/gen_matypes.c',
  111.         )
  112.         matypes = env.Command(
  113.             'matypes.h',
  114.             gen_matypes,
  115.             gen_matypes[0].abspath + ' > $TARGET',
  116.         )
  117.         # Add the dir containing the generated header (somewhere inside  the
  118.         # build dir) to the include path
  119.         env.Append(CPPPATH = [matypes[0].dir])
  120.  
  121.  
  122. def write_git_sha1_h_file(filename):
  123.     """Mesa looks for a git_sha1.h file at compile time in order to display
  124.     the current git hash id in the GL_VERSION string.  This function tries
  125.     to retrieve the git hashid and write the header file.  An empty file
  126.     will be created if anything goes wrong."""
  127.  
  128.     args = [ 'git', 'log', '-n', '1', '--oneline' ]
  129.     try:
  130.         (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
  131.     except:
  132.         # git log command didn't work
  133.         if not os.path.exists(filename):
  134.             dirname = os.path.dirname(filename)
  135.             if not os.path.exists(dirname):
  136.                 os.makedirs(dirname)
  137.             # create an empty file if none already exists
  138.             f = open(filename, "w")
  139.             f.close()
  140.         return
  141.  
  142.     commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
  143.     tempfile = "git_sha1.h.tmp"
  144.     f = open(tempfile, "w")
  145.     f.write(commit)
  146.     f.close()
  147.     if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
  148.         # The filename does not exist or it's different from the new file,
  149.         # so replace old file with new.
  150.         if os.path.exists(filename):
  151.             os.remove(filename)
  152.         os.rename(tempfile, filename)
  153.     return
  154.  
  155.  
  156. # Create the git_sha1.h header file
  157. write_git_sha1_h_file("main/git_sha1.h")
  158. # and update CPPPATH so the git_sha1.h header can be found
  159. env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
  160.  
  161.  
  162. #
  163. # Libraries
  164. #
  165.  
  166. mesa = env.ConvenienceLibrary(
  167.     target = 'mesa',
  168.     source = mesa_sources,
  169. )
  170.  
  171. env.Alias('mesa', mesa)
  172.  
  173. Export('mesa')
  174.  
  175. SConscript('drivers/SConscript')
  176.