4 from waflib
import Task
, TaskGen
, Utils
6 APPNAME
= 'VapourSynth'
12 class preproc(Task
.Task
):
13 "Preprocess Cython source files"
20 if self
.env
.CXX_NAME
== 'gcc':
21 params
= ['-E', '-x', 'c']
22 elif self
.env
.CXX_NAME
== 'msvc':
23 params
= ['/nologo', '/E']
25 args
= [Utils
.subst_vars('${CC}', self
.env
)] + params
+ [self
.inputs
[0].abspath()]
27 with
open(self
.outputs
[0].abspath(), 'w') as f
:
28 subprocess
.Popen(args
, stdout
= f
).wait()
30 @TaskGen.extension('.pyx')
31 def add_pyx_file(self
, node
):
32 self
.create_task('preproc', node
, node
.get_bld().change_ext('.pyx'))
34 class docs(Task
.Task
):
35 "Build Sphinx documentation"
42 subprocess
.Popen('make html BUILDDIR={0}'.format(os
.path
.join(os
.pardir
, OUT
)),
45 stdout
= subprocess
.PIPE
).wait()
47 @TaskGen.feature('docs')
48 @TaskGen.before_method('process_source')
53 for x
in self
.to_nodes(self
.source
):
54 if x
.name
.endswith('.rst'):
59 self
.source
= no_nodes
61 inst
= getattr(self
, 'install_path', '${PREFIX}/share/doc')
62 mod
= getattr(self
, 'chmod', Utils
.O644
)
67 for node
in rst_nodes
:
68 n
= self
.path
.find_node(OUT
).make_node('html')
73 while not cur
is self
.path
.find_node('doc'):
77 for dir in reversed(dirs
):
78 n
= n
.make_node(dir.name
)
80 n
= n
.make_node(node
.name
).change_ext('.html')
87 for dir in reversed(dirs
):
88 path
= os
.path
.join(path
, dir.name
)
90 setattr(self
, 'install_task_{0}'.format(i
), self
.bld
.install_files(path
, n
, env
= self
.env
, chmod
= mod
))
94 self
.rst_task
= self
.create_task('docs', rst_nodes
, bld_nodes
)
97 opt
.load('compiler_c')
98 opt
.load('compiler_cxx')
101 opt
.add_option('--mode', action
= 'store', default
= 'release', help = 'the mode to compile in (debug/release)')
102 opt
.add_option('--static', action
= 'store', default
= 'false', help = 'build a static library (true/false)')
103 opt
.add_option('--filters', action
= 'store', default
= 'true', help = 'build included filters (true/false)')
104 opt
.add_option('--cython', action
= 'store', default
= 'true', help = 'build Cython wrapper (true/false)')
105 opt
.add_option('--avisynth', action
= 'store', default
= 'true', help = 'build Avisynth compatibility layer (true/false)')
106 opt
.add_option('--docs', action
= 'store', default
= 'false', help = 'build the documentation (true/false)')
107 opt
.add_option('--examples', action
= 'store', default
= 'false', help = 'install SDK examples (true/false)')
110 def add_options(flags
, options
):
112 for option
in options
:
113 if option
not in conf
.env
[flag
]:
114 conf
.env
.append_value(flag
, option
)
116 conf
.load('compiler_c')
117 conf
.load('compiler_cxx')
120 # Load Yasm explicitly, then the Nasm module which
121 # supports both Nasm and Yasm.
122 conf
.find_program('yasm', var
= 'AS', mandatory
= True)
125 if conf
.env
.DEST_OS
in ['cygwin', 'darwin']:
126 if conf
.env
.CXX_NAME
== 'gcc':
127 add_options(['ASFLAGS'],
130 if conf
.env
.CXX_NAME
== 'gcc':
131 add_options(['CFLAGS', 'CXXFLAGS'],
134 elif conf
.env
.CXX_NAME
== 'msvc':
135 add_options(['CFLAGS', 'CXXFLAGS'],
140 add_options(['ASFLAGS'],
143 '-Wunrecognized-char'])
145 if conf
.env
.DEST_CPU
in ['x86_64', 'amd64', 'x64']:
146 add_options(['ASFLAGS'],
149 if conf
.env
.DEST_OS
== 'darwin':
151 elif conf
.env
.DEST_OS
== 'win32':
156 add_options(['ASFLAGS'],
159 if conf
.env
.DEST_OS
== 'darwin':
161 elif conf
.env
.DEST_OS
== 'win32':
166 add_options(['ASFLAGS'],
167 ['-f{0}'.format(fmt
)])
169 if conf
.options
.mode
== 'debug':
170 if conf
.env
.CXX_NAME
== 'gcc':
171 add_options(['CFLAGS', 'CXXFLAGS'],
176 elif conf
.env
.CXX_NAME
== 'msvc':
177 add_options(['CFLAGS', 'CXXFLAGS'],
181 add_options(['ASFLAGS'],
183 elif conf
.options
.mode
== 'release':
184 if conf
.env
.CXX_NAME
== 'gcc':
185 add_options(['CFLAGS', 'CXXFLAGS'],
187 elif conf
.env
.CXX_NAME
== 'msvc':
188 add_options(['CFLAGS', 'CXXFLAGS'],
191 conf
.fatal('--mode must be either debug or release.')
193 # Waf always uses gcc/g++ for linking when using a GCC
194 # compatible C/C++ compiler.
195 if conf
.env
.CXX_NAME
== 'gcc':
196 add_options(['LINKFLAGS_cxxshlib', 'LINKFLAGS_cxxprogram'],
199 conf
.env
.STATIC
= conf
.options
.static
200 conf
.env
.FILTERS
= conf
.options
.filters
201 conf
.env
.CYTHON
= conf
.options
.cython
202 conf
.env
.AVISYNTH
= conf
.options
.avisynth
203 conf
.env
.DOCS
= conf
.options
.docs
204 conf
.env
.EXAMPLES
= conf
.options
.examples
206 for opt
in ['static', 'filters', 'cython', 'avisynth', 'docs', 'examples']:
207 if not conf
.env
[opt
.upper()] in ['true', 'false']:
208 conf
.fatal('--%s must be either true or false.'.format(opt
))
210 conf
.check_cxx(use
= ['QTCORE'], header_name
= 'QtCore/QtCore')
211 conf
.check_cxx(use
= ['QTCORE'], header_name
= 'QtCore/QtCore', type_name
= 'QAtomicInt')
213 conf
.check_cc(lib
= 'avutil')
214 conf
.check_cc(use
= ['AVUTIL'], header_name
= 'libavutil/avutil.h')
215 conf
.check_cc(use
= ['AVUTIL'], header_name
= 'libavutil/avutil.h', function_name
= 'avutil_license')
217 conf
.check_cc(lib
= 'swscale')
218 conf
.check_cc(use
= ['SWSCALE'], header_name
= 'libswscale/swscale.h')
219 conf
.check_cc(use
= ['SWSCALE'], header_name
= 'libswscale/swscale.h', function_name
= 'swscale_license')
223 if not conf
.env
.DEST_OS
in ['darwin', 'freebsd', 'netbsd', 'openbsd']:
226 conf
.env
.LIBS
= libs
.strip()
229 def search_paths(paths
):
233 srcpaths
+= [os
.path
.join(path
, '*.c'),
234 os
.path
.join(path
, '*.cpp'),
235 os
.path
.join(path
, '*.asm')]
239 sources
= search_paths([os
.path
.join('src', 'core'),
240 os
.path
.join('src', 'core', 'asm')])
242 if bld
.env
.DEST_OS
== 'win32' and bld
.env
.AVISYNTH
== 'true':
243 sources
+= search_paths([os
.path
.join('src', 'avisynth')])
245 bld(features
= 'c qxx asm',
246 includes
= 'include',
247 use
= ['QTCORE', 'SWSCALE', 'AVUTIL'],
248 source
= bld
.path
.ant_glob(sources
),
251 bld(features
= 'c qxx asm cxxshlib',
253 target
= 'vapoursynth',
254 install_path
= '${PREFIX}/lib')
256 if bld
.env
.STATIC
== 'true':
257 bld(features
= 'c qxx asm cxxstlib',
258 use
= ['objs', 'QTCORE', 'SWSCALE', 'AVUTIL'],
259 target
= 'vapoursynth',
260 install_path
= '${PREFIX}/lib')
262 if bld
.env
.FILTERS
== 'true':
263 bld(features
= 'c qxx asm cxxshlib',
264 includes
= 'include',
265 use
= ['vapoursynth'],
266 source
= bld
.path
.ant_glob(search_paths([os
.path
.join('src', 'filters', 'eedi3')])),
268 install_path
= '${PREFIX}/lib/vapoursynth')
270 if bld
.env
.CYTHON
== 'true':
271 bld(features
= 'preproc',
272 source
= bld
.path
.ant_glob([os
.path
.join('src', 'cython', '*.pyx')]))
274 if bld
.env
.DOCS
== 'true':
275 bld(features
= 'docs',
276 source
= bld
.path
.ant_glob([os
.path
.join('doc', '*.rst'),
277 os
.path
.join('doc', '**', '*.rst')]),
278 install_path
= '${PREFIX}/share/doc/vapoursynth')
280 if bld
.env
.EXAMPLES
== 'true':
281 bld(features
= 'c cxxshlib',
282 includes
= 'include',
283 use
= ['vapoursynth'],
284 source
= os
.path
.join('sdk', 'filter_skeleton.c'),
285 target
= 'example_skeleton',
288 bld(features
= 'c cxxshlib',
289 includes
= 'include',
290 use
= ['vapoursynth'],
291 source
= os
.path
.join('sdk', 'invert_example.c'),
292 target
= 'example_invert',
295 bld
.install_files('${PREFIX}/share/doc/vapoursynth/examples',
296 bld
.path
.ant_glob([os
.path
.join('sdk', '*')]))
298 bld
.install_files('${PREFIX}/include', os
.path
.join('include', 'VapourSynth.h'))
300 bld(source
= 'vapoursynth.pc.in',
301 install_path
= '${PREFIX}/lib/pkgconfig',
302 PREFIX
= bld
.env
.PREFIX
,