blob: a563fd2ff0153dbe0dd69d4ad56de2953e63fbf3 [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
Jose Fonseca31e47a52015-03-19 13:35:18 +000042env.Append(YACCFLAGS = ['-d', '-p', '_mesa_program_'])
Jose Fonsecad3e9aa82015-03-18 14:22:41 +000043env.CFile('program/lex.yy.c', 'program/program_lexer.l')
44env.CFile('program/program_parse.tab.c', 'program/program_parse.y')
José Fonseca601498a2010-11-01 13:30:22 +000045
46mesa_sources = (
Jason Ekstranddcc29c12014-07-23 17:20:12 -070047 source_lists['MESA_FILES'] +
Jose Fonsecad3e9aa82015-03-18 14:22:41 +000048 source_lists['PROGRAM_FILES'] +
Jason Ekstranddcc29c12014-07-23 17:20:12 -070049 source_lists['STATETRACKER_FILES']
José Fonseca601498a2010-11-01 13:30:22 +000050)
51
Brian Pauldff36e92012-05-30 10:08:11 -060052GLAPI = '#src/mapi/glapi/'
53
Imre Deak98f880e2012-09-10 08:46:13 +030054get_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',
Brian Paul815ca0b2013-04-17 09:49:39 -060058 command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
Imre Deak98f880e2012-09-10 08:46:13 +030059)
60
Jason Ekstrand12610ff2014-06-20 15:52:10 -070061format_info = env.CodeGenerate(
Emil Velikov3f6c28f22015-03-02 15:58:17 +000062 target = 'main/format_info.h',
Jason Ekstrand12610ff2014-06-20 15:52:10 -070063 script = 'main/format_info.py',
64 source = 'main/formats.csv',
65 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
66)
67
Jason Ekstrande0439f72014-08-21 12:38:05 -070068format_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
Jason Ekstrande1fdcdd2014-08-22 09:49:09 -070075format_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
José Fonseca601498a2010-11-01 13:30:22 +000082#
83# Assembly sources
84#
José Fonseca16879322013-04-24 22:02:18 +010085if (env['gcc'] or env['clang']) and \
86 env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
José Fonsecaf9156eb2010-11-01 13:56:16 +000087 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 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -070094 mesa_sources += source_lists['X86_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +000095 elif env['machine'] == 'x86_64':
96 env.Append(CPPDEFINES = [
97 'USE_X86_64_ASM',
98 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -070099 mesa_sources += source_lists['X86_64_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +0000100 elif env['machine'] == 'sparc':
Jason Ekstranddcc29c12014-07-23 17:20:12 -0700101 mesa_sources += source_lists['SPARC_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +0000102 else:
103 pass
José Fonseca601498a2010-11-01 13:30:22 +0000104
José Fonsecaf9156eb2010-11-01 13:56:16 +0000105 # 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])
José Fonseca601498a2010-11-01 13:30:22 +0000120
Brian Paul0c245502011-04-05 14:07:41 -0600121
Brian Paulf83af362011-09-28 08:15:22 -0600122def 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
Jose Fonsecae6330f92015-03-19 13:31:37 +0000133 dirname = os.path.dirname(filename)
134 if not os.path.exists(dirname):
135 os.makedirs(dirname)
Brian Paulf83af362011-09-28 08:15:22 -0600136 # create an empty file if none already exists
137 f = open(filename, "w")
138 f.close()
139 return
140
Brian Pauld487cc22011-09-28 09:51:36 -0600141 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
Brian Paulf83af362011-09-28 08:15:22 -0600142 tempfile = "git_sha1.h.tmp"
143 f = open(tempfile, "w")
144 f.write(commit)
Vinson Lee622ee082011-04-05 15:32:39 -0700145 f.close()
Brian Paulf83af362011-09-28 08:15:22 -0600146 if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
147 # The filename does not exist or it's different from the new file,
148 # so replace old file with new.
Brian Paule1122872011-09-28 09:04:03 -0600149 if os.path.exists(filename):
150 os.remove(filename)
Brian Paulf83af362011-09-28 08:15:22 -0600151 os.rename(tempfile, filename)
152 return
153
154
155# Create the git_sha1.h header file
156write_git_sha1_h_file("main/git_sha1.h")
Vinson Lee622ee082011-04-05 15:32:39 -0700157# and update CPPPATH so the git_sha1.h header can be found
158env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
Brian Paul0c245502011-04-05 14:07:41 -0600159
160
José Fonseca601498a2010-11-01 13:30:22 +0000161#
162# Libraries
163#
164
165mesa = env.ConvenienceLibrary(
166 target = 'mesa',
167 source = mesa_sources,
168)
169
170env.Alias('mesa', mesa)
171
172Export('mesa')
José Fonseca8e8a56e2011-04-23 12:22:59 +0100173
174SConscript('drivers/SConscript')