• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Import('*')
2
3from sys import executable as python_cmd
4import os.path
5import distutils.version
6
7if not env['swr']:
8    Return()
9
10if not env['llvm']:
11    print 'warning: LLVM disabled: not building swr'
12    env['swr'] = False
13    Return()
14
15if env['LLVM_VERSION'] < distutils.version.LooseVersion('3.9'):
16    print "warning: swr requires LLVM >= 3.9: not building swr"
17    env['swr'] = False
18    Return()
19
20if env['platform'] != 'windows':
21    print "warning: swr scons build only supports windows: not building swr"
22    env['swr'] = False
23    Return()
24
25env.MSVC2013Compat()
26
27env = env.Clone()
28
29# construct llvm include dir
30if env['platform'] == 'windows':
31    # on windows there is no llvm-config, so LLVM is defined
32    llvm_includedir = os.path.join(os.environ['LLVM'], 'include')
33else:
34    llvm_config = os.environ.get('LLVM_CONFIG', 'llvm-config')
35    llvm_includedir = env.backtick('%s --includedir' % llvm_config).rstrip()
36    print "llvm include dir %s" % llvm_includedir
37
38# the loader is included in the mesa lib itself
39# All the remaining files are in loadable modules
40loadersource = env.ParseSourceList('Makefile.sources', [
41    'LOADER_SOURCES'
42])
43
44env.Append(CPPDEFINES = [
45    '__STDC_CONSTANT_MACROS',
46    '__STDC_LIMIT_MACROS'
47    ])
48
49if not env['msvc'] :
50    env.Append(CCFLAGS = [
51        '-std=c++11',
52    ])
53
54swrroot = '#src/gallium/drivers/swr/'
55
56env.CodeGenerate(
57    target = 'rasterizer/scripts/gen_knobs.cpp',
58    script = swrroot + 'rasterizer/scripts/gen_knobs.py',
59    source = 'rasterizer/scripts/templates/knobs.template',
60    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_cpp'
61)
62
63env.CodeGenerate(
64    target = 'rasterizer/scripts/gen_knobs.h',
65    script = swrroot + 'rasterizer/scripts/gen_knobs.py',
66    source = 'rasterizer/scripts/templates/knobs.template',
67    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_h'
68)
69
70env.CodeGenerate(
71    target = 'rasterizer/jitter/state_llvm.h',
72    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_types.py',
73    source = 'rasterizer/core/state.h',
74    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET'
75)
76
77env.CodeGenerate(
78    target = 'rasterizer/jitter/builder_gen.h',
79    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
80    source = os.path.join(llvm_includedir, 'llvm/IR/IRBuilder.h'),
81    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_h'
82)
83
84env.CodeGenerate(
85    target = 'rasterizer/jitter/builder_gen.cpp',
86    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
87    source = os.path.join(llvm_includedir, 'llvm/IR/IRBuilder.h'),
88    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_cpp'
89)
90
91env.CodeGenerate(
92    target = 'rasterizer/jitter/builder_x86.h',
93    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
94    source = '',
95    command = python_cmd + ' $SCRIPT --output $TARGET --gen_x86_h'
96)
97
98env.CodeGenerate(
99    target = 'rasterizer/jitter/builder_x86.cpp',
100    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
101    source = '',
102    command = python_cmd + ' $SCRIPT --output $TARGET --gen_x86_cpp'
103)
104
105env.CodeGenerate(
106    target = 'swr_context_llvm.h',
107    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_types.py',
108    source = 'swr_context.h',
109    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET'
110)
111
112env.CodeGenerate(
113    target = 'rasterizer/archrast/gen_ar_event.h',
114    script = swrroot + 'rasterizer/scripts/gen_archrast.py',
115    source = 'rasterizer/archrast/events.proto',
116    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_event_h'
117)
118
119env.CodeGenerate(
120    target = 'rasterizer/archrast/gen_ar_event.cpp',
121    script = swrroot + 'rasterizer/scripts/gen_archrast.py',
122    source = 'rasterizer/archrast/events.proto',
123    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_event_cpp'
124)
125
126env.CodeGenerate(
127    target = 'rasterizer/archrast/gen_ar_eventhandler.h',
128    script = swrroot + 'rasterizer/scripts/gen_archrast.py',
129    source = 'rasterizer/archrast/events.proto',
130    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandler_h'
131)
132
133env.CodeGenerate(
134    target = 'rasterizer/archrast/gen_ar_eventhandlerfile.h',
135    script = swrroot + 'rasterizer/scripts/gen_archrast.py',
136    source = 'rasterizer/archrast/events.proto',
137    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandlerfile_h'
138)
139
140# Auto-generated .cpp files (that need to generate object files)
141built_sources = [
142    'rasterizer/scripts/gen_knobs.cpp',
143    'rasterizer/jitter/builder_gen.cpp',
144    'rasterizer/jitter/builder_x86.cpp',
145    'rasterizer/archrast/gen_ar_event.cpp',
146    ]
147
148source = built_sources
149source += env.ParseSourceList(swrroot + 'Makefile.sources', [
150    'CXX_SOURCES',
151    'ARCHRAST_CXX_SOURCES',
152    'COMMON_CXX_SOURCES',
153    'CORE_CXX_SOURCES',
154    'JITTER_CXX_SOURCES',
155    'MEMORY_CXX_SOURCES'
156])
157
158env.Prepend(LIBS = [ mesautil, mesa, gallium ])
159
160env.Prepend(CPPPATH = [
161    '.',
162    'rasterizer',
163    'rasterizer/scripts',
164    'rasterizer/core',
165    'rasterizer/jitter',
166    'rasterizer/archrast',
167    ])
168
169# AVX lib
170envavx = env.Clone()
171
172envavx.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX'])
173if env['platform'] == 'windows':
174    envavx.Append(CCFLAGS = ['/arch:AVX'])
175else:
176    envavx.Append(CCFLAGS = ['-mavx'])
177
178swrAVX = envavx.SharedLibrary(
179    target = 'swrAVX',
180    source = source,
181    OBJPREFIX = 'avx_'
182    )
183env.Alias('swrAVX', swrAVX)
184
185# AVX2 lib
186envavx2 = env.Clone()
187
188envavx2.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX2'])
189if env['platform'] == 'windows':
190    envavx2.Append(CCFLAGS = ['/arch:AVX2'])
191else:
192    envavx2.Append(CCFLAGS = ['-mavx2'])
193
194swrAVX2 = envavx2.SharedLibrary(
195    target = 'swrAVX2',
196    source = source,
197    OBJPREFIX = 'avx2_'
198    )
199env.Alias('swrAVX2', swrAVX2)
200
201
202# main SWR lib
203swr = env.ConvenienceLibrary(
204    target = 'swr',
205    source = loadersource,
206    )
207
208
209# treat arch libs as dependencies, even though they are not linked
210# into swr, so we don't have to build them separately
211Depends(swr, ['swrAVX', 'swrAVX2'])
212
213env.Alias('swr', swr)
214
215env.Prepend(LIBS = [swr])
216
217Export('swr')
218