2012-08-14 01:42:43 +00:00
|
|
|
from distutils.core import setup, Extension
|
|
|
|
from os import environ
|
2013-06-08 13:33:01 +00:00
|
|
|
from os.path import dirname, join, exists
|
2012-08-14 01:42:43 +00:00
|
|
|
import sys
|
2014-08-19 18:06:44 +00:00
|
|
|
from platform import architecture
|
2012-08-14 01:42:43 +00:00
|
|
|
|
2012-08-20 23:19:43 +00:00
|
|
|
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 = []
|
2012-08-14 15:21:55 +00:00
|
|
|
include_dirs = []
|
2012-08-20 23:22:14 +00:00
|
|
|
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
|
2012-08-20 23:22:14 +00:00
|
|
|
install_requires.append('cython')
|
2012-08-14 01:42:43 +00:00
|
|
|
except ImportError:
|
|
|
|
from distutils.command.build_ext import build_ext
|
2012-08-20 23:19:43 +00:00
|
|
|
if platform != 'android':
|
2014-08-19 12:35:20 +00:00
|
|
|
print('\n\nYou need Cython to compile Pyjnius.\n\n')
|
2012-08-20 23:19:43 +00:00
|
|
|
raise
|
2012-08-23 21:45:16 +00:00
|
|
|
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']]
|
2012-10-16 15:25:34 +00:00
|
|
|
elif platform == 'darwin':
|
2015-02-26 03:32:12 +00:00
|
|
|
import subprocess
|
2015-05-01 01:29:55 +00:00
|
|
|
framework = subprocess.Popen('/usr/libexec/java_home',
|
2015-02-26 03:32:12 +00:00
|
|
|
shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
|
2015-05-01 01:29:55 +00:00
|
|
|
print('java_home: {0}\n'.format(framework));
|
2012-10-16 15:25:34 +00:00
|
|
|
if not framework:
|
|
|
|
raise Exception('You must install Java on your Mac OS X distro')
|
2015-05-01 01:29:55 +00:00
|
|
|
if '1.6' in framework:
|
|
|
|
extra_link_args = ['-framework', 'JavaVM']
|
|
|
|
include_dirs = [join(framework, 'System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers')]
|
|
|
|
else:
|
|
|
|
# TODO: This won't make a dylib that moves from one machine to another.
|
|
|
|
# TODO: it needs a switch to dlopen and a configuration of the path.
|
|
|
|
java_runtime_lib = '{0}/jre/lib/server'.format(framework)
|
|
|
|
extra_link_args = ['-L', java_runtime_lib, '-ljvm', '-rpath', java_runtime_lib]
|
|
|
|
include_dirs = ['{0}/include'.format(framework), '{0}/include/darwin'.format(framework)]
|
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:
|
2013-11-25 23:19:54 +00:00
|
|
|
if platform == 'win32':
|
|
|
|
env_var = environ.get('JAVA_HOME')
|
|
|
|
if env_var and 'jdk' in env_var:
|
|
|
|
jdk_home = env_var
|
|
|
|
|
|
|
|
# Remove /bin if it's appended to JAVA_HOME
|
|
|
|
if jdk_home[-3:] == 'bin':
|
|
|
|
jdk_home = jdk_home[:-4]
|
|
|
|
else:
|
|
|
|
jdk_home = subprocess.Popen('readlink -f `which javac` | sed "s:bin/javac::"',
|
|
|
|
shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
|
|
|
|
if not jdk_home or not exists(jdk_home):
|
2012-08-14 01:42:43 +00:00
|
|
|
raise Exception('Unable to determine JDK_HOME')
|
|
|
|
|
|
|
|
jre_home = environ.get('JRE_HOME')
|
2013-06-08 13:33:01 +00:00
|
|
|
if exists(join(jdk_home, 'jre')):
|
|
|
|
jre_home = join(jdk_home, 'jre')
|
2012-08-14 01:42:43 +00:00
|
|
|
if not jre_home:
|
2013-06-08 13:33:01 +00:00
|
|
|
jre_home = subprocess.Popen('readlink -f `which java` | sed "s:bin/java::"',
|
2012-08-14 01:42:43 +00:00
|
|
|
shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
|
|
|
|
if not jre_home:
|
|
|
|
raise Exception('Unable to determine JRE_HOME')
|
2014-08-19 18:06:44 +00:00
|
|
|
cpu = 'amd64' if architecture()[0] == '64bit' else 'i386'
|
2013-11-25 02:54:07 +00:00
|
|
|
|
2013-11-26 04:44:46 +00:00
|
|
|
if platform == 'win32':
|
|
|
|
incl_dir = join(jdk_home, 'include', 'win32')
|
|
|
|
else:
|
|
|
|
incl_dir = join(jdk_home, 'include', 'linux')
|
|
|
|
|
2012-08-14 01:42:43 +00:00
|
|
|
include_dirs = [
|
|
|
|
join(jdk_home, 'include'),
|
2013-11-26 04:44:46 +00:00
|
|
|
incl_dir]
|
2013-11-25 02:54:07 +00:00
|
|
|
if platform == 'win32':
|
|
|
|
library_dirs = [
|
|
|
|
join(jdk_home, 'lib'),
|
|
|
|
join(jre_home, 'bin', 'server')]
|
|
|
|
else:
|
|
|
|
library_dirs = [join(jre_home, 'lib', cpu, 'server')]
|
2012-08-14 01:42:43 +00:00
|
|
|
extra_link_args = ['-Wl,-rpath', library_dirs[0]]
|
|
|
|
libraries = ['jvm']
|
|
|
|
|
|
|
|
# generate the config.pxi
|
2012-08-14 13:09:48 +00:00
|
|
|
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))
|
|
|
|
|
2012-08-20 23:19:43 +00:00
|
|
|
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',
|
2012-08-20 23:19:43 +00:00
|
|
|
version=version,
|
2012-08-14 01:42:43 +00:00
|
|
|
cmdclass={'build_ext': build_ext},
|
2012-08-14 13:09:48 +00:00
|
|
|
packages=['jnius'],
|
2014-05-09 07:22:56 +00:00
|
|
|
py_modules=['jnius_config'],
|
2012-08-20 23:19:43 +00:00
|
|
|
url='http://pyjnius.readthedocs.org/',
|
|
|
|
author='Mathieu Virbel and Gabriel Pettier',
|
|
|
|
author_email='mat@kivy.org,gabriel@kivy.org',
|
2012-08-20 23:30:53 +00:00
|
|
|
license='LGPL',
|
|
|
|
description='Python library to access Java classes',
|
2012-08-20 23:22:14 +00:00
|
|
|
install_requires=install_requires,
|
2012-08-14 13:09:48 +00:00
|
|
|
ext_package='jnius',
|
2012-08-14 01:42:43 +00:00
|
|
|
ext_modules=[
|
|
|
|
Extension(
|
2012-08-20 23:19:43 +00:00
|
|
|
'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)
|
2012-08-20 23:22:14 +00:00
|
|
|
],
|
2012-08-20 23:30:53 +00:00
|
|
|
classifiers=[
|
|
|
|
'Development Status :: 4 - Beta',
|
|
|
|
'Intended Audience :: Developers',
|
2015-03-02 10:30:23 +00:00
|
|
|
'License :: OSI Approved :: MIT License',
|
2012-08-20 23:30:53 +00:00
|
|
|
'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'])
|