blob: 62e81ced1849a0b81905fed38f7954ca5c2e757c [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
José Fonseca601498a2010-11-01 13:30:22 +000013env.Append(CPPPATH = [
Kenneth Graunke1e0da622014-02-24 23:39:14 -080014 '#/src',
José Fonseca601498a2010-11-01 13:30:22 +000015 '#/src/mapi',
16 '#/src/glsl',
17 '#/src/mesa',
Eric Anholte8c5cbf2015-02-11 14:18:50 -080018 '#/src/gallium/include',
19 '#/src/gallium/auxiliary',
José Fonseca71c87e42013-01-21 17:47:51 +000020 Dir('../mapi'), # src/mapi build path
21 Dir('.'), # src/mesa build path
José Fonseca601498a2010-11-01 13:30:22 +000022])
José Fonseca2105b612009-01-06 16:20:12 +000023
José Fonseca601498a2010-11-01 13:30:22 +000024if env['platform'] == 'windows':
25 env.Append(CPPDEFINES = [
26 '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
27 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
José Fonseca601498a2010-11-01 13:30:22 +000028 ])
Chia-I Wubb770af2011-01-14 17:50:29 +080029 if not env['gles']:
30 # prevent _glapi_* from being declared __declspec(dllimport)
31 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
Chia-I Wubb045d32010-11-20 17:47:11 -080032else:
33 env.Append(CPPDEFINES = [
Tapani Pälli91214602012-08-28 14:01:51 +030034 ('HAVE_DLOPEN', '1'),
Chia-I Wubb045d32010-11-20 17:47:11 -080035 ])
José Fonseca5c9c6b02008-06-04 23:56:57 +090036
Jason Ekstranddcc29c12014-07-23 17:20:12 -070037# parse Makefile.sources
38source_lists = env.ParseSourceList('Makefile.sources')
José Fonseca601498a2010-11-01 13:30:22 +000039
Brian Paule78ebbc2012-09-15 09:01:02 -060040env.Append(YACCFLAGS = '-d -p "_mesa_program_"')
Kenneth Graunke8be58df2011-03-01 15:04:04 -080041program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
42program_parse = env.CFile('program/program_parse.tab.c',
43 'program/program_parse.y')
Jason Ekstranddcc29c12014-07-23 17:20:12 -070044program_sources = source_lists['PROGRAM_FILES'] + [
Kenneth Graunke8be58df2011-03-01 15:04:04 -080045 program_lex,
46 program_parse[0],
José Fonseca601498a2010-11-01 13:30:22 +000047]
48
49mesa_sources = (
Jason Ekstranddcc29c12014-07-23 17:20:12 -070050 source_lists['MESA_FILES'] +
José Fonseca601498a2010-11-01 13:30:22 +000051 program_sources +
Jason Ekstranddcc29c12014-07-23 17:20:12 -070052 source_lists['STATETRACKER_FILES']
José Fonseca601498a2010-11-01 13:30:22 +000053)
54
Brian Pauldff36e92012-05-30 10:08:11 -060055GLAPI = '#src/mapi/glapi/'
56
Imre Deak98f880e2012-09-10 08:46:13 +030057get_hash_header = env.CodeGenerate(
58 target = 'main/get_hash.h',
59 script = 'main/get_hash_generator.py',
60 source = GLAPI + 'gen/gl_and_es_API.xml',
Brian Paul815ca0b2013-04-17 09:49:39 -060061 command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
Imre Deak98f880e2012-09-10 08:46:13 +030062)
63
Jason Ekstrand12610ff2014-06-20 15:52:10 -070064format_info = env.CodeGenerate(
65 target = 'main/format_info.c',
66 script = 'main/format_info.py',
67 source = 'main/formats.csv',
68 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
69)
70
Jason Ekstrande0439f72014-08-21 12:38:05 -070071format_pack = env.CodeGenerate(
72 target = 'main/format_pack.c',
73 script = 'main/format_pack.py',
74 source = 'main/formats.csv',
75 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
76)
77
Jason Ekstrande1fdcdd2014-08-22 09:49:09 -070078format_unpack = env.CodeGenerate(
79 target = 'main/format_unpack.c',
80 script = 'main/format_unpack.py',
81 source = 'main/formats.csv',
82 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
83)
84
José Fonseca601498a2010-11-01 13:30:22 +000085#
86# Assembly sources
87#
José Fonseca16879322013-04-24 22:02:18 +010088if (env['gcc'] or env['clang']) and \
89 env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
José Fonsecaf9156eb2010-11-01 13:56:16 +000090 if env['machine'] == 'x86':
91 env.Append(CPPDEFINES = [
92 'USE_X86_ASM',
93 'USE_MMX_ASM',
94 'USE_3DNOW_ASM',
95 'USE_SSE_ASM',
96 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -070097 mesa_sources += source_lists['X86_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +000098 elif env['machine'] == 'x86_64':
99 env.Append(CPPDEFINES = [
100 'USE_X86_64_ASM',
101 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -0700102 mesa_sources += source_lists['X86_64_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +0000103 elif env['machine'] == 'sparc':
Jason Ekstranddcc29c12014-07-23 17:20:12 -0700104 mesa_sources += source_lists['SPARC_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +0000105 else:
106 pass
José Fonseca601498a2010-11-01 13:30:22 +0000107
José Fonsecaf9156eb2010-11-01 13:56:16 +0000108 # Generate matypes.h
109 if env['machine'] in ('x86', 'x86_64'):
110 # See http://www.scons.org/wiki/UsingCodeGenerators
111 gen_matypes = env.Program(
112 target = 'gen_matypes',
113 source = 'x86/gen_matypes.c',
114 )
115 matypes = env.Command(
116 'matypes.h',
117 gen_matypes,
118 gen_matypes[0].abspath + ' > $TARGET',
119 )
120 # Add the dir containing the generated header (somewhere inside the
121 # build dir) to the include path
122 env.Append(CPPPATH = [matypes[0].dir])
José Fonseca601498a2010-11-01 13:30:22 +0000123
Brian Paul0c245502011-04-05 14:07:41 -0600124
Brian Paulf83af362011-09-28 08:15:22 -0600125def write_git_sha1_h_file(filename):
126 """Mesa looks for a git_sha1.h file at compile time in order to display
127 the current git hash id in the GL_VERSION string. This function tries
128 to retrieve the git hashid and write the header file. An empty file
129 will be created if anything goes wrong."""
130
131 args = [ 'git', 'log', '-n', '1', '--oneline' ]
132 try:
133 (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
134 except:
135 # git log command didn't work
136 if not os.path.exists(filename):
137 # 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')