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':
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'))
35 opt
.load('compiler_c')
36 opt
.load('compiler_cxx')
39 opt
.add_option('--mode', action
= 'store', default
= 'debug', help = 'the mode to compile in (debug/release)')
40 opt
.add_option('--static', action
= 'store', default
= 'false', help = 'build a static library (true/false)')
41 opt
.add_option('--filters', action
= 'store', default
= 'true', help = 'build included filters (true/false)')
42 opt
.add_option('--cython', action
= 'store', default
= 'true', help = 'build Cython wrapper (true/false)')
43 opt
.add_option('--avisynth', action
= 'store', default
= 'true', help = 'build Avisynth compatibility layer (true/false)')
46 def add_options(flags
, options
):
48 for option
in options
:
49 if option
not in conf
.env
[flag
]:
50 conf
.env
.append_value(flag
, option
)
52 conf
.load('compiler_c')
53 conf
.load('compiler_cxx')
56 # Load Yasm explicitly, then the Nasm module which
57 # supports both Nasm and Yasm.
58 conf
.find_program('yasm', var
= 'AS', mandatory
= True)
61 if conf
.env
.DEST_OS
== 'darwin':
62 if conf
.env
.CXX_NAME
== 'gcc':
63 add_options(['ASFLAGS'],
66 if conf
.env
.CXX_NAME
== 'gcc':
67 add_options(['CFLAGS', 'CXXFLAGS'],
70 elif conf
.env
.CXX_NAME
== 'msvc':
71 add_options(['CFLAGS', 'CXXFLAGS'],
76 add_options(['ASFLAGS'],
79 '-Wunrecognized-char'])
81 if conf
.env
.DEST_CPU
in ['x86_64', 'amd64', 'x64']:
82 add_options(['ASFLAGS'],
85 if conf
.env
.DEST_OS
== 'darwin':
87 elif conf
.env
.DEST_OS
== 'win32':
92 add_options(['ASFLAGS'],
95 if conf
.env
.DEST_OS
== 'darwin':
97 elif conf
.env
.DEST_OS
== 'win32':
102 add_options(['ASFLAGS'],
103 ['-f{0}'.format(fmt
)])
105 if conf
.options
.mode
== 'debug':
106 if conf
.env
.CXX_NAME
== 'gcc':
107 add_options(['CFLAGS', 'CXXFLAGS'],
112 elif conf
.env
.CXX_NAME
== 'msvc':
113 add_options(['CFLAGS', 'CXXFLAGS'],
117 add_options(['ASFLAGS'],
119 elif conf
.options
.mode
== 'release':
120 if conf
.env
.CXX_NAME
== 'gcc':
121 add_options(['CFLAGS', 'CXXFLAGS'],
123 elif conf
.env
.CXX_NAME
== 'msvc':
124 add_options(['CFLAGS', 'CXXFLAGS'],
127 conf
.fatal('--mode must be either debug or release.')
129 # Waf always uses gcc/g++ for linking when using a GCC
130 # compatible C/C++ compiler.
131 if conf
.env
.CXX_NAME
== 'gcc':
132 add_options(['LINKFLAGS_cxxshlib', 'LINKFLAGS_cxxprogram'],
135 conf
.env
.STATIC
= conf
.options
.static
137 if not conf
.env
.STATIC
in ['true', 'false']:
138 conf
.fatal('--static must be either true or false.')
140 conf
.env
.FILTERS
= conf
.options
.filters
142 if not conf
.env
.FILTERS
in ['true', 'false']:
143 conf
.fatal('--filters must be either true or false.')
145 conf
.env
.CYTHON
= conf
.options
.cython
147 if not conf
.env
.CYTHON
in ['true', 'false']:
148 conf
.fatal('--cython must be either true or false.')
150 conf
.env
.AVISYNTH
= conf
.options
.avisynth
152 if not conf
.env
.AVISYNTH
in ['true', 'false']:
153 conf
.fatal('--avisynth must be either true or false.')
155 conf
.check_cxx(lib
= 'QtCore')
156 conf
.check_cxx(use
= ['QTCORE'], header_name
= 'QtCore/QtCore')
157 conf
.check_cxx(use
= ['QTCORE'], header_name
= 'QtCore/QtCore', type_name
= 'QAtomicInt')
159 conf
.check_cc(lib
= 'avutil')
160 conf
.check_cc(use
= ['AVUTIL'], header_name
= 'libavutil/avutil.h')
161 conf
.check_cc(use
= ['AVUTIL'], header_name
= 'libavutil/avutil.h', function_name
= 'avutil_license')
163 conf
.check_cc(lib
= 'swscale')
164 conf
.check_cc(use
= ['SWSCALE'], header_name
= 'libswscale/swscale.h')
165 conf
.check_cc(use
= ['SWSCALE'], header_name
= 'libswscale/swscale.h', function_name
= 'swscale_license')
168 def search_paths(paths
):
172 srcpaths
+= [os
.path
.join(path
, '*.c'),
173 os
.path
.join(path
, '*.cpp'),
174 os
.path
.join(path
, '*.asm')]
178 sources
= search_paths([os
.path
.join('src', 'core'),
179 os
.path
.join('src', 'core', 'asm')])
181 if bld
.env
.DEST_OS
== 'win32' and bld
.env
.AVISYNTH
== 'true':
182 sources
+= search_paths([os
.path
.join('src', 'avisynth')])
184 bld(features
= 'c qxx asm',
185 includes
= 'include',
186 use
= ['QTCORE', 'AVUTIL', 'SWSCALE'],
187 source
= bld
.path
.ant_glob(sources
),
190 bld(features
= 'c qxx asm cxxshlib',
192 target
= 'vapoursynth',
193 install_path
= '${PREFIX}/lib')
195 if bld
.env
.STATIC
== 'true':
196 bld(features
= 'c qxx asm cxxstlib',
197 use
= ['objs', 'QTCORE', 'AVUTIL', 'SWSCALE'],
198 target
= 'vapoursynth',
199 install_path
= '${PREFIX}/lib')
201 if bld
.env
.FILTERS
== 'true':
202 bld(features
= 'c qxx asm cxxshlib',
203 includes
= 'include',
204 use
= ['vapoursynth'],
205 source
= bld
.path
.ant_glob(search_paths([os
.path
.join('src', 'filters', 'eedi3')])),
207 install_path
= '${PREFIX}/lib/vapoursynth')
209 if bld
.env
.CYTHON
== 'true':
210 bld(features
= 'preproc',
211 source
= bld
.path
.ant_glob([os
.path
.join('src', 'cython', '*.pyx')]),
214 bld
.install_files('${PREFIX}/include', os
.path
.join('include', 'VapourSynth.h'))