forked from kivy/pyobjus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
72 lines (66 loc) · 1.96 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
from distutils.core import setup, Extension
from os import environ
from os.path import dirname, join, exists
import sys
import subprocess
import platform
dev_platform = sys.platform
kivy_ios_root = environ.get('KIVYIOSROOT', None)
arch = environ.get('ARCH', platform.machine())
if kivy_ios_root is not None:
dev_platform = 'ios'
# OSX
if dev_platform == 'darwin':
try:
from Cython.Distutils import build_ext
except ImportError:
raise
files = ['pyobjus.pyx']
# iOS
elif dev_platform == 'ios':
from distutils.command.build_ext import build_ext
files = ['pyobjus.c']
# create a configuration file for pyobjus (export the platform)
config_pxi_fn = join(dirname(__file__), 'pyobjus', 'config.pxi')
config_pxi_need_update = True
config_pxi = 'DEF PLATFORM = "{}"\n'.format(dev_platform)
config_pxi += 'DEF ARCH = "{}"'.format(arch)
if exists(config_pxi_fn):
with open(config_pxi_fn) as fd:
config_pxi_need_update = fd.read() != config_pxi
if config_pxi_need_update:
with open(config_pxi_fn, 'w') as fd:
fd.write(config_pxi)
if dev_platform == 'ios':
subprocess.call(['find', '.', '-name', '*.pyx', '-exec', 'cython', '{}', ';'])
libraries = ['ffi']
library_dirs = []
extra_compile_args = []
extra_link_args = []
include_dirs = []
depends = [join('pyobjus', x) for x in (
'config.pxi',
'common.pxi',
'ffi.pxi',
'objc_cy_types.pxi',
'pyobjus_conversions.pxi',
'pyobjus_types.pxi',
'runtime.pxi',
'type_enc.pxi',
'pyobjus.pyx')]
# create the extension
setup(name='pyobjus',
version='1.0',
cmdclass={'build_ext': build_ext},
packages=['pyobjus'],
ext_package='pyobjus',
ext_modules=[
Extension(
'pyobjus', [join('pyobjus', x) for x in files],
depends=depends,
libraries=libraries,
library_dirs=library_dirs,
include_dirs=include_dirs,
extra_link_args=extra_link_args)
]
)