• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import common
2
3Import('*')
4
5from sys import executable as python_cmd
6
7env = env.Clone()
8
9env.MSVC2013Compat()
10
11env.Prepend(CPPPATH = [
12    '#include',
13    '#src',
14    '#src/mapi',
15    '#src/mesa',
16    '#src/gallium/include',
17    '#src/gallium/auxiliary',
18    '#src/compiler/glsl',
19    '#src/compiler/glsl/glcpp',
20    '#src/compiler/nir',
21])
22
23env.Prepend(LIBS = [mesautil])
24
25# Make glcpp-parse.h and glsl_parser.h reachable from the include path.
26env.Prepend(CPPPATH = [Dir('.').abspath, Dir('glsl').abspath])
27# Make NIR headers reachable from the include path.
28env.Prepend(CPPPATH = [Dir('.').abspath, Dir('nir').abspath])
29
30glcpp_env = env.Clone()
31glcpp_env.Append(YACCFLAGS = [
32    '-d',
33    '-p', 'glcpp_parser_'
34])
35
36glsl_env = env.Clone()
37glsl_env.Append(YACCFLAGS = [
38    '--defines=%s' % File('glsl/glsl_parser.h').abspath,
39    '-p', '_mesa_glsl_',
40])
41
42# without this line scons will expect "glsl_parser.hpp" instead of
43# "glsl_parser.h", causing glsl_parser.cpp to be regenerated every time
44glsl_env['YACCHXXFILESUFFIX'] = '.h'
45
46glcpp_lexer = glcpp_env.CFile('glsl/glcpp/glcpp-lex.c', 'glsl/glcpp/glcpp-lex.l')
47glcpp_parser = glcpp_env.CFile('glsl/glcpp/glcpp-parse.c', 'glsl/glcpp/glcpp-parse.y')
48glsl_lexer = glsl_env.CXXFile('glsl/glsl_lexer.cpp', 'glsl/glsl_lexer.ll')
49glsl_parser = glsl_env.CXXFile('glsl/glsl_parser.cpp', 'glsl/glsl_parser.yy')
50
51# common generated sources
52glsl_sources = [
53    glcpp_lexer,
54    glcpp_parser[0],
55    glsl_lexer,
56    glsl_parser[0],
57]
58
59# parse Makefile.sources
60source_lists = env.ParseSourceList('Makefile.sources')
61
62# add non-generated sources
63for l in ('LIBGLCPP_FILES', 'LIBGLSL_FILES'):
64    glsl_sources += source_lists[l]
65
66glsl_sources += env.StaticObject("glsl/glcpp/pp_standalone_scaffolding.c")
67
68if env['msvc']:
69    env.Prepend(CPPPATH = ['#/src/getopt'])
70    env.PrependUnique(LIBS = [getopt])
71
72# Copy these files to avoid generation object files into src/mesa/program
73env.Prepend(CPPPATH = ['#src/mesa/main'])
74env.Command('glsl/extensions_table.c', '#src/mesa/main/extensions_table.c', Copy('$TARGET', '$SOURCE'))
75# Copy these files to avoid generation object files into src/mesa/program
76env.Prepend(CPPPATH = ['#src/mesa/program'])
77env.Command('glsl/symbol_table.c', '#src/mesa/program/symbol_table.c', Copy('$TARGET', '$SOURCE'))
78env.Command('glsl/dummy_errors.c', '#src/mesa/program/dummy_errors.c', Copy('$TARGET', '$SOURCE'))
79
80compiler_objs = env.StaticObject(source_lists['GLSL_COMPILER_CXX_FILES'])
81
82mesa_objs = env.StaticObject([
83    'glsl/extensions_table.c',
84    'glsl/symbol_table.c',
85    'glsl/dummy_errors.c',
86])
87
88compiler_objs += mesa_objs
89
90# GLSL generated sources
91env.CodeGenerate(
92    target = 'glsl/float64_glsl.h',
93    script = '../util/xxd.py',
94    source = ['glsl/float64.glsl'],
95    command = python_cmd + ' $SCRIPT $SOURCE $TARGET -n float64_source',
96)
97
98env.CodeGenerate(
99    target = 'glsl/ir_expression_operation.h',
100    script = 'glsl/ir_expression_operation.py',
101    source = [],
102    command = python_cmd + ' $SCRIPT enum > $TARGET'
103)
104env.CodeGenerate(
105    target = 'glsl/ir_expression_operation_constant.h',
106    script = 'glsl/ir_expression_operation.py',
107    source = [],
108    command = python_cmd + ' $SCRIPT constant > $TARGET'
109)
110env.CodeGenerate(
111    target = 'glsl/ir_expression_operation_strings.h',
112    script = 'glsl/ir_expression_operation.py',
113    source = [],
114    command = python_cmd + ' $SCRIPT strings > $TARGET'
115)
116
117glsl = env.ConvenienceLibrary(
118    target = 'glsl',
119    source = glsl_sources,
120)
121
122# SCons builtin dependency scanner doesn't detect that glsl_lexer.ll depends on
123# glsl_parser.h
124env.Depends(glsl, glsl_parser)
125
126Export('glsl')
127
128#
129# XXX: It's important to not add any generated source files after this point,
130# or it will break MinGW cross-compilation.
131#
132
133# Skip building these programs as they will cause SCons error "Two environments
134# with different actions were specified for the same target"
135if env['crosscompile'] or env['embedded']:
136    Return()
137
138env = env.Clone()
139
140if env['platform'] == 'windows':
141    env.PrependUnique(LIBS = [
142        'user32',
143    ])
144
145env.Prepend(LIBS = [compiler, glsl])
146
147compiler_objs += env.StaticObject("glsl/main.cpp")
148
149glsl_compiler = env.Program(
150    target = 'glsl_compiler',
151    source = compiler_objs,
152)
153env.Alias('glsl_compiler', glsl_compiler)
154
155glcpp = env.Program(
156    target = 'glsl/glcpp/glcpp',
157    source = ['glsl/glcpp/glcpp.c'] + mesa_objs,
158)
159env.Alias('glcpp', glcpp)
160