a9d38c163b71c0a44e3e674e90b6a14d3b4c1c2c
[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.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/glsl',
19 '#src/glsl/nir',
20 '#src/glsl/glcpp',
21 ])
22
23 env.Prepend(LIBS = [mesautil])
24
25 # Make glcpp-parse.h and glsl_parser.h reachable from the include path.
26 env.Append(CPPPATH = [Dir('.').abspath, Dir('glcpp').abspath])
27
28 glcpp_env = env.Clone()
29 glcpp_env.Append(YACCFLAGS = [
30 '-d',
31 '-p', 'glcpp_parser_'
32 ])
33
34 glsl_env = env.Clone()
35 glsl_env.Append(YACCFLAGS = [
36 '--defines=%s' % File('glsl_parser.h').abspath,
37 '-p', '_mesa_glsl_',
38 ])
39
40 # without this line scons will expect "glsl_parser.hpp" instead of
41 # "glsl_parser.h", causing glsl_parser.cpp to be regenerated every time
42 glsl_env['YACCHXXFILESUFFIX'] = '.h'
43
44 glcpp_lexer = glcpp_env.CFile('glcpp/glcpp-lex.c', 'glcpp/glcpp-lex.l')
45 glcpp_parser = glcpp_env.CFile('glcpp/glcpp-parse.c', 'glcpp/glcpp-parse.y')
46 glsl_lexer = glsl_env.CXXFile('glsl_lexer.cpp', 'glsl_lexer.ll')
47 glsl_parser = glsl_env.CXXFile('glsl_parser.cpp', 'glsl_parser.yy')
48
49 # common generated sources
50 glsl_sources = [
51 glcpp_lexer,
52 glcpp_parser[0],
53 glsl_lexer,
54 glsl_parser[0],
55 ]
56
57 # parse Makefile.sources
58 source_lists = env.ParseSourceList('Makefile.sources')
59
60 # add non-generated sources
61 for l in ('LIBGLCPP_FILES', 'LIBGLSL_FILES'):
62 glsl_sources += source_lists[l]
63
64 # add nir/glsl_types.cpp manually, because SCons still doesn't know about NIR.
65 # XXX: Remove this once we build NIR and NIR_FILES.
66 glsl_sources += [
67 'nir/glsl_types.cpp',
68 'nir/shader_enums.c',
69 ]
70
71 if env['msvc']:
72 env.Prepend(CPPPATH = ['#/src/getopt'])
73 env.PrependUnique(LIBS = [getopt])
74
75 # Copy these files to avoid generation object files into src/mesa/program
76 env.Prepend(CPPPATH = ['#src/mesa/main'])
77 env.Command('imports.c', '#src/mesa/main/imports.c', Copy('$TARGET', '$SOURCE'))
78 # Copy these files to avoid generation object files into src/mesa/program
79 env.Prepend(CPPPATH = ['#src/mesa/program'])
80 env.Command('prog_hash_table.c', '#src/mesa/program/prog_hash_table.c', Copy('$TARGET', '$SOURCE'))
81 env.Command('symbol_table.c', '#src/mesa/program/symbol_table.c', Copy('$TARGET', '$SOURCE'))
82 env.Command('dummy_errors.c', '#src/mesa/program/dummy_errors.c', Copy('$TARGET', '$SOURCE'))
83
84 compiler_objs = env.StaticObject(source_lists['GLSL_COMPILER_CXX_FILES'])
85
86 mesa_objs = env.StaticObject([
87 'imports.c',
88 'prog_hash_table.c',
89 'symbol_table.c',
90 'dummy_errors.c',
91 ])
92
93 compiler_objs += mesa_objs
94
95 glsl = env.ConvenienceLibrary(
96 target = 'glsl',
97 source = glsl_sources,
98 )
99
100 # SCons builtin dependency scanner doesn't detect that glsl_lexer.ll depends on
101 # glsl_parser.h
102 env.Depends(glsl, glsl_parser)
103
104 Export('glsl')
105
106 # Skip building these programs as they will cause SCons error "Two environments
107 # with different actions were specified for the same target"
108 if env['crosscompile'] or env['embedded']:
109 Return()
110
111 env = env.Clone()
112
113 if env['platform'] == 'windows':
114 env.PrependUnique(LIBS = [
115 'user32',
116 ])
117
118 env.Prepend(LIBS = [glsl])
119
120 glsl_compiler = env.Program(
121 target = 'glsl_compiler',
122 source = compiler_objs,
123 )
124 env.Alias('glsl_compiler', glsl_compiler)
125
126 glcpp = env.Program(
127 target = 'glcpp/glcpp',
128 source = ['glcpp/glcpp.c'] + mesa_objs,
129 )
130 env.Alias('glcpp', glcpp)