diff options
| author | ruki <[email protected]> | 2016-03-21 21:50:35 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-03-21 21:50:35 +0800 |
| commit | d1f010fc5582cdaabb2ed758b2aaf7ffa5a95a43 (patch) | |
| tree | d71bacbac82886d60e67ea8747de864d69dacf0f | |
| parent | 308b4d3661fad938dae830ee357778f85918f963 (diff) | |
add tool module for sandbox
| -rwxr-xr-x | xmake/actions/config/makefile.lua | 35 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 23 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/platform/tool.lua | 37 |
3 files changed, 91 insertions, 4 deletions
diff --git a/xmake/actions/config/makefile.lua b/xmake/actions/config/makefile.lua index 293fb45c0..62cd4084f 100755 --- a/xmake/actions/config/makefile.lua +++ b/xmake/actions/config/makefile.lua @@ -21,9 +21,10 @@ -- -- imports +import("core.platform.tool") import("core.project.project") --- get log file +-- get log makefile function _logfile() -- get it @@ -33,6 +34,34 @@ end -- make the object function _make_object(makefile, target, srcfile, objfile) + -- make object for the *.o/obj source makefile +--[[ if _make_object_for_object(makefile, target, srcfile, objfile) then return + elseif _make_object_for_static(makefile, target, srcfile, objfile) then return + end]] + + -- make command + local ccache = tool.shellname("ccache") + local compiler = target:compiler(srcfile) + local cmd = compiler:makecmd(target, srcfile, objfile, _logfile()) + if ccache then + cmd = ccache:append(cmd, " ") + end + + -- make head + makefile:printf("%s:", objfile) + + -- make dependence + makefile:print(" %s", srcfile) + + -- make body + makefile:print("\t@echo %scompiling.$(mode) %s", ifelse(ccache, "ccache ", ""), srcfile) + makefile:write(format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:encode())) + makefile:print("\t@xmake l mkdir %s", path.directory(objfile)) + makefile:print("\t@%s", cmd) + + -- make tail + makefile:print("") + end -- make all objects of the given target @@ -88,7 +117,7 @@ function _make_target(makefile, target) -- make body makefile:print("\t@echo linking.$(mode) %s", path.filename(targetfile)) - makefile:write("\t@xmake l $(VERBOSE) verbose \"%s\"\n", verbose) + makefile:write(format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", verbose)) makefile:print("\t@xmake l mkdir %s", path.directory(targetfile)) makefile:print("\t@%s", cmd) @@ -143,7 +172,7 @@ function make() -- enter project directory os.cd("$(projectdir)") - -- remove the log file first + -- remove the log makefile first os.rm(_logfile()) -- open the makefile diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 68dfefe3a..4fef8fbd6 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -30,6 +30,7 @@ local table = require("base/table") local option = require("project/option") local config = require("project/config") local linker = require("platform/linker") +local compiler = require("platform/compiler") local platform = require("platform/platform") -- get the filename from the given name and kind @@ -62,9 +63,12 @@ function target.name(self) return self._NAME end --- get the linker with the target kind +-- get the linker function target.linker(self) + -- check + assert(self) + -- init the linker from the given kind local result = linker.init(self:get("kind")) if not result then @@ -76,6 +80,23 @@ function target.linker(self) end +-- get the compiler with the given source file +function target.compiler(self, srcfile) + + -- check + assert(self and srcfile) + + -- init the linker from the given kind + local result, errors = compiler.init(srcfile) + if not result then + os.raise(errors) + end + + -- ok? + return result + +end + -- get the options function target.options(self) diff --git a/xmake/core/sandbox/modules/import/core/platform/tool.lua b/xmake/core/sandbox/modules/import/core/platform/tool.lua new file mode 100644 index 000000000..27cb9af52 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/platform/tool.lua @@ -0,0 +1,37 @@ +--!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 tool.lua +-- + +-- define module +local sandbox_core_platform_tool = sandbox_core_platform_tool or {} + +-- load modules +local platform = require("platform/platform") + +-- get the tool shell name +function sandbox_core_platform_tool.shellname(name) + + -- get it + return platform.tool(name) +end + +-- return module +return sandbox_core_platform_tool |
