Changeset 2232


Ignore:
Timestamp:
05/03/07 14:43:32 (12 years ago)
Author:
pjkersha
Message:

Dependencies/m2crypto/setup.py: Changed so that custom
build_ext class is specified using the cmdclass keyword to
setup rather having to sub class from build_ext directly.

Settings are made by overloading initialize_options and
finalize_options of build_ext in the _build_ext derived class.

_build_ext also has a modified version of user_options list
so that custom --openssl option is included in the help and
can be set in a config file.

Dependencies/m2crypto/setup.cfg: added note about setting
openssl option.

Location:
TI12-security/branches/Dependencies/m2crypto
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/branches/Dependencies/m2crypto/setup.cfg

    r2223 r2232  
    11[build_ext] 
    2 include_dirs=/usr/local/NDG/include 
    3 library_dirs=/usr/local/NDG/lib 
     2# Set openssl linking options here via openssl option or include_dirs/ 
     3# library_dirs e.g. 
     4#openssl=/usr/local 
     5# or ... 
     6#include_dirs=/usr/local/include 
     7#library_dirs=/usr/local/lib 
  • TI12-security/branches/Dependencies/m2crypto/setup.py

    r2223 r2232  
    1717import optparse 
    1818 
    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 
     19#  
    2120class _build_ext(build_ext.build_ext): 
     21    '''Specialization of build_ext to enable swig_opts to inherit any  
     22    include_dirs settings made at the command line or in a setup.cfg file''' 
     23    user_options = build_ext.build_ext.user_options + \ 
     24            [('openssl=', 'o', 'Prefix for openssl installation location')] 
     25 
     26    def initialize_options(self): 
     27        '''Overload to enable custom openssl settings to be picked up''' 
     28        build_ext.build_ext.initialize_options(self) 
     29         
     30        # openssl is the attribute corresponding to openssl directory prefix 
     31        # command line option 
     32        import pdb;pdb.set_trace() 
     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     
    2251    def finalize_options(self): 
     52        '''Overloaded build_ext implementation to append custom openssl 
     53        include file and library linking options''' 
    2354        build_ext.build_ext.finalize_options(self) 
    24         self.swig_opts = ['-I%s' % i for i in self.include_dirs] 
     55        import pdb;pdb.set_trace() 
    2556 
    26 # Custom Distribution class is also needed to enable build_ext class to be 
    27 # substitued with custom _build_ext     
    28 class _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      
    38 if os.name == 'nt': 
    39     defLibraries = ['ssleay32', 'libeay32'] 
    40     defOpenSSLPrefix = 'c:\\pkg' 
    41 else: 
    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 
    47 parser = 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 
    51 parser.add_option("-h",  
    52                   "--help", 
    53                   action="callback", 
    54                   callback=lambda option, optStr, value, parser: None) 
    55  
    56 parser.add_option("-I",  
    57                   "--include-dirs",  
    58                   default=[], 
    59                   dest="include_dirs") 
    60  
    61 parser.add_option("-L",  
    62                   "--library-dirs", 
    63                   default=[],  
    64                   dest="library_dirs") 
    65  
    66 parser.add_option("-l",  
    67                   "--libraries", 
    68                   default=defLibraries,  
    69                   dest="libraries") 
    70  
    71 parser.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  
    80 options.include_dirs += [os.path.join(options.openSSLPrefix,'include')]     
    81 options.library_dirs += [os.path.join(options.openSSLPrefix, 'lib')] 
    82  
    83 if 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         
    91 swig_opts = None#['-I' + ' -I'.join(options.include_dirs)]    
    92 options.include_dirs += [os.path.join(os.getcwd(), 'SWIG')] 
    93  
    94  
     57        opensslIncludeDir = os.path.join(self.openssl, 'include') 
     58        opensslLibraryDir = os.path.join(self.openssl, 'lib') 
     59         
     60        self.swig_opts = ['-I%s' % i for i in self.include_dirs + \ 
     61                          [opensslIncludeDir]] 
     62         
     63        self.include_dirs += [os.path.join(self.openssl, opensslIncludeDir)]         
     64        self.library_dirs += [os.path.join(self.openssl, opensslLibraryDir)] 
    9565 
    9666 
     
    152122m2crypto = Extension(name = '__m2crypto', 
    153123                     sources = ['SWIG/_m2crypto.i'], 
    154                      include_dirs = options.include_dirs, 
    155                      library_dirs = options.library_dirs, 
    156                      libraries = options.libraries, 
    157124                     extra_compile_args = ['-DTHREADING'], 
    158125                     #extra_link_args = ['-Wl,-search_paths_first'], 
    159                      swig_opts = swig_opts) 
     126                     ) 
    160127 
    161128setup(name = 'M2Crypto', 
     
    173140      ext_package = 'M2Crypto', 
    174141      ext_modules = [m2crypto], 
    175       distclass = _Distribution) 
     142      cmdclass={'build_ext': _build_ext}) 
    176143 
Note: See TracChangeset for help on using the changeset viewer.