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