diff options
| author | ruki <[email protected]> | 2017-06-21 18:53:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-21 18:53:20 +0800 |
| commit | e7fd0a5c178956eb4801de3780f2bc3c0e7a3e1e (patch) | |
| tree | c1691a33309a18cf9b5c54dda592f33a8a7abd66 | |
| parent | 45a54659f7449ead7ed073f9c0cbbe1da9fcdc06 (diff) | |
move tools dir to core.tools and improve tool module
| -rw-r--r-- | xmake/core/language/language.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 69 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 10 | ||||
| -rw-r--r-- | xmake/core/tool/extractor.lua | 10 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 10 | ||||
| -rw-r--r-- | xmake/core/tool/tool.lua | 167 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ar.lua (renamed from xmake/tools/ar.lua) | 53 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua (renamed from xmake/tools/cl.lua) | 83 | ||||
| -rw-r--r-- | xmake/modules/core/tools/clang.lua (renamed from xmake/tools/clang.lua) | 6 | ||||
| -rw-r--r-- | xmake/modules/core/tools/clangxx.lua (renamed from xmake/tools/clangxx.lua) | 7 | ||||
| -rw-r--r-- | xmake/modules/core/tools/dmd.lua (renamed from xmake/tools/dmd.lua) | 94 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua (renamed from xmake/tools/gcc.lua) | 124 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gccgo.lua (renamed from xmake/tools/gccgo.lua) | 24 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gdc.lua (renamed from xmake/tools/gdc.lua) | 6 | ||||
| -rw-r--r-- | xmake/modules/core/tools/go.lua (renamed from xmake/tools/go.lua) | 63 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gxx.lua (renamed from xmake/tools/gxx.lua) | 7 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ldc.lua (renamed from xmake/tools/ldc.lua) | 4 | ||||
| -rw-r--r-- | xmake/modules/core/tools/lib.lua (renamed from xmake/tools/lib.lua) | 37 | ||||
| -rw-r--r-- | xmake/modules/core/tools/link.lua (renamed from xmake/tools/link.lua) | 62 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ml.lua (renamed from xmake/tools/ml.lua) | 61 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ml64.lua (renamed from xmake/tools/ml64.lua) | 4 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rc.lua (renamed from xmake/tools/rc.lua) | 59 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rustc.lua (renamed from xmake/tools/rustc.lua) | 57 | ||||
| -rw-r--r-- | xmake/modules/core/tools/swiftc.lua (renamed from xmake/tools/swiftc.lua) | 78 | ||||
| -rwxr-xr-x | xmake/scripts/gas-preprocessor.pl | 2 |
26 files changed, 287 insertions, 816 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index c860b1a2a..e76d10b10 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -82,15 +82,11 @@ end -- get the language menu function _instance:menu() - - -- get it return self._INFO.menu end -- get the language name function _instance:name() - - -- get it return self._NAME end diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index fb753aed3..8990f7935 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -58,7 +58,7 @@ function sandbox_core_tool_compiler.compcmd(sourcefiles, objectfile, target, sou if not instance then raise(errors) end - + -- make command return instance:compcmd(sourcefiles, objectfile, target) end diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 43bed8bfa..d62eb4d1b 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -76,8 +76,8 @@ function builder:_mapflag(flag, mapflags) end end - -- check it - if self:check(flag) then + -- has this flag? + if self:has_flags(flag) then return flag end end @@ -103,9 +103,9 @@ function builder:_mapflags(flags) else - -- check flags + -- has flags? for _, flag in pairs(flags) do - if self:check(flag) then + if self:has_flags(flag) then table.insert(results, flag) end end @@ -261,8 +261,8 @@ function builder:_addflags_from_language(flags, target) for _, flagvalue in ipairs(table.wrap(getter(flagname))) do -- map and check flag - local flag = mapper(flagvalue, target, self:_targetkind()) - if flag and flag ~= "" and (not checkstate or self:check(flag)) then + local flag = mapper(self:_tool(), flagvalue, target, self:_targetkind()) + if flag and flag ~= "" and (not checkstate or self:has_flags(flag)) then table.join2(flags, flag) end end @@ -270,11 +270,29 @@ function builder:_addflags_from_language(flags, target) end end +-- get tool name +function builder:name() + return self:_tool():name() +end + +-- get tool kind +function builder:kind() + return self:_tool():kind() +end + +-- get tool program +function builder:program() + return self:_tool():program() +end + -- get properties of the tool function builder:get(name) + return self:_tool():get(name) +end - -- get it - return self:_tool().get(name) +-- has flags? +function builder:has_flags(flags) + return self:_tool():has_flags(name) end -- get the format of the given target kind @@ -297,40 +315,5 @@ function builder:feature(name) end end --- check the given flags -function builder:check(flags) - - -- the builder tool - local ctool = self:_tool() - - -- no check? - if not ctool.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(ctool.check, flags) - - -- trace - if option.get("verbose") then - utils.cprint("checking for the flags %s ... %s", flags, utils.ifelse(ok, "${green}ok", "${red}no")) - if not ok then - utils.cprint("${red}" .. errors or "") - end - end - - -- save the checked result - self._CHECKED[flags] = ok - - -- ok? - return ok -end - -- return module return builder diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index a550564da..d6a1c74ed 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -50,7 +50,7 @@ end function compiler:_addflags_from_platform(flags, targetkind) -- add flags - local toolkind = self:get("kind") + local toolkind = self:kind() for _, flagkind in ipairs(self:_flagkinds()) do -- add flags for platform @@ -128,28 +128,28 @@ end function compiler:build(sourcefiles, targetkind, targetfile, target) -- get it - return sandbox.load(self:_tool().build, sourcefiles, targetkind, targetfile, (self:compflags(target)) .. " " .. (target:linkflags())) + return sandbox.load(self:_tool().build, self:_tool(), sourcefiles, targetkind, targetfile, (self:compflags(target)) .. " " .. (target:linkflags())) end -- get the build command function compiler:buildcmd(sourcefiles, targetkind, targetfile, target) -- get it - return self:_tool().buildcmd(sourcefiles, targetkind, targetfile, (self:compflags(target) .. " " .. (target:linkflags()))) + return self:_tool():buildcmd(sourcefiles, targetkind, targetfile, (self:compflags(target) .. " " .. (target:linkflags()))) end -- compile the source files function compiler:compile(sourcefiles, objectfile, incdepfile, target) -- compile it - return sandbox.load(self:_tool().compile, sourcefiles, objectfile, incdepfile, (self:compflags(target))) + return sandbox.load(self:_tool().compile, self:_tool(), sourcefiles, objectfile, incdepfile, (self:compflags(target))) end -- get the compile command function compiler:compcmd(sourcefiles, objectfile, target) -- get it - return self:_tool().compcmd(sourcefiles, objectfile, (self:compflags(target))) + return self:_tool():compcmd(sourcefiles, objectfile, (self:compflags(target))) end -- get the compling flags diff --git a/xmake/core/tool/extractor.lua b/xmake/core/tool/extractor.lua index 1149e31aa..480005c68 100644 --- a/xmake/core/tool/extractor.lua +++ b/xmake/core/tool/extractor.lua @@ -38,8 +38,6 @@ local tool = require("tool/tool") -- get the current tool function extractor:_tool() - - -- get it return self._TOOL end @@ -72,16 +70,12 @@ end -- get properties of the tool function extractor:get(name) - - -- get it - return self:_tool().get(name) + 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) + return sandbox.load(self:_tool().extract, self:_tool(), libraryfile, objectdir) end -- return module diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 0ddf3165b..7427dbfac 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -44,7 +44,7 @@ local compiler = require("tool/compiler") function linker:_addflags_from_platform(flags, targetkind) -- add flags - local toolkind = self:get("kind") + local toolkind = self:kind() for _, flagkind in ipairs(self:_flagkinds()) do -- attempt to add special lanugage flags first, .e.g gc-ldflags, dc-arflags @@ -61,7 +61,7 @@ function linker:_addflags_from_compiler(flags, targetkind, sourcekinds) -- make flags local flags_of_compiler = {} - local toolkind = self:get("kind") + local toolkind = self:kind() for _, sourcekind in ipairs(table.wrap(sourcekinds)) do -- load compiler @@ -87,7 +87,7 @@ end function linker:_addflags_from_linker(flags) -- add flags - local toolkind = self:get("kind") + local toolkind = self:kind() for _, flagkind in ipairs(self:_flagkinds()) do -- attempt to add special lanugage flags first, .e.g gc-ldflags, dc-arflags @@ -176,14 +176,14 @@ end function linker:link(objectfiles, targetfile, target) -- link it - return sandbox.load(self:_tool().link, table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(target))) + return sandbox.load(self:_tool().link, self:_tool(), table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(target))) end -- get the link command function linker:linkcmd(objectfiles, targetfile, target) -- get it - return self:_tool().linkcmd(table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(target))) + return self:_tool():linkcmd(table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(target))) end -- get the link flags diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index 5185d7b2f..3be75f4d4 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -13,7 +13,7 @@ -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and +-- See the License for the specific tool governing permissions and -- limitations under the License. -- -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. @@ -24,6 +24,7 @@ -- define module local tool = tool or {} +local _instance = _instance or {} -- load modules local os = require("base/os") @@ -35,91 +36,63 @@ local sandbox = require("sandbox/sandbox") local platform = require("platform/platform") local import = require("sandbox/modules/import") --- load the given tool -function tool._load(kind, name, program) +-- new an instance +function _instance.new(kind, name, program) - -- calculate the cache key - local key = (kind or "") .. program - - -- get it directly from cache dirst - tool._TOOLS = tool._TOOLS or {} - if tool._TOOLS[key] then - return tool._TOOLS[key] + -- import "core.tools.xxx" + local toolclass = nil + if os.isfile(path.join(os.programdir(), "modules", "core", "tools", name .. ".lua")) then + toolclass = import("core.tools." .. name) end - -- not exists? - local toolpath = path.join(os.programdir(), "tools", name .. ".lua") - if not os.isfile(toolpath) then - return nil, string.format("%s not found!", name) + -- not found? + if not toolclass then + return nil, string.format("cannot import \"core.tool.%s\" module!", name) end - -- load script - local script, errors = loadfile(toolpath) - if script then + -- new an instance + local instance = table.inherit(_instance, toolclass) - -- make sandbox instance with the given script - local instance, errors = sandbox.new(script, nil, path.directory(toolpath)) - if not instance then - return nil, errors - end + -- save name, kind and program + instance._NAME = name + instance._KIND = kind + instance._PROGRAM = program - -- import the tool module - local module, errors = instance:import() - if not module then + -- init instance + if instance.init then + local ok, errors = sandbox.load(instance.init, instance) + if not ok then return nil, errors end - - -- init the tool module - if module.init then - module.init(program, kind) - end - - -- save tool to the cache - tool._TOOLS[key] = module - - -- ok? - return module end - -- failed - return nil, errors + -- ok + return instance end --- check the program -function tool._check(program, check) +-- get the tool name +function _instance:name() + return self._NAME +end - -- uses the passed checker - if check ~= nil then +-- get the tool kind +function _instance:kind() + return self._KIND +end - -- check it - local ok, errors = sandbox.load(check, program) - if not ok then - utils.verror(errors) - end +-- get the tool program +function _instance:program() + return self._PROGRAM +end - -- ok? - return ok - end - - -- load the tool module - local module, errors = tool._load(program) - if not module then - utils.verror(errors) - end +-- has the given flag? +function _instance:has_flags(flag) - -- no checker? attempt to run it directly - if not module or not module.check then - return 0 == os.exec(program, os.nuldev(), os.nuldev()) - end + -- import has_flags() + self._has_flags = self._has_flags or import("lib.detect.has_flags") - -- check it - local ok, errors = sandbox.load(module.check) - if not ok then - utils.verror(errors) - end - - -- ok? - return ok + -- has flags? + return self._has_flags(self:name(), flag, {program = self:program()}) end -- load the given tool from the given kind @@ -130,6 +103,12 @@ end -- function tool.load(kind) + -- get it directly from cache dirst + tool._TOOLS = tool._TOOLS or {} + if tool._TOOLS[kind] then + return tool._TOOLS[kind] + end + -- get the tool program local program = platform.tool(kind) if not program then @@ -140,50 +119,28 @@ function tool.load(kind) local find_toolname = import("lib.detect.find_toolname") -- get the tool name from the program - local name = find_toolname(program) - if not name then - return nil, string.format("cannot find tool name for %s", program) + local ok, name_or_errors = sandbox.load(find_toolname, program) + if not ok then + return nil, name_or_errors end - -- load it - return tool._load(kind, name, program) -end - --- check the tool and return the absolute path if exists -function tool.check(program, dirs, check) - - -- check - assert(program) - - -- attempt to get result from cache first - tool._CHECKINFO = tool._CHECKINFO or {} - local result = tool._CHECKINFO[program] - if result then - return result + -- get name + local name = name_or_errors + if not name then + return nil, string.format("cannot find tool name for %s", program) end - -- attempt to check it directly - if tool._check(program, check) then - tool._CHECKINFO[program] = program - return program + -- new an instance + local instance, errors = _instance.new(kind, name, program) + if not instance then + return nil, errors end - -- attempt to check it from the given directories - if not path.is_absolute(program) then - for _, dir in ipairs(table.wrap(dirs)) do + -- save instance to the cache + tool._TOOLS[kind] = instance - -- the tool path - local toolpath = path.join(dir, program) - if os.isexec(toolpath) then - - -- check it - if tool._check(toolpath, check) then - tool._CHECKINFO[program] = toolpath - return toolpath - end - end - end - end + -- ok + return instance end -- return module diff --git a/xmake/tools/ar.lua b/xmake/modules/core/tools/ar.lua index 5a0625dfd..9d7ddabeb 100644 --- a/xmake/tools/ar.lua +++ b/xmake/modules/core/tools/ar.lua @@ -26,28 +26,21 @@ import("core.tool.compiler") -- init it -function init(program, kind) +function init(self) - -- save the shell name - _g.program = program or "ar" - - -- save the tool kind - _g.kind = kind or "ar" - -- init arflags _g.arflags = { "-cr" } - end -- get the property -function get(name) +function get(self, name) -- get it return _g[name] end -- make the strip flag -function strip(level) +function strip(self, level) -- the maps local maps = @@ -61,17 +54,17 @@ function strip(level) end -- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) +function linkcmd(self, objectfiles, targetkind, targetfile, flags) -- check assert(targetkind == "static") -- make it - return format("%s %s %s %s", _g.program, flags, targetfile, objectfiles) + return format("%s %s %s %s", self:program(), flags, targetfile, objectfiles) end -- link the library file -function link(objectfiles, targetkind, targetfile, flags) +function link(self, objectfiles, targetkind, targetfile, flags) -- check assert(targetkind == "static", "the target kind: %s is not support for ar", targetkind) @@ -80,11 +73,11 @@ function link(objectfiles, targetkind, targetfile, flags) os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) end -- extract the static library to object directory -function extract(libraryfile, objectdir) +function extract(self, libraryfile, objectdir) -- make the object directory first os.mkdir(objectdir) @@ -96,11 +89,11 @@ function extract(libraryfile, objectdir) local olddir = os.cd(objectdir) -- extract it - os.run("%s -x %s", _g.program, libraryfile) + os.run("%s -x %s", self:program(), libraryfile) -- check repeat object name local repeats = {} - local objectfiles = os.iorun("%s -t %s", _g.program, libraryfile) + local objectfiles = os.iorun("%s -t %s", self:program(), libraryfile) for _, objectfile in ipairs(objectfiles:split('\n')) do if repeats[objectfile] then raise("object name(%s) conflicts in library: %s", objectfile, libraryfile) @@ -112,29 +105,3 @@ function extract(libraryfile, objectdir) os.cd(olddir) end --- check the given flags -function check(flags) - - -- make an stub source file - local libraryfile = os.tmpfile() .. ".a" - local objectfile = os.tmpfile() .. ".o" - local sourcefile = os.tmpfile() .. ".c" - io.writefile(sourcefile, "int test(void)\n{return 0;}") - - -- make flags - local arflags = table.concat(_g.arflags, " ") - if flags then - arflags = arflags .. " " .. flags - end - - -- compile it - compiler.compile(sourcefile, objectfile) - - -- check it - link(objectfile, "static", libraryfile, arflags) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) - os.rm(libraryfile) -end diff --git a/xmake/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 519451800..b55948ecd 100644 --- a/xmake/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -26,14 +26,8 @@ import("core.project.project") -- init it -function init(program, kind) +function init(self) - -- save the shell name - _g.program = program or "cl.exe" - - -- save kind - _g.kind = kind - -- init cxflags _g.cxflags = { "-nologo", "-Gd", "-MP4", "-D_MBCS", "-D_CRT_SECURE_NO_WARNINGS"} @@ -92,35 +86,21 @@ function init(program, kind) end -- get the property -function get(name) +function get(self, name) -- get it return _g[name] end -- make the symbol flag -function nf_symbol(level, target) - - -- check -FS flags - if _g._FS == nil then - local ok = try - { - function () - check("-ZI -FS -Fd" .. os.tmpfile() .. ".pdb") - return true - end - } - if ok then - _g._FS = true - end - end +function nf_symbol(self, level, target) -- debug? generate *.pdb file local flags = "" if level == "debug" then if target and target.symbolfile then flags = "-ZI -Fd" .. target:symbolfile() - if _g._FS then + if self:has_flags("-ZI -FS -Fd" .. os.tmpfile() .. ".pdb") then flags = "-FS " .. flags end else @@ -133,7 +113,7 @@ function nf_symbol(level, target) end -- make the warning flag -function nf_warning(level) +function nf_warning(self, level) -- the maps local maps = @@ -150,7 +130,7 @@ function nf_warning(level) end -- make the optimize flag -function nf_optimize(level) +function nf_optimize(self, level) -- the maps local maps = @@ -168,7 +148,7 @@ function nf_optimize(level) end -- make the vector extension flag -function nf_vectorext(extension) +function nf_vectorext(self, extension) -- the maps local maps = @@ -184,7 +164,7 @@ function nf_vectorext(extension) end -- make the language flag -function nf_language(stdname) +function nf_language(self, stdname) -- the stdc maps local cmaps = @@ -198,7 +178,7 @@ function nf_language(stdname) -- select maps local maps = cmaps - if _g.kind == "cxx" or _g.kind == "mxx" then + if self:kind() == "cxx" or self:kind() == "mxx" then maps = {} end @@ -207,35 +187,27 @@ function nf_language(stdname) end -- make the define flag -function nf_define(macro) - - -- make it +function nf_define(self, macro) return "-D" .. macro:gsub("\"", "\\\"") end -- make the undefine flag -function nf_undefine(macro) - - -- make it +function nf_undefine(self, macro) return "-U" .. macro end -- make the includedir flag -function nf_includedir(dir) - - -- make it +function nf_includedir(self, dir) return "-I" .. dir end -- make the complie command -function _compcmd1(sourcefile, objectfile, flags) - - -- make it - return format("%s -c %s -Fo%s %s", _g.program, flags, objectfile, sourcefile) +function _compcmd1(self, sourcefile, objectfile, flags) + return format("%s -c %s -Fo%s %s", self:program(), flags, objectfile, sourcefile) end -- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) +function _compile1(self, sourcefile, objectfile, incdepfile, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) @@ -249,7 +221,7 @@ function _compile1(sourcefile, objectfile, incdepfile, flags) local outdata = try { function () - return os.iorun(_compcmd1(sourcefile, objectfile, flags)) + return os.iorun(_compcmd1(self, sourcefile, objectfile, flags)) end, catch @@ -299,38 +271,23 @@ function _compile1(sourcefile, objectfile, incdepfile, flags) end -- make the complie command -function compcmd(sourcefiles, objectfile, flags) +function compcmd(self, sourcefiles, objectfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - return _compcmd1(sourcefiles, objectfile, flags) + return _compcmd1(self, sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) +function compile(self, sourcefiles, objectfile, incdepfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - _compile1(sourcefiles, objectfile, incdepfile, flags) + _compile1(self, sourcefiles, objectfile, incdepfile, flags) end --- check the given flags -function check(flags) - - -- make an stub source file - local objectfile = os.tmpfile() .. ".obj" - local sourcefile = os.tmpfile() .. ".c" - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") - - -- check it - os.run("%s -c %s -Fo%s %s", _g.program, ifelse(flags, flags, ""), objectfile, sourcefile) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) -end diff --git a/xmake/tools/clang.lua b/xmake/modules/core/tools/clang.lua index e93533f1f..f391b101e 100644 --- a/xmake/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -26,10 +26,10 @@ inherit("gcc") -- init it -function init(program, kind) +function init(self) -- init super - _super.init(program or "clang", kind) + _super.init(self) -- init shflags _super._g.shflags = { "-dynamiclib", "-fPIC" } @@ -45,7 +45,7 @@ function init(program, kind) end -- make the strip flag -function nf_strip(level) +function nf_strip(self, level) -- the maps local maps = diff --git a/xmake/tools/clangxx.lua b/xmake/modules/core/tools/clangxx.lua index b32061f75..3e31ac92e 100644 --- a/xmake/tools/clangxx.lua +++ b/xmake/modules/core/tools/clangxx.lua @@ -25,11 +25,4 @@ -- inherit clang inherit("clang") --- init it -function init(program, kind) - - -- init super - _super.init(program or "clang++", kind) - -end diff --git a/xmake/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index 620cddb9d..02178577e 100644 --- a/xmake/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -28,14 +28,8 @@ import("core.project.config") import("core.project.project") -- init it -function init(program, kind) +function init(self) - -- save the shell name - _g.program = program or "dmd" - - -- save the kind - _g.kind = kind - -- init arflags _g.arflags = { "-lib" } @@ -54,14 +48,12 @@ function init(program, kind) end -- get the property -function get(name) - - -- get it +function get(self, name) return _g[name] end -- make the optimize flag -function nf_optimize(level) +function nf_optimize(self, level) -- the maps local maps = @@ -79,7 +71,7 @@ function nf_optimize(level) end -- make the strip flag -function nf_strip(level) +function nf_strip(self, level) -- the maps local maps = @@ -93,7 +85,7 @@ function nf_strip(level) end -- make the symbol flag -function nf_symbol(level) +function nf_symbol(self, level) -- the maps local maps = @@ -107,7 +99,7 @@ function nf_symbol(level) end -- make the warning flag -function nf_warning(level) +function nf_warning(self, level) -- the maps local maps = @@ -124,7 +116,7 @@ function nf_warning(level) end -- make the vector extension flag -function nf_vectorext(extension) +function nf_vectorext(self, extension) -- the maps local maps = @@ -138,101 +130,55 @@ function nf_vectorext(extension) end -- make the includedir flag -function nf_includedir(dir) - - -- make it +function nf_includedir(self, dir) return "-I" .. dir end -- make the link flag -function nf_link(lib) - - -- make it +function nf_link(self, lib) return "-L-l" .. lib end -- make the linkdir flag -function nf_linkdir(dir) - - -- make it +function nf_linkdir(self, dir) return "-L-L" .. dir end -- make the rpathdir flag -function nf_rpathdir(dir) - - -- check this flag +function nf_rpathdir(self, dir) local flag = "-L-rpath=" .. dir - if _g._RPATH == nil then - _g._RPATH = try - { - function () - check(flag, true) - return true - end - } - end - - -- ok? - if _g._RPATH then + if self:has_flags(flag) then return flag end end -- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) - - -- make it - return format("%s %s -of%s %s", _g.program, flags, targetfile, objectfiles) +function linkcmd(self, objectfiles, targetkind, targetfile, flags) + return format("%s %s -of%s %s", self:program(), flags, targetfile, objectfiles) end -- link the target file -function link(objectfiles, targetkind, targetfile, flags) +function link(self, objectfiles, targetkind, targetfile, flags) -- ensure the target directory os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) end -- make the complie command -function compcmd(sourcefiles, objectfile, flags) - - -- make it - return format("%s -c %s -of%s %s", _g.program, flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) +function compcmd(self, sourcefiles, objectfile, flags) + return format("%s -c %s -of%s %s", self:program(), flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) +function compile(self, sourcefiles, objectfile, incdepfile, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) -- compile it - os.run(compcmd(sourcefiles, objectfile, flags)) + os.run(compcmd(self, sourcefiles, objectfile, flags)) end --- check the given flags -function check(flags, trylink) - - -- make an stub source file - local binaryfile = os.tmpfile() .. ".b" - local objectfile = os.tmpfile() .. ".o" - local sourcefile = os.tmpfile() .. ".d" - - -- make stub code - io.writefile(sourcefile, "void main() {\n}") - - -- check it, need check compflags and linkflags - if trylink then - os.run("%s %s -of%s %s", _g.program, ifelse(flags, flags, ""), binaryfile, sourcefile) - else - os.run("%s -c %s -of%s %s", _g.program, ifelse(flags, flags, ""), binaryfile, sourcefile) - end - - -- remove files - os.tryrm(binaryfile) - os.tryrm(objectfile) - os.tryrm(sourcefile) -end diff --git a/xmake/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index ffe73c0e9..4071ba100 100644 --- a/xmake/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -29,13 +29,7 @@ import("core.project.project") import("detect.tools.find_ccache") -- init it -function init(program, kind) - - -- save the shell name - _g.program = program or "gcc" - - -- save the kind - _g.kind = kind +function init(self) -- init mxflags _g.mxflags = { "-fmessage-length=0" @@ -53,7 +47,7 @@ function init(program, kind) _g.shared.cxflags = {"-fPIC"} -- suppress warning for clang (gcc -> clang on macosx) - if try { function () check("-Qunused-arguments"); return true end } then + if self:has_flags("-Qunused-arguments") then _g.cxflags = {"-Qunused-arguments"} _g.mxflags = {"-Qunused-arguments"} _g.asflags = {"-Qunused-arguments"} @@ -81,14 +75,14 @@ function init(program, kind) end -- get the property -function get(name) +function get(self, name) -- get it return _g[name] end -- make the strip flag -function nf_strip(level) +function nf_strip(self, level) -- the maps local maps = @@ -102,7 +96,7 @@ function nf_strip(level) end -- make the symbol flag -function nf_symbol(level) +function nf_symbol(self, level) -- the maps local maps = @@ -116,7 +110,7 @@ function nf_symbol(level) end -- make the warning flag -function nf_warning(level) +function nf_warning(self, level) -- the maps local maps = @@ -133,7 +127,7 @@ function nf_warning(level) end -- make the optimize flag -function nf_optimize(level) +function nf_optimize(self, level) -- the maps local maps = @@ -151,7 +145,7 @@ function nf_optimize(level) end -- make the vector extension flag -function nf_vectorext(extension) +function nf_vectorext(self, extension) -- the maps local maps = @@ -171,7 +165,7 @@ function nf_vectorext(extension) end -- make the language flag -function nf_language(stdname) +function nf_language(self, stdname) -- the stdc maps local cmaps = @@ -203,9 +197,9 @@ function nf_language(stdname) -- select maps local maps = cmaps - if _g.kind == "cxx" or _g.kind == "mxx" then + if self:kind() == "cxx" or self:kind() == "mxx" then maps = cxxmaps - elseif _g.kind == "sc" then + elseif self:kind() == "sc" then maps = {} end @@ -214,87 +208,59 @@ function nf_language(stdname) end -- make the define flag -function nf_define(macro) - - -- make it +function nf_define(self, macro) return "-D" .. macro:gsub("\"", "\\\"") end -- make the undefine flag -function nf_undefine(macro) - - -- make it +function nf_undefine(self, macro) return "-U" .. macro end -- make the includedir flag -function nf_includedir(dir) - - -- make it +function nf_includedir(self, dir) return "-I" .. dir end -- make the link flag -function nf_link(lib) - - -- make it +function nf_link(self, lib) return "-l" .. lib end -- make the linkdir flag -function nf_linkdir(dir) - - -- make it +function nf_linkdir(self, dir) return "-L" .. dir end -- make the rpathdir flag -function nf_rpathdir(dir) - - -- check this flag - local flag = "-Wl,-rpath=" .. dir - if _g._RPATH == nil then - _g._RPATH = try - { - function () - check(flag, true) - return true - end - } - end - - -- ok? - if _g._RPATH then +function nf_rpathdir(self, dir) + if self:has_flags("-Wl,-rpath=" .. dir) then return flag end end -- make the framework flag -function nf_framework(framework) - - -- make it +function nf_framework(self, framework) return "-framework " .. framework end -- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) - - -- make it - return format("%s -o %s %s %s", _g.program, targetfile, objectfiles, flags) +function linkcmd(self, objectfiles, targetkind, targetfile, flags) + return format("%s -o %s %s %s", self:program(), targetfile, objectfiles, flags) end -- link the target file -function link(objectfiles, targetkind, targetfile, flags) +function link(self, objectfiles, targetkind, targetfile, flags) -- ensure the target directory os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) end -- make the complie command -function _compcmd1(sourcefile, objectfile, flags) +function _compcmd1(self, sourcefile, objectfile, flags) -- get ccache local ccache = nil @@ -303,7 +269,7 @@ function _compcmd1(sourcefile, objectfile, flags) end -- make it - local command = format("%s -c %s -o %s %s", _g.program, flags, objectfile, sourcefile) + local command = format("%s -c %s -o %s %s", self:program(), flags, objectfile, sourcefile) if ccache then command = ccache:append(command, " ") end @@ -313,7 +279,7 @@ function _compcmd1(sourcefile, objectfile, flags) end -- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) +function _compile1(self, sourcefile, objectfile, incdepfile, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) @@ -322,7 +288,7 @@ function _compile1(sourcefile, objectfile, incdepfile, flags) try { function () - local outdata, errdata = os.iorun(_compcmd1(sourcefile, objectfile, flags)) + local outdata, errdata = os.iorun(_compcmd1(self, sourcefile, objectfile, flags)) return (outdata or "") .. (errdata or "") end, catch @@ -346,13 +312,13 @@ function _compile1(sourcefile, objectfile, incdepfile, flags) } -- generate includes file - if incdepfile and _g.kind ~= "as" then + if incdepfile and self:kind() ~= "as" then -- the temporary file local tmpfile = os.tmpfile() -- generate it - os.run("%s -c -MM %s -o %s %s", _g.program, flags or "", tmpfile, sourcefile) + os.run("%s -c -MM %s -o %s %s", self:program(), flags or "", tmpfile, sourcefile) -- translate it local results = {} @@ -374,46 +340,22 @@ function _compile1(sourcefile, objectfile, incdepfile, flags) end -- make the complie command -function compcmd(sourcefiles, objectfile, flags) +function compcmd(self, sourcefiles, objectfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - return _compcmd1(sourcefiles, objectfile, flags) + return _compcmd1(self, sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) +function compile(self, sourcefiles, objectfile, incdepfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - _compile1(sourcefiles, objectfile, incdepfile, flags) -end - --- check the given flags -function check(flags, trylink) - - -- make an stub source file - local binaryfile = os.tmpfile() .. ".b" - local objectfile = os.tmpfile() .. ".o" - local sourcefile = os.tmpfile() .. ".c" .. ifelse(_g.kind == "cxx", "pp", "") - - -- make stub code - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") - - -- check it, need check compflags and linkflags - if trylink then - os.run("%s %s -o %s %s", _g.program, ifelse(flags, flags, ""), binaryfile, sourcefile) - else - os.run("%s -c %s -o %s %s", _g.program, ifelse(flags, flags, ""), binaryfile, sourcefile) - end - - -- remove files - os.tryrm(binaryfile) - os.tryrm(objectfile) - os.tryrm(sourcefile) + _compile1(self, sourcefiles, objectfile, incdepfile, flags) end diff --git a/xmake/tools/gccgo.lua b/xmake/modules/core/tools/gccgo.lua index 997820c96..41f941cf4 100644 --- a/xmake/tools/gccgo.lua +++ b/xmake/modules/core/tools/gccgo.lua @@ -25,28 +25,4 @@ -- inherit gcc inherit("gcc") --- init it -function init(program, kind) - - -- init super - _super.init(program or "gccgo", kind) -end - --- check the given flags -function check(flags) - - -- make an stub source file - local objectfile = os.tmpfile() .. ".o" - local sourcefile = os.tmpfile() .. ".go" - - -- make stub code - io.writefile(sourcefile, "package main\nfunc main() {\n}") - - -- check it - os.run("%s -c %s -o %s %s", _super._g.program, ifelse(flags, flags, ""), objectfile, sourcefile) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) -end diff --git a/xmake/tools/gdc.lua b/xmake/modules/core/tools/gdc.lua index 70f1cc807..3682de49e 100644 --- a/xmake/tools/gdc.lua +++ b/xmake/modules/core/tools/gdc.lua @@ -25,11 +25,5 @@ -- inherit dmd inherit("dmd") --- init it -function init(program, kind) - - -- init super - _super.init(program or "gdc", kind) -end diff --git a/xmake/tools/go.lua b/xmake/modules/core/tools/go.lua index dc0e80f93..a3b49c8c4 100644 --- a/xmake/tools/go.lua +++ b/xmake/modules/core/tools/go.lua @@ -28,14 +28,8 @@ import("core.project.config") import("core.project.project") -- init it -function init(program, kind) +function init(self) - -- save the shell name - _g.program = program or "go" - - -- save the kind - _g.kind = kind - -- init arflags _g.arflags = { "grc" } @@ -51,14 +45,12 @@ function init(program, kind) end -- get the property -function get(name) - - -- get it +function get(self, name) return _g[name] end -- make the optimize flag -function nf_optimize(level) +function nf_optimize(self, level) -- the maps local maps = @@ -76,7 +68,7 @@ function nf_optimize(level) end -- make the symbol flag -function nf_symbol(level, target, mapkind) +function nf_symbol(self, level, target, mapkind) -- only for compiler if mapkind ~= "object" then @@ -95,7 +87,7 @@ function nf_symbol(level, target, mapkind) end -- make the strip flag -function nf_strip(level) +function nf_strip(self, level) -- the maps local maps = @@ -109,71 +101,48 @@ function nf_strip(level) end -- make the includedir flag -function nf_includedir(dir) - - -- make it +function nf_includedir(self, dir) return "-I " .. dir end -- make the linkdir flag -function nf_linkdir(dir) - - -- make it +function nf_linkdir(self, dir) return "-L " .. dir end -- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) +function linkcmd(self, objectfiles, targetkind, targetfile, flags) -- make it if targetkind == "static" then - return format("%s tool pack %s %s %s", _g.program, flags, targetfile, objectfiles) + return format("%s tool pack %s %s %s", self:program(), flags, targetfile, objectfiles) else - return format("%s tool link %s -o %s %s", _g.program, flags, targetfile, objectfiles) + return format("%s tool link %s -o %s %s", self:program(), flags, targetfile, objectfiles) end end -- link the target file -function link(objectfiles, targetkind, targetfile, flags) +function link(self, objectfiles, targetkind, targetfile, flags) -- ensure the target directory os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) end -- make the complie command -function compcmd(sourcefiles, objectfile, flags) - - -- make it - return format("%s tool compile %s -o %s %s", _g.program, flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) +function compcmd(self, sourcefiles, objectfile, flags) + return format("%s tool compile %s -o %s %s", self:program(), flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) +function compile(self, sourcefiles, objectfile, incdepfile, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) -- compile it - os.run(compcmd(sourcefiles, objectfile, flags)) + os.run(compcmd(self, sourcefiles, objectfile, flags)) end --- check the given flags -function check(flags) - - -- make an stub source file - local objectfile = os.tmpfile() .. ".o" - local sourcefile = os.tmpfile() .. ".go" - - -- make stub code - io.writefile(sourcefile, "package main\nfunc main() {\n}") - - -- check it - os.run("%s tool compile %s -o %s %s", _g.program, ifelse(flags, flags, ""), objectfile, sourcefile) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) -end diff --git a/xmake/tools/gxx.lua b/xmake/modules/core/tools/gxx.lua index 256b5270d..2c73c5473 100644 --- a/xmake/tools/gxx.lua +++ b/xmake/modules/core/tools/gxx.lua @@ -25,11 +25,4 @@ -- inherit gcc inherit("gcc") --- init it -function init(program, kind) - - -- init super - _super.init(program or "g++", kind) - -end diff --git a/xmake/tools/ldc.lua b/xmake/modules/core/tools/ldc.lua index eb051fd3a..b36fd446e 100644 --- a/xmake/tools/ldc.lua +++ b/xmake/modules/core/tools/ldc.lua @@ -26,10 +26,10 @@ inherit("dmd") -- init it -function init(program, kind) +function init(self) -- init super - _super.init(program or "ldc", kind) + _super.init(self) -- init shflags _super._g.shflags = { "-shared" } diff --git a/xmake/tools/lib.lua b/xmake/modules/core/tools/lib.lua index a59f7d713..a193b8788 100644 --- a/xmake/tools/lib.lua +++ b/xmake/modules/core/tools/lib.lua @@ -22,31 +22,21 @@ -- @file lib.lua -- --- init it -function init(program, kind) - - -- save the shell name - _g.program = program or "lib.exe" - - -- save the tool kind - _g.kind = kind -end - -- get the property -function get(name) +function get(self, name) -- get it return _g[name] end -- extract the static library to object directory -function extract(libraryfile, objectdir) +function extract(self, libraryfile, objectdir) -- make the object directory first os.mkdir(objectdir) -- list object files - local objectfiles = os.iorun("%s -nologo -list %s", _g.program, libraryfile) + local objectfiles = os.iorun("%s -nologo -list %s", self:program(), libraryfile) -- extrace all object files for _, objectfile in ipairs(objectfiles:split('\n')) do @@ -68,28 +58,9 @@ function extract(libraryfile, objectdir) end -- extract it - os.run("%s -nologo -extract:%s -out:%s %s", _g.program, objectfile, outputfile, libraryfile) + os.run("%s -nologo -extract:%s -out:%s %s", self:program(), objectfile, outputfile, libraryfile) end end end --- check the given flags -function check(flags) - - -- make an stub source file - local libfile = os.tmpfile() .. ".lib" - local objfile = os.tmpfile() .. ".obj" - local srcfile = os.tmpfile() .. ".c" - io.writefile(srcfile, "int test(void)\n{return 0;}") - - -- check it - os.run("cl -c -Fo%s %s", objfile, srcfile) - os.run("link -lib -out:%s %s", libfile, objfile) - os.run("%s %s -list %s", _g.program, ifelse(flags, flags, ""), libfile) - - -- remove files - os.rm(objfile) - os.rm(srcfile) - os.rm(libfile) -end diff --git a/xmake/tools/link.lua b/xmake/modules/core/tools/link.lua index c79d67a2a..6d11d3a94 100644 --- a/xmake/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -26,14 +26,8 @@ import("core.project.config") -- init it -function init(program, kind) +function init(self) - -- save the shell name - _g.program = program or "link.exe" - - -- save the tool kind - _g.kind = kind - -- the architecture local arch = config.get("arch") @@ -68,14 +62,12 @@ function init(program, kind) end -- get the property -function get(name) - - -- get it +function get(self, name) return _g[name] end -- make the symbol flag -function nf_symbol(level, target) +function nf_symbol(self, level, target) -- debug? generate *.pdb file local flags = "" @@ -92,30 +84,26 @@ function nf_symbol(level, target) end -- make the link flag -function nf_link(lib) - - -- make it +function nf_link(self, lib) return lib .. ".lib" end -- make the linkdir flag -function nf_linkdir(dir) - - -- make it +function nf_linkdir(self, dir) return "-libpath:" .. dir end -- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) +function linkcmd(self, objectfiles, targetkind, targetfile, flags) -- make it - local cmd = format("%s %s -out:%s %s", _g.program, flags, targetfile, objectfiles) + local cmd = format("%s %s -out:%s %s", self:program(), flags, targetfile, objectfiles) -- too long? if #cmd > 4096 then local argfile = targetfile .. ".arg" io.printf(argfile, "%s -out:%s %s", flags, targetfile, objectfiles) - cmd = format("%s @%s", _g.program, argfile) + cmd = format("%s @%s", self:program(), argfile) end -- ok? @@ -123,42 +111,12 @@ function linkcmd(objectfiles, targetkind, targetfile, flags) end -- link the target file -function link(objectfiles, targetkind, targetfile, flags) +function link(self, objectfiles, targetkind, targetfile, flags) -- ensure the target directory os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) -end - --- check the given flags -function check(flags) - - -- -def:"xxx.def"? pass directly - if flags and flags:lower():find("def:") then - return - end - - -- make an stub source file - local binaryfile = os.tmpfile() .. ".exe" - local objectfile = os.tmpfile() .. ".obj" - local sourcefile = os.tmpfile() .. ".c" - - -- main entry - if flags and flags:lower():find("subsystem:windows") then - io.writefile(sourcefile, "int WinMain(void* instance, void* previnst, char** argv, int argc)\n{return 0;}") - else - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") - end - - -- check it - os.run("cl -c -Fo%s %s", objectfile, sourcefile) - os.run("%s %s -out:%s %s", _g.program, ifelse(flags, flags, ""), binaryfile, objectfile) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) - os.rm(binaryfile) + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) end diff --git a/xmake/tools/ml.lua b/xmake/modules/core/tools/ml.lua index 709f81d58..74a8fc364 100644 --- a/xmake/tools/ml.lua +++ b/xmake/modules/core/tools/ml.lua @@ -23,16 +23,10 @@ -- -- init it -function init(program, kind) +function init(self) - -- save name - _g.program = program or "ml.exe" - - -- save kind - _g.kind = kind - -- init asflags - if _g.program:find("64") then + if self:program():find("64") then _g.asflags = { "-nologo"} else _g.asflags = { "-nologo", "-Gd"} @@ -66,14 +60,12 @@ function init(program, kind) end -- get the property -function get(name) - - -- get it +function get(self, name) return _g[name] end -- make the warning flag -function nf_warning(level) +function nf_warning(self, level) -- the maps local maps = @@ -90,75 +82,52 @@ function nf_warning(level) end -- make the define flag -function nf_define(macro) - - -- make it +function nf_define(self, macro) return "-D" .. macro:gsub("\"", "\\\"") end -- make the undefine flag -function nf_undefine(macro) - - -- make it +function nf_undefine(self, macro) return "-U" .. macro end -- make the includedir flag -function nf_includedir(dir) - - -- make it +function nf_includedir(self, dir) return "-I" .. dir end -- make the complie command -function _compcmd1(sourcefile, objectfile, flags) - - -- make it - return format("%s -c %s -Fo%s %s", _g.program, flags, objectfile, sourcefile) +function _compcmd1(self, sourcefile, objectfile, flags) + return format("%s -c %s -Fo%s %s", self:program(), flags, objectfile, sourcefile) end -- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) +function _compile1(self, sourcefile, objectfile, incdepfile, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) -- compile it - os.run(_compcmd1(sourcefile, objectfile, flags)) + os.run(_compcmd1(self, sourcefile, objectfile, flags)) end -- make the complie command -function compcmd(sourcefiles, objectfile, flags) +function compcmd(self, sourcefiles, objectfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - return _compcmd1(sourcefiles, objectfile, flags) + return _compcmd1(self, sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) +function compile(self, sourcefiles, objectfile, incdepfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - _compile1(sourcefiles, objectfile, incdepfile, flags) -end --- check the given flags -function check(flags) - - -- make an stub source file - local objectfile = os.tmpfile() .. ".obj" - local sourcefile = os.tmpfile() .. ".asm" - io.writefile(sourcefile, "end") - - -- check it - os.run("%s -c %s -Fo%s %s", _g.program, ifelse(flags, flags, ""), objectfile, sourcefile) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) + _compile1(self, sourcefiles, objectfile, incdepfile, flags) end diff --git a/xmake/tools/ml64.lua b/xmake/modules/core/tools/ml64.lua index f21e5466e..899ba9972 100644 --- a/xmake/tools/ml64.lua +++ b/xmake/modules/core/tools/ml64.lua @@ -25,8 +25,4 @@ -- inherit ml inherit("ml") --- init it -function init(program, kind) - _super.init(program or "ml64", kind) -end diff --git a/xmake/tools/rc.lua b/xmake/modules/core/tools/rc.lua index f64651d8c..a76d7493d 100644 --- a/xmake/tools/rc.lua +++ b/xmake/modules/core/tools/rc.lua @@ -27,58 +27,42 @@ import("core.base.option") import("core.project.project") -- init it -function init(program, kind) +function init(self) - -- save the shell name - _g.program = program or "rc.exe" - - -- save kind - _g.kind = kind - -- init features _g.features = { - ["object:sources"] = false + ["object:sources"] = false } end -- get the property -function get(name) - - -- get it +function get(self, name) return _g[name] end -- make the define flag -function nf_define(macro) - - -- make it +function nf_define(self, macro) return "-d" .. macro:gsub("\"", "\\\"") end -- make the undefine flag -function nf_undefine(macro) - - -- make it +function nf_undefine(self, macro) return "-u" .. macro end -- make the includedir flag -function nf_includedir(dir) - - -- make it +function nf_includedir(self, dir) return "-I" .. dir end -- make the complie command -function _compcmd1(sourcefile, objectfile, flags) - - -- make it - return format("%s %s -Fo%s %s", _g.program, flags, objectfile, sourcefile) +function _compcmd1(self, sourcefile, objectfile, flags) + return format("%s %s -Fo%s %s", self:program(), flags, objectfile, sourcefile) end -- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) +function _compile1(self, sourcefile, objectfile, incdepfile, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) @@ -87,7 +71,7 @@ function _compile1(sourcefile, objectfile, incdepfile, flags) try { function () - local outdata, errdata = os.iorun(_compcmd1(sourcefile, objectfile, flags)) + local outdata, errdata = os.iorun(_compcmd1(self, sourcefile, objectfile, flags)) return (outdata or "") .. (errdata or "") end, catch @@ -112,38 +96,23 @@ function _compile1(sourcefile, objectfile, incdepfile, flags) end -- make the complie command -function compcmd(sourcefiles, objectfile, flags) +function compcmd(self, sourcefiles, objectfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - return _compcmd1(sourcefiles, objectfile, flags) + return _compcmd1(self, sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) +function compile(self, sourcefiles, objectfile, incdepfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - _compile1(sourcefiles, objectfile, incdepfile, flags) + _compile1(self, sourcefiles, objectfile, incdepfile, flags) end --- check the given flags -function check(flags) - - -- make an stub source file - local objectfile = os.tmpfile() .. ".res" - local sourcefile = os.tmpfile() .. ".rc" - io.writefile(sourcefile, "#define RESID 1") - - -- check it - os.run("%s -fo%s %s", _g.program, objectfile, sourcefile) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) -end diff --git a/xmake/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua index df261545a..e480624d9 100644 --- a/xmake/tools/rustc.lua +++ b/xmake/modules/core/tools/rustc.lua @@ -28,14 +28,8 @@ import("core.project.config") import("core.project.project") -- init it -function init(program, kind) +function init(self) - -- save the shell name - _g.program = program or "rustc" - - -- save the kind - _g.kind = kind - -- init arflags _g.arflags = { "--crate-type=lib" } @@ -60,14 +54,12 @@ function init(program, kind) end -- get the property -function get(name) - - -- get it +function get(self, name) return _g[name] end -- make the optimize flag -function nf_optimize(level) +function nf_optimize(self, level) -- the maps local maps = @@ -85,7 +77,7 @@ function nf_optimize(level) end -- make the symbol flag -function nf_symbol(level) +function nf_symbol(self, level) -- the maps local maps = @@ -99,60 +91,37 @@ function nf_symbol(level) end -- make the linkdir flag -function nf_linkdir(dir) - - -- make it +function nf_linkdir(self, dir) return "-L " .. dir end -- make the build command -function buildcmd(sourcefiles, targetkind, targetfile, flags) - - -- make it - return format("%s %s -o %s %s", _g.program, flags, targetfile, table.concat(sourcefiles, " ")) +function buildcmd(self, sourcefiles, targetkind, targetfile, flags) + return format("%s %s -o %s %s", self:program(), flags, targetfile, table.concat(sourcefiles, " ")) end -- build the target file -function build(sourcefiles, targetkind, targetfile, flags) +function build(self, sourcefiles, targetkind, targetfile, flags) -- ensure the target directory os.mkdir(path.directory(targetfile)) -- build it - os.run(buildcmd(sourcefiles, targetkind, targetfile, flags)) + os.run(buildcmd(self, sourcefiles, targetkind, targetfile, flags)) end -- make the complie command -function compcmd(sourcefiles, objectfile, flags) - - -- make it - return format("%s --emit obj %s -o %s %s", _g.program, flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) +function compcmd(self, sourcefiles, objectfile, flags) + return format("%s --emit obj %s -o %s %s", self:program(), flags, objectfile, table.concat(table.wrap(sourcefiles), " ")) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) +function compile(self, sourcefiles, objectfile, incdepfile, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) -- compile it - os.run(compcmd(sourcefiles, objectfile, flags)) + os.run(compcmd(self, sourcefiles, objectfile, flags)) end --- check the given flags -function check(flags) - - -- make an stub source file - local objectfile = os.tmpfile() .. ".o" - local sourcefile = os.tmpfile() .. ".rs" - - -- make stub code - io.writefile(sourcefile, "fn main() {\n}") - - -- check it - os.run("%s --emit obj %s -o %s %s", _g.program, ifelse(flags, flags, ""), objectfile, sourcefile) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) -end diff --git a/xmake/tools/swiftc.lua b/xmake/modules/core/tools/swiftc.lua index b740a49a9..e1c18934e 100644 --- a/xmake/tools/swiftc.lua +++ b/xmake/modules/core/tools/swiftc.lua @@ -27,14 +27,8 @@ import("core.project.config") import("detect.tools.find_ccache") -- init it -function init(program, kind) +function init(self) - -- save the shell name - _g.program = program or "swiftc" - - -- init kind - _g.kind = kind - -- init flags map _g.mapflags = { @@ -70,14 +64,12 @@ function init(program, kind) end -- get the property -function get(name) - - -- get it +function get(self, name) return _g[name] end -- make the strip flag -function nf_strip(level) +function nf_strip(self, level) -- the maps local maps = @@ -91,7 +83,7 @@ function nf_strip(level) end -- make the symbol flag -function nf_symbol(level) +function nf_symbol(self, level) -- the maps local maps = @@ -104,7 +96,7 @@ function nf_symbol(level) end -- make the warning flag -function nf_warning(level) +function nf_warning(self, level) -- the maps local maps = @@ -121,7 +113,7 @@ function nf_warning(level) end -- make the optimize flag -function nf_optimize(level) +function nf_optimize(self, level) -- the maps local maps = @@ -139,7 +131,7 @@ function nf_optimize(level) end -- make the vector extension flag -function nf_vectorext(extension) +function nf_vectorext(self, extension) -- the maps local maps = @@ -159,66 +151,52 @@ function nf_vectorext(extension) end -- make the includedir flag -function nf_includedir(dir) - - -- make it +function nf_includedir(self, dir) return "-Xcc -I" .. dir end -- make the define flag -function nf_define(macro) - - -- make it +function nf_define(self, macro) return "-Xcc -D" .. macro:gsub("\"", "\\\"") end -- make the undefine flag -function nf_undefine(macro) - - -- make it +function nf_undefine(self, macro) return "-Xcc -U" .. macro end -- make the framework flag -function nf_framework(framework) - - -- make it +function nf_framework(self, framework) return "-framework" .. framework end -- make the link flag -function nf_link(lib) - - -- make it +function nf_link(self, lib) return "-l" .. lib end -- make the linkdir flag -function nf_linkdir(dir) - - -- make it +function nf_linkdir(self, dir) return "-L" .. dir end -- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) - - -- make it - return format("%s -o %s %s %s", _g.program, targetfile, objectfiles, flags) +function linkcmd(self, objectfiles, targetkind, targetfile, flags) + return format("%s -o %s %s %s", self:program(), targetfile, objectfiles, flags) end -- link the target file -function link(objectfiles, targetkind, targetfile, flags) +function link(self, objectfiles, targetkind, targetfile, flags) -- ensure the target directory os.mkdir(path.directory(targetfile)) -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) end -- make the compile command -function _compcmd1(sourcefile, objectfile, flags) +function _compcmd1(self, sourcefile, objectfile, flags) -- get ccache local ccache = nil @@ -227,7 +205,7 @@ function _compcmd1(sourcefile, objectfile, flags) end -- make it - local command = format("%s -c %s -o %s %s", _g.program, flags, objectfile, sourcefile) + local command = format("%s -c %s -o %s %s", self:program(), flags, objectfile, sourcefile) if ccache then command = ccache:append(command, " ") end @@ -237,38 +215,32 @@ function _compcmd1(sourcefile, objectfile, flags) end -- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) +function _compile1(self, sourcefile, objectfile, incdepfile, flags) -- ensure the object directory os.mkdir(path.directory(objectfile)) -- compile it - os.run(_compcmd1(sourcefile, objectfile, flags)) + os.run(_compcmd1(self, sourcefile, objectfile, flags)) end -- make the complie command -function compcmd(sourcefiles, objectfile, flags) +function compcmd(self, sourcefiles, objectfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - return _compcmd1(sourcefiles, objectfile, flags) + return _compcmd1(self, sourcefiles, objectfile, flags) end -- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) +function compile(self, sourcefiles, objectfile, incdepfile, flags) -- only support single source file now assert(type(sourcefiles) ~= "table", "'object:sources' not support!") -- for only single source file - _compile1(sourcefiles, objectfile, incdepfile, flags) + _compile1(self, sourcefiles, objectfile, incdepfile, flags) end --- check the given flags -function check(flags) - - -- check it - os.run("%s -h", _g.program) -end diff --git a/xmake/scripts/gas-preprocessor.pl b/xmake/scripts/gas-preprocessor.pl index 98dfe4ad9..7e0857a66 100755 --- a/xmake/scripts/gas-preprocessor.pl +++ b/xmake/scripts/gas-preprocessor.pl @@ -86,7 +86,7 @@ if (grep /\.c$/, @gcc_cmd) { } elsif (grep /\.[sS]$/, @gcc_cmd) { # asm file, just do C preprocessor @preprocess_c_cmd = (@gcc_cmd, "-E"); -} elsif (grep /-(v|-version|dumpversion)/, @gcc_cmd) { +} elsif (grep /-(v|-help|-version|dumpversion)/, @gcc_cmd) { # pass -v/--version along, used during probing. Matching '-v' might have # uninteded results but it doesn't matter much if gas-preprocessor or # the compiler fails. |
