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.
 
 
 
 
 

127 lines
5.0 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. import subprocess
  35. # retreive the version number form SWIG generated file
  36. cmd = [
  37. 'awk',
  38. '/ARCHIVE_VERSION_NUMBER/ { if (match($0,"[[:digit:]]+")) print substr($0, RSTART,RLENGTH) }',
  39. "libarchive/_libarchive_wrap.c",
  40. ]
  41. p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  42. vnum = int(p.stdout)
  43. name = 'python-libarchive-ext'
  44. version = '{}.{}.{}'.format(vnum // 1000000, (vnum // 1000) % 100, vnum % 100)
  45. versrel = version
  46. readme = 'README.rst'
  47. repourl = 'https://github.com/Vadiml1024/python-libarchive'
  48. repobranch = 'extended'
  49. download_url = repourl + f'/tarball/{repobranch}'
  50. long_description = open(readme).read()
  51. class build_ext_extra(build_ext, object):
  52. """
  53. Extend build_ext allowing extra_compile_args and extra_link_args to be set
  54. on the command-line.
  55. """
  56. user_options = build_ext.user_options
  57. user_options.append(('extra-compile-args=', None, 'Extra arguments passed directly to the compiler'))
  58. user_options.append(('extra-link-args=', None, 'Extra arguments passed directly to the linker'))
  59. def initialize_options(self):
  60. build_ext.initialize_options(self)
  61. self.extra_compile_args = None
  62. self.extra_link_args = None
  63. def build_extension(self, ext):
  64. if self.extra_compile_args:
  65. ext.extra_compile_args.append(self.extra_compile_args)
  66. if self.extra_link_args:
  67. ext.extra_link_args.append(self.extra_link_args)
  68. super(build_ext_extra, self).build_extension(ext)
  69. # Use a provided libarchive else default to hard-coded path.
  70. libarchivePrefix = environ.get('LIBARCHIVE_PREFIX')
  71. if libarchivePrefix:
  72. extra_compile_args = ['-I{0}/include'.format(libarchivePrefix)]
  73. extra_link_args = ['-Wl,-rpath={0}/lib'.format(libarchivePrefix)]
  74. environ['LDFLAGS'] = '-L{0}/lib {1}'.format(libarchivePrefix, environ.get('LDFLAGS', ''))
  75. else:
  76. extra_compile_args = []
  77. extra_link_args = ['-l:libarchive.so.13']
  78. __libarchive = Extension(
  79. name='libarchive.__libarchive',
  80. sources=['libarchive/_libarchive.i', 'libarchive/_libarchive_wrap.c'],
  81. libraries=['archive'],
  82. extra_compile_args=extra_compile_args,
  83. extra_link_args=extra_link_args,
  84. include_dirs=['libarchive'],
  85. )
  86. setup(
  87. name=name,
  88. version=versrel,
  89. description='A libarchive wrapper for Python supporting password protection.',
  90. long_description=long_description,
  91. license='BSD-style license',
  92. platforms=['any'],
  93. author='Vadim Lebedev, Ben Timby, Travis Cunningham, Ryan Johnston, SmartFile',
  94. author_email='vadiml1024@gmail.com',
  95. url=repourl,
  96. download_url=download_url,
  97. packages=['libarchive'],
  98. classifiers=[
  99. 'Development Status :: 4 - Beta',
  100. 'Intended Audience :: Developers',
  101. 'Operating System :: OS Independent',
  102. 'Programming Language :: C',
  103. 'Programming Language :: Python',
  104. 'Topic :: System :: Archiving :: Compression',
  105. 'Topic :: Software Development :: Libraries :: Python Modules',
  106. ],
  107. cmdclass={
  108. 'build_ext': build_ext_extra,
  109. },
  110. ext_modules=[__libarchive],
  111. )