2014-08-27 07:57:37 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from distutils.core import setup, Extension
|
2016-07-28 01:19:24 +02:00
|
|
|
from distutils.sysconfig import get_config_vars
|
2014-08-27 07:57:37 +02:00
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import sys
|
|
|
|
import shutil
|
|
|
|
import multiprocessing
|
|
|
|
import subprocess
|
|
|
|
|
2016-02-16 00:16:09 +01:00
|
|
|
class flags_parser:
|
|
|
|
def __init__(self):
|
|
|
|
self.include_dirs = []
|
|
|
|
self.library_dirs = []
|
|
|
|
self.libraries = []
|
|
|
|
|
|
|
|
def parse(self, args):
|
|
|
|
"""Parse out the -I -L -l directives and return a list of all other arguments"""
|
|
|
|
ret = []
|
|
|
|
for token in args.split():
|
|
|
|
prefix = token[:2]
|
|
|
|
if prefix == '-I':
|
|
|
|
self.include_dirs.append(token[2:])
|
|
|
|
elif prefix == '-L':
|
|
|
|
self.library_dirs.append(token[2:])
|
|
|
|
elif prefix == '-l':
|
|
|
|
self.libraries.append(token[2:])
|
2014-08-27 07:57:37 +02:00
|
|
|
else:
|
2016-02-16 00:16:09 +01:00
|
|
|
ret.append(token)
|
|
|
|
return ret
|
2014-08-27 07:57:37 +02:00
|
|
|
|
|
|
|
def arch():
|
|
|
|
if platform.system() != 'Darwin': return []
|
|
|
|
a = os.uname()[4]
|
|
|
|
if a == 'Power Macintosh': a = 'ppc'
|
|
|
|
return ['-arch', a]
|
|
|
|
|
|
|
|
def target_specific():
|
|
|
|
|
|
|
|
if platform.system() != 'Darwin': return []
|
|
|
|
|
|
|
|
# on mavericks, clang will fail when unknown arguments are
|
|
|
|
# passed in. python distutils will pass in arguments it doesn't
|
|
|
|
# know about
|
|
|
|
return ['-Wno-error=unused-command-line-argument-hard-error-in-future']
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open('compile_flags') as _file:
|
|
|
|
extra_cmd = _file.read()
|
|
|
|
|
|
|
|
except:
|
|
|
|
extra_cmd = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open('link_flags') as _file:
|
|
|
|
ldflags = _file.read()
|
|
|
|
|
|
|
|
except:
|
|
|
|
ldflags = None
|
|
|
|
|
|
|
|
ext = None
|
|
|
|
packages = None
|
|
|
|
|
2015-08-27 12:52:13 +02:00
|
|
|
if '--bjam' in sys.argv:
|
2014-08-27 07:57:37 +02:00
|
|
|
|
2014-11-14 10:35:39 +01:00
|
|
|
if '--bjam' in sys.argv:
|
|
|
|
del sys.argv[sys.argv.index('--bjam')]
|
2014-08-27 07:57:37 +02:00
|
|
|
|
|
|
|
if not '--help' in sys.argv \
|
|
|
|
and not '--help-commands' in sys.argv:
|
|
|
|
|
|
|
|
toolset = ''
|
|
|
|
file_ext = '.so'
|
|
|
|
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
# msvc 9.0 (2008) is the official windows compiler for python 2.6
|
|
|
|
# http://docs.python.org/whatsnew/2.6.html#build-and-c-api-changes
|
|
|
|
toolset = ' msvc-9.0'
|
|
|
|
file_ext = '.pyd'
|
|
|
|
|
2014-11-27 04:05:06 +01:00
|
|
|
parallel_builds = ' -j%d' % multiprocessing.cpu_count()
|
2014-08-27 07:57:37 +02:00
|
|
|
|
|
|
|
# build libtorrent using bjam and build the installer with distutils
|
2015-08-09 01:18:05 +02:00
|
|
|
cmdline = 'b2 libtorrent-link=static boost-link=static release optimization=space stage_module --abbreviate-paths' + toolset + parallel_builds
|
2014-08-27 07:57:37 +02:00
|
|
|
print(cmdline)
|
|
|
|
if os.system(cmdline) != 0:
|
|
|
|
print('build failed')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try: os.mkdir('build')
|
|
|
|
except: pass
|
|
|
|
try: shutil.rmtree('build/lib')
|
|
|
|
except: pass
|
|
|
|
try: os.mkdir('build/lib')
|
|
|
|
except: pass
|
|
|
|
try: os.mkdir('libtorrent')
|
|
|
|
except: pass
|
2015-09-23 18:13:00 +02:00
|
|
|
shutil.copyfile('libtorrent' + file_ext, 'build/lib/libtorrent' + file_ext)
|
2014-08-27 07:57:37 +02:00
|
|
|
|
|
|
|
packages = ['libtorrent']
|
|
|
|
|
|
|
|
else:
|
2015-11-20 23:46:36 +01:00
|
|
|
# Remove the '-Wstrict-prototypes' compiler option, which isn't valid for C++.
|
2016-07-28 01:19:24 +02:00
|
|
|
cfg_vars = get_config_vars()
|
|
|
|
for key, value in cfg_vars.items():
|
|
|
|
if isinstance(value, str):
|
|
|
|
cfg_vars[key] = value.replace('-Wstrict-prototypes', '')
|
2014-08-27 07:57:37 +02:00
|
|
|
|
|
|
|
source_list = os.listdir(os.path.join(os.path.dirname(__file__), "src"))
|
2015-08-03 17:14:06 +02:00
|
|
|
source_list = [os.path.abspath(os.path.join(os.path.dirname(__file__), "src", s)) for s in source_list if s.endswith(".cpp")]
|
2014-08-27 07:57:37 +02:00
|
|
|
|
2015-08-27 12:52:13 +02:00
|
|
|
if extra_cmd:
|
2016-02-16 00:16:09 +01:00
|
|
|
flags = flags_parser()
|
|
|
|
# ldflags must be parsed first to ensure the correct library search path order
|
|
|
|
extra_link = flags.parse(ldflags)
|
|
|
|
extra_compile = flags.parse(extra_cmd)
|
|
|
|
|
2016-12-08 02:09:57 +01:00
|
|
|
# for some reason distutils uses the CC environment variable to determine
|
|
|
|
# the compiler to use for C++
|
|
|
|
if 'CXX' in os.environ:
|
|
|
|
os.environ['CC'] = os.environ['CXX']
|
|
|
|
if 'CXXFLAGS' in os.environ:
|
|
|
|
os.environ['CFLAGS'] = os.environ['CXXFLAGS']
|
|
|
|
|
2015-08-27 12:52:13 +02:00
|
|
|
ext = [Extension('libtorrent',
|
|
|
|
sources = source_list,
|
|
|
|
language='c++',
|
2016-02-16 00:16:09 +01:00
|
|
|
include_dirs = flags.include_dirs,
|
|
|
|
library_dirs = flags.library_dirs,
|
|
|
|
extra_link_args = extra_link + arch(),
|
|
|
|
extra_compile_args = extra_compile + arch() + target_specific(),
|
|
|
|
libraries = ['torrent-rasterbar'] + flags.libraries)]
|
2014-08-27 07:57:37 +02:00
|
|
|
|
|
|
|
setup(name = 'python-libtorrent',
|
2016-08-13 13:12:23 +02:00
|
|
|
version = '1.1.1',
|
2014-08-27 07:57:37 +02:00
|
|
|
author = 'Arvid Norberg',
|
2014-10-14 04:06:20 +02:00
|
|
|
author_email = 'arvid@libtorrent.org',
|
2014-08-27 07:57:37 +02:00
|
|
|
description = 'Python bindings for libtorrent-rasterbar',
|
|
|
|
long_description = 'Python bindings for libtorrent-rasterbar',
|
|
|
|
url = 'http://libtorrent.org',
|
|
|
|
platforms = [platform.system() + '-' + platform.machine()],
|
|
|
|
license = 'BSD',
|
|
|
|
packages = packages,
|
|
|
|
ext_modules = ext
|
|
|
|
)
|