source: TI12-security/branches/Dependencies/m2crypto/setup.py @ 2223

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/branches/Dependencies/m2crypto/setup.py@2223
Revision 2223, 5.8 KB checked in by pjkersha, 13 years ago (diff)

Dependencies/m2crypto/setup.py: modifications to enable setup
to pick up command line or config file include_dirs,
library_dirs and libraries options. This will mean that it
will be more easily 'eggifiable'.

A customized Distribution class enables pick up of a
customized(!) build_ext class which ensures that swig_opts is
set to include the include_dirs settings.

Dependencies/m2crypto/setup.cfg: added this file with
include_dirs, library_dirs and libraries options to test
correct pick up from setup.py.

Line 
1#!/usr/bin/env python
2
3"""
4Distutils installer for M2Crypto.
5
6Copyright (c) 1999-2004, Ng Pheng Siong. All rights reserved.
7
8Portions created by Open Source Applications Foundation (OSAF) are
9Copyright (C) 2004-2006 OSAF. All Rights Reserved.
10"""
11
12import os, sys
13from distutils.core import setup, Extension
14from distutils.command import build_ext
15from distutils.dist import Distribution
16 
17import optparse
18
19# Specialization of build_ext to enable swig_opts to inherit any include_dirs
20# settings made at the command line or in a setup.cfg file
21class _build_ext(build_ext.build_ext):
22    def finalize_options(self):
23        build_ext.build_ext.finalize_options(self)
24        self.swig_opts = ['-I%s' % i for i in self.include_dirs]
25
26# Custom Distribution class is also needed to enable build_ext class to be
27# substitued with custom _build_ext   
28class _Distribution(Distribution):
29    def get_command_class(self, command):
30        klass = Distribution.get_command_class(self, command)
31
32        if klass == build_ext.build_ext:
33            return _build_ext
34        else:
35            return klass
36   
37   
38if os.name == 'nt':
39    defLibraries = ['ssleay32', 'libeay32']
40    defOpenSSLPrefix = 'c:\\pkg'
41else:
42    defLibraries = ['ssl', 'crypto']
43    defOpenSSLPrefix = '/usr'
44
45# Work around to enable other include_dirs, library_dirs and libraries
46# settings to be made over and above the OpenSSL defaults
47parser = optparse.OptionParser(add_help_option=False)
48
49# Along with the add_help_option keyword above, the callback is a fudge to
50# fool optparse into ignoring help options and letting setup deal with them
51parser.add_option("-h", 
52                  "--help",
53                  action="callback",
54                  callback=lambda option, optStr, value, parser: None)
55
56parser.add_option("-I", 
57                  "--include-dirs", 
58                  default=[],
59                  dest="include_dirs")
60
61parser.add_option("-L", 
62                  "--library-dirs",
63                  default=[], 
64                  dest="library_dirs")
65
66parser.add_option("-l", 
67                  "--libraries",
68                  default=defLibraries, 
69                  dest="libraries")
70
71parser.add_option("-s", 
72                  "--openssl",
73                  dest="openSSLPrefix",
74                  default=defOpenSSLPrefix,
75                  help="Prefix for openssl installation location")
76
77(options, args) = parser.parse_args()
78
79
80options.include_dirs += [os.path.join(options.openSSLPrefix,'include')]   
81options.library_dirs += [os.path.join(options.openSSLPrefix, 'lib')]
82
83if sys.platform == 'cygwin':
84    # Cygwin SHOULD work (there's code in distutils), but
85    # if one first starts a Windows command prompt, then bash,
86    # the distutils code does not seem to work. If you start
87    # Cygwin directly, then it would work even without this change.
88    # Someday distutils will be fixed and this won't be needed.
89    options.library_dirs += [os.path.join(options.openSSLPrefix, 'bin')]
90       
91swig_opts = None#['-I' + ' -I'.join(options.include_dirs)]   
92options.include_dirs += [os.path.join(os.getcwd(), 'SWIG')]
93
94
95
96
97if sys.version_info < (2,4):
98
99    # This copy of swig_sources is from Python 2.2.
100
101    def swig_sources (self, sources):
102
103        """Walk the list of source files in 'sources', looking for SWIG
104        interface (.i) files.  Run SWIG on all that are found, and
105        return a modified 'sources' list with SWIG source files replaced
106        by the generated C (or C++) files.
107        """
108
109        new_sources = []
110        swig_sources = []
111        swig_targets = {}
112
113        # XXX this drops generated C/C++ files into the source tree, which
114        # is fine for developers who want to distribute the generated
115        # source -- but there should be an option to put SWIG output in
116        # the temp dir.
117
118        if self.swig_cpp:
119            target_ext = '.cpp'
120        else:
121            target_ext = '.c'
122
123        for source in sources:
124            (base, ext) = os.path.splitext(source)
125            if ext == ".i":             # SWIG interface file
126                new_sources.append(base + target_ext)
127                swig_sources.append(source)
128                swig_targets[source] = new_sources[-1]
129            else:
130                new_sources.append(source)
131
132        if not swig_sources:
133            return new_sources
134
135        swig = self.find_swig()
136        swig_cmd = [swig, "-python", "-ISWIG"]
137        if self.swig_cpp:
138            swig_cmd.append("-c++")
139
140        swig_cmd.append(swig_opts_str)
141
142        for source in swig_sources:
143            target = swig_targets[source]
144            self.announce("swigging %s to %s" % (source, target))
145            self.spawn(swig_cmd + ["-o", target, source])
146
147        return new_sources
148   
149    build_ext.build_ext.swig_sources = swig_sources
150
151
152m2crypto = Extension(name = '__m2crypto',
153                     sources = ['SWIG/_m2crypto.i'],
154                     include_dirs = options.include_dirs,
155                     library_dirs = options.library_dirs,
156                     libraries = options.libraries,
157                     extra_compile_args = ['-DTHREADING'],
158                     #extra_link_args = ['-Wl,-search_paths_first'],
159                     swig_opts = swig_opts)
160
161setup(name = 'M2Crypto',
162      version = '0.16',
163      description = 'M2Crypto: A Python crypto and SSL toolkit',
164      long_description = 'M2Crypto is a wrapper for OpenSSL using SWIG.',
165      license = 'BSD-style license',
166      platforms = ['any'],
167      author = 'Ng Pheng Siong',
168      author_email = 'ngps@netmemetic.com',
169      maintainer = 'Heikki Toivonen',
170      maintainer_email = 'heikki@osafoundation.org',
171      url = 'http://wiki.osafoundation.org/bin/view/Projects/MeTooCrypto',
172      packages = ['M2Crypto', 'M2Crypto.SSL', 'M2Crypto.PGP'],
173      ext_package = 'M2Crypto',
174      ext_modules = [m2crypto],
175      distclass = _Distribution)
176
Note: See TracBrowser for help on using the repository browser.