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