diff options
| author | ruki <[email protected]> | 2015-06-04 13:50:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-04 13:50:59 +0800 |
| commit | 2f468e35a6c681a22308d1c6d1d37764c386c00c (patch) | |
| tree | fe1da0da8db6d61120ec176577aec8df41081f78 | |
| parent | 9f1d3468c22adabab1ad06cdb0014c4f6ef2caa6 (diff) | |
add make to tools
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 12 | ||||
| -rw-r--r-- | xmake/scripts/base/rule.lua | 6 | ||||
| -rw-r--r-- | xmake/scripts/platform/macosx/macosx.lua | 14 | ||||
| -rw-r--r-- | xmake/scripts/platform/platform.lua | 58 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/tools/nmake.lua (renamed from xmake/scripts/platform/windows/maker.lua) | 49 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/windows.lua | 19 | ||||
| -rw-r--r-- | xmake/scripts/tools/make.lua | 60 | ||||
| -rw-r--r-- | xmake/scripts/tools/tools.lua | 18 |
8 files changed, 163 insertions, 73 deletions
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index 3c18cfb87..aa598c916 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -31,6 +31,7 @@ local path = require("base/path") local utils = require("base/utils") local config = require("base/config") local project = require("base/project") +local tools = require("tools/tools") local platform = require("platform/platform") -- make the object to the makefile @@ -245,8 +246,15 @@ function makefile.build(target) local buildir = config.get("buildir") assert(buildir) - -- done build - return platform.build(buildir .. "/makefile", target) + -- load make + local make = tools.load(platform.tool("make")) + if not make then + utils.error("not found the make command!") + return false + end + + -- done make + return make.main(buildir .. "/makefile", target) end -- return module: makefile diff --git a/xmake/scripts/base/rule.lua b/xmake/scripts/base/rule.lua index bd2271549..795b7c1ab 100644 --- a/xmake/scripts/base/rule.lua +++ b/xmake/scripts/base/rule.lua @@ -48,12 +48,8 @@ function rule.filename(name, kind) -- check assert(name and kind) - -- get formats - local formats = platform.get("format") - assert(formats) - -- get format - local format = formats[kind] or {"", ""} + local format = platform.format(kind) or {"", ""} -- make it return format[1] .. name .. format[2] diff --git a/xmake/scripts/platform/macosx/macosx.lua b/xmake/scripts/platform/macosx/macosx.lua index 0ab0407b4..4591293f0 100644 --- a/xmake/scripts/platform/macosx/macosx.lua +++ b/xmake/scripts/platform/macosx/macosx.lua @@ -35,11 +35,15 @@ _macosx._ARCHS = {"x86", "x64"} -- make configure function _macosx.make(configs) - -- init the file name format - configs.format = {} - configs.format.static = {"lib", ".a"} - configs.format.object = {"", ".o"} - configs.format.shared = {"lib", ".dylib"} + -- init the file formats + configs.formats = {} + configs.formats.static = {"lib", ".a"} + configs.formats.object = {"", ".o"} + configs.formats.shared = {"lib", ".dylib"} + + -- init the toolchains + configs.tools = {} + configs.tools.make = "make" -- init the compiler configs.compiler = {} diff --git a/xmake/scripts/platform/platform.lua b/xmake/scripts/platform/platform.lua index 718587c84..bd1f79485 100644 --- a/xmake/scripts/platform/platform.lua +++ b/xmake/scripts/platform/platform.lua @@ -177,6 +177,34 @@ function platform.get(name) end end +-- get the given tool +function platform.tool(name) + + -- check + assert(name) + + -- get tools + local tools = platform.get("tools") + if tools then + return tools[name] + end + +end + +-- get the given format +function platform.format(kind) + + -- check + assert(kind) + + -- get formats + local formats = platform.get("formats") + if formats then + return formats[kind] + end + +end + -- get the linker from the given name function platform.linker(kind) @@ -397,36 +425,6 @@ function platform.probe(configs, is_global) end end end - --- build target from the given makefile -function platform.build(mkfile, target) - - -- attempt to done the platform special make first - local module = platform.module() - if module and module._MAKER and module._MAKER.done then - return module._MAKER.done(mkfile, target) - end - - -- is verbose? - local verbose = utils.ifelse(xmake._OPTIONS.verbose, "-v", "") - - -- make command - local cmd = nil - if mkfile and os.isfile(mkfile) then - cmd = string.format("make -j4 -f %s %s VERBOSE=%s", mkfile, target or "", verbose) - else - cmd = string.format("make -j4 %s VERBOSE=%s", target or "", verbose) - end - - -- done - local ok = os.execute(cmd) - if ok ~= 0 then - return false - end - - -- ok - return true -end -- return module: platform return platform diff --git a/xmake/scripts/platform/windows/maker.lua b/xmake/scripts/platform/windows/tools/nmake.lua index 81e8fd5de..81a41df88 100644 --- a/xmake/scripts/platform/windows/maker.lua +++ b/xmake/scripts/platform/windows/tools/nmake.lua @@ -17,7 +17,7 @@ -- Copyright (C) 2009 - 2015, ruki All rights reserved. -- -- @author ruki --- @file _maker.lua +-- @file nmake.lua -- -- load modules @@ -27,11 +27,11 @@ local utils = require("base/utils") local string = require("base/string") local config = require("base/config") --- define module: _maker -local _maker = _maker or {} +-- define module: nmake +local nmake = nmake or {} -- enter the given environment -function _maker._enter(name) +function nmake._enter(name) -- check assert(name) @@ -56,7 +56,7 @@ function _maker._enter(name) end -- leave the given environment -function _maker._leave(name, old) +function nmake._leave(name, old) -- check assert(name) @@ -67,38 +67,43 @@ function _maker._leave(name, old) end end --- build the target from the given makefile -function _maker.done(mkfile, target) - - -- enter the vs environment - local pathes = _maker._enter("path") - local libs = _maker._enter("lib") - local includes = _maker._enter("include") - local libpathes = _maker._enter("libpath") +-- the init function +function nmake.init() -- is verbose? - local verbose = utils.ifelse(xmake._OPTIONS.verbose, "-v", "") + nmake._VERBOSE = utils.ifelse(xmake._OPTIONS.verbose, "-v", "") + +end + +-- the main function +function nmake.main(mkfile, target) + + -- enter the vs environment + local pathes = nmake._enter("path") + local libs = nmake._enter("lib") + local includes = nmake._enter("include") + local libpathes = nmake._enter("libpath") -- make command local cmd = nil if mkfile and os.isfile(mkfile) then - cmd = string.format("nmake /f %s %s VERBOSE=%s 2> nul", mkfile, target or "", verbose) + cmd = string.format("nmake /f %s %s VERBOSE=%s 2> nul", mkfile, target or "", nmake._VERBOSE) else - cmd = string.format("nmake %s VERBOSE=%s 2> nul", target or "", verbose) + cmd = string.format("nmake %s VERBOSE=%s 2> nul", target or "", nmake._VERBOSE) end -- done local ok = os.execute(cmd) -- leave the vs environment - _maker._leave("path", pathes) - _maker._leave("lib", libs) - _maker._leave("include", includes) - _maker._leave("libpath", libpathes) + nmake._leave("path", pathes) + nmake._leave("lib", libs) + nmake._leave("include", includes) + nmake._leave("libpath", libpathes) -- ok? return utils.ifelse(ok == 0, true, false) end --- return module: _maker -return _maker +-- return module: nmake +return nmake diff --git a/xmake/scripts/platform/windows/windows.lua b/xmake/scripts/platform/windows/windows.lua index 310300bc1..5a7b48c72 100644 --- a/xmake/scripts/platform/windows/windows.lua +++ b/xmake/scripts/platform/windows/windows.lua @@ -32,18 +32,19 @@ _windows._HOST = "windows" -- init architectures _windows._ARCHS = {"x86", "x64"} --- init maker -_windows._MAKER = require("platform/windows/maker") - -- make configure function _windows.make(configs) - -- init the file name format - configs.format = {} - configs.format.static = {"", ".lib"} - configs.format.object = {"", ".obj"} - configs.format.shared = {"", ".dll"} - configs.format.binary = {"", ".exe"} + -- init the file formats + configs.formats = {} + configs.formats.static = {"", ".lib"} + configs.formats.object = {"", ".obj"} + configs.formats.shared = {"", ".dll"} + configs.formats.binary = {"", ".exe"} + + -- init the toolchains + configs.tools = {} + configs.tools.make = "nmake" -- init the compiler configs.compiler = {} diff --git a/xmake/scripts/tools/make.lua b/xmake/scripts/tools/make.lua new file mode 100644 index 000000000..c6a5ac088 --- /dev/null +++ b/xmake/scripts/tools/make.lua @@ -0,0 +1,60 @@ +--!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) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file make.lua +-- + +-- load modules +local os = require("base/os") +local utils = require("base/utils") + +-- define module: make +local make = make or {} + +-- the init function +function make.init() + + -- is verbose? + make._VERBOSE = utils.ifelse(xmake._OPTIONS.verbose, "-v", "") + +end + +-- the main function +function make.main(mkfile, target) + + -- make command + local cmd = nil + if mkfile and os.isfile(mkfile) then + cmd = string.format("make -j4 -f %s %s VERBOSE=%s", mkfile, target or "", make._VERBOSE) + else + cmd = string.format("make -j4 %s VERBOSE=%s", target or "", make._VERBOSE) + end + + -- done + local ok = os.execute(cmd) + if ok ~= 0 then + return false + end + + -- ok + return true +end + +-- return module: make +return make diff --git a/xmake/scripts/tools/tools.lua b/xmake/scripts/tools/tools.lua index 089f425e9..09e43dc94 100644 --- a/xmake/scripts/tools/tools.lua +++ b/xmake/scripts/tools/tools.lua @@ -98,6 +98,9 @@ end -- load tool from the given name and directory (optional) function tools.load(name, root) + -- check + assert(name) + -- find the tool file path local toolpath = tools.find(name, root) @@ -106,6 +109,21 @@ function tools.load(name, root) return end + -- load script + local script = loadfile(toolpath) + if script then + + -- load tool + local tool = script() + + -- init tool + if tool and tool.init then + tool.init() + end + + -- ok? + return tool + end end -- return module: tools |
