1 | #! /usr/bin/python |
---|
2 | # |
---|
3 | # waf build script, see http://code.google.com/p/waf/ |
---|
4 | # usage: |
---|
5 | # $ waf distclean configure build |
---|
6 | # get it: |
---|
7 | # $ svn co http://waf.googlecode.com/svn/trunk /path/to/waf |
---|
8 | # $ alias waf=/path/to/waf/waf-light |
---|
9 | # |
---|
10 | # TODO |
---|
11 | # - doc: add doxygen |
---|
12 | # - tests: move to new unit test system |
---|
13 | |
---|
14 | APPNAME = 'aubio' |
---|
15 | |
---|
16 | # read from VERSION |
---|
17 | for l in open('VERSION').readlines(): exec (l.strip()) |
---|
18 | |
---|
19 | VERSION = '.'.join \ |
---|
20 | ([str(x) for x in [AUBIO_MAJOR_VERSION, AUBIO_MINOR_VERSION, AUBIO_PATCH_VERSION]]) \ |
---|
21 | + AUBIO_VERSION_STATUS |
---|
22 | LIB_VERSION = '.'.join \ |
---|
23 | ([str(x) for x in [LIBAUBIO_LT_CUR, LIBAUBIO_LT_REV, LIBAUBIO_LT_AGE]]) |
---|
24 | |
---|
25 | import os.path, sys |
---|
26 | if os.path.exists('src/config.h') or os.path.exists('Makefile'): |
---|
27 | print "Please run 'make distclean' to clean-up autotools files before using waf" |
---|
28 | sys.exit(1) |
---|
29 | |
---|
30 | top = '.' |
---|
31 | out = 'build' |
---|
32 | |
---|
33 | def options(ctx): |
---|
34 | ctx.add_option('--enable-double', action='store_true', default=False, |
---|
35 | help='compile aubio in double precision mode') |
---|
36 | ctx.add_option('--enable-fftw', action='store_true', default=False, |
---|
37 | help='compile with ooura instead of fftw') |
---|
38 | ctx.add_option('--enable-fftw3f', action='store_true', default=False, |
---|
39 | help='compile with fftw3 instead of fftw3f') |
---|
40 | ctx.add_option('--enable-complex', action='store_true', default=False, |
---|
41 | help='compile with C99 complex') |
---|
42 | ctx.add_option('--enable-jack', action='store_true', default=False, |
---|
43 | help='compile with jack support') |
---|
44 | ctx.add_option('--enable-lash', action='store_true', default=False, |
---|
45 | help='compile with lash support') |
---|
46 | ctx.add_option('--enable-sndfile', action='store_true', default=False, |
---|
47 | help='compile with libsndfile support') |
---|
48 | ctx.add_option('--enable-samplerate', action='store_true', default=False, |
---|
49 | help='compile with libsamplerate support') |
---|
50 | ctx.add_option('--enable-swig', action='store_true', default=False, |
---|
51 | help='compile with swig support (obsolete)') |
---|
52 | ctx.add_option('--with-target-platform', type='string', |
---|
53 | help='set target platform for cross-compilation', dest='target_platform') |
---|
54 | ctx.load('compiler_c') |
---|
55 | ctx.load('gnu_dirs') |
---|
56 | ctx.load('waf_unit_test') |
---|
57 | |
---|
58 | def configure(ctx): |
---|
59 | import Options |
---|
60 | ctx.check_tool('compiler_c') |
---|
61 | ctx.check_tool('gnu_dirs') # helpful for autotools transition and .pc generation |
---|
62 | ctx.load('waf_unit_test') |
---|
63 | ctx.env.CFLAGS = ['-g'] |
---|
64 | |
---|
65 | if Options.options.target_platform: |
---|
66 | Options.platform = Options.options.target_platform |
---|
67 | |
---|
68 | if Options.platform == 'win32': |
---|
69 | ctx.env['shlib_PATTERN'] = 'lib%s.dll' |
---|
70 | |
---|
71 | if Options.platform == 'macfat': |
---|
72 | ctx.env.CFLAGS += ['-arch', 'i386', '-arch', 'x86_64'] |
---|
73 | ctx.env.LINKFLAGS += ['-arch', 'i386', '-arch', 'x86_64'] |
---|
74 | ctx.env.CC = 'llvm-gcc-4.2' |
---|
75 | ctx.env.LINK_CC = 'llvm-gcc-4.2' |
---|
76 | ctx.env.FRAMEWORK = ['CoreFoundation', 'AudioToolbox'] |
---|
77 | |
---|
78 | # check for required headers |
---|
79 | ctx.check(header_name='stdlib.h') |
---|
80 | ctx.check(header_name='stdio.h') |
---|
81 | ctx.check(header_name='math.h') |
---|
82 | ctx.check(header_name='string.h') |
---|
83 | ctx.check(header_name='limits.h') |
---|
84 | |
---|
85 | # optionally use complex.h |
---|
86 | if (Options.options.enable_complex == True): |
---|
87 | ctx.check(header_name='complex.h') |
---|
88 | |
---|
89 | # check dependencies |
---|
90 | if (Options.options.enable_sndfile == True): |
---|
91 | ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4', |
---|
92 | args = '--cflags --libs') |
---|
93 | if (Options.options.enable_samplerate == True): |
---|
94 | ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15', |
---|
95 | args = '--cflags --libs') |
---|
96 | |
---|
97 | # double precision mode |
---|
98 | if (Options.options.enable_double == True): |
---|
99 | ctx.define('HAVE_AUBIO_DOUBLE', 1) |
---|
100 | else: |
---|
101 | ctx.define('HAVE_AUBIO_DOUBLE', 0) |
---|
102 | |
---|
103 | # check if pkg-config is installed, optional |
---|
104 | try: |
---|
105 | ctx.find_program('pkg-config', var='PKGCONFIG') |
---|
106 | except ctx.errors.ConfigurationError: |
---|
107 | ctx.msg('Could not find pkg-config', 'disabling fftw, jack, and lash') |
---|
108 | ctx.msg('Could not find fftw', 'using ooura') |
---|
109 | |
---|
110 | # optional dependancies using pkg-config |
---|
111 | if ctx.env['PKGCONFIG']: |
---|
112 | |
---|
113 | if (Options.options.enable_fftw == True or Options.options.enable_fftw3f == True): |
---|
114 | # one of fftwf or fftw3f |
---|
115 | if (Options.options.enable_fftw3f == True): |
---|
116 | ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', |
---|
117 | args = '--cflags --libs') |
---|
118 | if (Options.options.enable_double == True): |
---|
119 | ctx.msg('Warning', 'fftw3f enabled, but aubio compiled in double precision!') |
---|
120 | else: |
---|
121 | # fftw3f not enabled, take most sensible one according to enable_double |
---|
122 | if (Options.options.enable_double == True): |
---|
123 | ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0', |
---|
124 | args = '--cflags --libs') |
---|
125 | else: |
---|
126 | ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', |
---|
127 | args = '--cflags --libs') |
---|
128 | ctx.define('HAVE_FFTW3', 1) |
---|
129 | else: |
---|
130 | # fftw disabled, use ooura |
---|
131 | ctx.msg('Checking for FFT implementation', 'ooura') |
---|
132 | pass |
---|
133 | |
---|
134 | if (Options.options.enable_jack == True): |
---|
135 | ctx.check_cfg(package = 'jack', atleast_version = '0.15.0', |
---|
136 | args = '--cflags --libs') |
---|
137 | |
---|
138 | if (Options.options.enable_lash == True): |
---|
139 | ctx.check_cfg(package = 'lash-1.0', atleast_version = '0.5.0', |
---|
140 | args = '--cflags --libs', uselib_store = 'LASH') |
---|
141 | |
---|
142 | # swig |
---|
143 | if (Options.options.enable_swig == True): |
---|
144 | try: |
---|
145 | ctx.find_program('swig', var='SWIG') |
---|
146 | except ctx.errors.ConfigurationError: |
---|
147 | ctx.to_log('swig was not found, not looking for (ignoring)') |
---|
148 | |
---|
149 | if ctx.env['SWIG']: |
---|
150 | ctx.check_tool('swig') |
---|
151 | ctx.check_swig_version() |
---|
152 | |
---|
153 | # python |
---|
154 | if ctx.find_program('python'): |
---|
155 | ctx.check_tool('python') |
---|
156 | ctx.check_python_version((2,4,2)) |
---|
157 | ctx.check_python_headers() |
---|
158 | |
---|
159 | # check support for C99 __VA_ARGS__ macros |
---|
160 | check_c99_varargs = ''' |
---|
161 | #include <stdio.h> |
---|
162 | #define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__) |
---|
163 | ''' |
---|
164 | if ctx.check_cc(fragment = check_c99_varargs, |
---|
165 | type='cstlib', |
---|
166 | msg = 'Checking for C99 __VA_ARGS__ macro'): |
---|
167 | ctx.define('HAVE_C99_VARARGS_MACROS', 1) |
---|
168 | |
---|
169 | # write configuration header |
---|
170 | ctx.write_config_header('src/config.h') |
---|
171 | |
---|
172 | # add some defines used in examples |
---|
173 | ctx.define('AUBIO_PREFIX', ctx.env['PREFIX']) |
---|
174 | ctx.define('PACKAGE', APPNAME) |
---|
175 | |
---|
176 | # check if docbook-to-man is installed, optional |
---|
177 | try: |
---|
178 | ctx.find_program('docbook-to-man', var='DOCBOOKTOMAN') |
---|
179 | except ctx.errors.ConfigurationError: |
---|
180 | ctx.to_log('docbook-to-man was not found (ignoring)') |
---|
181 | |
---|
182 | def build(ctx): |
---|
183 | ctx.env['VERSION'] = VERSION |
---|
184 | ctx.env['LIB_VERSION'] = LIB_VERSION |
---|
185 | |
---|
186 | # add sub directories |
---|
187 | ctx.add_subdirs(['src','examples']) |
---|
188 | if ctx.env['SWIG']: |
---|
189 | if ctx.env['PYTHON']: |
---|
190 | ctx.add_subdirs('python') |
---|
191 | |
---|
192 | # create the aubio.pc file for pkg-config |
---|
193 | if ctx.env['TARGET_PLATFORM'] == 'linux': |
---|
194 | aubiopc = ctx.new_task_gen('subst') |
---|
195 | aubiopc.source = 'aubio.pc.in' |
---|
196 | aubiopc.target = 'aubio.pc' |
---|
197 | aubiopc.install_path = '${PREFIX}/lib/pkgconfig' |
---|
198 | |
---|
199 | # build manpages from sgml files |
---|
200 | if ctx.env['DOCBOOKTOMAN']: |
---|
201 | import TaskGen |
---|
202 | TaskGen.declare_chain( |
---|
203 | name = 'docbooktoman', |
---|
204 | rule = '${DOCBOOKTOMAN} ${SRC} > ${TGT}', |
---|
205 | ext_in = '.sgml', |
---|
206 | ext_out = '.1', |
---|
207 | reentrant = 0, |
---|
208 | ) |
---|
209 | manpages = ctx.new_task_gen(name = 'docbooktoman', |
---|
210 | source=ctx.path.ant_glob('doc/*.sgml')) |
---|
211 | ctx.install_files('${MANDIR}/man1', ctx.path.ant_glob('doc/*.1')) |
---|
212 | |
---|
213 | # install woodblock sound |
---|
214 | ctx.install_files('${PREFIX}/share/sounds/aubio/', |
---|
215 | 'sounds/woodblock.aiff') |
---|
216 | |
---|
217 | # build and run the unit tests |
---|
218 | build_tests(ctx) |
---|
219 | |
---|
220 | def shutdown(ctx): |
---|
221 | pass |
---|
222 | |
---|
223 | # loop over all *.c filenames in tests/src to build them all |
---|
224 | # target name is filename.c without the .c |
---|
225 | def build_tests(ctx): |
---|
226 | for target_name in ctx.path.ant_glob('tests/src/**/*.c'): |
---|
227 | uselib = [] |
---|
228 | includes = ['src'] |
---|
229 | extra_source = [] |
---|
230 | if str(target_name).endswith('-jack.c') and ctx.env['JACK']: |
---|
231 | uselib += ['JACK'] |
---|
232 | includes += ['examples'] |
---|
233 | extra_source += ['examples/jackio.c'] |
---|
234 | |
---|
235 | this_target = ctx.new_task_gen( |
---|
236 | features = 'c cprogram test', |
---|
237 | uselib = uselib, |
---|
238 | source = [target_name] + extra_source, |
---|
239 | target = str(target_name).split('.')[0], |
---|
240 | includes = includes, |
---|
241 | defines = 'AUBIO_UNSTABLE_API=1', |
---|
242 | cflags = ['-g'], |
---|
243 | use = 'aubio') |
---|