blob: 434800e456029b677261809efd05e8af73dc2d6e [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 = [
Rob Clark1e93b0c2015-12-21 21:34:11 -050016 '../compiler/nir', # for generated nir_opcodes.h, etc
Kenneth Graunke1e0da622014-02-24 23:39:14 -080017 '#/src',
José Fonseca601498a2010-11-01 13:30:22 +000018 '#/src/mapi',
19 '#/src/glsl',
20 '#/src/mesa',
Eric Anholte8c5cbf2015-02-11 14:18:50 -080021 '#/src/gallium/include',
22 '#/src/gallium/auxiliary',
José Fonseca71c87e42013-01-21 17:47:51 +000023 Dir('../mapi'), # src/mapi build path
24 Dir('.'), # src/mesa build path
José Fonseca601498a2010-11-01 13:30:22 +000025])
José Fonseca2105b612009-01-06 16:20:12 +000026
José Fonseca601498a2010-11-01 13:30:22 +000027if env['platform'] == 'windows':
28 env.Append(CPPDEFINES = [
29 '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
30 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
José Fonseca601498a2010-11-01 13:30:22 +000031 ])
Chia-I Wubb770af2011-01-14 17:50:29 +080032 if not env['gles']:
33 # prevent _glapi_* from being declared __declspec(dllimport)
34 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
Chia-I Wubb045d32010-11-20 17:47:11 -080035else:
36 env.Append(CPPDEFINES = [
Tapani Pälli91214602012-08-28 14:01:51 +030037 ('HAVE_DLOPEN', '1'),
Chia-I Wubb045d32010-11-20 17:47:11 -080038 ])
José Fonseca5c9c6b02008-06-04 23:56:57 +090039
Jason Ekstranddcc29c12014-07-23 17:20:12 -070040# parse Makefile.sources
41source_lists = env.ParseSourceList('Makefile.sources')
José Fonseca601498a2010-11-01 13:30:22 +000042
Jose Fonseca31e47a52015-03-19 13:35:18 +000043env.Append(YACCFLAGS = ['-d', '-p', '_mesa_program_'])
Jose Fonsecad3e9aa82015-03-18 14:22:41 +000044env.CFile('program/lex.yy.c', 'program/program_lexer.l')
45env.CFile('program/program_parse.tab.c', 'program/program_parse.y')
José Fonseca601498a2010-11-01 13:30:22 +000046
47mesa_sources = (
Jason Ekstranddcc29c12014-07-23 17:20:12 -070048 source_lists['MESA_FILES'] +
Jose Fonsecad3e9aa82015-03-18 14:22:41 +000049 source_lists['PROGRAM_FILES'] +
Jason Ekstranddcc29c12014-07-23 17:20:12 -070050 source_lists['STATETRACKER_FILES']
José Fonseca601498a2010-11-01 13:30:22 +000051)
52
Brian Pauldff36e92012-05-30 10:08:11 -060053GLAPI = '#src/mapi/glapi/'
54
Imre Deak98f880e2012-09-10 08:46:13 +030055get_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',
Brian Paul815ca0b2013-04-17 09:49:39 -060059 command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
Imre Deak98f880e2012-09-10 08:46:13 +030060)
61
Jason Ekstrand12610ff2014-06-20 15:52:10 -070062format_info = env.CodeGenerate(
Emil Velikov3f6c28f22015-03-02 15:58:17 +000063 target = 'main/format_info.h',
Jason Ekstrand12610ff2014-06-20 15:52:10 -070064 script = 'main/format_info.py',
65 source = 'main/formats.csv',
66 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
67)
68
Jason Ekstrande0439f72014-08-21 12:38:05 -070069format_pack = env.CodeGenerate(
70 target = 'main/format_pack.c',
71 script = 'main/format_pack.py',
72 source = 'main/formats.csv',
73 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
74)
75
Jason Ekstrande1fdcdd2014-08-22 09:49:09 -070076format_unpack = env.CodeGenerate(
77 target = 'main/format_unpack.c',
78 script = 'main/format_unpack.py',
79 source = 'main/formats.csv',
80 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
81)
82
José Fonseca601498a2010-11-01 13:30:22 +000083#
84# Assembly sources
85#
Jose Fonseca9a25c8a2016-04-18 11:47:07 +010086if 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 Fonseca5db57b82015-03-23 10:48:31 +0000133 if not os.path.exists(filename):
134 dirname = os.path.dirname(filename)
135 if not os.path.exists(dirname):
136 os.makedirs(dirname)
Brian Paulf83af362011-09-28 08:15:22 -0600137 # create an empty file if none already exists
138 f = open(filename, "w")
139 f.close()
140 return
141
Brian Pauld487cc22011-09-28 09:51:36 -0600142 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
Brian Paulf83af362011-09-28 08:15:22 -0600143 tempfile = "git_sha1.h.tmp"
144 f = open(tempfile, "w")
145 f.write(commit)
Vinson Lee622ee082011-04-05 15:32:39 -0700146 f.close()
Brian Paulf83af362011-09-28 08:15:22 -0600147 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.
Brian Paule1122872011-09-28 09:04:03 -0600150 if os.path.exists(filename):
151 os.remove(filename)
Brian Paulf83af362011-09-28 08:15:22 -0600152 os.rename(tempfile, filename)
153 return
154
155
156# Create the git_sha1.h header file
157write_git_sha1_h_file("main/git_sha1.h")
Vinson Lee622ee082011-04-05 15:32:39 -0700158# and update CPPPATH so the git_sha1.h header can be found
159env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
Brian Paul0c245502011-04-05 14:07:41 -0600160
161
José Fonseca601498a2010-11-01 13:30:22 +0000162#
163# Libraries
164#
165
166mesa = env.ConvenienceLibrary(
167 target = 'mesa',
168 source = mesa_sources,
169)
170
171env.Alias('mesa', mesa)
172
173Export('mesa')
José Fonseca8e8a56e2011-04-23 12:22:59 +0100174
175SConscript('drivers/SConscript')