comparison lib/swig/swigwin-2.0.11/Tools/setup.py.tmpl @ 1899:b3009adc0e2f

Adding swig, gitignore, hgignore
author Nomad
date Mon, 21 Oct 2013 10:42:27 +0200
parents
children
comparison
equal deleted inserted replaced
1867:eb580660bbbb 1899:b3009adc0e2f
1 #!@PYTHON@
2 '''A setup.py script with better SWIG support. To use it, either
3 rename it to setup.py.in and have it pe processed by your configure
4 script (you will need to define @PYTHON@), or replace the @*@ strings
5 by hand.
6
7 Copyright 2001, Anthony Joseph Seward'''
8
9
10 from distutils.core import setup, Extension
11
12 ###############################################################################
13 ## Start of better Swig support
14 ###############################################################################
15 from distutils.command.build_ext import build_ext
16 import os
17 import string
18 class 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
114 package = '@PACKAGE@'
115 version = '@VERSION@'
116 include_dirs = ['@top_srcdir@']
117 lib_dirs = ['@top_srcdir@/@PACKAGE@']
118 libraries = ['@PACKAGE@', 'stdc++']
119
120 setup(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 )