diff options
| author | ruki <[email protected]> | 2015-06-04 15:23:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-04 15:23:45 +0800 |
| commit | 83295bd3a1b27f844759aeadbbdc23f51e2f2d89 (patch) | |
| tree | e4d371b95497d791b07af5f0224aea40dfe647dd /xmake/scripts | |
| parent | 740fa0e8d4948a7261bcbb19fe7c3ac16f1df041 (diff) | |
move clang compiler and linker to tools
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/base/compiler.lua (renamed from xmake/scripts/compiler/compiler.lua) | 181 | ||||
| -rw-r--r-- | xmake/scripts/base/linker.lua (renamed from xmake/scripts/linker/linker.lua) | 100 | ||||
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 15 | ||||
| -rw-r--r-- | xmake/scripts/linker/_clang.lua | 82 | ||||
| -rw-r--r-- | xmake/scripts/platform/macosx/macosx.lua | 22 | ||||
| -rw-r--r-- | xmake/scripts/platform/platform.lua | 63 | ||||
| -rw-r--r-- | xmake/scripts/tools/ar.lua (renamed from xmake/scripts/linker/_ar.lua) | 32 | ||||
| -rw-r--r-- | xmake/scripts/tools/clang.lua (renamed from xmake/scripts/compiler/_clang.lua) | 75 | ||||
| -rw-r--r-- | xmake/scripts/tools/make.lua | 63 | ||||
| -rw-r--r-- | xmake/scripts/tools/tools.lua | 2 |
10 files changed, 267 insertions, 368 deletions
diff --git a/xmake/scripts/compiler/compiler.lua b/xmake/scripts/base/compiler.lua index a92fc37e0..101347c19 100644 --- a/xmake/scripts/compiler/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -28,27 +28,24 @@ local path = require("base/path") local utils = require("base/utils") local string = require("base/string") local config = require("base/config") +local tools = require("tools/tools") -- map gcc flags to the given compiler flags -function compiler._mapflags(self, flags) +function compiler._mapflags(module, flags) -- check - assert(self and flags); + assert(module and flags) -- need not map flags? return it directly - if not self.mapflag then + if not module.mapflag then return flags end - -- the configure - local configs = self._CONFIGS - assert(configs) - -- map flags local flags_mapped = {} for _, flag in pairs(flags) do -- map it - local flag_mapped = self._mapflag(configs, flag) + local flag_mapped = module.flag_map(flag) if flag_mapped then table.insert(flags_mapped, flag_mapped) end @@ -58,32 +55,83 @@ function compiler._mapflags(self, flags) return flag_mapped end +-- get the compiler name from the source file type +function compiler._name(srcfile) + + -- get the source file type + local filetype = path.extension(srcfile) + if not filetype then + return nil + end + + -- get the lower file type + filetype = filetype:lower() + + -- get the compiler name + local name = nil + if filetype == ".c" then name = "cc" + elseif filetype == ".cpp" or filetype == ".cc" then name = "cxx" + elseif filetype == ".m" then name = "mm" + elseif filetype == ".mm" then name = "mxx" + elseif filetype == ".s" or filetype == ".asm" then name = "as" + end + + -- ok + return name +end + +-- get the compiler from the given source file +function compiler.get(srcfile) + + -- get the compiler name + local name = compiler._name(srcfile) + if not name then + return + end + + -- get compiler from the source file type + local module = tools.get(name) + if module then + + -- invalid compiler + if not module.command_compile then + return + end + + -- save name + module._NAME = name + end + + -- ok? + return module +end + -- make the compile command -function compiler._make(self, target, filetype, srcfile, objfile) +function compiler.make(module, target, srcfile, objfile) -- check - assert(self and target and filetype); + assert(module and target) - -- the configure - local configs = self._CONFIGS - assert(configs) + -- the compiler name + local name = module._NAME + assert(name) -- the flag names local flag_names = nil - if filetype == "cc" then flag_names = { "cxflags", "cflags" } - elseif filetype == "cxx" then flag_names = { "cxflags", "cxxflags" } - elseif filetype == "mm" then flag_names = { "mxflags", "mflags" } - elseif filetype == "mxx" then flag_names = { "mxflags", "mxxflags" } - elseif filetype == "as" then flag_names = { "asflags" } + if name == "cc" then flag_names = { "cxflags", "cflags" } + elseif name == "cxx" then flag_names = { "cxflags", "cxxflags" } + elseif name == "mm" then flag_names = { "mxflags", "mflags" } + elseif name == "mxx" then flag_names = { "mxflags", "mxxflags" } + elseif name == "as" then flag_names = { "asflags" } -- error - utils.error("unknown filetype for compiler: %s", filetype) + utils.error("unknown compiler: %s", name) return end -- get the common flags from the current compiler local flags_common = "" for _, flag_name in ipairs(flag_names) do - flags_common = flags_common:append(configs[flag_name], " ") + flags_common = flags_common:append(module[flag_name], " ") end -- get the target flags from the current project @@ -91,7 +139,7 @@ function compiler._make(self, target, filetype, srcfile, objfile) for _, flag_name in ipairs(flag_names) do -- get flags - local flags = table.concat(compiler._mapflags(self, utils.wrap(target[flag_name])), " ") + local flags = table.concat(compiler._mapflags(module, utils.wrap(target[flag_name])), " ") -- trim the spaces flags = flags:trim() @@ -103,18 +151,18 @@ function compiler._make(self, target, filetype, srcfile, objfile) end -- get the includedirs flags from the current project - if self._make_includedir then + if module._make_includedir then local includedirs = utils.wrap(target.includedirs) for _, includedir in ipairs(includedirs) do - flags_target = flags_target:append(self._make_includedir(configs, includedir), " ") + flags_target = flags_target:append(module.flag_includedir(includedir), " ") end end -- get the defines flags from the current project - if self._make_define then + if module._make_define then local defines = utils.wrap(target.defines) for _, define in ipairs(defines) do - flags_target = flags_target:append(self._make_define(configs, define), " ") + flags_target = flags_target:append(module.flag_define(define), " ") end end @@ -123,7 +171,7 @@ function compiler._make(self, target, filetype, srcfile, objfile) for _, flag_name in ipairs(flag_names) do -- get flags - local flags = table.concat(compiler._mapflags(self, utils.wrap(config.get(flag_name))), " ") + local flags = table.concat(compiler._mapflags(module, utils.wrap(config.get(flag_name))), " ") -- trim the spaces flags = flags:trim() @@ -141,86 +189,9 @@ function compiler._make(self, target, filetype, srcfile, objfile) flags = flags:append(flags_config, " ") flags = flags:trim() - -- get it - return self._make(configs, srcfile, objfile, flags) + -- make the compile command + return module.command_compile(srcfile, objfile, flags) end --- load the given compiler -function compiler.load(name) - - -- check - assert(name and type(name) == "string") - - -- gcc? - local module = nil - if name:find("gcc", 1, true) then module = "gcc" - -- clang? - elseif name:find("clang", 1, true) then module = "clang" - -- cl.exe? - elseif name:find("cl.exe", 1, true) then module = "msvc" - -- icc? - elseif name:find("icc", 1, true) then module = "icc" - -- as? - elseif name:find("as", 1, true) then module = "as" - -- unknown? - else - -- error - utils.error("unknown compiler: %s", name) - return nil - end - - -- load the given compiler - local c = require("compiler/_" .. module) - if not c then - return nil - end - - -- the compiler has been loaded? return it directly - if c._CONFIGS then - return c - end - - -- make the compiler configure - c._CONFIGS = {} - local configs = c._CONFIGS - - -- init the compiler name - configs.name = name - - -- init the compiler configure - c._init(configs) - - -- init interfaces - c["make"] = compiler._make - - -- ok? - return c -end - --- get the source file type -function compiler.filetype(srcfile) - - -- get the source file type - local filetype = path.extension(srcfile) - if not filetype then - return nil - end - - -- get the lower file type - filetype = filetype:lower() - - -- get the compiler name - local name = nil - if filetype == ".c" then name = "cc" - elseif filetype == ".cpp" or filetype == ".cc" then name = "cxx" - elseif filetype == ".m" then name = "mm" - elseif filetype == ".mm" then name = "mxx" - elseif filetype == ".s" or filetype == ".asm" then name = "as" - end - - -- ok - return name -end - -- return module: compiler return compiler diff --git a/xmake/scripts/linker/linker.lua b/xmake/scripts/base/linker.lua index c8f651971..2516bbd29 100644 --- a/xmake/scripts/linker/linker.lua +++ b/xmake/scripts/base/linker.lua @@ -27,27 +27,24 @@ local linker = linker or {} local utils = require("base/utils") local string = require("base/string") local config = require("base/config") +local tools = require("tools/tools") -- map gcc flags to the given linker flags -function linker._mapflags(self, flags) +function linker._mapflags(module, flags) -- check - assert(self and flags); + assert(module and flags); -- need not map flags? return it directly - if not self.mapflag then + if not module.mapflag then return flags end - -- the configure - local configs = self._CONFIGS - assert(configs) - -- map flags local flags_mapped = {} for _, flag in pairs(flags) do -- map it - local flag_mapped = self._mapflag(configs, flag) + local flag_mapped = module.flag_map(flag) if flag_mapped then table.insert(flags_mapped, flag_mapped) end @@ -57,15 +54,11 @@ function linker._mapflags(self, flags) return flags_mapped end --- make the command -function linker._make(self, target, objfiles, targetfile) +-- make the link command +function linker.make(module, target, objfiles, targetfile) -- check - assert(self and self._make and target) - - -- the configure - local configs = self._CONFIGS - assert(configs) + assert(module and target) -- the target kind local kind = target.kind or "" @@ -82,30 +75,30 @@ function linker._make(self, target, objfiles, targetfile) end -- get the common flags from the current linker - local flags_common = configs[flag_name] or "" + local flags_common = module[flag_name] or "" -- get the target flags from the current project - local flags_target = table.concat(linker._mapflags(self, utils.wrap(target[flag_name])), " ") + local flags_target = table.concat(linker._mapflags(module, utils.wrap(target[flag_name])), " ") assert(flags_target) -- get the linkdirs flags from the current project - if self._make_linkdir then + if module._make_linkdir then local linkdirs = utils.wrap(target.linkdirs) for _, linkdir in ipairs(linkdirs) do - flags_target = flags_target:append(self._make_linkdir(configs, linkdir), " ") + flags_target = flags_target:append(module.flag_linkdir(linkdir), " ") end end -- get the links flags from the current project - if self._make_link then + if module._make_link then local links = utils.wrap(target.links) for _, link in ipairs(links) do - flags_target = flags_target:append(self._make_link(configs, link), " ") + flags_target = flags_target:append(module.flag_link(link), " ") end end -- get the config flags - local flags_config = table.concat(linker._mapflags(self, utils.wrap(config.get(flag_name))), " ") + local flags_config = table.concat(linker._mapflags(module, utils.wrap(config.get(flag_name))), " ") assert(flags_config) -- make the flags string @@ -115,59 +108,34 @@ function linker._make(self, target, objfiles, targetfile) flags = flags:append(flags_config, " ") flags = flags:trim() - -- make it - return self._make(configs, table.concat(objfiles, " "), targetfile, flags) + -- make the link command + return module.command_link(table.concat(objfiles, " "), targetfile, flags) end --- load the given linker -function linker.load(name) +-- get the linker from the given kind +function linker.get(kind) -- check - assert(name and type(name) == "string") + assert(kind) - -- gcc? - local module = nil - if name:find("gcc", 1, true) then module = "gcc" - -- clang? - elseif name:find("clang", 1, true) then module = "clang" - -- ar? - elseif name:find("ar", 1, true) then module = "ar" - -- cl.exe? - elseif name:find("link.exe", 1, true) then module = "msvc" - -- unknown? - else - -- error - utils.error("unknown linker: %s", name) - return nil - end - - -- load the given linker - local l = require("linker/_" .. module) - if not l then - return nil - end + -- get the linker name from the kind + local name = nil + if kind == "binary" then name = "ld" + elseif kind == "static" then name = "ar" + elseif kind == "shared" then name = "sh" + else return end + + -- get it + local module = tools.get(name) - -- the linker has been loaded? return it directly - if l._CONFIGS then - return l + -- invalid linker? + if module and not module.command_link then + return end - -- make the linker configure - l._CONFIGS = {} - local configs = l._CONFIGS - - -- init the linker name - configs.name = name - - -- init the linker configure - l._init(configs) - - -- init interfaces - l["make"] = linker._make - -- ok? - return l + return module end - + -- return module: linker return linker diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index 17ec4aeda..c3af02d05 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -31,8 +31,9 @@ local path = require("base/path") local utils = require("base/utils") local config = require("base/config") local project = require("base/project") +local linker = require("base/linker") +local compiler = require("base/compiler") local tools = require("tools/tools") -local platform = require("platform/platform") -- make the object to the makefile function makefile._make_object(file, target, srcfile, objfile) @@ -40,8 +41,8 @@ function makefile._make_object(file, target, srcfile, objfile) -- check assert(file and target and srcfile and objfile) - -- get the compiler and filetype - local c, filetype = platform.compiler(srcfile); + -- get the compiler + local c = compiler.get(srcfile); if not c then -- error utils.error("unknown source file: %s", srcfile) @@ -55,7 +56,7 @@ function makefile._make_object(file, target, srcfile, objfile) file:write(string.format(" %s\n", srcfile)) -- make body - local cmd = c:make(target, filetype, srcfile, objfile) + local cmd = compiler.make(c, target, srcfile, objfile) file:write(string.format("\t@echo [%s]: compiling %s\n", config.get("mode"), srcfile)) file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("%s", "%%20"))) file:write(string.format("\t@xmake l mkdir %s\n", path.directory(objfile))) @@ -106,8 +107,8 @@ function makefile._make_target(file, name, target) local targetfile = rule.targetfile(name, target) assert(targetfile) - -- the linker - local l = platform.linker(target.kind) + -- get the linker from the given kind + local l = linker.get(target.kind) assert(l) -- make head @@ -130,7 +131,7 @@ function makefile._make_target(file, name, target) file:write("\n") -- make body - local cmd = l:make(target, objfiles, targetfile) + local cmd = linker.make(l, target, objfiles, targetfile) file:write(string.format("\t@echo [%s]: linking %s\n", config.get("mode"), path.filename(targetfile))) file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("%s", "%%20"))) file:write(string.format("\t@xmake l mkdir %s\n", path.directory(targetfile))) diff --git a/xmake/scripts/linker/_clang.lua b/xmake/scripts/linker/_clang.lua deleted file mode 100644 index f51efae3d..000000000 --- a/xmake/scripts/linker/_clang.lua +++ /dev/null @@ -1,82 +0,0 @@ ---!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 _clang.lua --- - --- define module: _clang -local _clang = _clang or {} - --- load modules -local utils = require("base/utils") -local string = require("base/string") -local config = require("base/config") - --- init the linker -function _clang._init(configs) - - -- the architecture - local arch = config.get("arch") - assert(arch) - - -- init flags for architecture - local flags_arch = "" - if arch == "x86" then flags_arch = "-m32" - elseif arch == "x64" then flags_arch = "-m64" - else flags_arch = "-arch " .. arch - end - - -- init ldflags - configs.ldflags = flags_arch - - -- init shflags - configs.shflags = flags_arch .. " -dynamiclib" - -end - --- make the command -function _clang._make(configs, objfiles, targetfile, flags) - - -- make it - return string.format("%s %s -o%s %s", configs.name, flags, targetfile, objfiles) -end - --- make the link flag -function _clang._make_link(configs, link) - - -- make it - return "-l" .. link -end - --- make the linkdir flag -function _clang._make_linkdir(configs, linkdir) - - -- make it - return "-L" .. linkdir -end - --- map gcc flag to the current linker flag -function _clang._mapflag(configs, flag) - - -- ok - return flag -end - --- return module: _clang -return _clang diff --git a/xmake/scripts/platform/macosx/macosx.lua b/xmake/scripts/platform/macosx/macosx.lua index 4591293f0..bad818081 100644 --- a/xmake/scripts/platform/macosx/macosx.lua +++ b/xmake/scripts/platform/macosx/macosx.lua @@ -42,21 +42,15 @@ function _macosx.make(configs) configs.formats.shared = {"lib", ".dylib"} -- init the toolchains - configs.tools = {} + configs.tools = {} configs.tools.make = "make" - - -- init the compiler - configs.compiler = {} - configs.compiler.cc = config.get("cc") or "xcrun -sdk macosx clang" - configs.compiler.cxx = config.get("cxx") or "xcrun -sdk macosx clang++" - configs.compiler.mm = config.get("mm") or configs.compiler.cc - configs.compiler.mxx = config.get("mxx") or configs.compiler.cxx - - -- init the linker - configs.linker = {} - configs.linker.binary = config.get("ld") or "xcrun -sdk macosx clang++" - configs.linker.static = config.get("ar") or "xcrun -sdk macosx ar" - configs.linker.shared = config.get("sh") or "xcrun -sdk macosx clang++" + configs.tools.cc = config.get("cc") or "xcrun -sdk macosx clang" + configs.tools.cxx = config.get("cxx") or "xcrun -sdk macosx clang++" + configs.tools.mm = config.get("mm") or configs.tools.cc + configs.tools.mxx = config.get("mxx") or configs.tools.cxx + configs.tools.ld = config.get("ld") or "xcrun -sdk macosx clang++" + configs.tools.ar = config.get("ar") or "xcrun -sdk macosx ar" + configs.tools.sh = config.get("sh") or "xcrun -sdk macosx clang++" -- init xcode sdk directory configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. config.get("xcode_sdkver") .. ".sdk" diff --git a/xmake/scripts/platform/platform.lua b/xmake/scripts/platform/platform.lua index bd1f79485..3f9d2feec 100644 --- a/xmake/scripts/platform/platform.lua +++ b/xmake/scripts/platform/platform.lua @@ -29,8 +29,6 @@ local path = require("base/path") local utils = require("base/utils") local config = require("base/config") local global = require("base/global") -local linker = require("linker/linker") -local compiler = require("compiler/compiler") -- load prober the given platform directory function platform._load_prober(root) @@ -205,67 +203,6 @@ function platform.format(kind) end --- get the linker from the given name -function platform.linker(kind) - - -- check - assert(kind) - - -- init linkers - platform._LINKERS = platform._LINKERS or {} - local linkers = platform._LINKERS - - -- return it directly if the linker has been cached - local l = linkers[kind] - if l then return l end - - -- get linker - local c = platform.get("linker") - assert(c) - - -- load linker - c = c[kind] - if c then return linker.load(c) end - - -- cache this linker - linkers[kind] = l - - -- ok - return l -end - --- get the compiler from the given source file -function platform.compiler(srcfile) - - -- get the source file type - local filetype = compiler.filetype(srcfile) - if not filetype then - return - end - - -- init compilers - platform._COMPILERS = platform._COMPILERS or {} - local compilers = platform._COMPILERS - - -- return it directly if the compiler has been cached - local c = compilers[filetype] - if c then return c, filetype end - - -- get compiler from the current platform - c = platform.get("compiler") - assert(c) - - -- load compiler - c = c[filetype] - if c then c = compiler.load(c) end - - -- cache this compiler - compilers[filetype] = c - - -- ok - return c, filetype -end - -- dump the platform configure function platform.dump() diff --git a/xmake/scripts/linker/_ar.lua b/xmake/scripts/tools/ar.lua index c45dbaccb..e39967117 100644 --- a/xmake/scripts/linker/_ar.lua +++ b/xmake/scripts/tools/ar.lua @@ -17,11 +17,11 @@ -- Copyright (C) 2009 - 2015, ruki All rights reserved. -- -- @author ruki --- @file _ar.lua +-- @file ar.lua -- --- define module: _ar -local _ar = _ar or {} +-- define module: ar +local ar = ar or {} -- load modules local utils = require("base/utils") @@ -29,26 +29,36 @@ local string = require("base/string") local config = require("base/config") -- init the linker -function _ar._init(configs) +function ar.init(name) + + -- save name + ar.name = name or "ar" -- init arflags - configs.arflags = "-crs" + ar.arflags = "-crs" end --- make the command -function _ar._make(configs, objfiles, targetfile, flags) +-- make the link command +function ar.command_link(objfiles, targetfile, flags) -- make it - return string.format("%s %s %s %s", configs.name, flags, targetfile, objfiles) + return string.format("%s %s %s %s", ar.name, flags, targetfile, objfiles) end -- map gcc flag to the current linker flag -function _ar._mapflag(configs, flag) +function ar.flag_map(flag) -- ok return flag end --- return module: _ar -return _ar +-- the main function +function ar.main(...) + + -- ok + return true +end + +-- return module: ar +return ar diff --git a/xmake/scripts/compiler/_clang.lua b/xmake/scripts/tools/clang.lua index 4b66e3924..c11eb822e 100644 --- a/xmake/scripts/compiler/_clang.lua +++ b/xmake/scripts/tools/clang.lua @@ -17,19 +17,22 @@ -- Copyright (C) 2009 - 2015, ruki All rights reserved. -- -- @author ruki --- @file _clang.lua +-- @file clang.lua -- --- define module: _clang -local _clang = _clang or {} - -- load modules local utils = require("base/utils") local string = require("base/string") local config = require("base/config") --- init the compiler -function _clang._init(configs) +-- define module: clang +local clang = clang or {} + +-- the init function +function clang.init(name) + + -- save name + clang.name = name or "clang" -- the architecture local arch = config.get("arch") @@ -43,49 +46,83 @@ function _clang._init(configs) end -- init cflags - configs.cflags = flags_arch + clang.cflags = flags_arch -- init cxxflags - configs.cxxflags = flags_arch + clang.cxxflags = flags_arch -- init mflags - configs.mflags = flags_arch + clang.mflags = flags_arch -- init mxxflags - configs.mxxflags = flags_arch + clang.mxxflags = flags_arch -- init asflags - configs.asflags = flags_arch + clang.asflags = flags_arch + + -- init ldflags + clang.ldflags = flags_arch + + -- init shflags + clang.shflags = flags_arch .. " -dynamiclib" end --- make the compiler command -function _clang._make(configs, srcfile, objfile, flags) +-- make the compile command +function clang.command_compile(srcfile, objfile, flags) -- make it - return string.format("%s -c %s -o%s %s", configs.name, flags, objfile, srcfile) + return string.format("%s -c %s -o%s %s", clang.name, flags, objfile, srcfile) +end + +-- make the link command +function clang.command_link(objfiles, targetfile, flags) + + -- make it + return string.format("%s %s -o%s %s", clang.name, flags, targetfile, objfiles) end -- make the define flag -function _clang._make_define(configs, define) +function clang.flag_define(define) -- make it return "-D" .. define end -- make the includedir flag -function _clang._make_includedir(configs, includedir) +function clang.flag_includedir(includedir) -- make it return "-I" .. includedir end +-- make the link flag +function clang.flag_link(link) + + -- make it + return "-l" .. link +end + +-- make the linkdir flag +function clang.flag_linkdir(linkdir) + + -- make it + return "-L" .. linkdir +end + -- map gcc flag to the current compiler flag -function _clang._mapflag(configs, flag) +function clang.flag_map(flag) -- ok return flag end --- return module: _clang -return _clang +-- the main function +function clang.main(...) + + -- ok + return true +end + +-- return module: clang +return clang diff --git a/xmake/scripts/tools/make.lua b/xmake/scripts/tools/make.lua new file mode 100644 index 000000000..06a3a92dc --- /dev/null +++ b/xmake/scripts/tools/make.lua @@ -0,0 +1,63 @@ +--!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(name) + + -- save name + make.name = name or "make" + + -- 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("%s -j4 -f %s %s VERBOSE=%s", make.name, mkfile, target or "", make._VERBOSE) + else + cmd = string.format("%s -j4 %s VERBOSE=%s", make.name, 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 e29a2718b..af095618e 100644 --- a/xmake/scripts/tools/tools.lua +++ b/xmake/scripts/tools/tools.lua @@ -40,7 +40,7 @@ function tools._match(name, toolname) if name:find("^" .. toolname .. "$") then return true end -- contains it? ok - if name:find(toolname, true) then return true end + if name:find(toolname, 1, true) then return true end -- not matched return false |
