Ignore .waf-*.
[vapoursynth-svn.git] / wscript
blobc4f77011012f7bf4a039a2a4305e2a8632980b0e
1 #!/usr/bin/env python
3 import os, subprocess
4 from waflib import Task, TaskGen, Utils
6 APPNAME = 'VapourSynth'
7 VERSION = '9'
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 = ['/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 def options(opt):
35 opt.load('compiler_c')
36 opt.load('compiler_cxx')
37 opt.load('qt4')
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)')
45 def configure(conf):
46 def add_options(flags, options):
47 for flag in flags:
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')
54 conf.load('qt4')
56 # Load Yasm explicitly, then the Nasm module which
57 # supports both Nasm and Yasm.
58 conf.find_program('yasm', var = 'AS', mandatory = True)
59 conf.load('nasm')
61 if conf.env.DEST_OS == 'darwin':
62 if conf.env.CXX_NAME == 'gcc':
63 add_options(['ASFLAGS'],
64 ['-DPREFIX'])
66 if conf.env.CXX_NAME == 'gcc':
67 add_options(['CFLAGS', 'CXXFLAGS'],
68 ['-DVSCORE_EXPORTS',
69 '-fPIC'])
70 elif conf.env.CXX_NAME == 'msvc':
71 add_options(['CFLAGS', 'CXXFLAGS'],
72 ['/DVSCORE_EXPORTS',
73 '/EHsc',
74 '/Zc:wchar_t-'])
76 add_options(['ASFLAGS'],
77 ['-w',
78 '-Worphan-labels',
79 '-Wunrecognized-char'])
81 if conf.env.DEST_CPU in ['x86_64', 'amd64', 'x64']:
82 add_options(['ASFLAGS'],
83 ['-DARCH_X86_64=1'])
85 if conf.env.DEST_OS == 'darwin':
86 fmt = 'macho64'
87 elif conf.env.DEST_OS == 'win32':
88 fmt = 'win64'
89 else:
90 fmt = 'elf64'
91 else:
92 add_options(['ASFLAGS'],
93 ['-DARCH_X86_64=0'])
95 if conf.env.DEST_OS == 'darwin':
96 fmt = 'macho32'
97 elif conf.env.DEST_OS == 'win32':
98 fmt = 'win32'
99 else:
100 fmt = 'elf32'
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'],
108 ['-DVSCORE_DEBUG',
109 '-g',
110 '-ggdb',
111 '-ftrapv'])
112 elif conf.env.CXX_NAME == 'msvc':
113 add_options(['CFLAGS', 'CXXFLAGS'],
114 ['/DVSCORE_DEBUG',
115 '/Z7'])
117 add_options(['ASFLAGS'],
118 ['-DVSCORE_DEBUG'])
119 elif conf.options.mode == 'release':
120 if conf.env.CXX_NAME == 'gcc':
121 add_options(['CFLAGS', 'CXXFLAGS'],
122 ['-O3'])
123 elif conf.env.CXX_NAME == 'msvc':
124 add_options(['CFLAGS', 'CXXFLAGS'],
125 ['/Ox'])
126 else:
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'],
133 ['-Wl,-Bsymbolic'])
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')
167 def build(bld):
168 def search_paths(paths):
169 srcpaths = []
171 for path in paths:
172 srcpaths += [os.path.join(path, '*.c'),
173 os.path.join(path, '*.cpp'),
174 os.path.join(path, '*.asm')]
176 return srcpaths
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),
188 target = 'objs')
190 bld(features = 'c qxx asm cxxshlib',
191 use = ['objs'],
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')])),
206 target = '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')]))
213 bld.install_files('${PREFIX}/include', os.path.join('include', 'VapourSynth.h'))