summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-05-29 21:19:59 +0800
committerruki <[email protected]>2016-05-29 21:19:59 +0800
commit42bd7e6e3fea157cb946387a01cbb4b39ecbe559 (patch)
tree77d4c827c05d49bc4129e08f7e1caaadde428ab7
parenta686ee37d66f509ba01dbe10c2999c32e96c59db (diff)
impl package
-rwxr-xr-xxmake/actions/build/main.lua5
-rwxr-xr-xxmake/actions/config/main.lua6
-rwxr-xr-xxmake/actions/package/main.lua207
-rwxr-xr-xxmake/actions/package/xmake.lua27
-rwxr-xr-xxmake/actions/run/main.lua7
-rw-r--r--xmake/core/project/target.lua10
6 files changed, 218 insertions, 44 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 3053d2b77..b44a53a42 100755
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -33,11 +33,6 @@ import("builder")
-- main
function main()
- -- check xmake.lua
- if not os.isfile(project.file()) then
- raise("xmake.lua not found!")
- end
-
-- get the target name
local targetname = option.get("target")
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 6997d8896..6ba35ee66 100755
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -157,11 +157,6 @@ function main()
-- load project
project.load()
- -- check xmake.lua
- if not os.isfile(project.file()) then
- raise("xmake.lua not found!")
- end
-
-- check target
if targetname and targetname ~= "all" and nil == project.target(targetname) then
raise("unknown target: %s", targetname)
@@ -190,5 +185,4 @@ function main()
-- trace
print("configure ok!")
-
end
diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua
new file mode 100755
index 000000000..5907517d8
--- /dev/null
+++ b/xmake/actions/package/main.lua
@@ -0,0 +1,207 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file main.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.task")
+import("core.project.config")
+import("core.project.global")
+import("core.project.project")
+import("core.platform.platform")
+
+-- package binary
+function _package_binary(target)
+
+ -- the output directory
+ local outputdir = option.get("outputdir") or config.get("buildir")
+
+ -- copy the target file
+ os.cp(target:targetfile(), format("%s/%s.pkg/bin/$(mode)/$(plat)/$(arch)/%s", outputdir, target:name(), path.filename(target:targetfile())))
+end
+
+-- package library
+function _package_library(target)
+
+ -- the output directory
+ local outputdir = option.get("outputdir") or config.get("buildir")
+
+ -- the target name
+ local targetname = target:name()
+
+ -- copy the library file to the output directory
+ os.cp(target:targetfile(), format("%s/%s.pkg/lib/$(mode)/$(plat)/$(arch)/%s", outputdir, targetname, path.filename(target:targetfile())))
+
+ -- copy the config.h to the output directory
+ local config_h = target:get("config_h")
+ if config_h then
+ os.cp(config_h, format("%s/%s.pkg/inc/$(plat)/%s", outputdir, targetname, path.filename(config_h)))
+ end
+
+ -- copy headers
+ local srcheaders, dstheaders = target:headerfiles(format("%s/%s.pkg/inc", outputdir, targetname))
+ if srcheaders and dstheaders then
+ local i = 1
+ for _, srcheader in ipairs(srcheaders) do
+ local dstheader = dstheaders[i]
+ if dstheader then
+ os.cp(srcheader, dstheader)
+ end
+ i = i + 1
+ end
+ end
+
+ -- make xmake.lua
+ local file = io.open(format("%s/%s.pkg/xmake.lua", outputdir, targetname), "w")
+ if file then
+
+ -- the xmake.lua content
+ local content = [[
+-- the [targetname] package
+option("[targetname]")
+
+ -- show menu
+ set_showmenu(true)
+
+ -- set category
+ set_category("package")
+
+ -- set description
+ set_description("The [targetname] package")
+
+ -- set language: c99, c++11
+ set_languages("c99", "cxx11")
+
+ -- add defines to config.h if checking ok
+ add_defines_h_if_ok("$(prefix)_PACKAGE_HAVE_[TARGETNAME]")
+
+ -- add links for checking
+ add_links("[targetname]")
+
+ -- add link directories
+ add_linkdirs("lib/$(mode)/$(plat)/$(arch)")
+
+ -- add c includes for checking
+ add_cincludes("[targetname]/[targetname].h")
+
+ -- add include directories
+ add_includedirs("inc/$(plat)", "inc")
+]]
+
+ -- save file
+ file:write((content:gsub("%[targetname%]", targetname):gsub("%[TARGETNAME%]", targetname:upper())))
+
+ -- exit file
+ file:close()
+ end
+end
+
+-- package target
+function _package_target(target)
+
+ -- get kind
+ local kind = target:get("kind")
+
+ -- get script
+ local scripts =
+ {
+ binary = _package_binary
+ , static = _package_library
+ , shared = _package_library
+ }
+
+ -- check
+ assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind)
+
+ -- package it
+ scripts[kind](target)
+end
+
+-- package the given target
+function _package(target)
+
+ -- enter project directory
+ os.cd(project.directory())
+
+ -- the target scripts
+ local scripts =
+ {
+ target:get("package_before")
+ , target:get("package") or _package_target
+ , target:get("package_after")
+ }
+
+ -- package the target scripts
+ for i = 1, 3 do
+ local script = scripts[i]
+ if script ~= nil then
+ script(target)
+ end
+ end
+
+ -- leave project directory
+ os.cd("-")
+end
+
+-- package the given target and deps
+function _package_target_and_deps(target)
+
+ -- this target have been finished?
+ if _g.finished[target:name()] then
+ return
+ end
+
+ -- package for all dependent targets
+ for _, depname in ipairs(target:get("deps")) do
+ _package_target_and_deps(project.target(depname))
+ end
+
+ -- package target
+ _package_target(target)
+
+ -- finished
+ _g.finished[target:name()] = true
+end
+
+-- main
+function main()
+
+ -- get the target name
+ local targetname = option.get("target")
+
+ -- init finished states
+ _g.finished = {}
+
+ -- build it first
+ task.run("build", {target = targetname})
+
+ -- package all?
+ if targetname == "all" then
+ for _, target in pairs(project.targets()) do
+ _package_target_and_deps(target)
+ end
+ else
+ _package_target_and_deps(project.target(targetname))
+ end
+
+ -- trace
+ print("package ok!")
+end
diff --git a/xmake/actions/package/xmake.lua b/xmake/actions/package/xmake.lua
index 76c60c728..9ebf7f6c4 100755
--- a/xmake/actions/package/xmake.lua
+++ b/xmake/actions/package/xmake.lua
@@ -26,6 +26,9 @@ task("package")
-- set category
set_category("action")
+ -- on run
+ on_run("main")
+
-- set menu
set_menu({
-- usage
@@ -40,29 +43,7 @@ task("package")
-- options
, options =
{
- {'a', "archs", "kv", nil, "Package multiple given architectures."
- , " .e.g --archs=\"armv7, arm64\" or -a i386"
- , ""
- -- show the description of all architectures
- , function ()
-
- -- import platform
- import("core.platform.platform")
-
- -- make description
- local description = {}
- for i, plat in ipairs(platform.plats()) do
- description[i] = " - " .. plat .. ":"
- for _, arch in ipairs(platform.archs(plat)) do
- description[i] = description[i] .. " " .. arch
- end
- end
-
- -- get it
- return description
- end }
-
- , {'o', "outputdir", "kv", nil, "Set the output directory." }
+ {'o', "outputdir", "kv", nil, "Set the output directory." }
, {}
, {nil, "target", "v", "all", "Package a given target" }
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index 84d5435e2..43b942240 100755
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -48,7 +48,7 @@ function _run_target(target)
}
-- check
- assert(scripts[kind], "this target(%s) with kind(%s) is not executable!", target:name(), kind)
+ assert(scripts[kind], "this target(%s) with kind(%s) can not be executed!", target:name(), kind)
-- run it
scripts[kind](target)
@@ -77,11 +77,6 @@ end
-- main
function main()
- -- check xmake.lua
- if not os.isfile(project.file()) then
- raise("xmake.lua not found!")
- end
-
-- get the target name
local targetname = option.get("target")
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index a040ce5dc..991816e96 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -278,13 +278,13 @@ function target:objectfiles()
end
-- get the header files
-function target:headerfiles()
+function target:headerfiles(outputdir)
-- check
assert(self)
-- cached? return it directly
- if self._HEADERFILES then
+ if self._HEADERFILES and outputdir == nil then
return self._HEADERFILES[1], self._HEADERFILES[2]
end
@@ -293,7 +293,7 @@ function target:headerfiles()
if not headers then return end
-- get the headerdir
- local headerdir = self:get("headerdir") or config.get("buildir")
+ local headerdir = outputdir or self:get("headerdir") or config.get("buildir")
assert(headerdir)
-- get the source pathes and destinate pathes
@@ -330,7 +330,9 @@ function target:headerfiles()
end
-- cache it
- self._HEADERFILES = {srcheaders, dstheaders}
+ if outputdir == nil then
+ self._HEADERFILES = {srcheaders, dstheaders}
+ end
-- ok?
return srcheaders, dstheaders