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