6981f041b39f0f687591c37f6e2ca2f81030082e
[mesa.git] / src / glsl / SConscript
1 import common
2
3 Import('*')
4
5 from sys import executable as python_cmd
6
7 env = env.Clone()
8
9 env.Prepend(CPPPATH = [
10 '#include',
11 '#src/mapi',
12 '#src/mesa',
13 '#src/glsl',
14 '#src/glsl/glcpp',
15 ])
16
17 # Make glcpp-parse.h and glsl_parser.h reachable from the include path.
18 env.Append(CPPPATH = [Dir('.').abspath, Dir('glcpp').abspath])
19
20 env.Append(YACCFLAGS = '-d -p "glcpp_parser_"')
21
22 parser_env = env.Clone()
23 parser_env.Append(YACCFLAGS = [
24 '--defines=%s' % File('glsl_parser.h').abspath,
25 '-p', '_mesa_glsl_',
26 ])
27
28 # without this line scons will expect "glsl_parser.hpp" instead of
29 # "glsl_parser.h", causing glsl_parser.cpp to be regenerated every time
30 parser_env['YACCHXXFILESUFFIX'] = '.h'
31
32 glcpp_lexer = env.CFile('glcpp/glcpp-lex.c', 'glcpp/glcpp-lex.l')
33 glcpp_parser = env.CFile('glcpp/glcpp-parse.c', 'glcpp/glcpp-parse.y')
34 glsl_lexer = parser_env.CXXFile('glsl_lexer.cpp', 'glsl_lexer.ll')
35 glsl_parser = parser_env.CXXFile('glsl_parser.cpp', 'glsl_parser.yy')
36
37 # common generated sources
38 glsl_sources = [
39 glcpp_lexer,
40 glcpp_parser[0],
41 glsl_lexer,
42 glsl_parser[0],
43 ]
44
45 # parse Makefile.sources
46 source_lists = env.ParseSourceList('Makefile.sources')
47
48 # add non-generated sources
49 for l in ('LIBGLCPP_FILES', 'LIBGLSL_FILES'):
50 glsl_sources += source_lists[l]
51
52 if env['msvc']:
53 env.Prepend(CPPPATH = ['#/src/getopt'])
54 env.PrependUnique(LIBS = [getopt])
55
56 if env['crosscompile'] and not env['embedded']:
57 Import('builtin_glsl_function')
58 else:
59 # Copy these files to avoid generation object files into src/mesa/program
60 env.Prepend(CPPPATH = ['#src/mesa/main'])
61 env.Command('hash_table.c', '#src/mesa/main/hash_table.c', Copy('$TARGET', '$SOURCE'))
62 # Copy these files to avoid generation object files into src/mesa/program
63 env.Prepend(CPPPATH = ['#src/mesa/program'])
64 env.Command('prog_hash_table.c', '#src/mesa/program/prog_hash_table.c', Copy('$TARGET', '$SOURCE'))
65 env.Command('symbol_table.c', '#src/mesa/program/symbol_table.c', Copy('$TARGET', '$SOURCE'))
66
67 compiler_objs = env.StaticObject(source_lists['GLSL_COMPILER_CXX_FILES'])
68
69 mesa_objs = env.StaticObject([
70 'hash_table.c',
71 'prog_hash_table.c',
72 'symbol_table.c',
73 ])
74
75 compiler_objs += mesa_objs
76
77 builtin_compiler = env.Program(
78 target = 'builtin_compiler/builtin_compiler',
79 source = compiler_objs + glsl_sources + \
80 source_lists['BUILTIN_COMPILER_CXX_FILES'],
81 )
82
83 # SCons builtin dependency scanner doesn't detect that glsl_lexer.ll
84 # depends on glsl_parser.h
85 env.Depends(builtin_compiler, glsl_parser)
86
87 builtin_glsl_function = env.CodeGenerate(
88 target = 'builtin_function.cpp',
89 script = 'builtins/tools/generate_builtins.py',
90 source = builtin_compiler,
91 command = python_cmd + ' $SCRIPT $SOURCE > $TARGET'
92 )
93
94 env.Depends(builtin_glsl_function, ['builtins/tools/generate_builtins.py', '#src/glsl/builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
95
96 Export('builtin_glsl_function')
97
98 if env['hostonly']:
99 Return()
100
101
102 glsl_sources += builtin_glsl_function
103
104 glsl = env.ConvenienceLibrary(
105 target = 'glsl',
106 source = glsl_sources,
107 )
108
109 # SCons builtin dependency scanner doesn't detect that glsl_lexer.ll depends on
110 # glsl_parser.h
111 env.Depends(glsl, glsl_parser)
112
113 Export('glsl')
114
115 # Skip building these programs as they will cause SCons error "Two environments
116 # with different actions were specified for the same target"
117 if env['crosscompile'] or env['embedded']:
118 Return()
119
120 env = env.Clone()
121
122 if env['platform'] == 'windows':
123 env.PrependUnique(LIBS = [
124 'user32',
125 ])
126
127 env.Prepend(LIBS = [glsl])
128
129 glsl2 = env.Program(
130 target = 'glsl2',
131 source = compiler_objs,
132 )
133 env.Alias('glsl2', glsl2)
134
135 glcpp = env.Program(
136 target = 'glcpp/glcpp',
137 source = ['glcpp/glcpp.c'] + mesa_objs,
138 )
139 env.Alias('glcpp', glcpp)