forked from rralf/mididings
-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
executable file
·186 lines (152 loc) · 5.02 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import platform
import sys
from distutils import sysconfig
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension
if sys.version_info >= (3,):
from subprocess import getstatusoutput
else:
from commands import getstatusoutput
version = '2.0.0'
status, output = getstatusoutput('git rev-parse --short HEAD')
if not status:
version = '%s+r%s' % (version, output)
config = {
'alsa-seq': (platform.system() == 'Linux'),
'jack-midi': True,
'debug': False,
}
include_dirs = []
libraries = []
library_dirs = []
define_macros = []
extra_compile_args = []
define_macros.append(('VERSION', '%s' % version))
# hack to modify the compiler flags from the distutils default
distutils_customize_compiler = sysconfig.customize_compiler
def my_customize_compiler(compiler):
retval = distutils_customize_compiler(compiler)
if not config['debug']:
# the -g flag might occur many times in python's compiler flags
compiler.compiler_so = [x for x in compiler.compiler_so if x != "-g"]
# immediately stop on error
compiler.compiler_so.append('-Wfatal-errors')
# some options to reduce the size of the binary
compiler.compiler_so.append('-fvisibility=hidden')
compiler.compiler_so.append('-fvisibility-inlines-hidden')
return retval
sysconfig.customize_compiler = my_customize_compiler
def pkgconfig(name):
"""
Run pkg-config for the given package, and add the required flags to our
list of build arguments.
"""
status, output = getstatusoutput('pkg-config --libs --cflags %s' % name)
if status:
sys.exit("couldn't find package '%s'" % name)
for token in output.split():
opt, val = token[:2], token[2:]
if opt == '-I':
include_dirs.append(val)
elif opt == '-l':
libraries.append(val)
elif opt == '-L':
library_dirs.append(val)
def library_path_dirs():
library_path = os.environ.get('LIBRARY_PATH')
return library_path.split(':') if library_path else []
def lib_dirs():
"""
Attempt to return the compiler's library search paths.
Also include paths from LIBRARY_PATH environment variable.
"""
env_libs = library_path_dirs()
try:
status, output = getstatusoutput('LC_ALL=C ' +
sysconfig.get_config_var('CC') + ' -print-search-dirs')
for line in output.splitlines():
if 'libraries: =' in line:
libdirs = [os.path.normpath(p)
for p in line.split('=', 1)[1].split(':')]
return env_libs + libdirs
return env_libs
except Exception:
return env_libs
def boost_lib_name(name, add_suffixes=[]):
"""
Try to figure out the correct boost library name (with or without "-mt"
suffix, or with any of the given additional suffixes).
"""
libdirs = lib_dirs()
for suffix in add_suffixes + ['', '-mt']:
for libdir in libdirs:
for ext in ['so'] + ['dylib'] * (sys.platform == 'darwin'):
libname = 'lib%s%s.%s' % (name, suffix, ext)
if os.path.isfile(os.path.join(libdir, libname)):
return name + suffix
return name
sources = [
'src/engine.cc',
'src/patch.cc',
'src/python_caller.cc',
'src/send_midi.cc',
'src/python_module.cc',
'src/backend/base.cc',
]
include_dirs.append('src')
boost_python_suffixes = ['-py%d%d' % sys.version_info[:2]]
if sys.version_info[0] == 3:
boost_python_suffixes.append('3')
boost_python_suffixes.append('%d%d' % sys.version_info[:2])
libraries.append(boost_lib_name('boost_python', boost_python_suffixes))
libraries.append(boost_lib_name('boost_thread'))
library_dirs.extend(library_path_dirs())
if config['alsa-seq']:
define_macros.append(('ENABLE_ALSA_SEQ', 1))
sources.append('src/backend/alsa.cc')
pkgconfig('alsa')
if config['jack-midi']:
define_macros.append(('ENABLE_JACK_MIDI', 1))
sources.extend(['src/backend/jack.cc',
'src/backend/jack_buffered.cc',
'src/backend/jack_realtime.cc'])
pkgconfig('jack')
setup(
name = 'mididings',
version = version,
author = 'Dominic Sacre',
author_email = '[email protected]',
url = 'http://das.nasophon.de/mididings/',
description = 'a MIDI router/processor',
license = 'GPL',
ext_modules = [
Extension(
name = '_mididings',
sources = sources,
include_dirs = include_dirs,
library_dirs = library_dirs,
libraries = libraries,
define_macros = define_macros,
extra_compile_args = extra_compile_args,
),
],
packages = [
'mididings',
'mididings.units',
'mididings.extra',
'mididings.live',
],
scripts = [
'scripts/mididings',
'scripts/livedings',
'scripts/send_midi',
],
install_requires=[
'decorator',
],
)