[5c411dc] | 1 | #! /usr/bin/python |
---|
[110ac90] | 2 | # |
---|
[21ee709] | 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 |
---|
[ee36175] | 11 | # - doc: add doxygen |
---|
[110ac90] | 12 | # - tests: move to new unit test system |
---|
[000b090] | 13 | |
---|
| 14 | APPNAME = 'aubio' |
---|
[5820107] | 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]]) |
---|
[e565c649] | 24 | |
---|
| 25 | import os.path, sys |
---|
| 26 | if os.path.exists('src/config.h') or os.path.exists('Makefile'): |
---|
[7684ff2] | 27 | print "Please run 'make distclean' to clean-up autotools files before using waf" |
---|
[e565c649] | 28 | sys.exit(1) |
---|
| 29 | |
---|
[46378b3] | 30 | top = '.' |
---|
| 31 | out = 'build' |
---|
[000b090] | 32 | |
---|
[d41bc4d] | 33 | def options(ctx): |
---|
| 34 | ctx.add_option('--enable-double', action='store_true', default=False, |
---|
[06d30f9] | 35 | help='compile aubio in double precision mode') |
---|
[d41bc4d] | 36 | ctx.add_option('--enable-fftw', action='store_true', default=False, |
---|
[729a3c0] | 37 | help='compile with ooura instead of fftw') |
---|
[d41bc4d] | 38 | ctx.add_option('--enable-fftw3f', action='store_true', default=False, |
---|
[000b090] | 39 | help='compile with fftw3 instead of fftw3f') |
---|
[d41bc4d] | 40 | ctx.add_option('--enable-complex', action='store_true', default=False, |
---|
[62b8ab2] | 41 | help='compile with C99 complex') |
---|
[d41bc4d] | 42 | ctx.add_option('--enable-jack', action='store_true', default=False, |
---|
[2a6e672] | 43 | help='compile with jack support') |
---|
[d41bc4d] | 44 | ctx.add_option('--enable-lash', action='store_true', default=False, |
---|
[2a6e672] | 45 | help='compile with lash support') |
---|
[d41bc4d] | 46 | ctx.add_option('--enable-sndfile', action='store_true', default=False, |
---|
[110ac90] | 47 | help='compile with libsndfile support') |
---|
[d41bc4d] | 48 | ctx.add_option('--enable-samplerate', action='store_true', default=False, |
---|
[2a6e672] | 49 | help='compile with libsamplerate support') |
---|
[d41bc4d] | 50 | ctx.add_option('--enable-swig', action='store_true', default=False, |
---|
[dda6ba6] | 51 | help='compile with swig support (obsolete)') |
---|
[d41bc4d] | 52 | ctx.add_option('--with-target-platform', type='string', |
---|
[5c411dc] | 53 | help='set target platform for cross-compilation', dest='target_platform') |
---|
[d41bc4d] | 54 | ctx.load('compiler_c') |
---|
| 55 | ctx.load('compiler_cxx') |
---|
| 56 | ctx.load('gnu_dirs') |
---|
| 57 | ctx.load('waf_unit_test') |
---|
[000b090] | 58 | |
---|
[d41bc4d] | 59 | def configure(ctx): |
---|
[000b090] | 60 | import Options |
---|
[d41bc4d] | 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') |
---|
[c325a11] | 66 | ctx.env.CFLAGS = ['-g'] |
---|
[000b090] | 67 | |
---|
[5c411dc] | 68 | if Options.options.target_platform: |
---|
| 69 | Options.platform = Options.options.target_platform |
---|
| 70 | |
---|
| 71 | if Options.platform == 'win32': |
---|
[d41bc4d] | 72 | ctx.env['shlib_PATTERN'] = 'lib%s.dll' |
---|
[5c411dc] | 73 | |
---|
[000b090] | 74 | # check for required headers |
---|
[d41bc4d] | 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') |
---|
[000b090] | 80 | |
---|
| 81 | # optionally use complex.h |
---|
[62b8ab2] | 82 | if (Options.options.enable_complex == True): |
---|
[d41bc4d] | 83 | ctx.check(header_name='complex.h') |
---|
[000b090] | 84 | |
---|
[2e4fb04] | 85 | # check dependencies |
---|
[110ac90] | 86 | if (Options.options.enable_sndfile == True): |
---|
[d41bc4d] | 87 | ctx.check_cfg(package = 'sndfile', atleast_version = '1.0.4', |
---|
[110ac90] | 88 | args = '--cflags --libs') |
---|
[82335b7] | 89 | if (Options.options.enable_samplerate == True): |
---|
[d41bc4d] | 90 | ctx.check_cfg(package = 'samplerate', atleast_version = '0.0.15', |
---|
[2e4fb04] | 91 | args = '--cflags --libs') |
---|
[000b090] | 92 | |
---|
[06d30f9] | 93 | # double precision mode |
---|
| 94 | if (Options.options.enable_double == True): |
---|
[d41bc4d] | 95 | ctx.define('HAVE_AUBIO_DOUBLE', 1) |
---|
[06d30f9] | 96 | else: |
---|
[d41bc4d] | 97 | ctx.define('HAVE_AUBIO_DOUBLE', 0) |
---|
[06d30f9] | 98 | |
---|
[110ac90] | 99 | # check if pkg-config is installed, optional |
---|
| 100 | try: |
---|
[d41bc4d] | 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') |
---|
[110ac90] | 105 | |
---|
[36f954a] | 106 | # optional dependancies using pkg-config |
---|
[d41bc4d] | 107 | if ctx.env['PKGCONFIG']: |
---|
[36f954a] | 108 | |
---|
[dda6ba6] | 109 | if (Options.options.enable_fftw == True or Options.options.enable_fftw3f == True): |
---|
[36f954a] | 110 | # one of fftwf or fftw3f |
---|
[dda6ba6] | 111 | if (Options.options.enable_fftw3f == True): |
---|
[d41bc4d] | 112 | ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', |
---|
[729a3c0] | 113 | args = '--cflags --libs') |
---|
[dda6ba6] | 114 | if (Options.options.enable_double == True): |
---|
[d41bc4d] | 115 | ctx.msg('Warning', 'fftw3f enabled, but aubio compiled in double precision!') |
---|
[729a3c0] | 116 | else: |
---|
[dda6ba6] | 117 | # fftw3f not enabled, take most sensible one according to enable_double |
---|
[36f954a] | 118 | if (Options.options.enable_double == True): |
---|
[d41bc4d] | 119 | ctx.check_cfg(package = 'fftw3', atleast_version = '3.0.0', |
---|
[36f954a] | 120 | args = '--cflags --libs') |
---|
| 121 | else: |
---|
[d41bc4d] | 122 | ctx.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', |
---|
[36f954a] | 123 | args = '--cflags --libs') |
---|
[d41bc4d] | 124 | ctx.define('HAVE_FFTW3', 1) |
---|
[36f954a] | 125 | else: |
---|
| 126 | # fftw disabled, use ooura |
---|
[c325a11] | 127 | ctx.msg('Checking for FFT implementation', 'ooura') |
---|
[36f954a] | 128 | pass |
---|
| 129 | |
---|
| 130 | if (Options.options.enable_jack == True): |
---|
[d41bc4d] | 131 | ctx.check_cfg(package = 'jack', atleast_version = '0.15.0', |
---|
[36f954a] | 132 | args = '--cflags --libs') |
---|
| 133 | |
---|
| 134 | if (Options.options.enable_lash == True): |
---|
[d41bc4d] | 135 | ctx.check_cfg(package = 'lash-1.0', atleast_version = '0.5.0', |
---|
[36f954a] | 136 | args = '--cflags --libs', uselib_store = 'LASH') |
---|
[000b090] | 137 | |
---|
| 138 | # swig |
---|
[dda6ba6] | 139 | if (Options.options.enable_swig == True): |
---|
| 140 | try: |
---|
[d41bc4d] | 141 | ctx.find_program('swig', var='SWIG') |
---|
| 142 | except ctx.errors.ConfigurationError: |
---|
| 143 | ctx.to_log('swig was not found, not looking for (ignoring)') |
---|
[dda6ba6] | 144 | |
---|
[d41bc4d] | 145 | if ctx.env['SWIG']: |
---|
| 146 | ctx.check_tool('swig') |
---|
| 147 | ctx.check_swig_version() |
---|
[dda6ba6] | 148 | |
---|
| 149 | # python |
---|
[d41bc4d] | 150 | if ctx.find_program('python'): |
---|
| 151 | ctx.check_tool('python') |
---|
| 152 | ctx.check_python_version((2,4,2)) |
---|
| 153 | ctx.check_python_headers() |
---|
[000b090] | 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 | ''' |
---|
[d41bc4d] | 160 | if ctx.check_cc(fragment = check_c99_varargs, |
---|
[46378b3] | 161 | type='cstlib', |
---|
[000b090] | 162 | msg = 'Checking for C99 __VA_ARGS__ macro'): |
---|
[d41bc4d] | 163 | ctx.define('HAVE_C99_VARARGS_MACROS', 1) |
---|
[000b090] | 164 | |
---|
| 165 | # write configuration header |
---|
[d41bc4d] | 166 | ctx.write_config_header('src/config.h') |
---|
[000b090] | 167 | |
---|
[110ac90] | 168 | # add some defines used in examples |
---|
[d41bc4d] | 169 | ctx.define('AUBIO_PREFIX', ctx.env['PREFIX']) |
---|
| 170 | ctx.define('PACKAGE', APPNAME) |
---|
[000b090] | 171 | |
---|
| 172 | # check if docbook-to-man is installed, optional |
---|
[110ac90] | 173 | try: |
---|
[d41bc4d] | 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)') |
---|
[000b090] | 177 | |
---|
[d41bc4d] | 178 | def build(ctx): |
---|
| 179 | ctx.env['VERSION'] = VERSION |
---|
| 180 | ctx.env['LIB_VERSION'] = LIB_VERSION |
---|
[000b090] | 181 | |
---|
| 182 | # add sub directories |
---|
[c325a11] | 183 | ctx.add_subdirs(['src','examples']) |
---|
[d41bc4d] | 184 | if ctx.env['SWIG']: |
---|
| 185 | if ctx.env['PYTHON']: |
---|
| 186 | ctx.add_subdirs('python') |
---|
[000b090] | 187 | |
---|
| 188 | # create the aubio.pc file for pkg-config |
---|
[d41bc4d] | 189 | if ctx.env['TARGET_PLATFORM'] == 'linux': |
---|
| 190 | aubiopc = ctx.new_task_gen('subst') |
---|
[110ac90] | 191 | aubiopc.source = 'aubio.pc.in' |
---|
| 192 | aubiopc.target = 'aubio.pc' |
---|
| 193 | aubiopc.install_path = '${PREFIX}/lib/pkgconfig' |
---|
[000b090] | 194 | |
---|
| 195 | # build manpages from sgml files |
---|
[d41bc4d] | 196 | if ctx.env['DOCBOOKTOMAN']: |
---|
[000b090] | 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 | ) |
---|
[d41bc4d] | 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')) |
---|
[000b090] | 208 | |
---|
| 209 | # install woodblock sound |
---|
[d41bc4d] | 210 | ctx.install_files('${PREFIX}/share/sounds/aubio/', |
---|
[000b090] | 211 | 'sounds/woodblock.aiff') |
---|
| 212 | |
---|
[f11d78d] | 213 | # build and run the unit tests |
---|
[d41bc4d] | 214 | build_tests(ctx) |
---|
[f11d78d] | 215 | |
---|
[d41bc4d] | 216 | def shutdown(ctx): |
---|
[000b090] | 217 | pass |
---|
| 218 | |
---|
[f11d78d] | 219 | # loop over all *.c filenames in tests/src to build them all |
---|
| 220 | # target name is filename.c without the .c |
---|
[d41bc4d] | 221 | def build_tests(ctx): |
---|
| 222 | for target_name in ctx.path.ant_glob('tests/src/**/*.c'): |
---|
[110ac90] | 223 | uselib = [] |
---|
[c325a11] | 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'] |
---|
[110ac90] | 230 | |
---|
[d41bc4d] | 231 | this_target = ctx.new_task_gen( |
---|
[46378b3] | 232 | features = 'c cprogram test', |
---|
[110ac90] | 233 | uselib = uselib, |
---|
| 234 | source = [target_name] + extra_source, |
---|
[46378b3] | 235 | target = str(target_name).split('.')[0], |
---|
[c325a11] | 236 | includes = includes, |
---|
[740f06b] | 237 | defines = 'AUBIO_UNSTABLE_API=1', |
---|
[c325a11] | 238 | cflags = ['-g'], |
---|
[46378b3] | 239 | use = 'aubio') |
---|