diff options
| author | ruki <[email protected]> | 2021-06-02 00:53:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-06-02 00:53:54 +0800 |
| commit | 3bfbab4917a5b396444c188e32bfa4846c6f5d3f (patch) | |
| tree | 9f995dd48c42653c82295662809efec4d29136fe | |
| parent | 9ce75674d39133415fc292381ec59c04b55cae14 (diff) | |
copy package files
| -rw-r--r-- | xmake/actions/package/local/main.lua | 89 |
1 files changed, 87 insertions, 2 deletions
diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index 8118bff7a..4be7769eb 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -25,10 +25,95 @@ import("core.project.rule") import("core.project.config") import("core.project.project") +-- package binary +function _package_binary(target) + + -- get the output directory + local outputdir = option.get("outputdir") or config.buildir() + + -- generate xmake.lua + local packagename = target:name():lower() + local file = io.open(path.join(outputdir, "packages", packagename:sub(1, 1), packagename, "xmake.lua"), "w") + if file then + file:print("package(\"%s\")", packagename) + file:print(" set_description(\"%s\")", "The " .. packagename .. " package.") + file:print(" set_kind(\"binary\")") + file:print(" on_fetch(function (package, opt)") + file:print(" return {program = \"%s\"}", target:targetfile()) + file:print(" end)") + file:close() + end +end + +-- package library +function _package_library(target) + + -- get the output directory + local outputdir = option.get("outputdir") or config.buildir() + local packagename = target:name():lower() + local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) + local binarydir = path.join(packagedir, "bin", target:plat(), target:arch(), config.mode()) + local librarydir = path.join(packagedir, "lib", target:plat(), target:arch(), config.mode()) + + -- copy the library file to the output directory + local targetfile = target:targetfile() + if target:is_shared() and target:is_plat("windows", "mingw") then + os.mkdir(binarydir) + os.vcp(targetfile, binarydir) + os.trycp(target:symbolfile(), binarydir) + local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") + if os.isfile(targetfile_lib) then + os.mkdir(librarydir) + os.vcp(targetfile_lib, librarydir) + end + else + os.mkdir(librarydir) + os.vcp(targetfile, librarydir) + os.trycp(target:symbolfile(), librarydir) + end + + -- copy headers + local srcheaders, dstheaders = target:headerfiles(path.join(packagedir, "include")) + if srcheaders and dstheaders then + local i = 1 + for _, srcheader in ipairs(srcheaders) do + local dstheader = dstheaders[i] + if dstheader then + os.vcp(srcheader, dstheader) + end + i = i + 1 + end + end + + -- generate xmake.lua + local file = io.open(path.join(packagedir, "xmake.lua"), "w") + if file then + file:print("package(\"%s\")", packagename) + file:print(" set_description(\"%s\")", "The " .. packagename .. " package.") + file:print(" on_fetch(function (package, opt)") + file:print(" local result = {}") + file:print(" result.links = \"%s\"", target:linkname()) + if target:version() then + file:print(" result.version = \"%s\"", (target:version())) + end + file:print(" return result") + file:print(" end)") + file:close() + end +end + -- do package target function _do_package_target(target) - if target:is_phony() then - return + if not target:is_phony() then + local scripts = + { + binary = _package_binary + , static = _package_library + , shared = _package_library + } + local kind = target:kind() + assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind) + scripts[kind](target) end end |
