rename a_version.alpha to a_version.alpha_
[liba.git] / java / xmake.lua
blob79f50440646bcdc5b0ce8904df990570e2d03348
1 ---@diagnostic disable
2 -- option: liba-java
3 option("liba-java")
4 set_default(false)
5 set_showmenu(true)
6 set_category("liba")
7 set_description("Enable/Disable Java")
8 option_end()
10 rule("jar")
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")
21 end)
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)
35 end
37 batchcmds:show_progress(opt.progress, "${color.build.object}compiling.java %s", path.filename(targetfile))
38 batchcmds:mkdir(out)
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[_])
45 end
46 end)
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))
56 end
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))
65 end)
66 on_install(function(target)
67 local installdir = target:installdir()
68 if installdir then
69 print("installing %s to %s ..", target:name(), installdir)
70 installdir = path.join(installdir, "share", "java")
71 os.mkdir(installdir)
72 os.vcp(target:targetfile(), installdir)
73 end
74 end)
75 rule_end()
77 if has_config("liba-java") then
78 target("ajar")
79 add_rules("jar")
80 add_files("src/**.java")
81 on_load(function(target)
82 target:set("targetdir", path.join(target:targetdir(), "java"))
83 end)
84 set_basename("liba")
85 target_end()
87 target("ajni")
88 set_kind("shared")
89 add_files("src/**.c")
90 add_defines("A_EXPORTS")
91 add_includedirs("include")
92 on_load(function(target)
93 import("lib.detect.find_path")
94 target:add(
95 "includedirs",
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"))
100 end)
101 on_install(function(target)
102 local installdir = target:installdir()
103 if installdir then
104 print("installing %s to %s ..", target:name(), installdir)
105 installdir = path.join(installdir, "lib", "jni")
106 os.mkdir(installdir)
107 os.vcp(target:targetfile(), installdir)
109 end)
110 if is_plat("windows", "mingw") then
111 set_filename("a.dll")
112 else
113 set_basename("a")
115 add_deps("a")
116 target_end()