1 #######################################################################
9 from sys import executable as python_cmd
13 env.Append(CPPPATH = [
17 Dir('../mapi'), # src/mapi build path
18 Dir('.'), # src/mesa build path
21 if env['platform'] == 'windows':
22 env.Append(CPPDEFINES = [
23 '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
24 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
27 # prevent _glapi_* from being declared __declspec(dllimport)
28 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
30 env.Append(CPPDEFINES = [
34 # parse Makefile.sources
35 source_lists = env.ParseSourceList('Makefile.sources')
37 env.Append(YACCFLAGS = '-d -p "_mesa_program_"')
38 program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
39 program_parse = env.CFile('program/program_parse.tab.c',
40 'program/program_parse.y')
41 program_sources = source_lists['PROGRAM_FILES'] + [
47 source_lists['MESA_FILES'] +
49 source_lists['STATETRACKER_FILES']
52 GLAPI = '#src/mapi/glapi/'
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'
64 if (env['gcc'] or env['clang']) and \
65 env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
66 if env['machine'] == 'x86':
67 env.Append(CPPDEFINES = [
73 mesa_sources += source_lists['X86_FILES']
74 elif env['machine'] == 'x86_64':
75 env.Append(CPPDEFINES = [
78 mesa_sources += source_lists['X86_64_FILES']
79 elif env['machine'] == 'sparc':
80 mesa_sources += source_lists['SPARC_FILES']
85 if env['machine'] in ('x86', 'x86_64'):
86 # See http://www.scons.org/wiki/UsingCodeGenerators
87 gen_matypes = env.Program(
88 target = 'gen_matypes',
89 source = 'x86/gen_matypes.c',
91 matypes = env.Command(
94 gen_matypes[0].abspath + ' > $TARGET',
96 # Add the dir containing the generated header (somewhere inside the
97 # build dir) to the include path
98 env.Append(CPPPATH = [matypes[0].dir])
101 def write_git_sha1_h_file(filename):
102 """Mesa looks for a git_sha1.h file at compile time in order to display
103 the current git hash id in the GL_VERSION string. This function tries
104 to retrieve the git hashid and write the header file. An empty file
105 will be created if anything goes wrong."""
107 args = [ 'git', 'log', '-n', '1', '--oneline' ]
109 (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
111 # git log command didn't work
112 if not os.path.exists(filename):
113 # create an empty file if none already exists
114 f = open(filename, "w")
118 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
119 tempfile = "git_sha1.h.tmp"
120 f = open(tempfile, "w")
123 if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
124 # The filename does not exist or it's different from the new file,
125 # so replace old file with new.
126 if os.path.exists(filename):
128 os.rename(tempfile, filename)
132 # Create the git_sha1.h header file
133 write_git_sha1_h_file("main/git_sha1.h")
134 # and update CPPPATH so the git_sha1.h header can be found
135 env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
142 mesa = env.ConvenienceLibrary(
144 source = mesa_sources,
147 env.Alias('mesa', mesa)
151 SConscript('drivers/SConscript')