blob: e7c4f5ca1f815442ac57428aea81f3c51bcea231 [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',
José Fonseca71c87e42013-01-21 17:47:51 +000018 Dir('../mapi'), # src/mapi build path
19 Dir('.'), # src/mesa build path
José Fonseca601498a2010-11-01 13:30:22 +000020])
José Fonseca2105b612009-01-06 16:20:12 +000021
José Fonseca601498a2010-11-01 13:30:22 +000022if env['platform'] == 'windows':
23 env.Append(CPPDEFINES = [
24 '_GDI32_', # prevent gl* being declared __declspec(dllimport) in MS headers
25 'BUILD_GL32', # declare gl* as __declspec(dllexport) in Mesa headers
José Fonseca601498a2010-11-01 13:30:22 +000026 ])
Chia-I Wubb770af2011-01-14 17:50:29 +080027 if not env['gles']:
28 # prevent _glapi_* from being declared __declspec(dllimport)
29 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
Chia-I Wubb045d32010-11-20 17:47:11 -080030else:
31 env.Append(CPPDEFINES = [
Tapani Pälli91214602012-08-28 14:01:51 +030032 ('HAVE_DLOPEN', '1'),
Chia-I Wubb045d32010-11-20 17:47:11 -080033 ])
José Fonseca5c9c6b02008-06-04 23:56:57 +090034
Jason Ekstranddcc29c12014-07-23 17:20:12 -070035# parse Makefile.sources
36source_lists = env.ParseSourceList('Makefile.sources')
José Fonseca601498a2010-11-01 13:30:22 +000037
Brian Paule78ebbc2012-09-15 09:01:02 -060038env.Append(YACCFLAGS = '-d -p "_mesa_program_"')
Kenneth Graunke8be58df2011-03-01 15:04:04 -080039program_lex = env.CFile('program/lex.yy.c', 'program/program_lexer.l')
40program_parse = env.CFile('program/program_parse.tab.c',
41 'program/program_parse.y')
Jason Ekstranddcc29c12014-07-23 17:20:12 -070042program_sources = source_lists['PROGRAM_FILES'] + [
Kenneth Graunke8be58df2011-03-01 15:04:04 -080043 program_lex,
44 program_parse[0],
José Fonseca601498a2010-11-01 13:30:22 +000045]
46
47mesa_sources = (
Jason Ekstranddcc29c12014-07-23 17:20:12 -070048 source_lists['MESA_FILES'] +
José Fonseca601498a2010-11-01 13:30:22 +000049 program_sources +
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(
63 target = 'main/format_info.c',
64 script = 'main/format_info.py',
65 source = 'main/formats.csv',
66 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
67)
68
José Fonseca601498a2010-11-01 13:30:22 +000069#
70# Assembly sources
71#
José Fonseca16879322013-04-24 22:02:18 +010072if (env['gcc'] or env['clang']) and \
73 env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
José Fonsecaf9156eb2010-11-01 13:56:16 +000074 if env['machine'] == 'x86':
75 env.Append(CPPDEFINES = [
76 'USE_X86_ASM',
77 'USE_MMX_ASM',
78 'USE_3DNOW_ASM',
79 'USE_SSE_ASM',
80 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -070081 mesa_sources += source_lists['X86_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +000082 elif env['machine'] == 'x86_64':
83 env.Append(CPPDEFINES = [
84 'USE_X86_64_ASM',
85 ])
Jason Ekstranddcc29c12014-07-23 17:20:12 -070086 mesa_sources += source_lists['X86_64_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +000087 elif env['machine'] == 'sparc':
Jason Ekstranddcc29c12014-07-23 17:20:12 -070088 mesa_sources += source_lists['SPARC_FILES']
José Fonsecaf9156eb2010-11-01 13:56:16 +000089 else:
90 pass
José Fonseca601498a2010-11-01 13:30:22 +000091
José Fonsecaf9156eb2010-11-01 13:56:16 +000092 # Generate matypes.h
93 if env['machine'] in ('x86', 'x86_64'):
94 # See http://www.scons.org/wiki/UsingCodeGenerators
95 gen_matypes = env.Program(
96 target = 'gen_matypes',
97 source = 'x86/gen_matypes.c',
98 )
99 matypes = env.Command(
100 'matypes.h',
101 gen_matypes,
102 gen_matypes[0].abspath + ' > $TARGET',
103 )
104 # Add the dir containing the generated header (somewhere inside the
105 # build dir) to the include path
106 env.Append(CPPPATH = [matypes[0].dir])
José Fonseca601498a2010-11-01 13:30:22 +0000107
Brian Paul0c245502011-04-05 14:07:41 -0600108
Brian Paulf83af362011-09-28 08:15:22 -0600109def write_git_sha1_h_file(filename):
110 """Mesa looks for a git_sha1.h file at compile time in order to display
111 the current git hash id in the GL_VERSION string. This function tries
112 to retrieve the git hashid and write the header file. An empty file
113 will be created if anything goes wrong."""
114
115 args = [ 'git', 'log', '-n', '1', '--oneline' ]
116 try:
117 (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
118 except:
119 # git log command didn't work
120 if not os.path.exists(filename):
121 # create an empty file if none already exists
122 f = open(filename, "w")
123 f.close()
124 return
125
Brian Pauld487cc22011-09-28 09:51:36 -0600126 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
Brian Paulf83af362011-09-28 08:15:22 -0600127 tempfile = "git_sha1.h.tmp"
128 f = open(tempfile, "w")
129 f.write(commit)
Vinson Lee622ee082011-04-05 15:32:39 -0700130 f.close()
Brian Paulf83af362011-09-28 08:15:22 -0600131 if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
132 # The filename does not exist or it's different from the new file,
133 # so replace old file with new.
Brian Paule1122872011-09-28 09:04:03 -0600134 if os.path.exists(filename):
135 os.remove(filename)
Brian Paulf83af362011-09-28 08:15:22 -0600136 os.rename(tempfile, filename)
137 return
138
139
140# Create the git_sha1.h header file
141write_git_sha1_h_file("main/git_sha1.h")
Vinson Lee622ee082011-04-05 15:32:39 -0700142# and update CPPPATH so the git_sha1.h header can be found
143env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
Brian Paul0c245502011-04-05 14:07:41 -0600144
145
José Fonseca601498a2010-11-01 13:30:22 +0000146#
147# Libraries
148#
149
150mesa = env.ConvenienceLibrary(
151 target = 'mesa',
152 source = mesa_sources,
153)
154
155env.Alias('mesa', mesa)
156
157Export('mesa')
José Fonseca8e8a56e2011-04-23 12:22:59 +0100158
159SConscript('drivers/SConscript')