forked from jpype-project/jpype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
145 lines (127 loc) · 5.37 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
import os
import sys
import platform
from distutils.core import setup as distSetup
from distutils.core import Extension
class JPypeSetup(object):
def __init__(self):
self.extra_compile_args = []
self.macros = []
def setupFiles(self):
cpp_files = [
map(lambda x: "src/native/common/" + x,
os.listdir("src/native/common")),
map(lambda x: "src/native/python/" + x,
os.listdir("src/native/python")),
]
all_src = []
for i in cpp_files:
all_src += i
self.cpp = filter(lambda x: x[-4:] == '.cpp', all_src)
self.objc = filter(lambda x: x[-2:] == '.m', all_src)
def setupWindows(self):
print 'Choosing the Windows profile'
self.javaHome = os.getenv("JAVA_HOME")
if self.javaHome is None:
print "environment variable JAVA_HOME must be set"
sys.exit(-1)
self.jdkInclude = "win32"
self.libraries = ["Advapi32"]
self.libraryDir = [self.javaHome + "/lib"]
self.macros = [("WIN32", 1)]
self.extra_compile_args = ['/EHsc']
def setupMacOSX(self):
# Changes according to:
# http://stackoverflow.com/questions/8525193/cannot-install-jpype-on-os-x-lion-to-use-with-neo4j
# and
# http://blog.y3xz.com/post/5037243230/installing-jpype-on-mac-os-x
osx = platform.mac_ver()[0][:4]
javaHome = '/Library/Java/Home'
if osx == '10.6':
# I'm not sure if this really works on all 10.6 - confirm please
# :)
javaHome = ('/Developer/SDKs/MacOSX10.6.sdk/System/Library/'
'Frameworks/JavaVM.framework/Versions/1.6.0/')
elif osx in ('10.7', '10.8'):
javaHome = ('/System/Library/Frameworks/JavaVM.framework/'
'Versions/Current/')
self.javaHome = javaHome
self.jdkInclude = ""
self.libraries = ["dl"]
self.libraryDir = [self.javaHome + "/Libraries"]
self.macros = [('MACOSX', 1)]
def setupLinux(self):
self.javaHome = os.getenv("JAVA_HOME")
if self.javaHome is None:
possibleHomes = ['/usr/lib/jvm/default-java',
'/usr/lib/jvm/java-6-sun',
'/usr/lib/jvm/java-1.5.0-gcj-4.4',
'/usr/lib/jvm/jdk1.6.0_30',
'/usr/lib/jvm/java-1.5.0-sun-1.5.0.08',
'/usr/java/jdk1.5.0_05',
'/usr/lib/jvm/java-6-openjdk-amd64', # xubuntu 12.10
'/usr/lib/jvm/java-7-openjdk-amd64' # java 7 ubuntu 12.04
]
for home in possibleHomes:
includePath = os.path.join(home, 'include')
if os.path.exists(includePath):
self.javaHome = home
break
else:
raise RuntimeError(
"No Java/JDK could be found. I looked in the following "
"directories: %s\nPlease check that you have it installed. "
"If you have and the destination is not in the above list "
"please consider opening a ticket or creating a pull request "
"on github: https://github.com/originell/jpype/"
% '\n'+'\n'.join(possibleHomes))
self.jdkInclude = "linux"
self.libraries = ["dl"]
self.libraryDir = [os.path.join(self.javaHome, "lib")]
def setupPlatform(self):
if sys.platform == 'win32':
self.setupWindows()
elif sys.platform == 'darwin':
self.setupMacOSX()
else:
self.setupLinux()
def setupInclusion(self):
if sys.platform == 'darwin':
headerDirName = 'Headers'
else:
headerDirName = 'include'
self.includeDirs = [
"src/native/common/include",
"src/native/python/include",
os.path.join(self.javaHome, headerDirName),
os.path.join(self.javaHome, headerDirName, self.jdkInclude)
]
def setup(self):
self.setupFiles()
self.setupPlatform()
self.setupInclusion()
jpypeLib = Extension("_jpype",
self.cpp,
libraries=self.libraries,
define_macros=self.macros,
include_dirs=self.includeDirs,
library_dirs=self.libraryDir,
extra_compile_args=self.extra_compile_args
)
distSetup(
name="JPype",
version="0.5.4.2",
description="Python-Java bridge",
author="Steve Menard",
author_email="[email protected]",
url="http://jpype.sourceforge.net/",
packages=[
"jpype", 'jpype.awt', 'jpype.awt.event',
'jpypex', 'jpypex.swing'],
package_dir={
"jpype": "src/python/jpype",
'jpypex': 'src/python/jpypex',
},
ext_modules=[jpypeLib]
)
JPypeSetup().setup()