PageRenderTime 37ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  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. Copyright 2001, Anthony Joseph Seward'''
  7. from distutils.core import setup, Extension
  8. ###############################################################################
  9. ## Start of better Swig support
  10. ###############################################################################
  11. from distutils.command.build_ext import build_ext
  12. import os
  13. import string
  14. class build_swig_ext(build_ext):
  15. '''Better swig support for Distutils'''
  16. ## __ Tell Distutils about the options
  17. user_options = build_ext.user_options
  18. boolean_options = build_ext.boolean_options
  19. user_options.append(
  20. ('swig-doc=', None,
  21. 'what type of documentation should SWIG produce (default: none)')
  22. )
  23. user_options.append(
  24. ('swig-inc=', None,
  25. 'a list of directories to add to the SWIG include path'
  26. + "(separated by ':')(default: SWIG)")
  27. )
  28. user_options.append(
  29. ('swig-shadow', None,
  30. 'have SWIG create shadow classes'
  31. + ' (also adds docstrings to the shadow classes')
  32. )
  33. boolean_options.append('swig-shadow')
  34. def initialize_options(self):
  35. '''Initialize the new options after the inherited ones'''
  36. build_ext.initialize_options(self)
  37. self.swig_doc = 'none'
  38. self.swig_inc = 'SWIG'
  39. self.swig_shadow = None
  40. def swig_sources(self, sources):
  41. """Override the definition of 'swig_sources' in build_ext. This
  42. is essentially the same function but with better swig support.
  43. I will now quote the original docstring:
  44. Walk the list of source files in 'sources', looking for SWIG
  45. interface (.i) files. Run SWIG on all that are found, and
  46. return a modified 'sources' list with SWIG source files replaced
  47. by the generated C (or C++) files.
  48. """
  49. new_sources = []
  50. swig_sources = []
  51. swig_targets = {}
  52. # XXX this drops generated C/C++ files into the source tree, which
  53. # is fine for developers who want to distribute the generated
  54. # source -- but there should be an option to put SWIG output in
  55. # the temp dir.
  56. if self.swig_cpp:
  57. target_ext = '.cpp'
  58. else:
  59. target_ext = '.c'
  60. for source in sources:
  61. (base, ext) = os.path.splitext(source)
  62. if ext == ".i": # SWIG interface file
  63. new_sources.append(base + target_ext)
  64. swig_sources.append(source)
  65. swig_targets[source] = new_sources[-1]
  66. else:
  67. new_sources.append(source)
  68. if not swig_sources:
  69. return new_sources
  70. includes = self.swig_inc
  71. if type(includes) is type(''):
  72. includes = string.split(includes, ':')
  73. includes = map(lambda x: '-I'+x, includes)
  74. includes = string.join(includes)
  75. swig = self.find_swig()
  76. ## swig_cmd = [swig, "-python", "-d%s" % self.swig_doc, includes]
  77. swig_cmd = [swig, '-v', '-python', '-d%s' % self.swig_doc, includes]
  78. if self.swig_cpp:
  79. swig_cmd.append('-c++')
  80. if self.swig_shadow:
  81. swig_cmd.append('-shadow')
  82. ## swig1.1 swig_cmd.append('-docstring')
  83. for source in swig_sources:
  84. target = swig_targets[source]
  85. self.announce('swigging %s to %s' % (source, target))
  86. self.spawn(swig_cmd + ['-o', target, source])
  87. return new_sources
  88. # swig_sources ()
  89. ###############################################################################
  90. ## End of improved swig support
  91. ###############################################################################
  92. package = '@PACKAGE@'
  93. version = '@VERSION@'
  94. include_dirs = ['@top_srcdir@']
  95. lib_dirs = ['@top_srcdir@/@PACKAGE@']
  96. libraries = ['@PACKAGE@', 'stdc++']
  97. setup(name = package,
  98. version = version,
  99. description = '',
  100. author = '',
  101. author_email = '',
  102. url = 'http://',
  103. cmdclass = {'build_ext': build_swig_ext},
  104. ext_modules = [Extension(package+'cmodule',
  105. [package+'.i'],
  106. include_dirs=include_dirs,
  107. library_dirs=lib_dirs,
  108. libraries=libraries,
  109. )],
  110. options = {'build_ext':
  111. {'swig_doc': 'html',
  112. 'swig_cpp': not None,
  113. 'swig_shadow': not None}
  114. }
  115. )