glsl: Use the generated constant expression code
[mesa.git] / src / compiler / SConscript.glsl
1 import common
2
3 Import('*')
4
5 from sys import executable as python_cmd
6
7 env = env.Clone()
8
9 env.MSVC2013Compat()
10
11 env.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
23 env.Prepend(LIBS = [mesautil])
24
25 # Make glcpp-parse.h and glsl_parser.h reachable from the include path.
26 env.Prepend(CPPPATH = [Dir('.').abspath, Dir('glsl').abspath])
27 # Make NIR headers reachable from the include path.
28 env.Prepend(CPPPATH = [Dir('.').abspath, Dir('nir').abspath])
29
30 glcpp_env = env.Clone()
31 glcpp_env.Append(YACCFLAGS = [
32 '-d',
33 '-p', 'glcpp_parser_'
34 ])
35
36 glsl_env = env.Clone()
37 glsl_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
44 glsl_env['YACCHXXFILESUFFIX'] = '.h'
45
46 glcpp_lexer = glcpp_env.CFile('glsl/glcpp/glcpp-lex.c', 'glsl/glcpp/glcpp-lex.l')
47 glcpp_parser = glcpp_env.CFile('glsl/glcpp/glcpp-parse.c', 'glsl/glcpp/glcpp-parse.y')
48 glsl_lexer = glsl_env.CXXFile('glsl/glsl_lexer.cpp', 'glsl/glsl_lexer.ll')
49 glsl_parser = glsl_env.CXXFile('glsl/glsl_parser.cpp', 'glsl/glsl_parser.yy')
50
51 # common generated sources
52 glsl_sources = [
53 glcpp_lexer,
54 glcpp_parser[0],
55 glsl_lexer,
56 glsl_parser[0],
57 ]
58
59 # parse Makefile.sources
60 source_lists = env.ParseSourceList('Makefile.sources')
61
62 # add non-generated sources
63 for l in ('LIBGLCPP_FILES', 'LIBGLSL_FILES'):
64 glsl_sources += source_lists[l]
65
66 if env['msvc']:
67 env.Prepend(CPPPATH = ['#/src/getopt'])
68 env.PrependUnique(LIBS = [getopt])
69
70 # Copy these files to avoid generation object files into src/mesa/program
71 env.Prepend(CPPPATH = ['#src/mesa/main'])
72 env.Command('glsl/imports.c', '#src/mesa/main/imports.c', Copy('$TARGET', '$SOURCE'))
73 env.Command('glsl/extensions_table.c', '#src/mesa/main/extensions_table.c', Copy('$TARGET', '$SOURCE'))
74 # Copy these files to avoid generation object files into src/mesa/program
75 env.Prepend(CPPPATH = ['#src/mesa/program'])
76 env.Command('glsl/prog_hash_table.c', '#src/mesa/program/prog_hash_table.c', Copy('$TARGET', '$SOURCE'))
77 env.Command('glsl/symbol_table.c', '#src/mesa/program/symbol_table.c', Copy('$TARGET', '$SOURCE'))
78 env.Command('glsl/dummy_errors.c', '#src/mesa/program/dummy_errors.c', Copy('$TARGET', '$SOURCE'))
79
80 compiler_objs = env.StaticObject(source_lists['GLSL_COMPILER_CXX_FILES'])
81
82 mesa_objs = env.StaticObject([
83 'glsl/extensions_table.c',
84 'glsl/imports.c',
85 'glsl/prog_hash_table.c',
86 'glsl/symbol_table.c',
87 'glsl/dummy_errors.c',
88 ])
89
90 compiler_objs += mesa_objs
91
92 glsl = env.ConvenienceLibrary(
93 target = 'glsl',
94 source = glsl_sources,
95 )
96
97 # SCons builtin dependency scanner doesn't detect that glsl_lexer.ll depends on
98 # glsl_parser.h
99 env.Depends(glsl, glsl_parser)
100
101 Export('glsl')
102
103 # Skip building these programs as they will cause SCons error "Two environments
104 # with different actions were specified for the same target"
105 if env['crosscompile'] or env['embedded']:
106 Return()
107
108 env = env.Clone()
109
110 if env['platform'] == 'windows':
111 env.PrependUnique(LIBS = [
112 'user32',
113 ])
114
115 env.Prepend(LIBS = [compiler, glsl])
116
117 compiler_objs += env.StaticObject("glsl/main.cpp")
118
119 # GLSL generated sources
120
121 env.CodeGenerate(
122 target = 'glsl/ir_expression_operation.h',
123 script = 'glsl/ir_expression_operation.py',
124 source = [],
125 command = python_cmd + ' $SCRIPT enum > $TARGET'
126 )
127 env.CodeGenerate(
128 target = 'glsl/ir_expression_operation_constant.h',
129 script = 'glsl/ir_expression_operation.py',
130 source = [],
131 command = python_cmd + ' $SCRIPT constant > $TARGET'
132 )
133 env.CodeGenerate(
134 target = 'glsl/ir_expression_operation_strings.h',
135 script = 'glsl/ir_expression_operation.py',
136 source = [],
137 command = python_cmd + ' $SCRIPT strings > $TARGET'
138 )
139
140 glsl_compiler = env.Program(
141 target = 'glsl_compiler',
142 source = compiler_objs,
143 )
144 env.Alias('glsl_compiler', glsl_compiler)
145
146 glcpp = env.Program(
147 target = 'glsl/glcpp/glcpp',
148 source = ['glsl/glcpp/glcpp.c'] + mesa_objs,
149 )
150 env.Alias('glcpp', glcpp)