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

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

Removed debug calls and substituted distutils setup import
with setuptools equivalent to allow creation of an egg.

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