Removing gstreamer plugin
[profile/ivi/pocketsphinx.git] / python / setup.py.in
1 try:
2     from setuptools import setup, Extension
3 except:
4     from distutils.core import setup, Extension
5
6 import distutils.command.install
7 import os
8 import commands
9 import sys
10
11 class bogus_uninstall(distutils.command.install.install):
12     """
13     Slightly bogus uninstall, just here to satisfy automake's make
14     distcheck.  Do NOT actually use this to uninstall the module!
15     """
16     def run(self):
17         # I believe the word 'bogus' is operative here.  When we run
18         # get_outputs() it will create subcommands, which will try to
19         # create the original 'install' object, which does not exist
20         # at this point.  We need to make sure that the --prefix
21         # argument gets propagated to said object.  This is not the
22         # right way to do that, but it works, for now.
23         install = self.distribution.get_command_obj('install')
24         install.prefix = self.prefix
25         install.ensure_finalized()
26         dirs = {}
27         for f in self.get_outputs():
28             dirs[os.path.dirname(f)] = 1
29             if os.path.isdir(f):
30                 dirs[f] = 1
31                 continue
32             print "Trying to remove file", f
33             try:
34                 os.unlink(f)
35             except:
36                 pass
37         # Gently try to remove any empty directories.
38         # This is really not guaranteed to work!!!
39         for d in dirs:
40             while d != self.prefix:
41                 print "Trying to remove dir", d
42                 try:
43                     if d.endswith(".egg-info"):
44                         files=[os.path.join(d,f) for f in os.listdir(d)]
45                         print "Trying to remove:", " ".join(files)
46                         for f in files: os.unlink(f)
47                     os.rmdir(d)
48                 except:
49                     pass
50                 d = os.path.dirname(d)
51
52 def pkgconfig(*packages, **kw):
53     flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
54     for token in commands.getoutput("pkg-config --libs --cflags %s" % ' '.join(packages)).split():
55         kw.setdefault(flag_map.get(token[:2]), []).append(token[2:])
56     return kw
57
58 # We actually just need the header files so that we know how to unbox things
59 try:
60     pygtk_includes = pkgconfig('pygtk-2.0')['include_dirs']
61 except KeyError:
62     pygtk_includes = []
63
64 # If there is no @sphinxbase@ and friends use pkg-config
65 if '@sphinxbase@' == '' or '@sphinxbasebuild@' == '':
66     sbconf = pkgconfig('sphinxbase')
67     sb_libdirs = sbconf.get('library_dirs', [])
68     sb_includes = sbconf.get('include_dirs', [])
69 else:
70     sb_includes = ['@sphinxbasebuild@/include',
71                    '@sphinxbase@/include']
72     sb_libdirs = ['@sphinxbasebuild@/src/libsphinxbase/.libs']
73
74 libraries = ['sphinxbase', 'pocketsphinx']
75 if sys.platform == "cygwin":
76       libraries.append('iconv')
77
78 setup(name = 'PocketSphinx',
79       version = '@VERSION@',
80       author = 'David Huggins-Daines',
81       author_email = 'dhuggins@cs.cmu.edu',
82       description = 'Python interface to CMU PocketSphinx speech recognition',
83       license = 'BSD',
84       url = 'http://cmusphinx.sourceforge.net',
85       ext_modules = [
86         Extension('pocketsphinx',
87                    sources=['pocketsphinx.c'],
88                    libraries=libraries,
89                    include_dirs=['@top_builddir@/include',
90                                  '@top_srcdir@/include',
91                                  '@top_srcdir@/python',
92                                  ] + sb_includes + pygtk_includes,
93                    library_dirs=['@top_builddir@/src/libpocketsphinx/.libs'] + sb_libdirs)
94         ],
95       cmdclass = {'bogus_uninstall' : bogus_uninstall}
96      )