summaryrefslogtreecommitdiff
path: root/xmake/core
diff options
context:
space:
mode:
authorruki <[email protected]>2016-07-09 22:34:16 +0800
committerruki <[email protected]>2016-07-09 22:34:16 +0800
commitf54223a97ba93b02128df84d52d3efe7abd2a36a (patch)
treeb6d5e5d1b4d70bd1eeadf936751eb50930f3bab6 /xmake/core
parent0d3075a0739eff0e28db11889a62ed3db8f4ab9f (diff)
add archiver and extractor
Diffstat (limited to 'xmake/core')
-rw-r--r--xmake/core/project/option.lua8
-rw-r--r--xmake/core/project/target.lua20
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/archiver.lua61
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/extractor.lua48
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/tool.lua16
-rw-r--r--xmake/core/tool/archiver.lua289
-rw-r--r--xmake/core/tool/compiler.lua17
-rw-r--r--xmake/core/tool/extractor.lua86
-rw-r--r--xmake/core/tool/linker.lua21
9 files changed, 489 insertions, 77 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 71226516f..1d554d887 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -52,7 +52,7 @@ function option:_check_link(sourcefile, objectfile, targetfile)
end
-- attempt to run this command
- local ok, errors = instance:run(instance:linkcmd(objectfile, targetfile, self))
+ local ok, errors = instance:link(objectfile, targetfile, self)
if not ok and option_.get("verbose") then
print(errors)
end
@@ -94,7 +94,7 @@ function option:_check_include(include, srcpath, objpath)
end
-- attempt to run this command
- local ok, errors = instance:run(instance:compcmd(srcpath, objpath, self))
+ local ok, errors = instance:compile(srcpath, objpath, self)
if not ok and option_.get("verbose") then
print(errors)
end
@@ -148,7 +148,7 @@ function option:_check_function(checkcode, srcpath, objpath)
srcfile:close()
-- execute the compile command
- local ok, errors = instance:run(instance:compcmd(srcpath, objpath, self))
+ local ok, errors = instance:compile(srcpath, objpath, self)
if not ok and option_.get("verbose") then
print(errors)
end
@@ -202,7 +202,7 @@ function option:_check_typedef(typedef, srcpath, objpath)
srcfile:close()
-- execute the compile command
- local ok, errors = instance:run(instance:compcmd(srcpath, objpath, self))
+ local ok, errors = instance:compile(srcpath, objpath, self)
if not ok and option_.get("verbose") then
print(errors)
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index a1f75be5f..5e3669c69 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -64,26 +64,6 @@ function target:name()
return self._NAME
end
--- get the linker
-function target:linker()
-
- -- check
- assert(self)
-
- -- load the linker from the given kind
- return linker.load(self:get("kind"))
-end
-
--- get the compiler with the given source file
-function target:compiler(srcfile)
-
- -- check
- assert(self and srcfile)
-
- -- load the compiler
- return compiler.load(compiler.kind_of_file(srcfile))
-end
-
-- get the options
function target:options()
diff --git a/xmake/core/sandbox/modules/import/core/tool/archiver.lua b/xmake/core/sandbox/modules/import/core/tool/archiver.lua
new file mode 100644
index 000000000..db354258c
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/tool/archiver.lua
@@ -0,0 +1,61 @@
+--!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 archiver.lua
+--
+
+-- define module
+local sandbox_core_tool_archiver = sandbox_core_tool_archiver or {}
+
+-- load modules
+local platform = require("platform/platform")
+local archiver = require("tool/archiver")
+local raise = require("sandbox/modules/raise")
+
+-- make command for archiving library file
+function sandbox_core_tool_archiver.archivecmd(objectfiles, targetfile, target)
+
+ -- get the archiver instance
+ local instance, errors = archiver.load()
+ if not instance then
+ raise(errors)
+ end
+
+ -- make command
+ return instance:archivecmd(objectfiles, targetfile, target)
+end
+
+-- archive library file
+function sandbox_core_tool_archiver.archive(objectfiles, targetfile, target)
+
+ -- get the archiver instance
+ local instance, errors = archiver.load()
+ if not instance then
+ raise(errors)
+ end
+
+ -- archive it
+ local ok, errors = instance:archive(objectfiles, targetfile, target)
+ if not ok then
+ raise(errors)
+ end
+end
+
+-- return module
+return sandbox_core_tool_archiver
diff --git a/xmake/core/sandbox/modules/import/core/tool/extractor.lua b/xmake/core/sandbox/modules/import/core/tool/extractor.lua
new file mode 100644
index 000000000..5c7ec29f1
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/tool/extractor.lua
@@ -0,0 +1,48 @@
+--!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 extractor.lua
+--
+
+-- define module
+local sandbox_core_tool_extractor = sandbox_core_tool_extractor or {}
+
+-- load modules
+local platform = require("platform/platform")
+local extractor = require("tool/extractor")
+local raise = require("sandbox/modules/raise")
+
+-- extract library file
+function sandbox_core_tool_extractor.extract(libraryfile, objectdir)
+
+ -- get the extractor instance
+ local instance, errors = extractor.load()
+ if not instance then
+ raise(errors)
+ end
+
+ -- extract it
+ local ok, errors = instance:extract(libraryfile, objectdir)
+ if not ok then
+ raise(errors)
+ end
+end
+
+-- return module
+return sandbox_core_tool_extractor
diff --git a/xmake/core/sandbox/modules/import/core/tool/tool.lua b/xmake/core/sandbox/modules/import/core/tool/tool.lua
index 539c9eeb6..27e20d6f4 100644
--- a/xmake/core/sandbox/modules/import/core/tool/tool.lua
+++ b/xmake/core/sandbox/modules/import/core/tool/tool.lua
@@ -36,22 +36,6 @@ function sandbox_core_tool.shellname(name)
return platform.tool(name)
end
--- run the tool
-function sandbox_core_tool.run(name, ...)
-
- -- check
- assert(name)
-
- -- load the tool instance
- local instance, errors = tool.load(name)
- if not instance then
- raise(errors)
- end
-
- -- run it
- instance.run(...)
-end
-
-- check the tool and return the absolute path if exists
function sandbox_core_tool.check(shellname, dirs, check)
diff --git a/xmake/core/tool/archiver.lua b/xmake/core/tool/archiver.lua
new file mode 100644
index 000000000..1fcb840b6
--- /dev/null
+++ b/xmake/core/tool/archiver.lua
@@ -0,0 +1,289 @@
+--!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 archiver.lua
+--
+
+-- define module
+local archiver = archiver or {}
+
+-- load modules
+local io = require("base/io")
+local path = require("base/path")
+local utils = require("base/utils")
+local table = require("base/table")
+local string = require("base/string")
+local config = require("project/config")
+local sandbox = require("sandbox/sandbox")
+local platform = require("platform/platform")
+local tool = require("tool/tool")
+
+-- get the current tool
+function archiver:_tool()
+
+ -- get it
+ return self._TOOL
+end
+
+-- get the current flag name
+function archiver:_flagname()
+
+ -- get it
+ return self._FLAGNAME
+end
+
+-- get the flags
+function archiver:_flags(target)
+
+ -- get the target key
+ local key = tostring(target)
+
+ -- get it directly from cache dirst
+ self._FLAGS = self._FLAGS or {}
+ if self._FLAGS[key] then
+ return self._FLAGS[key]
+ end
+
+ -- add flags from the configure
+ local flags = {}
+ self:_addflags_from_config(flags)
+
+ -- add flags from the target
+ self:_addflags_from_target(flags, target)
+
+ -- add flags from the platform
+ self:_addflags_from_platform(flags)
+
+ -- add flags from the archiver
+ self:_addflags_from_archiver(flags)
+
+ -- remove repeat
+ flags = table.unique(flags)
+
+ -- merge flags
+ flags = table.concat(flags, " "):trim()
+
+ -- save flags
+ self._FLAGS[key] = flags
+
+ -- get it
+ return flags
+end
+
+-- map gcc flag to the given archiver flag
+function archiver:_mapflag(flag, mapflags)
+
+ -- attempt to map it directly
+ local flag_mapped = mapflags[flag]
+ if flag_mapped then
+ return flag_mapped
+ end
+
+ -- find and replace it using pattern
+ for k, v in pairs(mapflags) do
+ local flag_mapped, count = flag:gsub("^" .. k .. "$", function (w) return v end)
+ if flag_mapped and count ~= 0 then
+ return utils.ifelse(#flag_mapped ~= 0, flag_mapped, nil)
+ end
+ end
+
+ -- check it
+ if self:check(flag) then
+ return flag
+ end
+end
+
+-- map gcc flags to the given archiver flags
+function archiver:_mapflags(flags)
+
+ -- wrap flags first
+ flags = table.wrap(flags)
+
+ -- done
+ local results = {}
+ local mapflags = self:get("mapflags")
+ if mapflags then
+
+ -- map flags
+ for _, flag in pairs(flags) do
+ local flag_mapped = self:_mapflag(flag, mapflags)
+ if flag_mapped then
+ table.insert(results, flag_mapped)
+ end
+ end
+
+ else
+
+ -- check flags
+ for _, flag in pairs(flags) do
+ if self:check(flag) then
+ table.insert(results, flag)
+ end
+ end
+
+ end
+
+ -- ok?
+ return results
+end
+
+-- get the named flags
+function archiver:_named_flags(names, flags)
+
+ -- map it
+ local flags_mapped = {}
+ for _, name in ipairs(table.wrap(names)) do
+ table.join2(flags_mapped, self:_mapflags(flags[name]))
+ end
+
+ -- get it
+ return flags_mapped
+end
+
+-- add flags from the configure
+function archiver:_addflags_from_config(flags)
+
+ -- done
+ table.join2(flags, config.get(self:_flagname()))
+end
+
+-- add flags from the target
+function archiver:_addflags_from_target(flags, target)
+
+ -- add the target flags
+ table.join2(flags, self:_mapflags(target:get(self:_flagname())))
+
+ -- add the strip flags
+ table.join2(flags, self:_named_flags(target:get("strip"), { debug = "-S"
+ , all = "-s"
+ }))
+end
+
+-- add flags from the platform
+function archiver:_addflags_from_platform(flags)
+
+ -- add flags
+ table.join2(flags, platform.get(self:_flagname()))
+end
+
+-- add flags from the archiver
+function archiver:_addflags_from_archiver(flags)
+
+ -- done
+ table.join2(flags, self:get(self:_flagname()))
+end
+
+-- load the archiver
+function archiver.load()
+
+ -- get it directly from cache dirst
+ if archiver._INSTANCE then
+ return archiver._INSTANCE
+ end
+
+ -- new instance
+ local instance = table.inherit(archiver)
+
+ -- load the archiver tool from the source file type
+ local result, errors = tool.load("ar")
+ if not result then
+ return nil, errors
+ end
+
+ -- save tool
+ instance._TOOL = result
+
+ -- init flag name
+ instance._FLAGNAME = "arflags"
+
+ -- save this instance
+ archiver._INSTANCE = instance
+
+ -- ok
+ return instance
+end
+
+-- get properties of the tool
+function archiver:get(name)
+
+ -- get it
+ return self:_tool().get(name)
+end
+
+-- archive the library file
+function archiver:archive(objectfiles, targetfile, target)
+
+ -- get flags
+ local flags = nil
+ if target then
+ flags = self:_flags(target)
+ end
+
+ -- archive it
+ return sandbox.load(self:_tool().archive, table.concat(table.wrap(objectfiles), " "), targetfile, flags or "")
+end
+
+-- get the archive command
+function archiver:archivecmd(objectfiles, targetfile, target)
+
+ -- get flags
+ local flags = nil
+ if target then
+ flags = self:_flags(target)
+ end
+
+ -- get it
+ return self:_tool().archivecmd(table.concat(table.wrap(objectfiles), " "), targetfile, flags or "")
+end
+
+-- check the given flags
+function archiver:check(flags)
+
+ -- the archiver tool
+ local ltool = self:_tool()
+
+ -- no check?
+ if not ltool.check then
+ return true
+ end
+
+ -- have been checked? return it directly
+ self._CHECKED = self._CHECKED or {}
+ if self._CHECKED[flags] ~= nil then
+ return self._CHECKED[flags]
+ end
+
+ -- check it
+ local ok, errors = sandbox.load(ltool.check, flags)
+
+ -- trace
+ utils.verbose("checking for the flags %s ... %s", flags, utils.ifelse(ok, "ok", "no"))
+ if not ok then
+ utils.verbose(errors)
+ end
+
+ -- save the checked result
+ self._CHECKED[flags] = ok
+
+ -- ok?
+ return ok
+end
+
+-- return module
+return archiver
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index da4e284fd..bb4aa2455 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -478,22 +478,5 @@ function compiler:check(flags)
return ok
end
--- run the command
-function compiler:run(...)
-
- -- the compiler tool
- local ctool = self:_tool()
-
- -- no run interface?
- if not ctool.run then
-
- -- run it
- return os.run(...)
- end
-
- -- run it
- return sandbox.load(ctool.run, ...)
-end
-
-- return module
return compiler
diff --git a/xmake/core/tool/extractor.lua b/xmake/core/tool/extractor.lua
new file mode 100644
index 000000000..cca1977a8
--- /dev/null
+++ b/xmake/core/tool/extractor.lua
@@ -0,0 +1,86 @@
+--!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 extractor.lua
+--
+
+-- define module
+local extractor = extractor or {}
+
+-- load modules
+local io = require("base/io")
+local path = require("base/path")
+local utils = require("base/utils")
+local table = require("base/table")
+local string = require("base/string")
+local config = require("project/config")
+local sandbox = require("sandbox/sandbox")
+local platform = require("platform/platform")
+local tool = require("tool/tool")
+
+-- get the current tool
+function extractor:_tool()
+
+ -- get it
+ return self._TOOL
+end
+
+-- load the extractor
+function extractor.load()
+
+ -- get it directly from cache dirst
+ if extractor._INSTANCE then
+ return extractor._INSTANCE
+ end
+
+ -- new instance
+ local instance = table.inherit(extractor)
+
+ -- load the extractor tool
+ local result, errors = tool.load("ex")
+ if not result then
+ return nil, errors
+ end
+
+ -- save tool
+ instance._TOOL = result
+
+ -- save this instance
+ extractor._INSTANCE = instance
+
+ -- ok
+ return instance
+end
+
+-- get properties of the tool
+function extractor:get(name)
+
+ -- get it
+ return self:_tool().get(name)
+end
+
+-- extract the library file
+function extractor:extract(libraryfile, objectdir)
+
+ -- extract it
+ return sandbox.load(self:_tool().extract, libraryfile, objectdir)
+end
+
+-- return module
+return extractor
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 41ce9bfd3..360259cb7 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -56,7 +56,6 @@ function linker._kind_of_target(targetkind)
local kinds =
{
["binary"] = "ld"
- , ["static"] = "ar"
, ["shared"] = "sh"
}
@@ -308,7 +307,6 @@ function linker.load(targetkind)
local flagname =
{
ld = "ldflags"
- , ar = "arflags"
, sh = "shflags"
}
instance._FLAGNAME = flagname[kind]
@@ -341,7 +339,7 @@ function linker:link(objectfiles, targetfile, target)
flags = self:_flags(target)
end
- -- get it
+ -- link it
return sandbox.load(self:_tool().link, table.concat(table.wrap(objectfiles), " "), targetfile, flags or "")
end
@@ -405,22 +403,5 @@ function linker:check(flags)
return ok
end
--- run the command
-function linker:run(...)
-
- -- the linker tool
- local ltool = self:_tool()
-
- -- no run interface?
- if not ltool.run then
-
- -- run it
- return os.run(...)
- end
-
- -- run it
- return sandbox.load(ltool.run, ...)
-end
-
-- return module
return linker