|
| 1 | +#!/usr/bin/env python |
| 2 | +# encoding: utf-8 |
| 3 | +import os |
| 4 | +import sys |
| 5 | +from glob import glob |
| 6 | +try: |
| 7 | + from setuptools import setup, Extension |
| 8 | + from distutils.command.build import build |
| 9 | + from setuptools.command.install import install |
| 10 | +except Extension as err: |
| 11 | + from distutils.core import setup |
| 12 | + from distutils.extension import Extension |
| 13 | + from distutils.command.build import build |
| 14 | + from distutils.command.install import install |
| 15 | + |
| 16 | +libsphinxbase = ( |
| 17 | + [s for s in glob('sphinxbase/src/libsphinxbase/lm/*.c') if 'lm3g_templates.c' not in s] + |
| 18 | + glob('sphinxbase/src/libsphinxbase/feat/*.c') + |
| 19 | + glob('sphinxbase/src/libsphinxbase/util/*.c') + |
| 20 | + glob('sphinxbase/src/libsphinxbase/fe/*.c') |
| 21 | +) |
| 22 | + |
| 23 | +libsphinxad = [] |
| 24 | + |
| 25 | +libpocketsphinx = glob('pocketsphinx/src/libpocketsphinx/*.c') |
| 26 | + |
| 27 | +sb_headers = ['sphinxbase/include', 'sphinxbase/include/win32'] |
| 28 | +ps_headers = ['pocketsphinx/include', 'sphinxbase/src/libpocketsphinx'] |
| 29 | + |
| 30 | +libraries = [] |
| 31 | + |
| 32 | +definitions = [ |
| 33 | + ('SPHINXBASE_EXPORTS', None), |
| 34 | + ('POCKETSPHINX_EXPORTS', None), |
| 35 | + ('HAVE_CONFIG_H', None), |
| 36 | + ('_CRT_SECURE_NO_DEPRECATE', None), |
| 37 | + ('_USRDLL', None), |
| 38 | + ('SPHINXDLL', None) |
| 39 | +] |
| 40 | + |
| 41 | +if sys.platform.startswith('linux'): |
| 42 | + pass |
| 43 | +elif sys.platform.startswith('win'): |
| 44 | + libsphinxad.extend(['sphinxbase/src/libsphinxad/play_win32.c', 'sphinxbase/src/libsphinxad/rec_win32.c']) |
| 45 | + libraries.append('winmm') |
| 46 | + definitions.extend([('WIN32', None), ('_WINDOWS', None), ('YY_NO_UNISTD_H', None)]) |
| 47 | +elif sys.platform.startswith('darwin'): |
| 48 | + pass |
| 49 | +elif sys.platform == 'cygwin': |
| 50 | + libraries.append('iconv') |
| 51 | + |
| 52 | + |
| 53 | +class Build(build): |
| 54 | + def run(self): |
| 55 | + self.run_command('build_ext') |
| 56 | + build.run(self) |
| 57 | + |
| 58 | + |
| 59 | +class Install(install): |
| 60 | + def run(self): |
| 61 | + self.run_command('build_ext') |
| 62 | + install.run(self) |
| 63 | + |
| 64 | + |
| 65 | +def read(filename): |
| 66 | + return open(os.path.join(os.path.dirname(__file__), filename)).read() |
| 67 | + |
| 68 | + |
| 69 | +setup( |
| 70 | + name = 'PyPocketSphinx', |
| 71 | + version = '12608', |
| 72 | + description = 'Python interface to CMU SphinxBase and PocketSphinx libraries', |
| 73 | + long_description = read('readme.md'), |
| 74 | + author = 'Dmitry Prazdnichnov', |
| 75 | + author_email = 'dp@bambucha.org', |
| 76 | + maintainer = '', |
| 77 | + maintainer_email = '', |
| 78 | + url = 'https://github.com/bambocher/PyPocketSphinx', |
| 79 | + download_url = '', |
| 80 | + packages = ['sphinxbase', 'pocketsphinx'], |
| 81 | + ext_modules = [ |
| 82 | + Extension( |
| 83 | + name = 'sphinxbase._sphinxbase', |
| 84 | + sources = libsphinxbase + libsphinxad + ['sphinxbase/swig/sphinxbase.i'], |
| 85 | + swig_opts = ['-modern'] + ['-I' + h for h in sb_headers] + ['-outdir', 'sphinxbase/swig/python'], |
| 86 | + include_dirs = sb_headers, |
| 87 | + libraries = libraries, |
| 88 | + define_macros = definitions |
| 89 | + ), |
| 90 | + Extension( |
| 91 | + name = 'pocketsphinx._pocketsphinx', |
| 92 | + sources = libsphinxbase + libsphinxad + libpocketsphinx + ['pocketsphinx/swig/pocketsphinx.i'], |
| 93 | + swig_opts = ['-modern'] + ['-I' + h for h in sb_headers] + ['-I' + h for h in ps_headers] + ['-Isphinxbase/swig'] + ['-outdir', 'pocketsphinx/swig/python'], |
| 94 | + include_dirs = sb_headers + ps_headers, |
| 95 | + libraries = libraries, |
| 96 | + define_macros = definitions |
| 97 | + ) |
| 98 | + ], |
| 99 | + cmdclass = {'build': Build, 'install': Install}, |
| 100 | + classifiers = [ |
| 101 | + 'License :: OSI Approved :: BSD License', |
| 102 | + 'Operating System :: Microsoft :: Windows', |
| 103 | + 'Programming Language :: Python :: 2.7', |
| 104 | + 'Programming Language :: Python :: 3.4', |
| 105 | + ], |
| 106 | + license = 'BSD', |
| 107 | + keywords = ['sphinxbase', 'pocketsphinx'], |
| 108 | + platforms = ['Windows'], |
| 109 | + package_dir = { |
| 110 | + 'sphinxbase': 'sphinxbase/swig/python', |
| 111 | + 'pocketsphinx': 'pocketsphinx/swig/python' |
| 112 | + } |
| 113 | +) |
0 commit comments