7 set_description("Enable/Disable Java")
11 set_extensions(".java")
12 on_load(function(target
)
13 import("lib.detect.find_tool")
14 local opt
= { paths
= { "$(env JAVA_HOME)/bin" }, check
= function(...) end }
15 target
:set("javac", assert(find_tool("javac", opt
), "javac not found!").program
)
16 local opt
= { paths
= { "$(env JAVA_HOME)/bin" }, check
= function(...) end }
17 target
:set("jar", assert(find_tool("jar", opt
), "jar not found!").program
)
18 target
:set("kind", "static")
19 target
:set("prefixname", "")
20 target
:set("extension", ".jar")
22 on_buildcmd_files(function(target
, batchcmds
, sourcebatch
, opt
)
23 local src
= path
.join(target
:scriptdir(), "src")
24 local src
= path
.relative(src
, os
.projectdir())
25 local out
= path
.join(target
:objectdir(), src
)
26 local targetfile
= target
:targetfile()
28 sourcebatch
.objectfiles
= {}
29 sourcebatch
.dependfiles
= {}
30 for _
, sourcefile
in ipairs(sourcebatch
.sourcefiles
) do
31 local objectfile
= target
:objectfile(sourcefile
):gsub("(.+)%.java.+$", "%1.class")
32 local dependfile
= target
:dependfile(objectfile
)
33 table.insert(sourcebatch
.objectfiles
, objectfile
)
34 table.insert(sourcebatch
.dependfiles
, dependfile
)
37 batchcmds
:show_progress(opt
.progress
, "${color.build.object}compiling.java %s", path
.filename(targetfile
))
39 batchcmds
:vrunv(target
:get("javac"), table.join("-classpath", src
, "-d", out
, sourcebatch
.sourcefiles
))
41 batchcmds
:add_depfiles(sourcebatch
.sourcefiles
)
42 for _
, objectfile
in ipairs(sourcebatch
.objectfiles
) do
43 batchcmds
:set_depmtime(os
.mtime(objectfile
))
44 batchcmds
:set_depcache(sourcebatch
.dependfiles
[_
])
47 on_linkcmd(function(target
, batchcmds
, opt
)
48 local src
= path
.join(target
:scriptdir(), "src")
49 local src
= path
.relative(src
, os
.projectdir())
50 local cwd
= path
.join(target
:objectdir(), src
)
51 local targetfile
= target
:targetfile()
53 local objectfiles
= {}
54 for _
, objectfile
in ipairs(target
:objectfiles()) do
55 table.insert(objectfiles
, path
.relative(objectfile
, cwd
))
58 batchcmds
:show_progress(opt
.progress
, "${color.build.target}archiving.java %s", path
.filename(targetfile
))
59 batchcmds
:mkdir(target
:targetdir())
60 batchcmds
:vrunv(target
:get("jar"), table.join("-cf", path
.absolute(targetfile
), objectfiles
), { curdir
= cwd
})
62 batchcmds
:add_depfiles(target
:objectfiles())
63 batchcmds
:set_depmtime(os
.mtime(targetfile
))
64 batchcmds
:set_depcache(target
:dependfile(targetfile
))
66 on_install(function(target
)
67 local installdir
= target
:installdir()
69 print("installing %s to %s ..", target
:name(), installdir
)
70 installdir
= path
.join(installdir
, "share", "java")
72 os
.vcp(target
:targetfile(), installdir
)
77 if has_config("liba-java") then
80 add_files("src/**.java")
81 on_load(function(target
)
82 target
:set("targetdir", path
.join(target
:targetdir(), "java"))
90 add_defines("A_EXPORTS")
91 add_includedirs("include")
92 on_load(function(target
)
93 import("lib.detect.find_path")
96 find_path("jni.h", "$(env JAVA_HOME)/include"),
97 find_path("jni_md.h", "$(env JAVA_HOME)/include/*")
99 target
:set("targetdir", path
.join(target
:targetdir(), "java"))
101 on_install(function(target
)
102 local installdir
= target
:installdir()
104 print("installing %s to %s ..", target
:name(), installdir
)
105 installdir
= path
.join(installdir
, "lib", "jni")
107 os
.vcp(target
:targetfile(), installdir
)
110 if is_plat("windows", "mingw") then
111 set_filename("a.dll")