diff options
| author | ruki <[email protected]> | 2015-06-29 11:11:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-29 11:11:22 +0800 |
| commit | bb38407c1a929f2b098022b1e3d9f1dc75798dbf (patch) | |
| tree | 9cc0b395e7a6613b97e07c8741ec4822d5d3218c /xmake/scripts | |
| parent | de65696cf95ff6c266d3b0174c9c10e3711bb643 (diff) | |
package binary and static target
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/action/_package.lua | 20 | ||||
| -rw-r--r-- | xmake/scripts/base/os.lua | 30 | ||||
| -rw-r--r-- | xmake/scripts/base/package.lua | 60 | ||||
| -rw-r--r-- | xmake/scripts/base/rule.lua | 4 |
4 files changed, 86 insertions, 28 deletions
diff --git a/xmake/scripts/action/_package.lua b/xmake/scripts/action/_package.lua index 6c71e4fa1..af7cac9bf 100644 --- a/xmake/scripts/action/_package.lua +++ b/xmake/scripts/action/_package.lua @@ -121,12 +121,12 @@ function _package._makeconf(target_name, target) configs[target_name] = configs[target_name] or {} local configs_target = configs[target_name] - -- init configs for files - configs_target.files = configs_target.files or {} + -- init configs for architectures + configs_target.archs = configs_target.archs or {} -- init configs for architecture - configs_target.files[arch] = configs_target.files[arch] or {} - local configs_arch = configs_target.files[arch] + configs_target.archs[arch] = configs_target.archs[arch] or {} + local configs_arch = configs_target.archs[arch] -- save name configs_target.name = target_name @@ -134,17 +134,17 @@ function _package._makeconf(target_name, target) -- save kind configs_target.kind = target.kind - -- save the root directory - configs_arch.rootdir = rule.packagedir(target_name, arch) + -- save the target directory + configs_arch.targetdir = rule.backupdir(target_name, arch) -- save the config file - configs_arch.config_h = _package._backup(configs_arch.rootdir, rule.config_h(target)) + configs_arch.config_h = _package._backup(configs_arch.targetdir, rule.config_h(target)) -- save the target file - configs_arch.targetfile = _package._backup(configs_arch.rootdir, rule.targetfile(target_name, target)) + configs_arch.targetfile = _package._backup(configs_arch.targetdir, rule.targetfile(target_name, target)) - -- save the target directory - configs_arch.targetdir = options.outputdir or target.targetdir or config.get("buildir") + -- save the output directory + configs_arch.outputdir = options.outputdir or config.get("buildir") -- save the header files configs_arch.headerfiles = rule.headerfiles(target) diff --git a/xmake/scripts/base/os.lua b/xmake/scripts/base/os.lua index c20c2cb63..2e06b61c3 100644 --- a/xmake/scripts/base/os.lua +++ b/xmake/scripts/base/os.lua @@ -97,15 +97,21 @@ function os.cp(src, dst) -- is file? if os.isfile(src) then + + -- the destination is directory? append the filename + if os.isdir(dst) then + dst = string.format("%s/%s", dst, path.filename(src)) + end + -- copy file if not os.cpfile(src, dst) then - return false, string.format("cannot copy file %s to %s!", src, dst) + return false, string.format("cannot copy file %s to %s", src, dst) end -- is directory? elseif os.isdir(src) then -- copy directory if not os.cpdir(src, dst) then - return false, string.format("cannot copy directory %s to %s!", src, dst) + return false, string.format("cannot copy directory %s to %s", src, dst) end -- cp dir/*? elseif src:find("%*") then @@ -119,14 +125,14 @@ function os.cp(src, dst) for _, file in ipairs(files) do local dstfile = string.format("%s/%s", dst, file:sub(starpos)) if not os.cpfile(file, dstfile) then - return false, string.format("cannot copy file %s to %s!", file, dstfile) + return false, string.format("cannot copy file %s to %s", file, dstfile) end end end -- not exists? else - return false, string.format("cannot copy file %s, not found this file!", src) + return false, string.format("cannot copy file %s, not found this file", src) end -- ok @@ -143,11 +149,11 @@ function os.mv(src, dst) if os.exists(src) then -- move file or directory if not os.rename(src, dst) then - return false, string.format("cannot move %s to %s!", src, dst) + return false, string.format("cannot move %s to %s", src, dst) end -- not exists? else - return false, string.format("cannot move %s to %s, not found this file!", src, dst) + return false, string.format("cannot move %s to %s, not found this file", src, dst) end -- ok @@ -164,17 +170,17 @@ function os.rm(path) if os.isfile(path) then -- remove file if not os.rmfile(path) then - return false, string.format("cannot remove file %s!", path) + return false, string.format("cannot remove file %s", path) end -- is directory? elseif os.isdir(path) then -- remove directory if not os.rmdir(path) then - return false, string.format("cannot remove directory %s!", path) + return false, string.format("cannot remove directory %s", path) end -- not exists? else - return false, string.format("cannot remove file %s, not found this file!", path) + return false, string.format("cannot remove file %s, not found this file", path) end -- ok @@ -195,7 +201,7 @@ function os.cd(path) os._PREDIR = nil else -- error - return false, string.format("not found the previous directory!") + return false, string.format("not found the previous directory") end end @@ -207,7 +213,7 @@ function os.cd(path) -- change to directory if not os.chdir(path) then - return false, string.format("cannot change directory %s!", path) + return false, string.format("cannot change directory %s", path) end -- save the previous directory @@ -215,7 +221,7 @@ function os.cd(path) -- not exists? else - return false, string.format("cannot change directory %s, not found this directory!", path) + return false, string.format("cannot change directory %s, not found this directory", path) end -- ok diff --git a/xmake/scripts/base/package.lua b/xmake/scripts/base/package.lua index 6a0e66afa..6407bf428 100644 --- a/xmake/scripts/base/package.lua +++ b/xmake/scripts/base/package.lua @@ -25,6 +25,7 @@ local package = package or {} -- load modules local os = require("base/os") +local rule = require("base/rule") local path = require("base/path") local utils = require("base/utils") local config = require("base/config") @@ -33,9 +34,32 @@ local platform = require("platform/platform") -- package target for the static library function package._done_static(target) + -- check + assert(target and target.name and target.archs) - -- continue - return 0 + -- the plat and mode + local plat = config.get("plat") + local mode = config.get("mode") + assert(plat and mode) + + -- package it + for arch, info in pairs(target.archs) do + + -- check + assert(info.targetdir and info.targetfile and info.outputdir) + + -- copy the static library file to the output directory + local ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.targetfile), string.format("%s/%s.pkg/lib/%s/%s/%s/%s", info.outputdir, target.name, mode, plat, arch, path.filename(info.targetfile))) + + -- ok? + if not ok then + utils.error(errors) + return -1 + end + end + + -- ok + return 1 end -- package target for the shared library @@ -49,9 +73,37 @@ end -- package target for the binary library function package._done_binary(target) + -- check + assert(target and target.archs) + + -- the count of architectures + local count = 0 + for _, _ in pairs(target.archs) do count = count + 1 end - -- continue - return 0 + -- package it + local ok = nil + local errors = nil + for arch, info in pairs(target.archs) do + + -- check + assert(info.targetdir and info.targetfile and info.outputdir) + + -- copy the binary file to the output directory + if count == 1 then + ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.targetfile), info.outputdir) + else + ok, errors = os.cp(string.format("%s/%s", info.targetdir, info.targetfile), string.format("%s/%s", info.outputdir, rule.filename(path.basename(info.targetfile) .. "_" .. arch, "binary"))) + end + + -- ok? + if not ok then + utils.error(errors) + return -1 + end + end + + -- ok + return 1 end -- package target from the default script diff --git a/xmake/scripts/base/rule.lua b/xmake/scripts/base/rule.lua index bf28eb098..bafc054bc 100644 --- a/xmake/scripts/base/rule.lua +++ b/xmake/scripts/base/rule.lua @@ -73,8 +73,8 @@ function rule.config_h(target) return config_h end --- get the temporary package directory -function rule.packagedir(target_name, arch) +-- get the temporary backup directory for package +function rule.backupdir(target_name, arch) -- the temporary directory local tmpdir = os.tmpdir() |
