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('compiler_cxx') |
---|
56 | ctx.load('gnu_dirs') |
---|
57 | ctx.load('waf_unit_test') |
---|
58 | |
---|
59 | def configure(ctx): |
---|
60 | import Options |
---|
61 | ctx.check_tool('compiler_c') |
---|
62 | ctx.check_tool('compiler_cxx') |
---|
63 | ctx.check_tool('gnu_dirs') # helpful for autotools transition and .pc generation |
---|
64 | #ctx.check_tool('misc') # needed for subst |
---|
65 | ctx.load('waf_unit_test') |
---|
66 | ctx.env.CFLAGS = ['-g'] |
---|
67 | |
---|
68 | if Options.options.target_platform: |
---|
69 | Options.platform = Options.options.target_platform |
---|
70 | |
---|
71 | if Options.platform == 'win32': |
---|
72 | ctx.env['shlib_PATTERN'] = 'lib%s.dll' |
---|
73 | |
---|
74 | # check for required headers |
---|
75 | ctx.check(header_name='stdlib.h') |
---|
76 | ctx.check(header_name='stdio.h') |
---|
77 | ctx.check(header_name='math.h') |
---|
78 | ctx.check(header_name='string.h') |
---|
79 | ctx.check(header_name='limits.h') |
---|
80 | |
---|
81 | # optionally use complex.h |
---|
82 | if (Options.options.enable_complex == True): |
---|
83 | ctx.check(header_name='complex.h') |
---|
84 | |
---|
85 | # check dependencies |
---|
86 | if (Options.options.enable_sndfile == True): |
---|
87 | ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4', |
---|
88 | args = '--cflags --libs') |
---|
89 | if (Options.options.enable_samplerate == True): |
---|
90 | ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15', |
---|
91 | args = '--cflags --libs') |
---|
92 | |
---|
93 | # double precision mode |
---|
94 | if (Options.options.enable_double == True): |
---|
95 | ctx.define('HAVE_AUBIO_DOUBLE', 1) |
---|
96 | else: |
---|
97 | ctx.define('HAVE_AUBIO_DOUBLE', 0) |
---|
98 | |
---|
99 | # check if pkg-config is installed, optional |
---|
100 | try: |
---|
101 | ctx.find_program('pkg-config', var='PKGCONFIG') |
---|
102 | except ctx.errors.ConfigurationError: |
---|
103 | ctx.msg('Could not find pkg-config', 'disabling fftw, jack, and lash') |
---|
104 | ctx.msg('Could not find fftw', 'using ooura') |
---|
105 | |
---|
106 | # optional dependancies using pkg-config |
---|
107 | if ctx.env['PKGCONFIG']: |
---|
108 | |
---|
109 | if (Options.options.enable_fftw == True or Options.options.enable_fftw3f == True): |
---|
110 | # one of fftwf or fftw3f |
---|
111 | if (Options.options.enable_fftw3f == True): |
---|
112 | ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', |
---|
113 | args = '--cflags --libs') |
---|
114 | if (Options.options.enable_double == True): |
---|
115 | ctx.msg('Warning', 'fftw3f enabled, but aubio compiled in double precision!') |
---|
116 | else: |
---|
117 | # fftw3f not enabled, take most sensible one according to enable_double |
---|
118 | if (Options.options.enable_double == True): |
---|
119 | ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0', |
---|
120 | args = '--cflags --libs') |
---|
121 | else: |
---|
122 | ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', |
---|
123 | args = '--cflags --libs') |
---|
124 | ctx.define('HAVE_FFTW3', 1) |
---|
125 | else: |
---|
126 | # fftw disabled, use ooura |
---|
127 | ctx.msg('Checking for FFT implementation', 'ooura') |
---|
128 | pass |
---|
129 | |
---|
130 | if (Options.options.enable_jack == True): |
---|
131 | ctx.check_cfg(package = 'jack', atleast_version = '0.15.0', |
---|
132 | args = '--cflags --libs') |
---|
133 | |
---|
134 | if (Options.options.enable_lash == True): |
---|
135 | ctx.check_cfg(package = 'lash-1.0', atleast_version = '0.5.0', |
---|
136 | args = '--cflags --libs', uselib_store = 'LASH') |
---|
137 | |
---|
138 | # swig |
---|
139 | if (Options.options.enable_swig == True): |
---|
140 | try: |
---|
141 | ctx.find_program('swig', var='SWIG') |
---|
142 | except ctx.errors.ConfigurationError: |
---|
143 | ctx.to_log('swig was not found, not looking for (ignoring)') |
---|
144 | |
---|
145 | if ctx.env['SWIG']: |
---|
146 | ctx.check_tool('swig') |
---|
147 | ctx.check_swig_version() |
---|
148 | |
---|
149 | # python |
---|
150 | if ctx.find_program('python'): |
---|
151 | ctx.check_tool('python') |
---|
152 | ctx.check_python_version((2,4,2)) |
---|
153 | ctx.check_python_headers() |
---|
154 | |
---|
155 | # check support for C99 __VA_ARGS__ macros |
---|
156 | check_c99_varargs = ''' |
---|
157 | #include <stdio.h> |
---|
158 | #define AUBIO_ERR(...) fprintf(stderr, __VA_ARGS__) |
---|
159 | ''' |
---|
160 | if ctx.check_cc(fragment = check_c99_varargs, |
---|
161 | type='cstlib', |
---|
162 | msg = 'Checking for C99 __VA_ARGS__ macro'): |
---|
163 | ctx.define('HAVE_C99_VARARGS_MACROS', 1) |
---|
164 | |
---|
165 | # write configuration header |
---|
166 | ctx.write_config_header('src/config.h') |
---|
167 | |
---|
168 | # add some defines used in examples |
---|
169 | ctx.define('AUBIO_PREFIX', ctx.env['PREFIX']) |
---|
170 | ctx.define('PACKAGE', APPNAME) |
---|
171 | |
---|
172 | # check if docbook-to-man is installed, optional |
---|
173 | try: |
---|
174 | ctx.find_program('docbook-to-man', var='DOCBOOKTOMAN') |
---|
175 | except ctx.errors.ConfigurationError: |
---|
176 | ctx.to_log('docbook-to-man was not found (ignoring)') |
---|
177 | |
---|
178 | def build(ctx): |
---|
179 | ctx.env['VERSION'] = VERSION |
---|
180 | ctx.env['LIB_VERSION'] = LIB_VERSION |
---|
181 | |
---|
182 | # add sub directories |
---|
183 | ctx.add_subdirs(['src','examples']) |
---|
184 | if ctx.env['SWIG']: |
---|
185 | if ctx.env['PYTHON']: |
---|
186 | ctx.add_subdirs('python') |
---|
187 | |
---|
188 | # create the aubio.pc file for pkg-config |
---|
189 | if ctx.env['TARGET_PLATFORM'] == 'linux': |
---|
190 | aubiopc = ctx.new_task_gen('subst') |
---|
191 | aubiopc.source = 'aubio.pc.in' |
---|
192 | aubiopc.target = 'aubio.pc' |
---|
193 | aubiopc.install_path = '${PREFIX}/lib/pkgconfig' |
---|
194 | |
---|
195 | # build manpages from sgml files |
---|
196 | if ctx.env['DOCBOOKTOMAN']: |
---|
197 | import TaskGen |
---|
198 | TaskGen.declare_chain( |
---|
199 | name = 'docbooktoman', |
---|
200 | rule = '${DOCBOOKTOMAN} ${SRC} > ${TGT}', |
---|
201 | ext_in = '.sgml', |
---|
202 | ext_out = '.1', |
---|
203 | reentrant = 0, |
---|
204 | ) |
---|
205 | manpages = ctx.new_task_gen(name = 'docbooktoman', |
---|
206 | source=ctx.path.ant_glob('doc/*.sgml')) |
---|
207 | ctx.install_files('${MANDIR}/man1', ctx.path.ant_glob('doc/*.1')) |
---|
208 | |
---|
209 | # install woodblock sound |
---|
210 | ctx.install_files('${PREFIX}/share/sounds/aubio/', |
---|
211 | 'sounds/woodblock.aiff') |
---|
212 | |
---|
213 | # build and run the unit tests |
---|
214 | build_tests(ctx) |
---|
215 | |
---|
216 | def shutdown(ctx): |
---|
217 | pass |
---|
218 | |
---|
219 | # loop over all *.c filenames in tests/src to build them all |
---|
220 | # target name is filename.c without the .c |
---|
221 | def build_tests(ctx): |
---|
222 | for target_name in ctx.path.ant_glob('tests/src/**/*.c'): |
---|
223 | uselib = [] |
---|
224 | includes = ['src'] |
---|
225 | extra_source = [] |
---|
226 | if str(target_name).endswith('-jack.c') and ctx.env['JACK']: |
---|
227 | uselib += ['JACK'] |
---|
228 | includes += ['examples'] |
---|
229 | extra_source += ['examples/jackio.c'] |
---|
230 | |
---|
231 | this_target = ctx.new_task_gen( |
---|
232 | features = 'c cprogram test', |
---|
233 | uselib = uselib, |
---|
234 | source = [target_name] + extra_source, |
---|
235 | target = str(target_name).split('.')[0], |
---|
236 | includes = includes, |
---|
237 | defines = 'AUBIO_UNSTABLE_API=1', |
---|
238 | cflags = ['-g'], |
---|
239 | use = 'aubio') |
---|