Skip to content

Commit 70c2ecd

Browse files
authored
Merge pull request #35 from jmgurney/detect_prefix
Detect prefix for building
2 parents 15480e7 + 6be53f2 commit 70c2ecd

File tree

1 file changed

+129
-122
lines changed

1 file changed

+129
-122
lines changed

setup.py

Lines changed: 129 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,129 @@
1-
#!/usr/bin/env python
2-
#
3-
# Copyright (c) 2015, SmartFile <[email protected]>
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-
28-
from os import environ
29-
30-
try:
31-
from setuptools import setup, Extension
32-
from setuptools.command.build_ext import build_ext
33-
except ImportError:
34-
from distutils.core import setup, Extension
35-
from distutils.command.build_ext import build_ext
36-
37-
38-
39-
# Use a provided libarchive else default to hard-coded path.
40-
libarchivePrefix = environ.get('LIBARCHIVE_PREFIX')
41-
42-
if libarchivePrefix:
43-
includePath = libarchivePrefix + '/include'
44-
else:
45-
includePath = '/usr/local/include'
46-
47-
48-
49-
50-
name = 'python-libarchive'
51-
version = '4.2.0'
52-
readme = 'README.rst'
53-
repourl = 'https://github.com/smartfile/python-libarchive'
54-
long_description = open(readme).read()
55-
56-
57-
class build_ext_extra(build_ext, object):
58-
"""
59-
Extend build_ext allowing extra_compile_args and extra_link_args to be set
60-
on the command-line.
61-
"""
62-
63-
user_options = build_ext.user_options
64-
user_options.append(('extra-compile-args=', None, 'Extra arguments passed directly to the compiler'))
65-
user_options.append(('extra-link-args=', None, 'Extra arguments passed directly to the linker'))
66-
67-
def initialize_options(self):
68-
build_ext.initialize_options(self)
69-
self.extra_compile_args = None
70-
self.extra_link_args = None
71-
72-
def build_extension(self, ext):
73-
if self.extra_compile_args:
74-
ext.extra_compile_args.append(self.extra_compile_args)
75-
if self.extra_link_args:
76-
ext.extra_link_args.append(self.extra_link_args)
77-
super(build_ext_extra, self).build_extension(ext)
78-
79-
80-
if libarchivePrefix:
81-
extra_compile_args = ['-I{0}/include'.format(libarchivePrefix)]
82-
extra_link_args = ['-Wl,-rpath,{0}/lib'.format(libarchivePrefix)]
83-
environ['LDFLAGS'] = '-L{0}/lib {1}'.format(libarchivePrefix, environ.get('LDFLAGS', ''))
84-
else:
85-
extra_compile_args = []
86-
extra_link_args = ['-l:libarchive.so']
87-
88-
__libarchive = Extension(
89-
name='libarchive.__libarchive',
90-
sources=['libarchive/_libarchive_wrap.c'],
91-
libraries=['archive'],
92-
extra_compile_args=extra_compile_args,
93-
extra_link_args=extra_link_args,
94-
include_dirs=[includePath, 'libarchive'],
95-
)
96-
97-
98-
setup(
99-
name=name,
100-
version=version,
101-
description='A libarchive wrapper for Python supporting password protection.',
102-
long_description=long_description,
103-
license='BSD-style license',
104-
platforms=['any'],
105-
author='Vadim Lebedev, Ben Timby, Travis Cunningham, Ryan Johnston, SmartFile',
106-
author_email='[email protected]',
107-
url=repourl,
108-
packages=['libarchive'],
109-
classifiers=[
110-
'Development Status :: 5 - Production/Stable',
111-
'Intended Audience :: Developers',
112-
'Operating System :: OS Independent',
113-
'Programming Language :: C',
114-
'Programming Language :: Python',
115-
'Topic :: System :: Archiving :: Compression',
116-
'Topic :: Software Development :: Libraries :: Python Modules',
117-
],
118-
cmdclass={
119-
'build_ext': build_ext_extra,
120-
},
121-
ext_modules=[__libarchive],
122-
)
1+
#!/usr/bin/env python
2+
#
3+
# Copyright (c) 2015, SmartFile <[email protected]>
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+
28+
from os import environ
29+
30+
try:
31+
from setuptools import setup, Extension
32+
from setuptools.command.build_ext import build_ext
33+
except ImportError:
34+
from distutils.core import setup, Extension
35+
from distutils.command.build_ext import build_ext
36+
37+
38+
39+
# Use a provided libarchive else default to hard-coded path.
40+
libarchivePrefix = environ.get('LIBARCHIVE_PREFIX')
41+
if libarchivePrefix is None:
42+
import pathlib
43+
for i in [ '/usr', '/usr/local', '/opt/local' ]:
44+
libdir = pathlib.Path(i) / 'lib'
45+
if any(libdir.glob('**/libarchive.*')):
46+
libarchivePrefix = i
47+
break
48+
49+
if libarchivePrefix:
50+
includePath = libarchivePrefix + '/include'
51+
else:
52+
includePath = '/usr/local/include'
53+
54+
55+
56+
57+
name = 'python-libarchive'
58+
version = '4.2.0'
59+
readme = 'README.rst'
60+
repourl = 'https://github.com/smartfile/python-libarchive'
61+
long_description = open(readme).read()
62+
63+
64+
class build_ext_extra(build_ext, object):
65+
"""
66+
Extend build_ext allowing extra_compile_args and extra_link_args to be set
67+
on the command-line.
68+
"""
69+
70+
user_options = build_ext.user_options
71+
user_options.append(('extra-compile-args=', None, 'Extra arguments passed directly to the compiler'))
72+
user_options.append(('extra-link-args=', None, 'Extra arguments passed directly to the linker'))
73+
74+
def initialize_options(self):
75+
build_ext.initialize_options(self)
76+
self.extra_compile_args = None
77+
self.extra_link_args = None
78+
79+
def build_extension(self, ext):
80+
if self.extra_compile_args:
81+
ext.extra_compile_args.append(self.extra_compile_args)
82+
if self.extra_link_args:
83+
ext.extra_link_args.append(self.extra_link_args)
84+
super(build_ext_extra, self).build_extension(ext)
85+
86+
87+
if libarchivePrefix:
88+
extra_compile_args = ['-I{0}/include'.format(libarchivePrefix)]
89+
extra_link_args = ['-Wl,-rpath,{0}/lib'.format(libarchivePrefix)]
90+
environ['LDFLAGS'] = '-L{0}/lib {1}'.format(libarchivePrefix, environ.get('LDFLAGS', ''))
91+
else:
92+
extra_compile_args = []
93+
extra_link_args = ['-l:libarchive.so']
94+
95+
__libarchive = Extension(
96+
name='libarchive.__libarchive',
97+
sources=['libarchive/_libarchive_wrap.c'],
98+
libraries=['archive'],
99+
extra_compile_args=extra_compile_args,
100+
extra_link_args=extra_link_args,
101+
include_dirs=[includePath, 'libarchive'],
102+
)
103+
104+
105+
setup(
106+
name=name,
107+
version=version,
108+
description='A libarchive wrapper for Python supporting password protection.',
109+
long_description=long_description,
110+
license='BSD-style license',
111+
platforms=['any'],
112+
author='Vadim Lebedev, Ben Timby, Travis Cunningham, Ryan Johnston, SmartFile',
113+
author_email='[email protected]',
114+
url=repourl,
115+
packages=['libarchive'],
116+
classifiers=[
117+
'Development Status :: 5 - Production/Stable',
118+
'Intended Audience :: Developers',
119+
'Operating System :: OS Independent',
120+
'Programming Language :: C',
121+
'Programming Language :: Python',
122+
'Topic :: System :: Archiving :: Compression',
123+
'Topic :: Software Development :: Libraries :: Python Modules',
124+
],
125+
cmdclass={
126+
'build_ext': build_ext_extra,
127+
},
128+
ext_modules=[__libarchive],
129+
)

0 commit comments

Comments
 (0)