blob: d6ff0835445dd5c51cd9f9b87f48370a96b3785d [file] [log] [blame]
José Fonsecac42e6252008-01-31 13:14:35 +09001#######################################################################
José Fonseca33ceb672008-02-18 10:52:44 +00002# SConscript for Mesa
José Fonsecac42e6252008-01-31 13:14:35 +09003
4
5Import('*')
Brian Paulf83af362011-09-28 08:15:22 -06006import filecmp
7import os
8import subprocess
Brian Pauldff36e92012-05-30 10:08:11 -06009from sys import executable as python_cmd
José Fonsecac42e6252008-01-31 13:14:35 +090010
José Fonseca601498a2010-11-01 13:30:22 +000011env = env.Clone()
José Fonsecab9da3792008-02-19 15:07:53 +090012
Jose Fonseca00faf9f2015-03-04 14:23:52 +000013env.MSVC2013Compat()
14
José Fonseca601498a2010-11-01 13:30:22 +000015env.Append(CPPPATH = [
Kenneth Graunke1e0da622014-02-24 23:39:14 -080016 '#/src',
José Fonseca601498a2010-11-01 13:30:22 +000017 '#/src/mapi',
18 '#/src/glsl',
19 '#/src/mesa',
Eric Anholte8c5cbf2015-02-11 14:18:50 -080020 '#/src/gallium/include',
21 '#/src/gallium/auxiliary',
José Fonseca71c87e42013-01-21 17:47:51 +000022 Dir('../mapi'), # src/mapi build path
23 Dir('.'), # src/mesa build path
José Fonseca601498a2010-11-01 13:30:22 +000024])
José Fonseca2105b612009-01-06 16:20:12 +000025
José Fonseca601498a2010-11-01 13:30:22 +000026if 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
José Fonseca601498a2010-11-01 13:30:22 +000030 ])
Chia-I Wubb770af2011-01-14 17:50:29 +080031 if not env['gles']:
32 # prevent _glapi_* from being declared __declspec(dllimport)
33 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
Chia-I Wubb045d32010-11-20 17:47:11 -080034else:
35 env.Append(CPPDEFINES = [
Tapani Pälli91214602012-08-28 14:01:51 +030036 ('HAVE_DLOPEN', '1'),
Chia-I Wubb045d32010-11-20 17:47:11 -080037 ])
José Fonseca5c9c6b02008-06-04 23:56:57 +090038
Jason Ekstranddcc29c12014-07-23 17:20:12 -070039# parse Makefile.sources
40source_lists = env.ParseSourceList('Makefile.sources')
José Fonseca601498a2010-11-01 13:30:22 +000041
Brian Paule78ebbc2012-09-15 09:01:02 -060042env.Append(YACCFLAGS = '-d -p "_mesa_program_"')
Kenneth Graunke8be58df2011-03-01 15:04:04 -080043program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
44program_parse = env.CFile('program/program_parse.tab.c',
45 'program/program_parse.y')
Jason Ekstranddcc29c12014-07-23 17:20:12 -070046program_sources = source_lists['PROGRAM_FILES'] + [
Kenneth Graunke8be58df2011-03-01 15:04:04 -080047 program_lex,
48 program_parse[0],
José Fonseca601498a2010-11-01 13:30:22 +000049]
50
51mesa_sources = (
Jason Ekstranddcc29c12014-07-23 17:20:12 -070052 source_lists['MESA_FILES'] +
José Fonseca601498a2010-11-01 13:30:22 +000053 program_sources +
Jason Ekstranddcc29c12014-07-23 17:20:12 -070054 source_lists['STATETRACKER_FILES']
José Fonseca601498a2010-11-01 13:30:22 +000055)
56
Brian Pauldff36e92012-05-30 10:08:11 -060057GLAPI = '#src/mapi/glapi/'
58
Imre Deak98f880e2012-09-10 08:46:13 +030059get_hash_header = env.CodeGenerate(
60 target = 'main/get_hash.h',
61 script = 'main/get_hash_generator.py',
62 source = GLAPI + 'gen/gl_and_es_API.xml',
Brian Paul815ca0b2013-04-17 09:49:39 -060063 command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
Imre Deak98f880e2012-09-10 08:46:13 +030064)
65
Jason Ekstrand12610ff2014-06-20 15:52:10 -070066format_info = env.CodeGenerate(
67 target = 'main/format_info.c',
68 script = 'main/format_info.py',
69 source = 'main/formats.csv',
70 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
71)
72
Jason Ekstrande0439f72014-08-21 12:38:05 -070073format_pack = env.CodeGenerate(
74 target = 'main/format_pack.c',
75 script = 'main/format_pack.py',
76 source = 'main/formats.csv',
77 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
78)
79
Jason Ekstrande1fdcdd2014-08-22 09:49:09 -070080format_unpack = env.CodeGenerate(
81 target = 'main/format_unpack.c',
82 script = 'main/format_unpack.py',
83 source = 'main/formats.csv',
84 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
85)
86
José Fonseca601498a2010-11-01 13:30:22 +000087#
88# Assembly sources
89#
José Fonseca16879322013-04-24 22:02:18 +010090if (env['gcc'] or env['clang']) and \
91 env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
José Fonsecaf9156eb2010-11-01 13:56:16 +000092 if env['machine'] == 'x86':
93 env.Append(CPPDEFINES = [
94 'USE_X86_ASM',
95 'USE_MMX_ASM',
96 'USE_3DNOW_ASM',
97 'USE_SSE_ASM',
98 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -070099 mesa_sources += source_lists['X86_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +0000100 elif env['machine'] == 'x86_64':
101 env.Append(CPPDEFINES = [
102 'USE_X86_64_ASM',
103 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -0700104 mesa_sources += source_lists['X86_64_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +0000105 elif env['machine'] == 'sparc':
Jason Ekstranddcc29c12014-07-23 17:20:12 -0700106 mesa_sources += source_lists['SPARC_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +0000107 else:
108 pass
José Fonseca601498a2010-11-01 13:30:22 +0000109
José Fonsecaf9156eb2010-11-01 13:56:16 +0000110 # Generate matypes.h
111 if env['machine'] in ('x86', 'x86_64'):
112 # See http://www.scons.org/wiki/UsingCodeGenerators
113 gen_matypes = env.Program(
114 target = 'gen_matypes',
115 source = 'x86/gen_matypes.c',
116 )
117 matypes = env.Command(
118 'matypes.h',
119 gen_matypes,
120 gen_matypes[0].abspath + ' > $TARGET',
121 )
122 # Add the dir containing the generated header (somewhere inside the
123 # build dir) to the include path
124 env.Append(CPPPATH = [matypes[0].dir])
José Fonseca601498a2010-11-01 13:30:22 +0000125
Brian Paul0c245502011-04-05 14:07:41 -0600126
Brian Paulf83af362011-09-28 08:15:22 -0600127def write_git_sha1_h_file(filename):
128 """Mesa looks for a git_sha1.h file at compile time in order to display
129 the current git hash id in the GL_VERSION string. This function tries
130 to retrieve the git hashid and write the header file. An empty file
131 will be created if anything goes wrong."""
132
133 args = [ 'git', 'log', '-n', '1', '--oneline' ]
134 try:
135 (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
136 except:
137 # git log command didn't work
138 if not os.path.exists(filename):
139 # create an empty file if none already exists
140 f = open(filename, "w")
141 f.close()
142 return
143
Brian Pauld487cc22011-09-28 09:51:36 -0600144 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
Brian Paulf83af362011-09-28 08:15:22 -0600145 tempfile = "git_sha1.h.tmp"
146 f = open(tempfile, "w")
147 f.write(commit)
Vinson Lee622ee082011-04-05 15:32:39 -0700148 f.close()
Brian Paulf83af362011-09-28 08:15:22 -0600149 if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
150 # The filename does not exist or it's different from the new file,
151 # so replace old file with new.
Brian Paule1122872011-09-28 09:04:03 -0600152 if os.path.exists(filename):
153 os.remove(filename)
Brian Paulf83af362011-09-28 08:15:22 -0600154 os.rename(tempfile, filename)
155 return
156
157
158# Create the git_sha1.h header file
159write_git_sha1_h_file("main/git_sha1.h")
Vinson Lee622ee082011-04-05 15:32:39 -0700160# and update CPPPATH so the git_sha1.h header can be found
161env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
Brian Paul0c245502011-04-05 14:07:41 -0600162
163
José Fonseca601498a2010-11-01 13:30:22 +0000164#
165# Libraries
166#
167
168mesa = env.ConvenienceLibrary(
169 target = 'mesa',
170 source = mesa_sources,
171)
172
173env.Alias('mesa', mesa)
174
175Export('mesa')
José Fonseca8e8a56e2011-04-23 12:22:59 +0100176
177SConscript('drivers/SConscript')