1 #######################################################################
9 from sys import executable as python_cmd
13 env.Append(CPPPATH = [
18 Dir('../mapi'), # src/mapi build path
19 Dir('.'), # src/mesa build path
22 if env['platform'] == 'windows':
23 env.Append(CPPDEFINES = [
24 '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
25 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
28 # prevent _glapi_* from being declared __declspec(dllimport)
29 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
31 env.Append(CPPDEFINES = [
35 # parse Makefile.sources
36 source_lists = env.ParseSourceList('Makefile.sources')
38 env.Append(YACCFLAGS = '-d -p "_mesa_program_"')
39 program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
40 program_parse = env.CFile('program/program_parse.tab.c',
41 'program/program_parse.y')
42 program_sources = source_lists['PROGRAM_FILES'] + [
48 source_lists['MESA_FILES'] +
50 source_lists['STATETRACKER_FILES']
53 GLAPI = '#src/mapi/glapi/'
55 get_hash_header = env.CodeGenerate(
56 target = 'main/get_hash.h',
57 script = 'main/get_hash_generator.py',
58 source = GLAPI + 'gen/gl_and_es_API.xml',
59 command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
62 format_info = env.CodeGenerate(
63 target = 'main/format_info.c',
64 script = 'main/format_info.py',
65 source = 'main/formats.csv',
66 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
72 if (env['gcc'] or env['clang']) and \
73 env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
74 if env['machine'] == 'x86':
75 env.Append(CPPDEFINES = [
81 mesa_sources += source_lists['X86_FILES']
82 elif env['machine'] == 'x86_64':
83 env.Append(CPPDEFINES = [
86 mesa_sources += source_lists['X86_64_FILES']
87 elif env['machine'] == 'sparc':
88 mesa_sources += source_lists['SPARC_FILES']
93 if env['machine'] in ('x86', 'x86_64'):
94 # See http://www.scons.org/wiki/UsingCodeGenerators
95 gen_matypes = env.Program(
96 target = 'gen_matypes',
97 source = 'x86/gen_matypes.c',
99 matypes = env.Command(
102 gen_matypes[0].abspath + ' > $TARGET',
104 # Add the dir containing the generated header (somewhere inside the
105 # build dir) to the include path
106 env.Append(CPPPATH = [matypes[0].dir])
109 def write_git_sha1_h_file(filename):
110 """Mesa looks for a git_sha1.h file at compile time in order to display
111 the current git hash id in the GL_VERSION string. This function tries
112 to retrieve the git hashid and write the header file. An empty file
113 will be created if anything goes wrong."""
115 args = [ 'git', 'log', '-n', '1', '--oneline' ]
117 (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
119 # git log command didn't work
120 if not os.path.exists(filename):
121 # create an empty file if none already exists
122 f = open(filename, "w")
126 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
127 tempfile = "git_sha1.h.tmp"
128 f = open(tempfile, "w")
131 if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
132 # The filename does not exist or it's different from the new file,
133 # so replace old file with new.
134 if os.path.exists(filename):
136 os.rename(tempfile, filename)
140 # Create the git_sha1.h header file
141 write_git_sha1_h_file("main/git_sha1.h")
142 # and update CPPPATH so the git_sha1.h header can be found
143 env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
150 mesa = env.ConvenienceLibrary(
152 source = mesa_sources,
155 env.Alias('mesa', mesa)
159 SConscript('drivers/SConscript')