Ignore:
Timestamp:
Dec 5, 2018, 10:34:39 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
283a619a
Parents:
5b46bc3 (diff), f19db54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/pitchshift

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/lib/moresetuptools.py

    r5b46bc3 r633400d  
    33import sys, os, glob, subprocess
    44import distutils, distutils.command.clean, distutils.dir_util
    5 from .gen_external import generate_external, header, output_path
     5from gen_external import generate_external, header, output_path
     6
     7from this_version import get_aubio_version
    68
    79# inspired from https://gist.github.com/abergmeier/9488990
     
    2224
    2325    for package in packages:
     26        print("checking for {:s}".format(package))
    2427        cmd = ['pkg-config', '--libs', '--cflags', package]
    2528        try:
     
    5558def add_local_aubio_sources(ext):
    5659    """ build aubio inside python module instead of linking against libaubio """
    57     print("Warning: libaubio was not built with waf, adding src/")
    58     # create an empty header, macros will be passed on the command line
    59     fake_config_header = os.path.join('python', 'ext', 'config.h')
    60     distutils.file_util.write_file(fake_config_header, "")
    61     aubio_sources = glob.glob(os.path.join('src', '**.c'))
    62     aubio_sources += glob.glob(os.path.join('src', '*', '**.c'))
     60    print("Info: libaubio was not installed or built locally with waf, adding src/")
     61    aubio_sources = sorted(glob.glob(os.path.join('src', '**.c')))
     62    aubio_sources += sorted(glob.glob(os.path.join('src', '*', '**.c')))
    6363    ext.sources += aubio_sources
     64
     65def add_local_macros(ext, usedouble = False):
     66    if usedouble:
     67        ext.define_macros += [('HAVE_AUBIO_DOUBLE', 1)]
    6468    # define macros (waf puts them in build/src/config.h)
    6569    for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H',
     
    7074        ext.define_macros += [(define_macro, 1)]
    7175
     76def add_external_deps(ext, usedouble = False):
    7277    # loof for additional packages
    7378    print("Info: looking for *optional* additional packages")
    74     packages = ['libavcodec', 'libavformat', 'libavutil', 'libavresample',
     79    packages = ['libavcodec', 'libavformat', 'libavutil',
     80                'libswresample', 'libavresample',
    7581                'jack',
    76                 'sndfile', 'samplerate',
     82                'sndfile',
    7783                'rubberband',
    7884                #'fftw3f',
    7985               ]
     86    # samplerate only works with float
     87    if usedouble is False:
     88        packages += ['samplerate']
     89    else:
     90        print("Info: not adding libsamplerate in double precision mode")
    8091    add_packages(packages, ext=ext)
    8192    if 'avcodec' in ext.libraries \
    8293            and 'avformat' in ext.libraries \
    83             and 'avutil' in ext.libraries \
    84             and 'avresample' in ext.libraries:
    85         ext.define_macros += [('HAVE_LIBAV', 1)]
    86     if 'jack' in ext.libraries:
    87         ext.define_macros += [('HAVE_JACK', 1)]
     94            and 'avutil' in ext.libraries:
     95        if 'swresample' in ext.libraries:
     96            ext.define_macros += [('HAVE_SWRESAMPLE', 1)]
     97        elif 'avresample' in ext.libraries:
     98            ext.define_macros += [('HAVE_AVRESAMPLE', 1)]
     99        if 'swresample' in ext.libraries or 'avresample' in ext.libraries:
     100            ext.define_macros += [('HAVE_LIBAV', 1)]
    88101    if 'sndfile' in ext.libraries:
    89102        ext.define_macros += [('HAVE_SNDFILE', 1)]
     
    108121    ext.define_macros += [('HAVE_WAVWRITE', 1)]
    109122    ext.define_macros += [('HAVE_WAVREAD', 1)]
    110     # TODO:
    111     # add cblas
     123
     124    # TODO: add cblas
    112125    if 0:
    113126        ext.libraries += ['cblas']
     
    116129def add_system_aubio(ext):
    117130    # use pkg-config to find aubio's location
    118     add_packages(['aubio'], ext)
     131    aubio_version = get_aubio_version()
     132    add_packages(['aubio = ' + aubio_version], ext)
    119133    if 'aubio' not in ext.libraries:
    120         print("Error: libaubio not found")
     134        print("Info: aubio " + aubio_version + " was not found by pkg-config")
     135    else:
     136        print("Info: using system aubio " + aubio_version + " found in " + ' '.join(ext.library_dirs))
     137
     138def add_libav_on_win(ext):
     139    """ no pkg-config on windows, simply assume these libs are available """
     140    ext.libraries += ['avformat', 'avutil', 'avcodec', 'swresample']
     141    for define_macro in ['HAVE_LIBAV', 'HAVE_SWRESAMPLE']:
     142        ext.define_macros += [(define_macro, 1)]
    121143
    122144class CleanGenerated(distutils.command.clean.clean):
    123145    def run(self):
    124         distutils.dir_util.remove_tree(output_path)
    125         distutils.command.clean.clean.run(self)
     146        if os.path.isdir(output_path):
     147            distutils.dir_util.remove_tree(output_path)
    126148
    127 class GenerateCommand(distutils.cmd.Command):
    128     description = 'generate gen/gen-*.c files from ../src/aubio.h'
    129     user_options = [
     149from distutils.command.build_ext import build_ext as _build_ext
     150class build_ext(_build_ext):
     151
     152    user_options = _build_ext.user_options + [
    130153            # The format is (long option, short option, description).
    131154            ('enable-double', None, 'use HAVE_AUBIO_DOUBLE=1 (default: 0)'),
     
    133156
    134157    def initialize_options(self):
     158        _build_ext.initialize_options(self)
    135159        self.enable_double = False
    136160
    137161    def finalize_options(self):
     162        _build_ext.finalize_options(self)
    138163        if self.enable_double:
    139164            self.announce(
     
    141166                    level=distutils.log.INFO)
    142167
    143     def run(self):
    144         self.announce( 'Generating code', level=distutils.log.INFO)
    145         generated_object_files = generate_external(header, output_path, usedouble=self.enable_double)
     168    def build_extension(self, extension):
     169        if self.enable_double or 'HAVE_AUBIO_DOUBLE' in os.environ:
     170            enable_double = True
     171        else:
     172            enable_double = False
     173        # seack for aubio headers and lib in PKG_CONFIG_PATH
     174        add_system_aubio(extension)
     175        # the lib was not installed on this system
     176        if 'aubio' not in extension.libraries:
     177            # use local src/aubio.h
     178            if os.path.isfile(os.path.join('src', 'aubio.h')):
     179                add_local_aubio_header(extension)
     180            add_local_macros(extension, usedouble=enable_double)
     181            # look for a local waf build
     182            if os.path.isfile(os.path.join('build','src', 'fvec.c.1.o')):
     183                add_local_aubio_lib(extension)
     184            else:
     185                # check for external dependencies
     186                add_external_deps(extension, usedouble=enable_double)
     187                # force adding libav on windows
     188                if os.name == 'nt' and ('WITH_LIBAV' in os.environ \
     189                        or 'CONDA_PREFIX' in os.environ):
     190                    add_libav_on_win(extension)
     191                # add libaubio sources and look for optional deps with pkg-config
     192                add_local_aubio_sources(extension)
     193        # generate files python/gen/*.c, python/gen/aubio-generated.h
     194        extension.include_dirs += [ output_path ]
     195        extension.sources += generate_external(header, output_path, overwrite = False,
     196                usedouble=enable_double)
     197        return _build_ext.build_extension(self, extension)
Note: See TracChangeset for help on using the changeset viewer.