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

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

Clean up ready for submission as M2Crypto patch:

  • conditional import of setuptools
  • move self.include_dirs and self.library_dirs initialisation into

finalize_options method otherwise they get overwritten if a config file
containing their equivalent is set

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
13try:
14    from setuptools import setup
15except ImportError:
16    from distutils.core import setup
17
18from distutils.core import Extension
19from distutils.command import build_ext
20from distutils.dist import Distribution
21 
22import optparse
23
24
25class _M2CryptoBuildExt(build_ext.build_ext):
26    '''Specialization of build_ext to enable swig_opts to inherit any
27    include_dirs settings made at the command line or in a setup.cfg file'''
28    user_options = build_ext.build_ext.user_options + \
29            [('openssl=', 'o', 'Prefix for openssl installation location')]
30
31    def initialize_options(self):
32        '''Overload to enable custom openssl settings to be picked up'''
33
34        build_ext.build_ext.initialize_options(self)
35       
36        # openssl is the attribute corresponding to openssl directory prefix
37        # command line option
38        if os.name == 'nt':
39            self.libraries = ['ssleay32', 'libeay32']
40            self.openssl = 'c:\\pkg'
41        else:
42            self.libraries = ['ssl', 'crypto']
43            self.openssl = '/usr'
44       
45   
46    def finalize_options(self):
47        '''Overloaded build_ext implementation to append custom openssl
48        include file and library linking options'''
49
50        build_ext.build_ext.finalize_options(self)
51
52        opensslIncludeDir = os.path.join(self.openssl, 'include')
53        opensslLibraryDir = os.path.join(self.openssl, 'lib')
54       
55        self.swig_opts = ['-I%s' % i for i in self.include_dirs + \
56                          [opensslIncludeDir]]
57       
58        self.include_dirs += [os.path.join(self.openssl, opensslIncludeDir),
59                              os.path.join(os.getcwd(), 'SWIG')]       
60           
61        if sys.platform == 'cygwin':
62            # Cygwin SHOULD work (there's code in distutils), but
63            # if one first starts a Windows command prompt, then bash,
64            # the distutils code does not seem to work. If you start
65            # Cygwin directly, then it would work even without this change.
66            # Someday distutils will be fixed and this won't be needed.
67            self.library_dirs += [os.path.join(self.openssl, 'bin')]
68               
69        self.library_dirs += [os.path.join(self.openssl, opensslLibraryDir)]
70
71
72if sys.version_info < (2,4):
73
74    # This copy of swig_sources is from Python 2.2.
75
76    def swig_sources (self, sources):
77
78        """Walk the list of source files in 'sources', looking for SWIG
79        interface (.i) files.  Run SWIG on all that are found, and
80        return a modified 'sources' list with SWIG source files replaced
81        by the generated C (or C++) files.
82        """
83
84        new_sources = []
85        swig_sources = []
86        swig_targets = {}
87
88        # XXX this drops generated C/C++ files into the source tree, which
89        # is fine for developers who want to distribute the generated
90        # source -- but there should be an option to put SWIG output in
91        # the temp dir.
92
93        if self.swig_cpp:
94            target_ext = '.cpp'
95        else:
96            target_ext = '.c'
97
98        for source in sources:
99            (base, ext) = os.path.splitext(source)
100            if ext == ".i":             # SWIG interface file
101                new_sources.append(base + target_ext)
102                swig_sources.append(source)
103                swig_targets[source] = new_sources[-1]
104            else:
105                new_sources.append(source)
106
107        if not swig_sources:
108            return new_sources
109
110        swig = self.find_swig()
111        swig_cmd = [swig, "-python", "-ISWIG"]
112        if self.swig_cpp:
113            swig_cmd.append("-c++")
114
115        swig_cmd.append(swig_opts_str)
116
117        for source in swig_sources:
118            target = swig_targets[source]
119            self.announce("swigging %s to %s" % (source, target))
120            self.spawn(swig_cmd + ["-o", target, source])
121
122        return new_sources
123   
124    build_ext.build_ext.swig_sources = swig_sources
125
126
127m2crypto = Extension(name = '__m2crypto',
128                     sources = ['SWIG/_m2crypto.i'],
129                     extra_compile_args = ['-DTHREADING'],
130                     #extra_link_args = ['-Wl,-search_paths_first'],
131                     )
132
133setup(name = 'M2Crypto',
134      version = '0.16',
135      description = 'M2Crypto: A Python crypto and SSL toolkit',
136      long_description = 'M2Crypto is a wrapper for OpenSSL using SWIG.',
137      license = 'BSD-style license',
138      platforms = ['any'],
139      author = 'Ng Pheng Siong',
140      author_email = 'ngps@netmemetic.com',
141      maintainer = 'Heikki Toivonen',
142      maintainer_email = 'heikki@osafoundation.org',
143      url = 'http://wiki.osafoundation.org/bin/view/Projects/MeTooCrypto',
144      packages = ['M2Crypto', 'M2Crypto.SSL', 'M2Crypto.PGP'],
145      ext_package = 'M2Crypto',
146      ext_modules = [m2crypto],
147      cmdclass = {'build_ext': _M2CryptoBuildExt},
148      zip_safe = False)
149
Note: See TracBrowser for help on using the repository browser.