Cygwin needs PREFIX.
[vapoursynth-svn.git] / wscript
bloba8b6ff323cc601c6947889b39a95d5a6f24670f2
1 #!/usr/bin/env python
3 import os, subprocess
4 from waflib import Task, TaskGen, Utils
6 APPNAME = 'VapourSynth'
7 VERSION = '10'
9 TOP = os.curdir
10 OUT = 'build'
12 class preproc(Task.Task):
13 "Preprocess Cython source files"
15 ext_out = ['.pyx']
16 inst_to = None
17 color = 'CYAN'
19 def run(self):
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"
37 ext_out = ['.html']
38 inst_to = None
39 color = 'PINK'
41 def run(self):
42 subprocess.Popen('make html BUILDDIR={0}'.format(os.path.join(os.pardir, OUT)),
43 shell = True,
44 cwd = 'doc',
45 stdout = subprocess.PIPE).wait()
47 @TaskGen.feature('docs')
48 @TaskGen.before_method('process_source')
49 def apply_rst(self):
50 rst_nodes = []
51 no_nodes = []
53 for x in self.to_nodes(self.source):
54 if x.name.endswith('.rst'):
55 rst_nodes.append(x)
56 else:
57 no_nodes.append(x)
59 self.source = no_nodes
61 inst = getattr(self, 'install_path', '${PREFIX}/share/doc')
62 mod = getattr(self, 'chmod', Utils.O644)
64 bld_nodes = []
65 i = 0
67 for node in rst_nodes:
68 n = self.path.find_node(OUT).make_node('html')
70 cur = node.parent
71 dirs = []
73 while not cur is self.path.find_node('doc'):
74 dirs.append(cur)
75 cur = cur.parent
77 for dir in reversed(dirs):
78 n = n.make_node(dir.name)
80 n = n.make_node(node.name).change_ext('.html')
82 bld_nodes.append(n)
84 if inst:
85 path = inst
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))
92 i += 1
94 self.rst_task = self.create_task('docs', rst_nodes, bld_nodes)
96 def options(opt):
97 opt.load('compiler_c')
98 opt.load('compiler_cxx')
99 opt.load('qt4')
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)')
109 def configure(conf):
110 def add_options(flags, options):
111 for flag in flags:
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')
118 conf.load('qt4')
120 # Load Yasm explicitly, then the Nasm module which
121 # supports both Nasm and Yasm.
122 conf.find_program('yasm', var = 'AS', mandatory = True)
123 conf.load('nasm')
125 if conf.env.DEST_OS in ['cygwin', 'darwin']:
126 if conf.env.CXX_NAME == 'gcc':
127 add_options(['ASFLAGS'],
128 ['-DPREFIX'])
130 if conf.env.CXX_NAME == 'gcc':
131 add_options(['CFLAGS', 'CXXFLAGS'],
132 ['-DVSCORE_EXPORTS',
133 '-fPIC'])
134 elif conf.env.CXX_NAME == 'msvc':
135 add_options(['CFLAGS', 'CXXFLAGS'],
136 ['/DVSCORE_EXPORTS',
137 '/EHsc',
138 '/Zc:wchar_t-'])
140 add_options(['ASFLAGS'],
141 ['-w',
142 '-Worphan-labels',
143 '-Wunrecognized-char'])
145 if conf.env.DEST_CPU in ['x86_64', 'amd64', 'x64']:
146 add_options(['ASFLAGS'],
147 ['-DARCH_X86_64=1'])
149 if conf.env.DEST_OS == 'darwin':
150 fmt = 'macho64'
151 elif conf.env.DEST_OS == 'win32':
152 fmt = 'win64'
153 else:
154 fmt = 'elf64'
155 else:
156 add_options(['ASFLAGS'],
157 ['-DARCH_X86_64=0'])
159 if conf.env.DEST_OS == 'darwin':
160 fmt = 'macho32'
161 elif conf.env.DEST_OS == 'win32':
162 fmt = 'win32'
163 else:
164 fmt = 'elf32'
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'],
172 ['-DVSCORE_DEBUG',
173 '-g',
174 '-ggdb',
175 '-ftrapv'])
176 elif conf.env.CXX_NAME == 'msvc':
177 add_options(['CFLAGS', 'CXXFLAGS'],
178 ['/DVSCORE_DEBUG',
179 '/Z7'])
181 add_options(['ASFLAGS'],
182 ['-DVSCORE_DEBUG'])
183 elif conf.options.mode == 'release':
184 if conf.env.CXX_NAME == 'gcc':
185 add_options(['CFLAGS', 'CXXFLAGS'],
186 ['-O3'])
187 elif conf.env.CXX_NAME == 'msvc':
188 add_options(['CFLAGS', 'CXXFLAGS'],
189 ['/Ox'])
190 else:
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'],
197 ['-Wl,-Bsymbolic'])
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')
221 libs = '-lm '
223 if not conf.env.DEST_OS in ['darwin', 'freebsd', 'netbsd', 'openbsd']:
224 libs += '-ldl '
226 conf.env.LIBS = libs.strip()
228 def build(bld):
229 def search_paths(paths):
230 srcpaths = []
232 for path in paths:
233 srcpaths += [os.path.join(path, '*.c'),
234 os.path.join(path, '*.cpp'),
235 os.path.join(path, '*.asm')]
237 return srcpaths
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),
249 target = 'objs')
251 bld(features = 'c qxx asm cxxshlib',
252 use = ['objs'],
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')])),
267 target = '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',
286 install_path = None)
288 bld(features = 'c cxxshlib',
289 includes = 'include',
290 use = ['vapoursynth'],
291 source = os.path.join('sdk', 'invert_example.c'),
292 target = 'example_invert',
293 install_path = None)
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,
303 LIBS = bld.env.LIBS,
304 VERSION = VERSION)