-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
166 lines (140 loc) · 4.66 KB
/
wscript
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python
# encoding: utf-8
import os
import waf_java_utils
######################
###### options #######
######################
def options (opt):
opt.add_option ("--with-jni", action="store_true", dest="WITH_JNI",
help = "enable the compilation of the JNI adapter (note: your JAVA_HOME environment variable must be properly set if you want to use this option)")
grp = opt.add_option_group ("Options for the plugin JNI/Java")
grp.add_option ("--java-package-name", action="store", type="string",
dest="JAVA_PACKAGE", default="ibex",
help="name of the java package to be build (default is ibex)")
opt.plugins["jni"] = "WITH_JNI"
######################
##### configure ######
######################
def configure (conf):
conf.env.WITH_JNI = conf.options.WITH_JNI
conf.start_msg ("JNI plugin")
if not conf.env.WITH_JNI:
conf.end_msg ("not used")
return
conf.end_msg ("enabled")
if not conf.env.ENABLE_SHARED:
conf.fatal ("To install the Java plugin, you must set the option --enable-shared")
# Load java tools, detect binaries and jni headers
conf.load ("waf_java_utils")
# Set java package name
conf.env.JAVA_PACKAGE = conf.options.JAVA_PACKAGE
if conf.env.DEST_OS == "win32":
# fix name-mangling for linking with the JVM on windows
# http://permalink.gmane.org/gmane.comp.gnu.mingw.user/6782
# http://stackoverflow.com/questions/8063842/mingw32-g-and-stdcall-suffix1
conf.env.append_unique ("LINKFLAGS_JAVA", "-Wl,--kill-at")
# Set important env variables about Java build
conf.env.JAVA_INSTALLDIR = os.path.join (conf.env.PREFIX, "share", "java")
conf.env.JAVA_SIGNATURE = conf.env.JAVA_PACKAGE.replace (".", "_")
######################
####### build ########
######################
def build (bld):
if not bld.env.WITH_JNI:
return
# Generate src/* from src/*.*.in (need bld.env.JAVA_PACKAGE and
# bld.env.JAVA_SIGNATURE)
for f in bld.path.ant_glob ("src/**/*.in"):
bld (
features = "subst",
source = f,
target = f.change_ext ("", ".in"),
)
# Set CLASSPATH for JAVA
java_bld = bld.path.get_bld()
bld.env.append_unique ("CLASSPATH_JAVA", java_bld.abspath())
bld.env.append_unique ("CLASSPATH_JAVA", java_bld.make_node("src").abspath())
# Compile src/Ibex.java into Ibex.class with javac
path = bld.env.JAVA_PACKAGE.replace (".", os.path.sep)
java_ibex_class = os.path.join (path, "Ibex.class")
bld (
features = "myjavac",
source = "src/Ibex.java",
target = java_ibex_class,
use = ["JAVA"],
)
java_ibex_header = "src/%s_Ibex.h" % bld.env.JAVA_SIGNATURE
# Generate C++ header with javah
pathdir = os.path.dirname (bld.env.JAVAC[0])
if os.path.exists(pathdir+"/bin/javah"): # valid for JDK<10
bld (
features = "myjavah",
source = java_ibex_class,
target = java_ibex_header,
use = ["JAVA"],
)
else:
bld (
features = "myjavah",
source = "src/Ibex.java",
target = "src", # target directory only
use = ["JAVA"],
)
# Generate jar
bld (
features = "myjar",
source = java_ibex_class,
target = bld.env.JAVA_PACKAGE + ".jar",
install_path = bld.env.JAVA_INSTALLDIR,
)
# Generate shared library
if bld.env.INSTALL_3RD:
rpath = bld.env.LIBDIR + ":" + bld.env.LIBDIR_3RD
else:
rpath = bld.env.LIBDIR
bld.shlib (
target = "ibex-java",
source = "src/ibex_Java.cpp",
use = [ "JAVA", "ibex", java_ibex_header ],
rpath = rpath,
install_path = bld.env.LIBDIR,
)
######################
####### utest ########
######################
def utest (tst):
if not tst.env.WITH_JNI:
return
# Generate tests/* from tests/*.in (need bld.env.JAVA_PACKAGE)
for f in tst.path.ant_glob ("tests/**/*.in"):
tst (
features = "subst",
source = f,
target = f.change_ext ("", ".in"),
)
# Add to LD_LIBRARY_PATH the path to the install directory of libs
tst.env.append_unique ("LD_LIBRARY_PATH_JAVA_TESTS", tst.env.LIBDIR)
# Add to CLASSPATH the path to the needed jar archive
ibexjar = os.path.join (tst.env.JAVA_INSTALLDIR, tst.env.JAVA_PACKAGE + ".jar")
tst.env.append_unique ("CLASSPATH_JAVA_TESTS", ibexjar)
java_tst = tst.path.find_node ("tests").abspath()
for jar in [ "junit-4.11.jar", "hamcrest-core-1.3.jar" ]:
tst.env.append_unique ("CLASSPATH_JAVA_TESTS", os.path.join (java_tst, jar))
# Compile src/Test.java into Test.class with javac and run the test
tst (
features = "myjavac javatest",
source = "tests/Test.java",
target = "tests/Test.class",
outdir = "tests",
use = ["JAVA_TESTS"],
)
# Compile src/IbexTest.java into IbexTest.class with javac and run the test
tst (
features = "myjavac javatest",
source = "tests/IbexTest.java",
target = "tests/IbexTest.class",
outdir = "tests",
use = ["JAVA_TESTS"],
classname_extra = "org.junit.runner.JUnitCore"
)