-
Notifications
You must be signed in to change notification settings - Fork 1
/
wscript
541 lines (426 loc) · 19.6 KB
/
wscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
import glob, os, subprocess, sys
from waflib import Build, Task, TaskGen, Utils
APPNAME = 'VapourSynth'
VERSION = '19'
TOP = os.curdir
OUT = 'build'
class docs(Task.Task):
"Build Sphinx documentation"
ext_out = ['.html']
inst_to = None
color = 'PINK'
def run(self):
subprocess.Popen('make html BUILDDIR={0}'.format(os.path.join(os.pardir, OUT)),
shell = True,
cwd = 'doc',
stdout = subprocess.PIPE).wait()
@TaskGen.feature('docs')
@TaskGen.before_method('process_source')
def apply_rst(self):
rst_nodes = []
no_nodes = []
for x in self.to_nodes(self.source):
if x.name.endswith('.rst'):
rst_nodes.append(x)
else:
no_nodes.append(x)
self.source = no_nodes
inst = getattr(self, 'install_path', '${DOCDIR}')
mod = getattr(self, 'chmod', Utils.O644)
bld_nodes = []
i = 0
for node in rst_nodes:
n = self.path.find_node(OUT).make_node('html')
cur = node.parent
dirs = []
while not cur is self.path.find_node('doc'):
dirs.append(cur)
cur = cur.parent
for dir in reversed(dirs):
n = n.make_node(dir.name)
n = n.make_node(node.name).change_ext('.html')
bld_nodes.append(n)
if inst:
path = inst
for dir in reversed(dirs):
path = os.path.join(path, dir.name)
setattr(self, 'install_task_{0}'.format(i), self.bld.install_files(path, n, env = self.env, chmod = mod))
i += 1
self.rst_task = self.create_task('docs', rst_nodes, bld_nodes)
def options(opt):
opt.load('compiler_c')
opt.load('compiler_cxx')
opt.load('qt4')
opt.add_option('--libdir', action = 'store', default = '${PREFIX}/lib', help = 'library installation directory')
opt.add_option('--plugindir', action = 'store', default = '${LIBDIR}/vapoursynth', help = 'plugin installation directory')
opt.add_option('--docdir', action = 'store', default = '${PREFIX}/share/doc/vapoursynth', help = 'documentation installation directory')
opt.add_option('--includedir', action = 'store', default = '${PREFIX}/include/vapoursynth', help = 'header installation directory')
opt.add_option('--mode', action = 'store', default = 'release', help = 'the mode to compile in (debug/release)')
opt.add_option('--shared', action = 'store', default = 'true', help = 'build shared libraries (true/false)')
opt.add_option('--static', action = 'store', default = 'false', help = 'build static libraries (true/false)')
opt.add_option('--core', action = 'store', default = 'true', help = 'build the libvapoursynth library (true/false)')
opt.add_option('--avisynth', action = 'store', default = 'true', help = 'build Avisynth compatibility layer (true/false)')
opt.add_option('--script', action = 'store', default = 'true', help = 'build the libvapoursynth-script library (true/false)')
opt.add_option('--pipe', action = 'store', default = 'true', help = 'build the vspipe program (true/false)')
opt.add_option('--filters', action = 'store', default = 'true', help = 'build included filters (true/false)')
opt.add_option('--examples', action = 'store', default = 'false', help = 'install SDK examples (true/false)')
opt.add_option('--cuda', action = 'store', default = 'true', help = 'build with CUDA enhancements (true/false)')
opt.add_option('--docs', action = 'store', default = 'false', help = 'build the documentation (true/false)')
def configure(conf):
def add_options(flags, options):
for flag in flags:
conf.env.append_unique(flag, options)
conf.load('compiler_c')
conf.load('compiler_cxx')
# Normalize OS.
os = 'windows' if conf.env.DEST_OS in ['win32', 'cygwin', 'msys', 'uwin'] else conf.env.DEST_OS
conf.define('VS_TARGET_OS_' + os.upper(), 1)
conf.msg('Settting DEST_OS to', conf.env.DEST_OS)
# Normalize CPU values.
if conf.env.DEST_CPU in ['x86', 'x86_64', 'x64', 'amd64', 'x86_amd64']:
cpu = 'x86'
elif conf.env.DEST_CPU == 'ia':
cpu = 'ia64'
elif conf.env.DEST_CPU in ['aarch64', 'thumb']:
cpu = 'arm'
elif conf.env.DEST_CPU == 's390x':
cpu = 's390'
else:
cpu = conf.env.DEST_CPU
conf.define('VS_TARGET_CPU_' + cpu.upper(), 1)
conf.msg('Settting DEST_CPU to', conf.env.DEST_CPU)
# No need to sanitize BINFMT.
conf.define('VS_TARGET_BINFMT_' + conf.env.DEST_BINFMT.upper(), 1)
conf.msg('Settting DEST_BINFMT to', conf.env.DEST_BINFMT)
for x in ['shared',
'static',
'core',
'avisynth',
'script',
'pipe',
'filters',
'examples',
'docs',
'cuda']:
val = conf.options.__dict__[x]
if not val in ['true', 'false']:
conf.fatal('--{0} must be either true or false.'.format(x))
else:
u = x.upper()
conf.env[u] = val
conf.define('VS_FEATURE_' + u, 1 if val == 'true' else 0)
if conf.env.CORE == 'false':
conf.env.AVISYNTH = 'false'
conf.env.SCRIPT = 'false'
if 'false' in [conf.env.CORE, conf.env.SCRIPT]:
conf.env.PIPE = 'false'
if conf.env.CORE == 'false' and \
conf.env.SCRIPT == 'false' and \
conf.env.FILTERS == 'false' and \
conf.env.EXAMPLES == 'false':
conf.env.SHARED = 'false'
conf.env.STATIC = 'false'
else:
if (conf.env.SHARED, conf.env.STATIC) == ('false', 'false') and not have_libs:
conf.fatal('--static and --shared cannot both be false.')
for (x, y) in [('SHARED', 'shared libraries'),
('STATIC', 'static libraries'),
('CORE', 'libvapoursynth'),
('AVISYNTH', 'Avisynth compatibility'),
('SCRIPT', 'libvapoursynth-script'),
('PIPE', 'vspipe'),
('FILTERS', 'included filters'),
('EXAMPLES', 'plugin examples'),
('DOCS', 'documentation'),
('CUDA', 'CUDA support')]:
conf.msg('Enabling {0}?'.format(y), 'yes' if conf.env[x] == 'true' else 'no')
conf.define('VS_PATH_PREFIX', conf.env.PREFIX)
conf.msg('Setting PREFIX to', conf.env.PREFIX)
for dir in ['libdir', 'plugindir', 'docdir', 'includedir']:
u = dir.upper()
conf.env[u] = Utils.subst_vars(conf.options.__dict__[dir], conf.env)
conf.define('VS_PATH_' + u, conf.env[u])
conf.msg('Setting {0} to'.format(u), conf.env[u])
if conf.options.cuda == 'true':
conf.load('cuda')
gpu_archs = ['-gencode', 'arch=compute_20,code=sm_20',
'-gencode', 'arch=compute_20,code=sm_21',
'-gencode', 'arch=compute_30,code=sm_30',
'-gencode', 'arch=compute_35,code=sm_35']
for arch in gpu_archs:
conf.env.append_value('CUDAFLAGS', arch)
if conf.env.DEST_CPU in ['x86', 'x86_64', 'x64', 'amd64', 'x86_amd64']:
# Load Yasm explicitly, then the Nasm module which
# supports both Nasm and Yasm.
conf.find_program('yasm', var = 'AS', mandatory = True)
conf.load('nasm')
add_options(['ASFLAGS'],
['-w',
'-Worphan-labels',
'-Wunrecognized-char',
'-Dprogram_name=vs'])
else:
# For all non-x86 targets, use the GNU assembler.
# Waf uses GCC instead of the assembler directly.
conf.load('gas')
if conf.env.DEST_OS == 'darwin' and conf.env.DEST_CPU in ['x86', 'x86_64']:
if conf.env.CXX_NAME == 'gcc':
add_options(['ASFLAGS'],
['-DPREFIX=1'])
if conf.env.CXX_NAME == 'gcc':
add_options(['CFLAGS', 'CXXFLAGS'],
['-DVS_CORE_EXPORTS',
'-fPIC'])
elif conf.env.CXX_NAME == 'msvc':
add_options(['CFLAGS', 'CXXFLAGS'],
['/DVS_CORE_EXPORTS',
'/EHsc',
'/Zc:wchar_t-'])
if conf.env.DEST_CPU in ['x86_64', 'x64', 'amd64', 'x86_amd64']:
add_options(['ASFLAGS'],
['-DARCH_X86_64=1',
'-DPIC=1'])
if conf.options.cuda == 'true':
add_options(['CUDAFLAGS'], ['-m64'])
if conf.env.DEST_OS == 'darwin':
fmt = 'macho64'
elif conf.env.DEST_OS in ['win32', 'cygwin', 'msys', 'uwin']:
fmt = 'win64'
else:
fmt = 'elf64'
elif conf.env.DEST_CPU == 'x86':
add_options(['ASFLAGS'],
['-DARCH_X86_64=0'])
if conf.options.cuda == 'true':
add_options(['CUDAFLAGS'], ['-m32'])
if conf.env.DEST_OS == 'darwin':
fmt = 'macho32'
elif conf.env.DEST_OS in ['win32', 'cygwin', 'msys', 'uwin']:
fmt = 'win32'
else:
fmt = 'elf32'
if conf.env.DEST_CPU in ['x86', 'x86_64', 'x64', 'amd64', 'x86_amd64']:
add_options(['ASFLAGS'],
['-f{0}'.format(fmt)])
if conf.options.mode == 'debug':
if conf.env.CXX_NAME == 'gcc':
add_options(['CFLAGS', 'CXXFLAGS'],
['-DVS_CORE_DEBUG',
'-g',
'-ggdb',
'-ftrapv'])
elif conf.env.CXX_NAME == 'msvc':
add_options(['CFLAGS', 'CXXFLAGS'],
['/DVS_CORE_DEBUG',
'/Z7'])
add_options(['ASFLAGS'],
['-DVS_CORE_DEBUG'])
if conf.env.DEST_CPU in ['x86', 'x86_64', 'x64', 'amd64', 'x86_amd64']:
if conf.env.DEST_OS in ['win32', 'cygwin', 'msys', 'uwin']:
dbgfmt = 'cv8'
else:
dbgfmt = 'dwarf2'
add_options(['ASFLAGS'],
['-g{0}'.format(dbgfmt)])
else:
add_options(['ASFLAGS'],
['-Wa,-g'])
if conf.options.cuda == 'true':
add_options(['NVCC_CXXFLAGS'], ['-g', '-G'])
elif conf.options.mode == 'release':
if conf.env.CXX_NAME == 'gcc':
add_options(['CFLAGS', 'CXXFLAGS'],
['-O3'])
elif conf.env.CXX_NAME == 'msvc':
add_options(['CFLAGS', 'CXXFLAGS'],
['/Ox'])
else:
conf.fatal('--mode must be either debug or release.')
# Waf always uses gcc/g++ for linking when using a GCC
# compatible C/C++ compiler.
if conf.env.CXX_NAME == 'gcc':
if not conf.env.DEST_OS in ['darwin', 'win32', 'cygwin', 'msys', 'uwin']:
add_options(['LINKFLAGS_cshlib',
'LINKFLAGS_cprogram',
'LINKFLAGS_cxxshlib',
'LINKFLAGS_cxxprogram'],
['-Wl,-Bsymbolic',
'-Wl,-z,noexecstack'])
if conf.env.CORE == 'true':
conf.load('qt4')
conf.check_cxx(use = ['QTCORE'], header_name = 'QtCore/QtCore')
conf.check_cxx(use = ['QTCORE'], header_name = 'QtCore/QtCore', type_name = 'QAtomicInt')
conf.check_cc(lib = 'swscale')
conf.check_cc(use = ['SWSCALE'], header_name = 'libswscale/swscale.h')
conf.check_cc(use = ['SWSCALE'], header_name = 'libswscale/swscale.h', function_name = 'swscale_license')
conf.check_cc(lib = 'avutil')
conf.check_cc(use = ['AVUTIL'], header_name = 'libavutil/avutil.h')
conf.check_cc(use = ['AVUTIL'], header_name = 'libavutil/avutil.h', function_name = 'avutil_license')
conf.check_cc(lib = 'avcodec')
conf.check_cc(use = ['AVCODEC'], header_name = 'libavcodec/avcodec.h')
conf.check_cc(use = ['AVCODEC'], header_name = 'libavcodec/avcodec.h', function_name = 'avcodec_license')
if conf.env.SCRIPT == 'true':
conf.load('python')
conf.check_python_version((3, 0, 0))
conf.check_python_headers()
if 'true' in [conf.env.CORE, conf.env.SCRIPT]:
libs = '-lm '
if not conf.env.DEST_OS in ['darwin', 'freebsd', 'netbsd', 'openbsd']:
libs += '-ldl '
conf.env.LIBS = libs.strip()
if conf.env.FILTERS == 'true':
conf.check_cc(lib = 'ass', mandatory = False)
conf.check_cc(use = ['ASS'], header_name = 'ass/ass.h', mandatory = False)
conf.check_cc(use = ['ASS'], header_name = 'ass/ass.h', function_name = 'ass_library_init', mandatory = False)
def convert_cuda_cxx_options():
""" This function is necessary because CUDA's nvcc compiler does not
understand certain options such as 'fPIC', and requires a special secondary flag,
'-Xcompiler', in order to successfully pass 'fPIC' to the C/C++ compiler.
We can't simply change the CXXFLAGS, as -Xcompiler is an invalid option for GCC,
so we simply copy over all options, modifying the 'fPIC' option as we go."""
unsafe_options = conf.env['CXXFLAGS']
safe_options = []
xcompiler_options = []
for option in unsafe_options:
if option in ['-fPIC', '-ggdb', '-ftrapv']:
xcompiler_options.append(option)
else:
safe_options.append(option)
if xcompiler_options:
safe_options.extend(['-Xcompiler', ','.join(xcompiler_options)])
add_options(['NVCC_CXXFLAGS'], safe_options)
convert_cuda_cxx_options()
# Handle CUDA compilation on GCC > 4.6
if conf.env.CC_VERSION >= ('4','7','0'):
print("Fixing CUDA compilation with GCC >= 4.7")
add_options(['NVCC_CXXFLAGS'],['-include','../include/fix_cuda_cxx.h'])
def build(bld):
def search_paths(paths):
srcpaths = []
for path in paths:
srcpaths += [os.path.join(path, '*.c'),
os.path.join(path, '*.cpp')]
if bld.env.CUDA == 'true':
srcpaths += [os.path.join(path, '*.cu')]
if bld.env.DEST_CPU in ['x86', 'x86_64', 'x64', 'amd64', 'x86_amd64']:
srcpaths += [os.path.join(path, '*.asm')]
else:
srcpaths += [os.path.join(path, '*.S')]
return srcpaths
if bld.env.CORE == 'true':
sources = search_paths([os.path.join('src', 'core'),
os.path.join('src', 'core', 'asm')])
if bld.env.DEST_OS in ['win32', 'cygwin', 'msys', 'uwin'] and bld.env.AVISYNTH == 'true':
sources += search_paths([os.path.join('src', 'avisynth')])
bld(features = 'c qxx asm',
includes = 'include',
use = ['QTCORE', 'SWSCALE', 'AVUTIL', 'AVCODEC', 'CUDA', 'CUDART'],
source = bld.path.ant_glob(sources),
target = 'objs')
if bld.env.SHARED == 'true':
bld(features = 'c qxx asm cxxshlib',
use = ['objs'],
target = 'vapoursynth',
install_path = '${LIBDIR}')
if bld.env.STATIC == 'true':
bld(features = 'c qxx asm cxxstlib',
use = ['objs', 'QTCORE', 'SWSCALE', 'AVUTIL', 'AVCODEC'],
target = 'vapoursynth',
install_path = '${LIBDIR}')
if bld.env.SCRIPT == 'true':
script_sources = search_paths([os.path.join('src', 'vsscript')])
bld(features = 'c qxx asm pyembed',
includes = 'include',
use = ['QTCORE', 'SWSCALE', 'AVUTIL', 'AVCODEC'],
source = bld.path.ant_glob(script_sources),
target = 'script_objs')
if bld.env.SHARED == 'true':
bld(features = 'c qxx asm cxxshlib pyembed',
use = ['script_objs'],
target = 'vapoursynth-script',
install_path = '${LIBDIR}')
if bld.env.STATIC == 'true':
bld(features = 'c qxx asm cxxstlib pyembed',
use = ['script_objs', 'QTCORE', 'SWSCALE', 'AVUTIL', 'AVCODEC'],
target = 'vapoursynth-script',
install_path = '${LIBDIR}')
if bld.env.PIPE == 'true':
pipe_sources = search_paths([os.path.join('src', 'vspipe')])
bld(features = 'c qxx asm',
includes = 'include',
use = ['QTCORE', 'SWSCALE', 'AVUTIL', 'AVCODEC'],
source = bld.path.ant_glob(pipe_sources),
target = 'pipe_objs')
bld(features = 'c qxx asm cxxprogram',
includes = 'include',
use = ['pipe_objs', 'vapoursynth', 'vapoursynth-script', 'QTCORE', 'SWSCALE', 'AVUTIL', 'AVCODEC'],
target = 'vspipe')
if bld.env.FILTERS == 'true':
bld(features = 'c qxx asm cxxshlib',
includes = 'include',
source = bld.path.ant_glob(search_paths([os.path.join('src', 'filters', 'eedi3')])),
target = 'eedi3',
install_path = '${PLUGINDIR}')
bld(features = 'c qxx asm cxxshlib',
includes = 'include',
source = bld.path.ant_glob(search_paths([os.path.join('src', 'filters', 'vivtc')])),
target = 'vivtc',
install_path = '${PLUGINDIR}')
if bld.env.LIB_ASS:
bld(features = 'c cxxshlib',
includes = 'include',
use = ['ASS'],
source = bld.path.ant_glob(search_paths([os.path.join('src', 'filters', 'assvapour')])),
target = 'assvapour',
install_path = '${PLUGINDIR}')
bld(features = 'cxx cxxshlib',
includes = 'include',
use = ['CUDA', 'CUDART'],
source = bld.path.ant_glob(search_paths([os.path.join('src', 'filters', 'cuinvert')])),
target = 'cuinvert',
install_path = '${PLUGINDIR}')
if bld.env.DOCS == 'true':
bld(features = 'docs',
source = bld.path.ant_glob([os.path.join('doc', '*.rst'),
os.path.join('doc', '**', '*.rst')]),
install_path = '${DOCDIR}')
if bld.env.EXAMPLES == 'true':
bld(features = 'c cxxshlib',
includes = 'include',
source = os.path.join('sdk', 'filter_skeleton.c'),
target = 'example_skeleton',
install_path = '${PLUGINDIR}')
bld(features = 'c cxxshlib',
includes = 'include',
source = os.path.join('sdk', 'invert_example.c'),
target = 'example_invert',
install_path = '${PLUGINDIR}')
bld.install_files('${DOCDIR}/examples',
bld.path.ant_glob([os.path.join('sdk', '*')]))
if bld.env.CORE == 'true':
bld.install_files('${INCLUDEDIR}', [os.path.join('include', 'VapourSynth.h'),
os.path.join('include', 'VSHelper.h')])
bld(source = os.path.join('pc', 'vapoursynth.pc.in'),
install_path = '${LIBDIR}/pkgconfig',
PREFIX = bld.env.PREFIX,
LIBDIR = bld.env.LIBDIR,
INCLUDEDIR = bld.env.INCLUDEDIR,
LIBS = bld.env.LIBS,
VERSION = VERSION)
if bld.env.SCRIPT == 'true':
bld.install_files('${INCLUDEDIR}', [os.path.join('include', 'VSScript.h')])
bld(source = os.path.join('pc', 'vapoursynth-script.pc.in'),
install_path = '${LIBDIR}/pkgconfig',
PREFIX = bld.env.PREFIX,
LIBDIR = bld.env.LIBDIR,
INCLUDEDIR = bld.env.INCLUDEDIR,
LIBS = bld.env.LIBS,
VERSION = VERSION)
def test(ctx):
'''runs the Cython tests'''
for name in glob.glob(os.path.join('test', '*.py')):
if subprocess.Popen([ctx.env.PYTHON[0], name]).wait() != 0:
ctx.fatal('Test {0} failed'.format(name))
class TestContext(Build.BuildContext):
cmd = 'test'
fun = 'test'