You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

123 lines
4.6 KiB

  1. #!/usr/bin/env python
  2. #
  3. # Copyright (c) 2015, SmartFile <tcunningham@smartfile.com>
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are met:
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. # * Neither the name of the organization nor the
  14. # names of its contributors may be used to endorse or promote products
  15. # derived from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  21. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. from os import environ
  28. try:
  29. from setuptools import setup, Extension
  30. from setuptools.command.build_ext import build_ext
  31. except ImportError:
  32. from distutils.core import setup, Extension
  33. from distutils.command.build_ext import build_ext
  34. # Use a provided libarchive else default to hard-coded path.
  35. libarchivePrefix = environ.get('LIBARCHIVE_PREFIX')
  36. if libarchivePrefix:
  37. includePath = libarchivePrefix + '/include'
  38. else:
  39. includePath = '/usr/local/include'
  40. name = 'python-libarchive'
  41. version = '4.1.3'
  42. readme = 'README.rst'
  43. repourl = 'https://github.com/smartfile/python-libarchive'
  44. long_description = open(readme).read()
  45. class build_ext_extra(build_ext, object):
  46. """
  47. Extend build_ext allowing extra_compile_args and extra_link_args to be set
  48. on the command-line.
  49. """
  50. user_options = build_ext.user_options
  51. user_options.append(('extra-compile-args=', None, 'Extra arguments passed directly to the compiler'))
  52. user_options.append(('extra-link-args=', None, 'Extra arguments passed directly to the linker'))
  53. def initialize_options(self):
  54. build_ext.initialize_options(self)
  55. self.extra_compile_args = None
  56. self.extra_link_args = None
  57. def build_extension(self, ext):
  58. if self.extra_compile_args:
  59. ext.extra_compile_args.append(self.extra_compile_args)
  60. if self.extra_link_args:
  61. ext.extra_link_args.append(self.extra_link_args)
  62. super(build_ext_extra, self).build_extension(ext)
  63. if libarchivePrefix:
  64. extra_compile_args = ['-I{0}/include'.format(libarchivePrefix)]
  65. extra_link_args = ['-Wl,-rpath={0}/lib'.format(libarchivePrefix)]
  66. environ['LDFLAGS'] = '-L{0}/lib {1}'.format(libarchivePrefix, environ.get('LDFLAGS', ''))
  67. else:
  68. extra_compile_args = []
  69. extra_link_args = ['-l:libarchive.so']
  70. __libarchive = Extension(
  71. name='libarchive.__libarchive',
  72. sources=['libarchive/_libarchive_wrap.c'],
  73. libraries=['archive'],
  74. extra_compile_args=extra_compile_args,
  75. extra_link_args=extra_link_args,
  76. include_dirs=[includePath, 'libarchive'],
  77. )
  78. setup(
  79. name=name,
  80. version=version,
  81. description='A libarchive wrapper for Python supporting password protection.',
  82. long_description=long_description,
  83. license='BSD-style license',
  84. platforms=['any'],
  85. author='Vadim Lebedev, Ben Timby, Travis Cunningham, Ryan Johnston, SmartFile',
  86. author_email='tech@smartfile.com',
  87. url=repourl,
  88. packages=['libarchive'],
  89. classifiers=[
  90. 'Development Status :: 4 - Beta',
  91. 'Intended Audience :: Developers',
  92. 'Operating System :: OS Independent',
  93. 'Programming Language :: C',
  94. 'Programming Language :: Python',
  95. 'Topic :: System :: Archiving :: Compression',
  96. 'Topic :: Software Development :: Libraries :: Python Modules',
  97. ],
  98. cmdclass={
  99. 'build_ext': build_ext_extra,
  100. },
  101. ext_modules=[__libarchive],
  102. )