summaryrefslogtreecommitdiff
path: root/setup.py
blob: c5c02473bb6dd4c95856bbcf30a7e4bdf118d499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) AB Strakt 2001, All rights reserved
# Copyright (C) Jean-Paul Calderone 2008, All rights reserved
#
# @(#) $Id: setup.py,v 1.28 2004/08/10 10:59:01 martin Exp $
#

"""
Installation script for the OpenSSL module
"""

try:
    from ez_setup import use_setuptools
except ImportError:
    pass
else:
    use_setuptools(download_delay=0)

import os, sys

def pylibdir(prefixdir):
    pyver = "python%d.%d" % (sys.version_info[:2])
    if sys.platform == "win32":
        return os.path.join(prefixdir, "Lib", "site-packages")
    else:
        return os.path.join(prefixdir, "lib", pyver, "site-packages")
    
for i in range(len(sys.argv)):
    arg = sys.argv[i]
    prefixdir = None
    if arg.startswith("--prefix="):
        prefixdir = arg[len("--prefix="):]
    if arg == "--prefix":
        if len(sys.argv) > i+1:
            prefixdir = sys.argv[i+1]
        
    if prefixdir:
        libdir = pylibdir(prefixdir)
        try:
            os.makedirs(libdir)
        except EnvironmentError, le:
            # Okay, maybe the dir was already there.
            pass
        sys.path.append(libdir)
        print "os.environ.get('PYTHONPATH') is now ", os.environ.get('PYTHONPATH')
        pp = os.environ.get('PYTHONPATH','').split(':')
        pp.append(libdir)
        os.environ['PYTHONPATH'] = ':'.join(pp)
        print "os.environ.get('PYTHONPATH') is now ", os.environ.get('PYTHONPATH')

        
        
        
    

# Use setuptools if it's available.
from setuptools import Extension, setup
from glob import glob

from version import __version__

# A hack to determine if Extension objects support the depends keyword arg.
try:
    init_func = Extension.__init__.func_code
    has_dep = 'depends' in init_func.co_varnames
except:
    has_dep = 0
if not has_dep:
    # If it doesn't, create a local replacement that removes depends
    # from the kwargs before calling the regular constructor.
    _Extension = Extension
    class Extension(_Extension):
        def __init__(self, name, sources, **kwargs):
            kwargs.pop('depends', None)
            _Extension.__init__(self, name, sources, **kwargs)


crypto_src = ['src/crypto/crypto.c', 'src/crypto/x509.c',
              'src/crypto/x509name.c', 'src/crypto/pkey.c',
              'src/crypto/x509store.c', 'src/crypto/x509req.c',
              'src/crypto/x509ext.c', 'src/crypto/pkcs7.c',
              'src/crypto/pkcs12.c', 'src/crypto/netscape_spki.c',
              'src/util.c']
crypto_dep = ['src/crypto/crypto.h', 'src/crypto/x509.h',
              'src/crypto/x509name.h', 'src/crypto/pkey.h',
              'src/crypto/x509store.h', 'src/crypto/x509req.h',
              'src/crypto/x509ext.h', 'src/crypto/pkcs7.h',
              'src/crypto/pkcs12.h', 'src/crypto/netscape_spki.h',
              'src/util.h']
rand_src = ['src/rand/rand.c', 'src/util.c']
rand_dep = ['src/util.h']
ssl_src = ['src/ssl/connection.c', 'src/ssl/context.c', 'src/ssl/ssl.c',
           'src/util.c']
ssl_dep = ['src/ssl/connection.h', 'src/ssl/context.h', 'src/ssl/ssl.h',
           'src/util.h']

IncludeDirs = None
LibraryDirs = None

# Add more platforms here when needed
if os.name == 'nt' or sys.platform == 'win32':
    Libraries = ['eay32', 'Ws2_32']
    ExtraObjects = [r"c:\Python25\libs\ssleay32.a"]
else:
    Libraries = ['ssl', 'crypto']
    ExtraObjects = []

if sys.platform == 'darwin':
    IncludeDirs = ['/sw/include']
    LibraryDirs = ['/sw/lib']

# Use the SSL_LIB and SSL_INC environment variables to extend
# the library and header directories we pass to the extensions.
ssl_lib = os.environ.get('SSL_LIB', [])
if ssl_lib:
    if LibraryDirs:
        LibraryDirs += [ssl_lib]
    else:
        LibraryDirs = [ssl_lib]
ssl_inc = os.environ.get('SSL_INC', [])
if ssl_inc:
    if IncludeDirs:
        IncludeDirs += [ssl_inc]
    else:
        IncludeDirs = [ssl_inc]

# On Windows, make sure the necessary .dll's get added to the egg.
data_files = []
if sys.platform == 'win32':
    data_files = [("OpenSSL", glob(os.path.join(ssl_lib, '*.dll')))]

def mkExtension(name):
    modname = 'OpenSSL.' + name
    src = globals()[name.lower() + '_src']
    dep = globals()[name.lower() + '_dep']
    return Extension(modname, src, libraries=Libraries, depends=dep,
                     include_dirs=IncludeDirs, library_dirs=LibraryDirs,
                     extra_objects=ExtraObjects)

setup(name='pyOpenSSL', version=__version__,
      package_dir = {'OpenSSL': '.'},
      ext_modules = [mkExtension('crypto'), mkExtension('rand'),
                     mkExtension('SSL')],
      py_modules  = ['OpenSSL.__init__', 'OpenSSL.tsafe',
                     'OpenSSL.version', 'OpenSSL.test.__init__',
                     'OpenSSL.test.test_crypto',
                     'OpenSSL.test.test_ssl'],
      data_files = data_files,
      description = 'Python wrapper module around the OpenSSL library',
      author = 'Martin Sjögren, AB Strakt',
      author_email = 'msjogren@gmail.com',
      maintainer = 'Jean-Paul Calderone',
      maintainer_email = 'exarkun@twistedmatrix.com',
      url = 'http://pyopenssl.sourceforge.net/',
      license = 'LGPL',
      long_description = """\
High-level wrapper around a subset of the OpenSSL library, includes
 * SSL.Connection objects, wrapping the methods of Python's portable
   sockets
 * Callbacks written in Python
 * Extensive error-handling mechanism, mirroring OpenSSL's error codes
...  and much more ;)"""
     )