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

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

Further tidying up ready for submission as patch for M2Crypto.

  • removed used imports
  • copied settings as of version 0.18 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
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
20
21
22class _M2CryptoBuildExt(build_ext.build_ext):
23    '''Specialization of build_ext to enable swig_opts to inherit any
24    include_dirs settings made at the command line or in a setup.cfg file'''
25    user_options = build_ext.build_ext.user_options + \
26            [('openssl=', 'o', 'Prefix for openssl installation location')]
27
28    def initialize_options(self):
29        '''Overload to enable custom openssl settings to be picked up'''
30
31        build_ext.build_ext.initialize_options(self)
32       
33        # openssl is the attribute corresponding to openssl directory prefix
34        # command line option
35        if os.name == 'nt':
36            self.libraries = ['ssleay32', 'libeay32']
37            self.openssl = 'c:\\pkg'
38        else:
39            self.libraries = ['ssl', 'crypto']
40            self.openssl = '/usr'
41       
42   
43    def finalize_options(self):
44        '''Overloaded build_ext implementation to append custom openssl
45        include file and library linking options'''
46
47        build_ext.build_ext.finalize_options(self)
48
49        opensslIncludeDir = os.path.join(self.openssl, 'include')
50        opensslLibraryDir = os.path.join(self.openssl, 'lib')
51       
52        self.swig_opts = ['-I%s' % i for i in self.include_dirs + \
53                          [opensslIncludeDir]]
54       
55        self.include_dirs += [os.path.join(self.openssl, opensslIncludeDir),
56                              os.path.join(os.getcwd(), 'SWIG')]       
57           
58        if sys.platform == 'cygwin':
59            # Cygwin SHOULD work (there's code in distutils), but
60            # if one first starts a Windows command prompt, then bash,
61            # the distutils code does not seem to work. If you start
62            # Cygwin directly, then it would work even without this change.
63            # Someday distutils will be fixed and this won't be needed.
64            self.library_dirs += [os.path.join(self.openssl, 'bin')]
65               
66        self.library_dirs += [os.path.join(self.openssl, opensslLibraryDir)]
67
68
69if sys.version_info < (2,4):
70
71    # This copy of swig_sources is from Python 2.2.
72
73    def swig_sources (self, sources):
74
75        """Walk the list of source files in 'sources', looking for SWIG
76        interface (.i) files.  Run SWIG on all that are found, and
77        return a modified 'sources' list with SWIG source files replaced
78        by the generated C (or C++) files.
79        """
80
81        new_sources = []
82        swig_sources = []
83        swig_targets = {}
84
85        # XXX this drops generated C/C++ files into the source tree, which
86        # is fine for developers who want to distribute the generated
87        # source -- but there should be an option to put SWIG output in
88        # the temp dir.
89
90        if self.swig_cpp:
91            target_ext = '.cpp'
92        else:
93            target_ext = '.c'
94
95        for source in sources:
96            (base, ext) = os.path.splitext(source)
97            if ext == ".i":             # SWIG interface file
98                new_sources.append(base + target_ext)
99                swig_sources.append(source)
100                swig_targets[source] = new_sources[-1]
101            else:
102                new_sources.append(source)
103
104        if not swig_sources:
105            return new_sources
106
107        swig = self.find_swig()
108        swig_cmd = [swig, "-python", "-ISWIG"]
109        if self.swig_cpp:
110            swig_cmd.append("-c++")
111
112        swig_cmd.append(swig_opts_str)
113
114        for source in swig_sources:
115            target = swig_targets[source]
116            self.announce("swigging %s to %s" % (source, target))
117            self.spawn(swig_cmd + ["-o", target, source])
118
119        return new_sources
120   
121    build_ext.build_ext.swig_sources = swig_sources
122
123
124m2crypto = Extension(name = 'M2Crypto.__m2crypto',
125                     sources = ['SWIG/_m2crypto.i'],
126                     extra_compile_args = ['-DTHREADING'],
127                     #extra_link_args = ['-Wl,-search_paths_first'], # Uncomment to build Universal Mac binaries
128                     swig_opts = ['-includeall',
129                                  #'-D__i386__', # Uncomment for early OpenSSL 0.9.7 versions
130                                  ]
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_modules = [m2crypto],
146      test_suite='tests.alltests.suite',
147      cmdclass = {'build_ext': _M2CryptoBuildExt}
148      )
Note: See TracBrowser for help on using the repository browser.