-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
executable file
·97 lines (78 loc) · 2.82 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
#!/usr/bin/env python3
'''
Created on 1 Dec 2017
@author: julianporter
'''
from setuptools import setup, Extension
from setuptools.config import read_configuration
import utils
import os
import os.path
from collections import namedtuple
from sys import exit
import platform
checker=utils.CheckCompiler('-std=c++14')
if not checker.run():
print('Cannot build pcm2mp3 unless compiler supports -std=c++14')
exit(1)
for lib in ['mp3lame','tag']:
checker=utils.CheckLibrary(lib)
if not checker.run():
print('Cannot build pcm2mp3 unless lib{0} is installed and on the compiler path'.format(lib))
exit(1)
configuration=read_configuration('setup.cfg')
metadata=configuration['metadata']
def sourceFilesIn(folder,exclude=[]):
try:
items=os.listdir(folder)
return [os.path.join(folder,item) for item in items if item.endswith('.cpp') and item not in exclude]
except:
return []
def getLibPaths(libs=[]):
paths=[]
OS=platform.system()
if OS == 'Darwin':
paths=['/usr/lib','/usr/local/lib','/opt/local/lib']
elif OS == 'Linux':
paths=['/usr/lib','/usr/local/lib','/usr/lib/x86_64-linux-gnu']
elif OS == 'Windows':
print('Windows is not supported - you\'re on your own')
else:
print('Unidentified OS {}'.format(OS))
return [p for p in paths if os.path.exists(p)]
Version = namedtuple('Version',['major','minor','maintenance'])
def processVersion():
version=metadata['version']
parts=version.split('.')
if len(parts)<3: parts.extend([0,0,0])
return Version(*(parts[:3]))
def makeExtension(module,src):
#print("Making {} with {}".format(module,src))
v=processVersion()
mv='"{0}.{1}.{2}"'.format(v.major,v.minor,v.maintenance)
libs=['mp3lame','tag']
libpaths=getLibPaths(libs)
return Extension(module,
define_macros = [('MAJOR_VERSION', v.major),
('MINOR_VERSION', v.minor),
('MAINTENANCE_VERSION', v.maintenance),
('MODULE_VERSION', mv)],
sources = src,
language = 'c++14',
include_dirs=['/usr/include'],
libraries = libs,
library_dirs = libpaths)
src=[]
src.extend(sourceFilesIn('src'))
src.extend(sourceFilesIn('pcm2mp3-cpp/src/info',['CRC16.cpp','info.cpp']))
src.extend(sourceFilesIn('pcm2mp3-cpp/src/transcode',['transcode.cpp']))
# src.extend(sourceFilesIn('pcm2mp3-cpp/src/id3',['main.cpp']))
coder = makeExtension('pcm2mp3',src)
with open('README.rst') as readme:
longDescription = readme.read()
setup (
cmdclass = {'cleaner' : utils.Cleaner },
ext_modules = [coder],
long_description = longDescription,
test_suite = 'nose.collector'
)