Changeset 633400d for python/lib/moresetuptools.py
- Timestamp:
- Dec 5, 2018, 10:34:39 PM (6 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/moresetuptools.py
r5b46bc3 r633400d 3 3 import sys, os, glob, subprocess 4 4 import distutils, distutils.command.clean, distutils.dir_util 5 from .gen_external import generate_external, header, output_path 5 from gen_external import generate_external, header, output_path 6 7 from this_version import get_aubio_version 6 8 7 9 # inspired from https://gist.github.com/abergmeier/9488990 … … 22 24 23 25 for package in packages: 26 print("checking for {:s}".format(package)) 24 27 cmd = ['pkg-config', '--libs', '--cflags', package] 25 28 try: … … 55 58 def add_local_aubio_sources(ext): 56 59 """ 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'))) 63 63 ext.sources += aubio_sources 64 65 def add_local_macros(ext, usedouble = False): 66 if usedouble: 67 ext.define_macros += [('HAVE_AUBIO_DOUBLE', 1)] 64 68 # define macros (waf puts them in build/src/config.h) 65 69 for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H', … … 70 74 ext.define_macros += [(define_macro, 1)] 71 75 76 def add_external_deps(ext, usedouble = False): 72 77 # loof for additional packages 73 78 print("Info: looking for *optional* additional packages") 74 packages = ['libavcodec', 'libavformat', 'libavutil', 'libavresample', 79 packages = ['libavcodec', 'libavformat', 'libavutil', 80 'libswresample', 'libavresample', 75 81 'jack', 76 'sndfile', 'samplerate',82 'sndfile', 77 83 'rubberband', 78 84 #'fftw3f', 79 85 ] 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") 80 91 add_packages(packages, ext=ext) 81 92 if 'avcodec' in ext.libraries \ 82 93 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)] 88 101 if 'sndfile' in ext.libraries: 89 102 ext.define_macros += [('HAVE_SNDFILE', 1)] … … 108 121 ext.define_macros += [('HAVE_WAVWRITE', 1)] 109 122 ext.define_macros += [('HAVE_WAVREAD', 1)] 110 # TODO: 111 # add cblas123 124 # TODO: add cblas 112 125 if 0: 113 126 ext.libraries += ['cblas'] … … 116 129 def add_system_aubio(ext): 117 130 # 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) 119 133 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 138 def 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)] 121 143 122 144 class CleanGenerated(distutils.command.clean.clean): 123 145 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) 126 148 127 class GenerateCommand(distutils.cmd.Command): 128 description = 'generate gen/gen-*.c files from ../src/aubio.h' 129 user_options = [ 149 from distutils.command.build_ext import build_ext as _build_ext 150 class build_ext(_build_ext): 151 152 user_options = _build_ext.user_options + [ 130 153 # The format is (long option, short option, description). 131 154 ('enable-double', None, 'use HAVE_AUBIO_DOUBLE=1 (default: 0)'), … … 133 156 134 157 def initialize_options(self): 158 _build_ext.initialize_options(self) 135 159 self.enable_double = False 136 160 137 161 def finalize_options(self): 162 _build_ext.finalize_options(self) 138 163 if self.enable_double: 139 164 self.announce( … … 141 166 level=distutils.log.INFO) 142 167 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.