pyjnius/setup.py

116 lines
3.9 KiB
Python
Raw Normal View History

2012-08-14 01:42:43 +00:00
from distutils.core import setup, Extension
from os import environ
from os.path import dirname, join
import sys
files = [
'jni.pxi',
'jnius_conversion.pxi',
'jnius_export_class.pxi',
'jnius_export_func.pxi',
'jnius_jvm_android.pxi',
'jnius_jvm_desktop.pxi',
'jnius_localref.pxi',
'jnius.pyx',
'jnius_utils.pxi',
]
2012-08-14 01:42:43 +00:00
libraries = []
library_dirs = []
extra_link_args = []
include_dirs = []
install_requires = []
2012-08-14 01:42:43 +00:00
# detect Python for android
platform = sys.platform
ndkplatform = environ.get('NDKPLATFORM')
if ndkplatform is not None and environ.get('LIBLINK'):
platform = 'android'
# detect cython
try:
from Cython.Distutils import build_ext
install_requires.append('cython')
2012-08-14 01:42:43 +00:00
except ImportError:
from distutils.command.build_ext import build_ext
if platform != 'android':
print '\n\nYou need Cython to compile Pyjnius.\n\n'
raise
files = [fn[:-3] + 'c' for fn in files if fn.endswith('pyx')]
2012-08-14 01:42:43 +00:00
if platform == 'android':
# for android, we use SDL...
libraries = ['sdl', 'log']
library_dirs = ['libs/' + environ['ARCH']]
elif platform == 'darwin':
import objc
framework = objc.pathForFramework('JavaVM.framework')
if not framework:
raise Exception('You must install Java on your Mac OS X distro')
extra_link_args = [ '-framework', 'JavaVM' ]
include_dirs = [ join(framework, 'Versions/A/Headers') ]
2012-08-14 01:42:43 +00:00
else:
import subprocess
# otherwise, we need to search the JDK_HOME
jdk_home = environ.get('JDK_HOME')
if not jdk_home:
jdk_home = subprocess.Popen('readlink -f /usr/bin/javac | sed "s:bin/javac::"',
shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
if not jdk_home:
raise Exception('Unable to determine JDK_HOME')
jre_home = environ.get('JRE_HOME')
if not jre_home:
jre_home = subprocess.Popen('readlink -f /usr/bin/java | sed "s:bin/java::"',
shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
if not jre_home:
raise Exception('Unable to determine JRE_HOME')
cpu = 'i386' if sys.maxint == 2147483647 else 'amd64'
include_dirs = [
join(jdk_home, 'include'),
join(jdk_home, 'include', 'linux')]
library_dirs = [join(jre_home, 'lib', cpu, 'server')]
extra_link_args = ['-Wl,-rpath', library_dirs[0]]
libraries = ['jvm']
# generate the config.pxi
with open(join(dirname(__file__), 'jnius', 'config.pxi'), 'w') as fd:
2012-08-14 01:42:43 +00:00
fd.write('DEF JNIUS_PLATFORM = {0!r}'.format(platform))
with open(join('jnius', '__init__.py')) as fd:
versionline = [x for x in fd.readlines() if x.startswith('__version__')]
version = versionline[0].split("'")[-2]
2012-08-14 01:42:43 +00:00
# create the extension
setup(name='jnius',
version=version,
2012-08-14 01:42:43 +00:00
cmdclass={'build_ext': build_ext},
packages=['jnius'],
url='http://pyjnius.readthedocs.org/',
author='Mathieu Virbel and Gabriel Pettier',
author_email='mat@kivy.org,gabriel@kivy.org',
license='LGPL',
description='Python library to access Java classes',
install_requires=install_requires,
ext_package='jnius',
2012-08-14 01:42:43 +00:00
ext_modules=[
Extension(
'jnius', [join('jnius', x) for x in files],
2012-08-14 01:42:43 +00:00
libraries=libraries,
library_dirs=library_dirs,
include_dirs=include_dirs,
extra_link_args=extra_link_args)
],
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Library or Lesser '
'General Public License (LGPL)',
'Natural Language :: English',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Software Development :: Libraries :: Application Frameworks'])