/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Tools/setup.py.tmpl
Go Template | 139 lines | 115 code | 24 blank | 0 comment | 0 complexity | 6b01917b03ad97d5f3bb6fcee4fc7570 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1#!@PYTHON@
2'''A setup.py script with better SWIG support. To use it, either
3rename it to setup.py.in and have it pe processed by your configure
4script (you will need to define @PYTHON@), or replace the @*@ strings
5by hand.
6
7Copyright 2001, Anthony Joseph Seward'''
8
9
10from distutils.core import setup, Extension
11
12###############################################################################
13## Start of better Swig support
14###############################################################################
15from distutils.command.build_ext import build_ext
16import os
17import string
18class build_swig_ext(build_ext):
19 '''Better swig support for Distutils'''
20
21 ## __ Tell Distutils about the options
22 user_options = build_ext.user_options
23 boolean_options = build_ext.boolean_options
24
25 user_options.append(
26 ('swig-doc=', None,
27 'what type of documentation should SWIG produce (default: none)')
28 )
29 user_options.append(
30 ('swig-inc=', None,
31 'a list of directories to add to the SWIG include path'
32 + "(separated by ':')(default: SWIG)")
33 )
34 user_options.append(
35 ('swig-shadow', None,
36 'have SWIG create shadow classes'
37 + ' (also adds docstrings to the shadow classes')
38 )
39
40 boolean_options.append('swig-shadow')
41
42 def initialize_options(self):
43 '''Initialize the new options after the inherited ones'''
44 build_ext.initialize_options(self)
45 self.swig_doc = 'none'
46 self.swig_inc = 'SWIG'
47 self.swig_shadow = None
48
49 def swig_sources(self, sources):
50 """Override the definition of 'swig_sources' in build_ext. This
51 is essentially the same function but with better swig support.
52 I will now quote the original docstring:
53
54 Walk the list of source files in 'sources', looking for SWIG
55 interface (.i) files. Run SWIG on all that are found, and
56 return a modified 'sources' list with SWIG source files replaced
57 by the generated C (or C++) files.
58 """
59
60 new_sources = []
61 swig_sources = []
62 swig_targets = {}
63
64 # XXX this drops generated C/C++ files into the source tree, which
65 # is fine for developers who want to distribute the generated
66 # source -- but there should be an option to put SWIG output in
67 # the temp dir.
68
69 if self.swig_cpp:
70 target_ext = '.cpp'
71 else:
72 target_ext = '.c'
73
74 for source in sources:
75 (base, ext) = os.path.splitext(source)
76 if ext == ".i": # SWIG interface file
77 new_sources.append(base + target_ext)
78 swig_sources.append(source)
79 swig_targets[source] = new_sources[-1]
80 else:
81 new_sources.append(source)
82
83 if not swig_sources:
84 return new_sources
85
86 includes = self.swig_inc
87 if type(includes) is type(''):
88 includes = string.split(includes, ':')
89 includes = map(lambda x: '-I'+x, includes)
90 includes = string.join(includes)
91
92 swig = self.find_swig()
93## swig_cmd = [swig, "-python", "-d%s" % self.swig_doc, includes]
94 swig_cmd = [swig, '-v', '-python', '-d%s' % self.swig_doc, includes]
95 if self.swig_cpp:
96 swig_cmd.append('-c++')
97
98 if self.swig_shadow:
99 swig_cmd.append('-shadow')
100## swig1.1 swig_cmd.append('-docstring')
101
102 for source in swig_sources:
103 target = swig_targets[source]
104 self.announce('swigging %s to %s' % (source, target))
105 self.spawn(swig_cmd + ['-o', target, source])
106
107 return new_sources
108
109 # swig_sources ()
110###############################################################################
111## End of improved swig support
112###############################################################################
113
114package = '@PACKAGE@'
115version = '@VERSION@'
116include_dirs = ['@top_srcdir@']
117lib_dirs = ['@top_srcdir@/@PACKAGE@']
118libraries = ['@PACKAGE@', 'stdc++']
119
120setup(name = package,
121 version = version,
122 description = '',
123 author = '',
124 author_email = '',
125 url = 'http://',
126
127 cmdclass = {'build_ext': build_swig_ext},
128 ext_modules = [Extension(package+'cmodule',
129 [package+'.i'],
130 include_dirs=include_dirs,
131 library_dirs=lib_dirs,
132 libraries=libraries,
133 )],
134 options = {'build_ext':
135 {'swig_doc': 'html',
136 'swig_cpp': not None,
137 'swig_shadow': not None}
138 }
139 )