Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / mesa / SConscript
1 #######################################################################
2 # SConscript for Mesa
3
4
5 Import('*')
6 import filecmp
7 import os
8 import subprocess
9 from sys import executable as python_cmd
10
11 env = env.Clone()
12
13 env.MSVC2013Compat()
14
15 env.Append(CPPPATH = [
16 '#/src',
17 '#/src/mapi',
18 '#/src/glsl',
19 '#/src/glsl/nir',
20 '#/src/mesa',
21 '#/src/gallium/include',
22 '#/src/gallium/auxiliary',
23 Dir('../mapi'), # src/mapi build path
24 Dir('.'), # src/mesa build path
25 ])
26
27 if 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
31 ])
32 if not env['gles']:
33 # prevent _glapi_* from being declared __declspec(dllimport)
34 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
35 else:
36 env.Append(CPPDEFINES = [
37 ('HAVE_DLOPEN', '1'),
38 ])
39
40 # parse Makefile.sources
41 source_lists = env.ParseSourceList('Makefile.sources')
42
43 env.Append(YACCFLAGS = ['-d', '-p', '_mesa_program_'])
44 env.CFile('program/lex.yy.c', 'program/program_lexer.l')
45 env.CFile('program/program_parse.tab.c', 'program/program_parse.y')
46
47 mesa_sources = (
48 source_lists['MESA_FILES'] +
49 source_lists['PROGRAM_FILES'] +
50 source_lists['STATETRACKER_FILES']
51 )
52
53 GLAPI = '#src/mapi/glapi/'
54
55 get_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',
59 command = python_cmd + ' $SCRIPT ' + ' -f $SOURCE > $TARGET'
60 )
61
62 format_info = env.CodeGenerate(
63 target = 'main/format_info.h',
64 script = 'main/format_info.py',
65 source = 'main/formats.csv',
66 command = python_cmd + ' $SCRIPT ' + ' $SOURCE > $TARGET'
67 )
68
69 format_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
76 format_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
83 #
84 # Assembly sources
85 #
86 if (env['gcc'] or env['clang']) and \
87 env['platform'] not in ('cygwin', 'darwin', 'windows', 'haiku'):
88 if env['machine'] == 'x86':
89 env.Append(CPPDEFINES = [
90 'USE_X86_ASM',
91 'USE_MMX_ASM',
92 'USE_3DNOW_ASM',
93 'USE_SSE_ASM',
94 ])
95 mesa_sources += source_lists['X86_FILES']
96 elif env['machine'] == 'x86_64':
97 env.Append(CPPDEFINES = [
98 'USE_X86_64_ASM',
99 ])
100 mesa_sources += source_lists['X86_64_FILES']
101 elif env['machine'] == 'sparc':
102 mesa_sources += source_lists['SPARC_FILES']
103 else:
104 pass
105
106 # Generate matypes.h
107 if env['machine'] in ('x86', 'x86_64'):
108 # See http://www.scons.org/wiki/UsingCodeGenerators
109 gen_matypes = env.Program(
110 target = 'gen_matypes',
111 source = 'x86/gen_matypes.c',
112 )
113 matypes = env.Command(
114 'matypes.h',
115 gen_matypes,
116 gen_matypes[0].abspath + ' > $TARGET',
117 )
118 # Add the dir containing the generated header (somewhere inside the
119 # build dir) to the include path
120 env.Append(CPPPATH = [matypes[0].dir])
121
122
123 def write_git_sha1_h_file(filename):
124 """Mesa looks for a git_sha1.h file at compile time in order to display
125 the current git hash id in the GL_VERSION string. This function tries
126 to retrieve the git hashid and write the header file. An empty file
127 will be created if anything goes wrong."""
128
129 args = [ 'git', 'log', '-n', '1', '--oneline' ]
130 try:
131 (commit, foo) = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
132 except:
133 # git log command didn't work
134 if not os.path.exists(filename):
135 dirname = os.path.dirname(filename)
136 if not os.path.exists(dirname):
137 os.makedirs(dirname)
138 # create an empty file if none already exists
139 f = open(filename, "w")
140 f.close()
141 return
142
143 commit = '#define MESA_GIT_SHA1 "git-%s"\n' % commit[0:7]
144 tempfile = "git_sha1.h.tmp"
145 f = open(tempfile, "w")
146 f.write(commit)
147 f.close()
148 if not os.path.exists(filename) or not filecmp.cmp(tempfile, filename):
149 # The filename does not exist or it's different from the new file,
150 # so replace old file with new.
151 if os.path.exists(filename):
152 os.remove(filename)
153 os.rename(tempfile, filename)
154 return
155
156
157 # Create the git_sha1.h header file
158 write_git_sha1_h_file("main/git_sha1.h")
159 # and update CPPPATH so the git_sha1.h header can be found
160 env.Append(CPPPATH = ["#" + env['build_dir'] + "/mesa/main"])
161
162
163 #
164 # Libraries
165 #
166
167 mesa = env.ConvenienceLibrary(
168 target = 'mesa',
169 source = mesa_sources,
170 )
171
172 env.Alias('mesa', mesa)
173
174 Export('mesa')
175
176 SConscript('drivers/SConscript')