From e7fd0a5c178956eb4801de3780f2bc3c0e7a3e1e Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 21 Jun 2017 18:53:20 +0800 Subject: move tools dir to core.tools and improve tool module --- xmake/core/language/language.lua | 4 - .../sandbox/modules/import/core/tool/compiler.lua | 2 +- xmake/core/tool/builder.lua | 69 ++-- xmake/core/tool/compiler.lua | 10 +- xmake/core/tool/extractor.lua | 10 +- xmake/core/tool/linker.lua | 10 +- xmake/core/tool/tool.lua | 167 +++----- xmake/modules/core/tools/ar.lua | 107 ++++++ xmake/modules/core/tools/cl.lua | 293 ++++++++++++++ xmake/modules/core/tools/clang.lua | 59 +++ xmake/modules/core/tools/clangxx.lua | 28 ++ xmake/modules/core/tools/dmd.lua | 184 +++++++++ xmake/modules/core/tools/gcc.lua | 361 ++++++++++++++++++ xmake/modules/core/tools/gccgo.lua | 28 ++ xmake/modules/core/tools/gdc.lua | 29 ++ xmake/modules/core/tools/go.lua | 148 ++++++++ xmake/modules/core/tools/gxx.lua | 28 ++ xmake/modules/core/tools/ldc.lua | 42 +++ xmake/modules/core/tools/lib.lua | 66 ++++ xmake/modules/core/tools/link.lua | 122 ++++++ xmake/modules/core/tools/ml.lua | 133 +++++++ xmake/modules/core/tools/ml64.lua | 28 ++ xmake/modules/core/tools/rc.lua | 118 ++++++ xmake/modules/core/tools/rustc.lua | 127 +++++++ xmake/modules/core/tools/swiftc.lua | 246 ++++++++++++ xmake/scripts/gas-preprocessor.pl | 2 +- xmake/tools/ar.lua | 140 ------- xmake/tools/cl.lua | 336 ----------------- xmake/tools/clang.lua | 59 --- xmake/tools/clangxx.lua | 35 -- xmake/tools/dmd.lua | 238 ------------ xmake/tools/gcc.lua | 419 --------------------- xmake/tools/gccgo.lua | 52 --- xmake/tools/gdc.lua | 35 -- xmake/tools/go.lua | 179 --------- xmake/tools/gxx.lua | 35 -- xmake/tools/ldc.lua | 42 --- xmake/tools/lib.lua | 95 ----- xmake/tools/link.lua | 164 -------- xmake/tools/ml.lua | 164 -------- xmake/tools/ml64.lua | 32 -- xmake/tools/rc.lua | 149 -------- xmake/tools/rustc.lua | 158 -------- xmake/tools/swiftc.lua | 274 -------------- 44 files changed, 2249 insertions(+), 2778 deletions(-) create mode 100644 xmake/modules/core/tools/ar.lua create mode 100644 xmake/modules/core/tools/cl.lua create mode 100644 xmake/modules/core/tools/clang.lua create mode 100644 xmake/modules/core/tools/clangxx.lua create mode 100644 xmake/modules/core/tools/dmd.lua create mode 100644 xmake/modules/core/tools/gcc.lua create mode 100644 xmake/modules/core/tools/gccgo.lua create mode 100644 xmake/modules/core/tools/gdc.lua create mode 100644 xmake/modules/core/tools/go.lua create mode 100644 xmake/modules/core/tools/gxx.lua create mode 100644 xmake/modules/core/tools/ldc.lua create mode 100644 xmake/modules/core/tools/lib.lua create mode 100644 xmake/modules/core/tools/link.lua create mode 100644 xmake/modules/core/tools/ml.lua create mode 100644 xmake/modules/core/tools/ml64.lua create mode 100644 xmake/modules/core/tools/rc.lua create mode 100644 xmake/modules/core/tools/rustc.lua create mode 100644 xmake/modules/core/tools/swiftc.lua delete mode 100644 xmake/tools/ar.lua delete mode 100644 xmake/tools/cl.lua delete mode 100644 xmake/tools/clang.lua delete mode 100644 xmake/tools/clangxx.lua delete mode 100644 xmake/tools/dmd.lua delete mode 100644 xmake/tools/gcc.lua delete mode 100644 xmake/tools/gccgo.lua delete mode 100644 xmake/tools/gdc.lua delete mode 100644 xmake/tools/go.lua delete mode 100644 xmake/tools/gxx.lua delete mode 100644 xmake/tools/ldc.lua delete mode 100644 xmake/tools/lib.lua delete mode 100644 xmake/tools/link.lua delete mode 100644 xmake/tools/ml.lua delete mode 100644 xmake/tools/ml64.lua delete mode 100644 xmake/tools/rc.lua delete mode 100644 xmake/tools/rustc.lua delete mode 100644 xmake/tools/swiftc.lua 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) - - -- uses the passed checker - if check ~= nil then +-- get the tool name +function _instance:name() + return self._NAME +end - -- check it - local ok, errors = sandbox.load(check, program) - if not ok then - utils.verror(errors) - end +-- get the tool kind +function _instance:kind() + return self._KIND +end - -- ok? - return ok - end - - -- load the tool module - local module, errors = tool._load(program) - if not module then - utils.verror(errors) - end +-- get the tool program +function _instance:program() + return self._PROGRAM +end - -- 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 +-- has the given flag? +function _instance:has_flags(flag) - -- check it - local ok, errors = sandbox.load(module.check) - if not ok then - utils.verror(errors) - end + -- import has_flags() + self._has_flags = self._has_flags or import("lib.detect.has_flags") - -- 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) + local ok, name_or_errors = sandbox.load(find_toolname, program) + if not ok then + return nil, name_or_errors + end + + -- get name + local name = name_or_errors if not name then return nil, string.format("cannot find tool name for %s", program) 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 + -- new an instance + local instance, errors = _instance.new(kind, name, program) + if not instance then + return nil, errors end - -- attempt to check it directly - if tool._check(program, check) then - tool._CHECKINFO[program] = program - return program - end + -- save instance to the cache + tool._TOOLS[kind] = instance - -- attempt to check it from the given directories - if not path.is_absolute(program) then - for _, dir in ipairs(table.wrap(dirs)) do - - -- 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/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua new file mode 100644 index 000000000..9d7ddabeb --- /dev/null +++ b/xmake/modules/core/tools/ar.lua @@ -0,0 +1,107 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file ar.lua +-- + +-- imports +import("core.tool.compiler") + +-- init it +function init(self) + + -- init arflags + _g.arflags = { "-cr" } +end + +-- get the property +function get(self, name) + + -- get it + return _g[name] +end + +-- make the strip flag +function strip(self, level) + + -- the maps + local maps = + { + debug = "-S" + , all = "-s" + } + + -- make it + return maps[level] or "" +end + +-- make the link command +function linkcmd(self, objectfiles, targetkind, targetfile, flags) + + -- check + assert(targetkind == "static") + + -- make it + return format("%s %s %s %s", self:program(), flags, targetfile, objectfiles) +end + +-- link the library file +function link(self, objectfiles, targetkind, targetfile, flags) + + -- check + assert(targetkind == "static", "the target kind: %s is not support for ar", targetkind) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) +end + +-- extract the static library to object directory +function extract(self, libraryfile, objectdir) + + -- make the object directory first + os.mkdir(objectdir) + + -- get the absolute path of this library + libraryfile = path.absolute(libraryfile) + + -- enter the object directory + local olddir = os.cd(objectdir) + + -- extract it + os.run("%s -x %s", self:program(), libraryfile) + + -- check repeat object name + local repeats = {} + 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) + end + repeats[objectfile] = true + end + + -- leave the object directory + os.cd(olddir) +end + diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua new file mode 100644 index 000000000..b55948ecd --- /dev/null +++ b/xmake/modules/core/tools/cl.lua @@ -0,0 +1,293 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cl.lua +-- + +-- imports +import("core.project.project") + +-- init it +function init(self) + + -- init cxflags + _g.cxflags = { "-nologo", "-Gd", "-MP4", "-D_MBCS", "-D_CRT_SECURE_NO_WARNINGS"} + + -- init flags map + _g.mapflags = + { + -- optimize + ["-O0"] = "-Od" + , ["-O1"] = "" + , ["-Os"] = "-O1" + , ["-O3"] = "-Ox" + , ["-Ofast"] = "-Ox -fp:fast" + , ["-fomit-frame-pointer"] = "-Oy" + + -- symbols + , ["-g"] = "-Z7" + , ["-fvisibility=.*"] = "" + + -- warnings + , ["-Wall"] = "-W3" -- = "-Wall" will enable too more warnings + , ["-W1"] = "-W1" + , ["-W2"] = "-W2" + , ["-W3"] = "-W3" + , ["-Werror"] = "-WX" + , ["%-Wno%-error=.*"] = "" + , ["%-fno%-.*"] = "" + + -- vectorexts + , ["-mmmx"] = "-arch:MMX" + , ["-msse"] = "-arch:SSE" + , ["-msse2"] = "-arch:SSE2" + , ["-msse3"] = "-arch:SSE3" + , ["-mssse3"] = "-arch:SSSE3" + , ["-mavx"] = "-arch:AVX" + , ["-mavx2"] = "-arch:AVX2" + , ["-mfpu=.*"] = "" + + -- language + , ["-ansi"] = "" + , ["-std=c99"] = "-TP" -- compile as c++ files because msvc only support c89 + , ["-std=c11"] = "-TP" -- compile as c++ files because msvc only support c89 + , ["-std=gnu99"] = "-TP" -- compile as c++ files because msvc only support c89 + , ["-std=gnu11"] = "-TP" -- compile as c++ files because msvc only support c89 + , ["-std=.*"] = "" + + -- others + , ["-ftrapv"] = "" + , ["-fsanitize=address"] = "" + } + + -- init features + _g.features = + { + ["object:sources"] = false + } +end + +-- get the property +function get(self, name) + + -- get it + return _g[name] +end + +-- make the symbol flag +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 self:has_flags("-ZI -FS -Fd" .. os.tmpfile() .. ".pdb") then + flags = "-FS " .. flags + end + else + flags = "-ZI" + end + end + + -- none + return flags +end + +-- make the warning flag +function nf_warning(self, level) + + -- the maps + local maps = + { + none = "-W0" + , less = "-W1" + , more = "-W3" + , all = "-W3" -- = "-Wall" will enable too more warnings + , error = "-WX" + } + + -- make it + return maps[level] or "" +end + +-- make the optimize flag +function nf_optimize(self, level) + + -- the maps + local maps = + { + none = "-Od" + , fast = "" + , faster = "-Ox" + , fastest = "-Ox -fp:fast" + , smallest = "-O1" + , aggressive = "-Ox -fp:fast" + } + + -- make it + return maps[level] or "" +end + +-- make the vector extension flag +function nf_vectorext(self, extension) + + -- the maps + local maps = + { + sse = "-arch:SSE" + , sse2 = "-arch:SSE2" + , avx = "-arch:AVX" + , avx2 = "-arch:AVX2" + } + + -- make it + return maps[extension] or "" +end + +-- make the language flag +function nf_language(self, stdname) + + -- the stdc maps + local cmaps = + { + -- stdc + c99 = "-TP" -- compile as c++ files because msvc only support c89 + , gnu99 = "-TP" + , c11 = "-TP" + , gnu11 = "-TP" + } + + -- select maps + local maps = cmaps + if self:kind() == "cxx" or self:kind() == "mxx" then + maps = {} + end + + -- make it + return maps[stdname] or "" +end + +-- make the define flag +function nf_define(self, macro) + return "-D" .. macro:gsub("\"", "\\\"") +end + +-- make the undefine flag +function nf_undefine(self, macro) + return "-U" .. macro +end + +-- make the includedir flag +function nf_includedir(self, dir) + return "-I" .. dir +end + +-- make the complie command +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(self, sourcefile, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- generate includes file + if incdepfile then + flags = (flags or "") .. " -showIncludes" + end + + -- compile it + local outdata = try + { + function () + return os.iorun(_compcmd1(self, sourcefile, objectfile, flags)) + end, + + catch + { + function (errors) + + -- get prefix: "Note: including file:", @note maybe not english language + local including_file = errors:match("\n(.-: .-:)%s*.-\r*\n") + + -- filter includes notes + if errors and including_file then + errors = errors:gsub((including_file or "") .. ".-\r*\n", "") + end + os.raise(errors) + end + } + } + + -- parse include dependencies + if incdepfile and outdata then + + -- translate it + local results = {} + local uniques = {} + for includefile in string.gmatch(outdata, ".-: .-:%s*(.-)\r*\n") do + + -- slower, only for debuging +-- assert(os.isfile(includefile), "invalid include file: %s for %s", includefile, incdepfile) + + -- get the relative + includefile = path.relative(includefile, project.directory()) + + -- save it if belong to the project + if not path.is_absolute(includefile) then + + -- insert it and filter repeat + if not uniques[includefile] then + table.insert(results, includefile) + uniques[includefile] = true + end + end + end + + -- update it + io.save(incdepfile, results) + end +end + +-- make the complie command +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(self, sourcefiles, objectfile, flags) +end + +-- complie the source file +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(self, sourcefiles, objectfile, incdepfile, flags) +end + + diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua new file mode 100644 index 000000000..f391b101e --- /dev/null +++ b/xmake/modules/core/tools/clang.lua @@ -0,0 +1,59 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file clang.lua +-- + +-- inherit gcc +inherit("gcc") + +-- init it +function init(self) + + -- init super + _super.init(self) + + -- init shflags + _super._g.shflags = { "-dynamiclib", "-fPIC" } + + -- suppress warning + _super._g.cxflags = {"-Qunused-arguments"} + _super._g.mxflags = {"-Qunused-arguments"} + _super._g.asflags = {"-Qunused-arguments"} + + -- init flags map + _super._g.mapflags["-s"] = "-Wl,-S" + _super._g.mapflags["-S"] = "-Wl,-S" +end + +-- make the strip flag +function nf_strip(self, level) + + -- the maps + local maps = + { + debug = "-Wl,-S" + , all = "-Wl,-S" + } + + -- make it + return maps[level] or "" +end diff --git a/xmake/modules/core/tools/clangxx.lua b/xmake/modules/core/tools/clangxx.lua new file mode 100644 index 000000000..3e31ac92e --- /dev/null +++ b/xmake/modules/core/tools/clangxx.lua @@ -0,0 +1,28 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file clang++.lua +-- + +-- inherit clang +inherit("clang") + + diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua new file mode 100644 index 000000000..02178577e --- /dev/null +++ b/xmake/modules/core/tools/dmd.lua @@ -0,0 +1,184 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file dmd.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") + +-- init it +function init(self) + + -- init arflags + _g.arflags = { "-lib" } + + -- init shflags + _g.shflags = { "-shared", "-fPIC" } + + -- init dcflags for the kind: shared + _g.shared = {} + _g.shared.dcflags = {"-fPIC"} + + -- init features + _g.features = + { + ["object:sources"] = false + } +end + +-- get the property +function get(self, name) + return _g[name] +end + +-- make the optimize flag +function nf_optimize(self, level) + + -- the maps + local maps = + { + none = "" + , fast = "-O" + , faster = "-O -release" + , fastest = "-O -release -inline -boundscheck=off" + , smallest = "-O -release -boundscheck=off" + , aggressive = "-O -release -inline -boundscheck=off" + } + + -- make it + return maps[level] or "" +end + +-- make the strip flag +function nf_strip(self, level) + + -- the maps + local maps = + { + debug = "-L-S" + , all = "-L-s" + } + + -- make it + return maps[level] or "" +end + +-- make the symbol flag +function nf_symbol(self, level) + + -- the maps + local maps = + { + debug = "-g -debug" + , hidden = "" + } + + -- make it + return maps[level] or "" +end + +-- make the warning flag +function nf_warning(self, level) + + -- the maps + local maps = + { + none = "-d" + , less = "-w" + , more = "-w -wi" + , all = "-w -wi" + , error = "-de" + } + + -- make it + return maps[level] or "" +end + +-- make the vector extension flag +function nf_vectorext(self, extension) + + -- the maps + local maps = + { + avx = "-mcpu=avx" + , avx2 = "-mcpu=avx" + } + + -- make it + return maps[extension] or "" +end + +-- make the includedir flag +function nf_includedir(self, dir) + return "-I" .. dir +end + +-- make the link flag +function nf_link(self, lib) + return "-L-l" .. lib +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return "-L-L" .. dir +end + +-- make the rpathdir flag +function nf_rpathdir(self, dir) + local flag = "-L-rpath=" .. dir + if self:has_flags(flag) then + return flag + end +end + +-- make the link command +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(self, objectfiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) +end + +-- make the complie command +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(self, sourcefiles, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + os.run(compcmd(self, sourcefiles, objectfile, flags)) +end + diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua new file mode 100644 index 000000000..4071ba100 --- /dev/null +++ b/xmake/modules/core/tools/gcc.lua @@ -0,0 +1,361 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file gcc.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") +import("detect.tools.find_ccache") + +-- init it +function init(self) + + -- init mxflags + _g.mxflags = { "-fmessage-length=0" + , "-pipe" + , "-fpascal-strings" + , "\"-DIBOutlet=__attribute__((iboutlet))\"" + , "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\"" + , "\"-DIBAction=void)__attribute__((ibaction)\""} + + -- init shflags + _g.shflags = { "-shared", "-fPIC" } + + -- init cxflags for the kind: shared + _g.shared = {} + _g.shared.cxflags = {"-fPIC"} + + -- suppress warning for clang (gcc -> clang on macosx) + if self:has_flags("-Qunused-arguments") then + _g.cxflags = {"-Qunused-arguments"} + _g.mxflags = {"-Qunused-arguments"} + _g.asflags = {"-Qunused-arguments"} + end + + -- init flags map + _g.mapflags = + { + -- warnings + ["-W1"] = "-Wall" + , ["-W2"] = "-Wall" + , ["-W3"] = "-Wall" + + -- strip + , ["-s"] = "-s" + , ["-S"] = "-S" + + } + + -- init features + _g.features = + { + ["object:sources"] = false + } +end + +-- get the property +function get(self, name) + + -- get it + return _g[name] +end + +-- make the strip flag +function nf_strip(self, level) + + -- the maps + local maps = + { + debug = "-S" + , all = "-s" + } + + -- make it + return maps[level] or "" +end + +-- make the symbol flag +function nf_symbol(self, level) + + -- the maps + local maps = + { + debug = "-g" + , hidden = "-fvisibility=hidden" + } + + -- make it + return maps[level] or "" +end + +-- make the warning flag +function nf_warning(self, level) + + -- the maps + local maps = + { + none = "-w" + , less = "-W1" + , more = "-W3" + , all = "-Wall" + , error = "-Werror" + } + + -- make it + return maps[level] or "" +end + +-- make the optimize flag +function nf_optimize(self, level) + + -- the maps + local maps = + { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-Os" + , aggressive = "-Ofast" + } + + -- make it + return maps[level] or "" +end + +-- make the vector extension flag +function nf_vectorext(self, extension) + + -- the maps + local maps = + { + mmx = "-mmmx" + , sse = "-msse" + , sse2 = "-msse2" + , sse3 = "-msse3" + , ssse3 = "-mssse3" + , avx = "-mavx" + , avx2 = "-mavx2" + , neon = "-mfpu=neon" + } + + -- make it + return maps[extension] or "" +end + +-- make the language flag +function nf_language(self, stdname) + + -- the stdc maps + local cmaps = + { + -- stdc + ansi = "-ansi" + , c89 = "-std=c89" + , gnu89 = "-std=gnu89" + , c99 = "-std=c99" + , gnu99 = "-std=gnu99" + , c11 = "-std=c11" + , gnu11 = "-std=gnu11" + } + + -- the stdc++ maps + local cxxmaps = + { + cxx98 = "-std=c++98" + , gnuxx98 = "-std=gnu++98" + , cxx11 = "-std=c++11" + , gnuxx11 = "-std=gnu++11" + , cxx14 = "-std=c++14" + , gnuxx14 = "-std=gnu++14" + , cxx1z = "-std=c++1z" + , gnuxx1z = "-std=gnu++1z" + , cxx17 = "-std=c++17" + , gnuxx17 = "-std=gnu++17" + } + + -- select maps + local maps = cmaps + if self:kind() == "cxx" or self:kind() == "mxx" then + maps = cxxmaps + elseif self:kind() == "sc" then + maps = {} + end + + -- make it + return maps[stdname] or "" +end + +-- make the define flag +function nf_define(self, macro) + return "-D" .. macro:gsub("\"", "\\\"") +end + +-- make the undefine flag +function nf_undefine(self, macro) + return "-U" .. macro +end + +-- make the includedir flag +function nf_includedir(self, dir) + return "-I" .. dir +end + +-- make the link flag +function nf_link(self, lib) + return "-l" .. lib +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return "-L" .. dir +end + +-- make the rpathdir flag +function nf_rpathdir(self, dir) + if self:has_flags("-Wl,-rpath=" .. dir) then + return flag + end +end + +-- make the framework flag +function nf_framework(self, framework) + return "-framework " .. framework +end + +-- make the link command +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(self, objectfiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) +end + +-- make the complie command +function _compcmd1(self, sourcefile, objectfile, flags) + + -- get ccache + local ccache = nil + if config.get("ccache") then + ccache = find_ccache() + end + + -- make it + local command = format("%s -c %s -o %s %s", self:program(), flags, objectfile, sourcefile) + if ccache then + command = ccache:append(command, " ") + end + + -- ok + return command +end + +-- complie the source file +function _compile1(self, sourcefile, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + try + { + function () + local outdata, errdata = os.iorun(_compcmd1(self, sourcefile, objectfile, flags)) + return (outdata or "") .. (errdata or "") + end, + catch + { + function (errors) + + -- compiling errors + os.raise(errors) + end + }, + finally + { + function (ok, warnings) + + -- print some warnings + if warnings and #warnings > 0 and option.get("verbose") then + cprint("${yellow}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) + end + end + } + } + + -- generate includes file + 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", self:program(), flags or "", tmpfile, sourcefile) + + -- translate it + local results = {} + local incdeps = io.readfile(tmpfile) + for includefile in string.gmatch(incdeps, "%s+([%w/%.%-%+_%$%.]+)") do + + -- save it if belong to the project + if not path.is_absolute(includefile) then + table.insert(results, includefile) + end + end + + -- update it + io.save(incdepfile, results) + + -- remove the temporary file + os.rm(tmpfile) + end +end + +-- make the complie command +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(self, sourcefiles, objectfile, flags) +end + +-- complie the source file +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(self, sourcefiles, objectfile, incdepfile, flags) +end + diff --git a/xmake/modules/core/tools/gccgo.lua b/xmake/modules/core/tools/gccgo.lua new file mode 100644 index 000000000..41f941cf4 --- /dev/null +++ b/xmake/modules/core/tools/gccgo.lua @@ -0,0 +1,28 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file gccgo.lua +-- + +-- inherit gcc +inherit("gcc") + + diff --git a/xmake/modules/core/tools/gdc.lua b/xmake/modules/core/tools/gdc.lua new file mode 100644 index 000000000..3682de49e --- /dev/null +++ b/xmake/modules/core/tools/gdc.lua @@ -0,0 +1,29 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file gdc.lua +-- + +-- inherit dmd +inherit("dmd") + + + diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua new file mode 100644 index 000000000..a3b49c8c4 --- /dev/null +++ b/xmake/modules/core/tools/go.lua @@ -0,0 +1,148 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file go.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") + +-- init it +function init(self) + + -- init arflags + _g.arflags = { "grc" } + + -- init the file formats + _g.formats = {} + _g.formats.static = {"", ".a"} + + -- init features + _g.features = + { + ["object:sources"] = true + } +end + +-- get the property +function get(self, name) + return _g[name] +end + +-- make the optimize flag +function nf_optimize(self, level) + + -- the maps + local maps = + { + none = "-N" + , fast = "" + , faster = "" + , fastest = "" + , smallest = "" + , aggressive = "" + } + + -- make it + return maps[level] or "" +end + +-- make the symbol flag +function nf_symbol(self, level, target, mapkind) + + -- only for compiler + if mapkind ~= "object" then + return "" + end + + -- the maps + local maps = + { + debug = "-E" + , hidden = "" + } + + -- make it + return maps[level] or "" +end + +-- make the strip flag +function nf_strip(self, level) + + -- the maps + local maps = + { + debug = "-s" + , all = "-s" + } + + -- make it + return maps[level] or "" +end + +-- make the includedir flag +function nf_includedir(self, dir) + return "-I " .. dir +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return "-L " .. dir +end + +-- make the link command +function linkcmd(self, objectfiles, targetkind, targetfile, flags) + + -- make it + if targetkind == "static" then + return format("%s tool pack %s %s %s", self:program(), flags, targetfile, objectfiles) + else + return format("%s tool link %s -o %s %s", self:program(), flags, targetfile, objectfiles) + end +end + +-- link the target file +function link(self, objectfiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) +end + +-- make the complie command +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(self, sourcefiles, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + os.run(compcmd(self, sourcefiles, objectfile, flags)) +end + diff --git a/xmake/modules/core/tools/gxx.lua b/xmake/modules/core/tools/gxx.lua new file mode 100644 index 000000000..2c73c5473 --- /dev/null +++ b/xmake/modules/core/tools/gxx.lua @@ -0,0 +1,28 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file g++.lua +-- + +-- inherit gcc +inherit("gcc") + + diff --git a/xmake/modules/core/tools/ldc.lua b/xmake/modules/core/tools/ldc.lua new file mode 100644 index 000000000..b36fd446e --- /dev/null +++ b/xmake/modules/core/tools/ldc.lua @@ -0,0 +1,42 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file ldc.lua +-- + +-- inherit dmd +inherit("dmd") + +-- init it +function init(self) + + -- init super + _super.init(self) + + -- init shflags + _super._g.shflags = { "-shared" } + + -- init cxflags for the kind: shared + _super._g.shared = {} +end + + + diff --git a/xmake/modules/core/tools/lib.lua b/xmake/modules/core/tools/lib.lua new file mode 100644 index 000000000..a193b8788 --- /dev/null +++ b/xmake/modules/core/tools/lib.lua @@ -0,0 +1,66 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file lib.lua +-- + +-- get the property +function get(self, name) + + -- get it + return _g[name] +end + +-- extract the static library to object directory +function extract(self, libraryfile, objectdir) + + -- make the object directory first + os.mkdir(objectdir) + + -- list object files + local objectfiles = os.iorun("%s -nologo -list %s", self:program(), libraryfile) + + -- extrace all object files + for _, objectfile in ipairs(objectfiles:split('\n')) do + + -- is object file? + if objectfile:find("%.obj") then + + -- make the outputfile + local outputfile = path.translate(format("%s\\%s", objectdir, path.filename(objectfile))) + + -- repeat? rename it + if os.isfile(outputfile) then + for i = 0, 10 do + outputfile = path.translate(format("%s\\%d_%s", objectdir, i, path.filename(objectfile))) + if not os.isfile(outputfile) then + break + end + end + end + + -- extract it + os.run("%s -nologo -extract:%s -out:%s %s", self:program(), objectfile, outputfile, libraryfile) + end + end +end + + diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua new file mode 100644 index 000000000..6d11d3a94 --- /dev/null +++ b/xmake/modules/core/tools/link.lua @@ -0,0 +1,122 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file link.lua +-- + +-- imports +import("core.project.config") + +-- init it +function init(self) + + -- the architecture + local arch = config.get("arch") + + -- init flags for architecture + local flags_arch = "" + if arch == "x86" then + flags_arch = "-machine:x86" + elseif arch == "x64" then + flags_arch = "-machine:x64" + end + + -- init ldflags + _g.ldflags = { "-nologo", "-dynamicbase", "-nxcompat", flags_arch} + + -- init arflags + _g.arflags = {"-nologo", flags_arch} + + -- init shflags + _g.shflags = {"-nologo", flags_arch} + + -- init flags map + _g.mapflags = + { + -- strip + ["-s"] = "" + , ["-S"] = "" + + -- others + , ["-ftrapv"] = "" + , ["-fsanitize=address"] = "" + } +end + +-- get the property +function get(self, name) + return _g[name] +end + +-- make the symbol flag +function nf_symbol(self, level, target) + + -- debug? generate *.pdb file + local flags = "" + if level == "debug" then + if target and target.symbolfile then + flags = "-debug -pdb:" .. target:symbolfile() + else + flags = "-debug" + end + end + + -- none + return flags +end + +-- make the link flag +function nf_link(self, lib) + return lib .. ".lib" +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return "-libpath:" .. dir +end + +-- make the link command +function linkcmd(self, objectfiles, targetkind, targetfile, flags) + + -- make it + 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", self:program(), argfile) + end + + -- ok? + return cmd +end + +-- link the target file +function link(self, objectfiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) +end + diff --git a/xmake/modules/core/tools/ml.lua b/xmake/modules/core/tools/ml.lua new file mode 100644 index 000000000..74a8fc364 --- /dev/null +++ b/xmake/modules/core/tools/ml.lua @@ -0,0 +1,133 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file ml.lua +-- + +-- init it +function init(self) + + -- init asflags + if self:program():find("64") then + _g.asflags = { "-nologo"} + else + _g.asflags = { "-nologo", "-Gd"} + end + + -- init flags map + _g.mapflags = + { + -- symbols + ["-g"] = "-Z7" + , ["-fvisibility=.*"] = "" + + -- warnings + , ["-Wall"] = "-W3" -- = "-Wall" will enable too more warnings + , ["-W1"] = "-W1" + , ["-W2"] = "-W2" + , ["-W3"] = "-W3" + , ["-Werror"] = "-WX" + , ["%-Wno%-error=.*"] = "" + + -- others + , ["-ftrapv"] = "" + , ["-fsanitize=address"] = "" + } + + -- init features + _g.features = + { + ["object:sources"] = false + } +end + +-- get the property +function get(self, name) + return _g[name] +end + +-- make the warning flag +function nf_warning(self, level) + + -- the maps + local maps = + { + none = "-w" + , less = "-W1" + , more = "-W3" + , all = "-W3" + , error = "-WX" + } + + -- make it + return maps[level] or "" +end + +-- make the define flag +function nf_define(self, macro) + return "-D" .. macro:gsub("\"", "\\\"") +end + +-- make the undefine flag +function nf_undefine(self, macro) + return "-U" .. macro +end + +-- make the includedir flag +function nf_includedir(self, dir) + return "-I" .. dir +end + +-- make the complie command +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(self, sourcefile, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + os.run(_compcmd1(self, sourcefile, objectfile, flags)) +end + +-- make the complie command +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(self, sourcefiles, objectfile, flags) +end + +-- complie the source file +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(self, sourcefiles, objectfile, incdepfile, flags) +end + diff --git a/xmake/modules/core/tools/ml64.lua b/xmake/modules/core/tools/ml64.lua new file mode 100644 index 000000000..899ba9972 --- /dev/null +++ b/xmake/modules/core/tools/ml64.lua @@ -0,0 +1,28 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file ml64.lua +-- + +-- inherit ml +inherit("ml") + + diff --git a/xmake/modules/core/tools/rc.lua b/xmake/modules/core/tools/rc.lua new file mode 100644 index 000000000..a76d7493d --- /dev/null +++ b/xmake/modules/core/tools/rc.lua @@ -0,0 +1,118 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file rc.lua +-- + +-- imports +import("core.base.option") +import("core.project.project") + +-- init it +function init(self) + + -- init features + _g.features = + { + ["object:sources"] = false + } +end + +-- get the property +function get(self, name) + return _g[name] +end + +-- make the define flag +function nf_define(self, macro) + return "-d" .. macro:gsub("\"", "\\\"") +end + +-- make the undefine flag +function nf_undefine(self, macro) + return "-u" .. macro +end + +-- make the includedir flag +function nf_includedir(self, dir) + return "-I" .. dir +end + +-- make the complie command +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(self, sourcefile, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + try + { + function () + local outdata, errdata = os.iorun(_compcmd1(self, sourcefile, objectfile, flags)) + return (outdata or "") .. (errdata or "") + end, + catch + { + function (errors) + + -- compiling errors + os.raise(errors) + end + }, + finally + { + function (ok, warnings) + + -- print some warnings + if warnings and #warnings > 0 and option.get("verbose") then + cprint("${yellow}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) + end + end + } + } +end + +-- make the complie command +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(self, sourcefiles, objectfile, flags) +end + +-- complie the source file +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(self, sourcefiles, objectfile, incdepfile, flags) +end + + diff --git a/xmake/modules/core/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua new file mode 100644 index 000000000..e480624d9 --- /dev/null +++ b/xmake/modules/core/tools/rustc.lua @@ -0,0 +1,127 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file rustc.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") + +-- init it +function init(self) + + -- init arflags + _g.arflags = { "--crate-type=lib" } + + -- init shflags + _g.shflags = { "--crate-type=dylib" } + + -- init ldflags + _g.ldflags = { "--crate-type=bin" } + + -- init the file formats + _g.formats = {} + _g.formats.static = {"lib", ".rlib"} + + -- init features + _g.features = + { + ["object:sources"] = false -- compile multiple source filess to the single object + , ["binary:sources"] = true -- build multiple source files to the binary target file + , ["static:sources"] = true -- build multiple source files to the static target file + , ["shared:sources"] = true -- build multiple source files to the shared target file + } +end + +-- get the property +function get(self, name) + return _g[name] +end + +-- make the optimize flag +function nf_optimize(self, level) + + -- the maps + local maps = + { + none = "-C opt-level=0" + , fast = "-C opt-level=1" + , faster = "-C opt-level=2" + , fastest = "-C opt-level=3" + , smallest = "-C opt-level=s" + , aggressive = "-C opt-level=z" + } + + -- make it + return maps[level] or "" +end + +-- make the symbol flag +function nf_symbol(self, level) + + -- the maps + local maps = + { + debug = "-C debuginfo=2" + , hidden = "" + } + + -- make it + return maps[level] or "" +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return "-L " .. dir +end + +-- make the build command +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(self, sourcefiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- build it + os.run(buildcmd(self, sourcefiles, targetkind, targetfile, flags)) +end + +-- make the complie command +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(self, sourcefiles, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + os.run(compcmd(self, sourcefiles, objectfile, flags)) +end + diff --git a/xmake/modules/core/tools/swiftc.lua b/xmake/modules/core/tools/swiftc.lua new file mode 100644 index 000000000..e1c18934e --- /dev/null +++ b/xmake/modules/core/tools/swiftc.lua @@ -0,0 +1,246 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- 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 +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file swiftc.lua +-- + +-- imports +import("core.project.config") +import("detect.tools.find_ccache") + +-- init it +function init(self) + + -- init flags map + _g.mapflags = + { + -- symbols + ["-fvisibility=hidden"] = "" + + -- warnings + , ["-w"] = "" + , ["-W.*"] = "" + + -- optimize + , ["-O0"] = "-Onone" + , ["-Ofast"] = "-Ounchecked" + , ["-O.*"] = "-O" + + -- vectorexts + , ["-m.*"] = "" + + -- strip + , ["-s"] = "" + , ["-S"] = "" + + -- others + , ["-ftrapv"] = "" + , ["-fsanitize=address"] = "" + } + + -- init features + _g.features = + { + ["object:sources"] = false + } +end + +-- get the property +function get(self, name) + return _g[name] +end + +-- make the strip flag +function nf_strip(self, level) + + -- the maps + local maps = + { + debug = "-Xlinker -S" + , all = "-Xlinker -s" + } + + -- make it + return maps[level] or "" +end + +-- make the symbol flag +function nf_symbol(self, level) + + -- the maps + local maps = + { + debug = "-g" + } + + -- make it + return maps[level] or "" +end + +-- make the warning flag +function nf_warning(self, level) + + -- the maps + local maps = + { + none = "-w" + , less = "-W1" + , more = "-W3" + , all = "-Wall" + , error = "-Werror" + } + + -- make it + return maps[level] or "" +end + +-- make the optimize flag +function nf_optimize(self, level) + + -- the maps + local maps = + { + none = "-Onone" + , fast = "-O" + , faster = "-O" + , fastest = "-O" + , smallest = "-O" + , aggressive = "-Ounchecked" + } + + -- make it + return maps[level] or "" +end + +-- make the vector extension flag +function nf_vectorext(self, extension) + + -- the maps + local maps = + { + mmx = "-mmmx" + , sse = "-msse" + , sse2 = "-msse2" + , sse3 = "-msse3" + , ssse3 = "-mssse3" + , avx = "-mavx" + , avx2 = "-mavx2" + , neon = "-mfpu=neon" + } + + -- make it + return maps[extension] or "" +end + +-- make the includedir flag +function nf_includedir(self, dir) + return "-Xcc -I" .. dir +end + +-- make the define flag +function nf_define(self, macro) + return "-Xcc -D" .. macro:gsub("\"", "\\\"") +end + +-- make the undefine flag +function nf_undefine(self, macro) + return "-Xcc -U" .. macro +end + +-- make the framework flag +function nf_framework(self, framework) + return "-framework" .. framework +end + +-- make the link flag +function nf_link(self, lib) + return "-l" .. lib +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return "-L" .. dir +end + +-- make the link command +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(self, objectfiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.run(linkcmd(self, objectfiles, targetkind, targetfile, flags)) +end + +-- make the compile command +function _compcmd1(self, sourcefile, objectfile, flags) + + -- get ccache + local ccache = nil + if config.get("ccache") then + ccache = find_ccache() + end + + -- make it + local command = format("%s -c %s -o %s %s", self:program(), flags, objectfile, sourcefile) + if ccache then + command = ccache:append(command, " ") + end + + -- ok + return command +end + +-- complie the source file +function _compile1(self, sourcefile, objectfile, incdepfile, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + os.run(_compcmd1(self, sourcefile, objectfile, flags)) +end + +-- make the complie command +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(self, sourcefiles, objectfile, flags) +end + +-- complie the source file +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(self, sourcefiles, objectfile, incdepfile, flags) +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. diff --git a/xmake/tools/ar.lua b/xmake/tools/ar.lua deleted file mode 100644 index 5a0625dfd..000000000 --- a/xmake/tools/ar.lua +++ /dev/null @@ -1,140 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file ar.lua --- - --- imports -import("core.tool.compiler") - --- init it -function init(program, kind) - - -- 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) - - -- get it - return _g[name] -end - --- make the strip flag -function strip(level) - - -- the maps - local maps = - { - debug = "-S" - , all = "-s" - } - - -- make it - return maps[level] or "" -end - --- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) - - -- check - assert(targetkind == "static") - - -- make it - return format("%s %s %s %s", _g.program, flags, targetfile, objectfiles) -end - --- link the library file -function link(objectfiles, targetkind, targetfile, flags) - - -- check - assert(targetkind == "static", "the target kind: %s is not support for ar", targetkind) - - -- ensure the target directory - os.mkdir(path.directory(targetfile)) - - -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) -end - --- extract the static library to object directory -function extract(libraryfile, objectdir) - - -- make the object directory first - os.mkdir(objectdir) - - -- get the absolute path of this library - libraryfile = path.absolute(libraryfile) - - -- enter the object directory - local olddir = os.cd(objectdir) - - -- extract it - os.run("%s -x %s", _g.program, libraryfile) - - -- check repeat object name - local repeats = {} - local objectfiles = os.iorun("%s -t %s", _g.program, libraryfile) - for _, objectfile in ipairs(objectfiles:split('\n')) do - if repeats[objectfile] then - raise("object name(%s) conflicts in library: %s", objectfile, libraryfile) - end - repeats[objectfile] = true - end - - -- leave the object directory - 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/tools/cl.lua deleted file mode 100644 index 519451800..000000000 --- a/xmake/tools/cl.lua +++ /dev/null @@ -1,336 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file cl.lua --- - --- imports -import("core.project.project") - --- init it -function init(program, kind) - - -- 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"} - - -- init flags map - _g.mapflags = - { - -- optimize - ["-O0"] = "-Od" - , ["-O1"] = "" - , ["-Os"] = "-O1" - , ["-O3"] = "-Ox" - , ["-Ofast"] = "-Ox -fp:fast" - , ["-fomit-frame-pointer"] = "-Oy" - - -- symbols - , ["-g"] = "-Z7" - , ["-fvisibility=.*"] = "" - - -- warnings - , ["-Wall"] = "-W3" -- = "-Wall" will enable too more warnings - , ["-W1"] = "-W1" - , ["-W2"] = "-W2" - , ["-W3"] = "-W3" - , ["-Werror"] = "-WX" - , ["%-Wno%-error=.*"] = "" - , ["%-fno%-.*"] = "" - - -- vectorexts - , ["-mmmx"] = "-arch:MMX" - , ["-msse"] = "-arch:SSE" - , ["-msse2"] = "-arch:SSE2" - , ["-msse3"] = "-arch:SSE3" - , ["-mssse3"] = "-arch:SSSE3" - , ["-mavx"] = "-arch:AVX" - , ["-mavx2"] = "-arch:AVX2" - , ["-mfpu=.*"] = "" - - -- language - , ["-ansi"] = "" - , ["-std=c99"] = "-TP" -- compile as c++ files because msvc only support c89 - , ["-std=c11"] = "-TP" -- compile as c++ files because msvc only support c89 - , ["-std=gnu99"] = "-TP" -- compile as c++ files because msvc only support c89 - , ["-std=gnu11"] = "-TP" -- compile as c++ files because msvc only support c89 - , ["-std=.*"] = "" - - -- others - , ["-ftrapv"] = "" - , ["-fsanitize=address"] = "" - } - - -- init features - _g.features = - { - ["object:sources"] = false - } -end - --- get the property -function get(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 - - -- 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 - flags = "-FS " .. flags - end - else - flags = "-ZI" - end - end - - -- none - return flags -end - --- make the warning flag -function nf_warning(level) - - -- the maps - local maps = - { - none = "-W0" - , less = "-W1" - , more = "-W3" - , all = "-W3" -- = "-Wall" will enable too more warnings - , error = "-WX" - } - - -- make it - return maps[level] or "" -end - --- make the optimize flag -function nf_optimize(level) - - -- the maps - local maps = - { - none = "-Od" - , fast = "" - , faster = "-Ox" - , fastest = "-Ox -fp:fast" - , smallest = "-O1" - , aggressive = "-Ox -fp:fast" - } - - -- make it - return maps[level] or "" -end - --- make the vector extension flag -function nf_vectorext(extension) - - -- the maps - local maps = - { - sse = "-arch:SSE" - , sse2 = "-arch:SSE2" - , avx = "-arch:AVX" - , avx2 = "-arch:AVX2" - } - - -- make it - return maps[extension] or "" -end - --- make the language flag -function nf_language(stdname) - - -- the stdc maps - local cmaps = - { - -- stdc - c99 = "-TP" -- compile as c++ files because msvc only support c89 - , gnu99 = "-TP" - , c11 = "-TP" - , gnu11 = "-TP" - } - - -- select maps - local maps = cmaps - if _g.kind == "cxx" or _g.kind == "mxx" then - maps = {} - end - - -- make it - return maps[stdname] or "" -end - --- make the define flag -function nf_define(macro) - - -- make it - return "-D" .. macro:gsub("\"", "\\\"") -end - --- make the undefine flag -function nf_undefine(macro) - - -- make it - return "-U" .. macro -end - --- make the includedir flag -function nf_includedir(dir) - - -- make it - 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) -end - --- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) - - -- ensure the object directory - os.mkdir(path.directory(objectfile)) - - -- generate includes file - if incdepfile then - flags = (flags or "") .. " -showIncludes" - end - - -- compile it - local outdata = try - { - function () - return os.iorun(_compcmd1(sourcefile, objectfile, flags)) - end, - - catch - { - function (errors) - - -- get prefix: "Note: including file:", @note maybe not english language - local including_file = errors:match("\n(.-: .-:)%s*.-\r*\n") - - -- filter includes notes - if errors and including_file then - errors = errors:gsub((including_file or "") .. ".-\r*\n", "") - end - os.raise(errors) - end - } - } - - -- parse include dependencies - if incdepfile and outdata then - - -- translate it - local results = {} - local uniques = {} - for includefile in string.gmatch(outdata, ".-: .-:%s*(.-)\r*\n") do - - -- slower, only for debuging --- assert(os.isfile(includefile), "invalid include file: %s for %s", includefile, incdepfile) - - -- get the relative - includefile = path.relative(includefile, project.directory()) - - -- save it if belong to the project - if not path.is_absolute(includefile) then - - -- insert it and filter repeat - if not uniques[includefile] then - table.insert(results, includefile) - uniques[includefile] = true - end - end - end - - -- update it - io.save(incdepfile, results) - end -end - --- make the complie command -function compcmd(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) -end - --- complie the source file -function compile(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() .. ".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/tools/clang.lua deleted file mode 100644 index e93533f1f..000000000 --- a/xmake/tools/clang.lua +++ /dev/null @@ -1,59 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file clang.lua --- - --- inherit gcc -inherit("gcc") - --- init it -function init(program, kind) - - -- init super - _super.init(program or "clang", kind) - - -- init shflags - _super._g.shflags = { "-dynamiclib", "-fPIC" } - - -- suppress warning - _super._g.cxflags = {"-Qunused-arguments"} - _super._g.mxflags = {"-Qunused-arguments"} - _super._g.asflags = {"-Qunused-arguments"} - - -- init flags map - _super._g.mapflags["-s"] = "-Wl,-S" - _super._g.mapflags["-S"] = "-Wl,-S" -end - --- make the strip flag -function nf_strip(level) - - -- the maps - local maps = - { - debug = "-Wl,-S" - , all = "-Wl,-S" - } - - -- make it - return maps[level] or "" -end diff --git a/xmake/tools/clangxx.lua b/xmake/tools/clangxx.lua deleted file mode 100644 index b32061f75..000000000 --- a/xmake/tools/clangxx.lua +++ /dev/null @@ -1,35 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file clang++.lua --- - --- 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/tools/dmd.lua deleted file mode 100644 index 620cddb9d..000000000 --- a/xmake/tools/dmd.lua +++ /dev/null @@ -1,238 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file dmd.lua --- - --- imports -import("core.base.option") -import("core.project.config") -import("core.project.project") - --- init it -function init(program, kind) - - -- save the shell name - _g.program = program or "dmd" - - -- save the kind - _g.kind = kind - - -- init arflags - _g.arflags = { "-lib" } - - -- init shflags - _g.shflags = { "-shared", "-fPIC" } - - -- init dcflags for the kind: shared - _g.shared = {} - _g.shared.dcflags = {"-fPIC"} - - -- init features - _g.features = - { - ["object:sources"] = false - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the optimize flag -function nf_optimize(level) - - -- the maps - local maps = - { - none = "" - , fast = "-O" - , faster = "-O -release" - , fastest = "-O -release -inline -boundscheck=off" - , smallest = "-O -release -boundscheck=off" - , aggressive = "-O -release -inline -boundscheck=off" - } - - -- make it - return maps[level] or "" -end - --- make the strip flag -function nf_strip(level) - - -- the maps - local maps = - { - debug = "-L-S" - , all = "-L-s" - } - - -- make it - return maps[level] or "" -end - --- make the symbol flag -function nf_symbol(level) - - -- the maps - local maps = - { - debug = "-g -debug" - , hidden = "" - } - - -- make it - return maps[level] or "" -end - --- make the warning flag -function nf_warning(level) - - -- the maps - local maps = - { - none = "-d" - , less = "-w" - , more = "-w -wi" - , all = "-w -wi" - , error = "-de" - } - - -- make it - return maps[level] or "" -end - --- make the vector extension flag -function nf_vectorext(extension) - - -- the maps - local maps = - { - avx = "-mcpu=avx" - , avx2 = "-mcpu=avx" - } - - -- make it - return maps[extension] or "" -end - --- make the includedir flag -function nf_includedir(dir) - - -- make it - return "-I" .. dir -end - --- make the link flag -function nf_link(lib) - - -- make it - return "-L-l" .. lib -end - --- make the linkdir flag -function nf_linkdir(dir) - - -- make it - return "-L-L" .. dir -end - --- make the rpathdir flag -function nf_rpathdir(dir) - - -- check this flag - 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 - 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) -end - --- link the target file -function link(objectfiles, targetkind, targetfile, flags) - - -- ensure the target directory - os.mkdir(path.directory(targetfile)) - - -- link it - os.run(linkcmd(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), " ")) -end - --- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) - - -- ensure the object directory - os.mkdir(path.directory(objectfile)) - - -- compile it - os.run(compcmd(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/tools/gcc.lua deleted file mode 100644 index ffe73c0e9..000000000 --- a/xmake/tools/gcc.lua +++ /dev/null @@ -1,419 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file gcc.lua --- - --- imports -import("core.base.option") -import("core.project.config") -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 - - -- init mxflags - _g.mxflags = { "-fmessage-length=0" - , "-pipe" - , "-fpascal-strings" - , "\"-DIBOutlet=__attribute__((iboutlet))\"" - , "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\"" - , "\"-DIBAction=void)__attribute__((ibaction)\""} - - -- init shflags - _g.shflags = { "-shared", "-fPIC" } - - -- init cxflags for the kind: shared - _g.shared = {} - _g.shared.cxflags = {"-fPIC"} - - -- suppress warning for clang (gcc -> clang on macosx) - if try { function () check("-Qunused-arguments"); return true end } then - _g.cxflags = {"-Qunused-arguments"} - _g.mxflags = {"-Qunused-arguments"} - _g.asflags = {"-Qunused-arguments"} - end - - -- init flags map - _g.mapflags = - { - -- warnings - ["-W1"] = "-Wall" - , ["-W2"] = "-Wall" - , ["-W3"] = "-Wall" - - -- strip - , ["-s"] = "-s" - , ["-S"] = "-S" - - } - - -- init features - _g.features = - { - ["object:sources"] = false - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the strip flag -function nf_strip(level) - - -- the maps - local maps = - { - debug = "-S" - , all = "-s" - } - - -- make it - return maps[level] or "" -end - --- make the symbol flag -function nf_symbol(level) - - -- the maps - local maps = - { - debug = "-g" - , hidden = "-fvisibility=hidden" - } - - -- make it - return maps[level] or "" -end - --- make the warning flag -function nf_warning(level) - - -- the maps - local maps = - { - none = "-w" - , less = "-W1" - , more = "-W3" - , all = "-Wall" - , error = "-Werror" - } - - -- make it - return maps[level] or "" -end - --- make the optimize flag -function nf_optimize(level) - - -- the maps - local maps = - { - none = "-O0" - , fast = "-O1" - , faster = "-O2" - , fastest = "-O3" - , smallest = "-Os" - , aggressive = "-Ofast" - } - - -- make it - return maps[level] or "" -end - --- make the vector extension flag -function nf_vectorext(extension) - - -- the maps - local maps = - { - mmx = "-mmmx" - , sse = "-msse" - , sse2 = "-msse2" - , sse3 = "-msse3" - , ssse3 = "-mssse3" - , avx = "-mavx" - , avx2 = "-mavx2" - , neon = "-mfpu=neon" - } - - -- make it - return maps[extension] or "" -end - --- make the language flag -function nf_language(stdname) - - -- the stdc maps - local cmaps = - { - -- stdc - ansi = "-ansi" - , c89 = "-std=c89" - , gnu89 = "-std=gnu89" - , c99 = "-std=c99" - , gnu99 = "-std=gnu99" - , c11 = "-std=c11" - , gnu11 = "-std=gnu11" - } - - -- the stdc++ maps - local cxxmaps = - { - cxx98 = "-std=c++98" - , gnuxx98 = "-std=gnu++98" - , cxx11 = "-std=c++11" - , gnuxx11 = "-std=gnu++11" - , cxx14 = "-std=c++14" - , gnuxx14 = "-std=gnu++14" - , cxx1z = "-std=c++1z" - , gnuxx1z = "-std=gnu++1z" - , cxx17 = "-std=c++17" - , gnuxx17 = "-std=gnu++17" - } - - -- select maps - local maps = cmaps - if _g.kind == "cxx" or _g.kind == "mxx" then - maps = cxxmaps - elseif _g.kind == "sc" then - maps = {} - end - - -- make it - return maps[stdname] or "" -end - --- make the define flag -function nf_define(macro) - - -- make it - return "-D" .. macro:gsub("\"", "\\\"") -end - --- make the undefine flag -function nf_undefine(macro) - - -- make it - return "-U" .. macro -end - --- make the includedir flag -function nf_includedir(dir) - - -- make it - return "-I" .. dir -end - --- make the link flag -function nf_link(lib) - - -- make it - return "-l" .. lib -end - --- make the linkdir flag -function nf_linkdir(dir) - - -- make it - 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 - return flag - end -end - --- make the framework flag -function nf_framework(framework) - - -- make it - 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) -end - --- link the target file -function link(objectfiles, targetkind, targetfile, flags) - - -- ensure the target directory - os.mkdir(path.directory(targetfile)) - - -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) -end - --- make the complie command -function _compcmd1(sourcefile, objectfile, flags) - - -- get ccache - local ccache = nil - if config.get("ccache") then - ccache = find_ccache() - end - - -- make it - local command = format("%s -c %s -o %s %s", _g.program, flags, objectfile, sourcefile) - if ccache then - command = ccache:append(command, " ") - end - - -- ok - return command -end - --- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) - - -- ensure the object directory - os.mkdir(path.directory(objectfile)) - - -- compile it - try - { - function () - local outdata, errdata = os.iorun(_compcmd1(sourcefile, objectfile, flags)) - return (outdata or "") .. (errdata or "") - end, - catch - { - function (errors) - - -- compiling errors - os.raise(errors) - end - }, - finally - { - function (ok, warnings) - - -- print some warnings - if warnings and #warnings > 0 and option.get("verbose") then - cprint("${yellow}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) - end - end - } - } - - -- generate includes file - if incdepfile and _g.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) - - -- translate it - local results = {} - local incdeps = io.readfile(tmpfile) - for includefile in string.gmatch(incdeps, "%s+([%w/%.%-%+_%$%.]+)") do - - -- save it if belong to the project - if not path.is_absolute(includefile) then - table.insert(results, includefile) - end - end - - -- update it - io.save(incdepfile, results) - - -- remove the temporary file - os.rm(tmpfile) - end -end - --- make the complie command -function compcmd(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) -end - --- complie the source file -function compile(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) -end - diff --git a/xmake/tools/gccgo.lua b/xmake/tools/gccgo.lua deleted file mode 100644 index 997820c96..000000000 --- a/xmake/tools/gccgo.lua +++ /dev/null @@ -1,52 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file gccgo.lua --- - --- 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/tools/gdc.lua deleted file mode 100644 index 70f1cc807..000000000 --- a/xmake/tools/gdc.lua +++ /dev/null @@ -1,35 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file gdc.lua --- - --- 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/tools/go.lua deleted file mode 100644 index dc0e80f93..000000000 --- a/xmake/tools/go.lua +++ /dev/null @@ -1,179 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file go.lua --- - --- imports -import("core.base.option") -import("core.project.config") -import("core.project.project") - --- init it -function init(program, kind) - - -- save the shell name - _g.program = program or "go" - - -- save the kind - _g.kind = kind - - -- init arflags - _g.arflags = { "grc" } - - -- init the file formats - _g.formats = {} - _g.formats.static = {"", ".a"} - - -- init features - _g.features = - { - ["object:sources"] = true - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the optimize flag -function nf_optimize(level) - - -- the maps - local maps = - { - none = "-N" - , fast = "" - , faster = "" - , fastest = "" - , smallest = "" - , aggressive = "" - } - - -- make it - return maps[level] or "" -end - --- make the symbol flag -function nf_symbol(level, target, mapkind) - - -- only for compiler - if mapkind ~= "object" then - return "" - end - - -- the maps - local maps = - { - debug = "-E" - , hidden = "" - } - - -- make it - return maps[level] or "" -end - --- make the strip flag -function nf_strip(level) - - -- the maps - local maps = - { - debug = "-s" - , all = "-s" - } - - -- make it - return maps[level] or "" -end - --- make the includedir flag -function nf_includedir(dir) - - -- make it - return "-I " .. dir -end - --- make the linkdir flag -function nf_linkdir(dir) - - -- make it - return "-L " .. dir -end - --- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) - - -- make it - if targetkind == "static" then - return format("%s tool pack %s %s %s", _g.program, flags, targetfile, objectfiles) - else - return format("%s tool link %s -o %s %s", _g.program, flags, targetfile, objectfiles) - end -end - --- link the target file -function link(objectfiles, targetkind, targetfile, flags) - - -- ensure the target directory - os.mkdir(path.directory(targetfile)) - - -- link it - os.run(linkcmd(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), " ")) -end - --- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) - - -- ensure the object directory - os.mkdir(path.directory(objectfile)) - - -- compile it - os.run(compcmd(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/tools/gxx.lua deleted file mode 100644 index 256b5270d..000000000 --- a/xmake/tools/gxx.lua +++ /dev/null @@ -1,35 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file g++.lua --- - --- 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/tools/ldc.lua deleted file mode 100644 index eb051fd3a..000000000 --- a/xmake/tools/ldc.lua +++ /dev/null @@ -1,42 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file ldc.lua --- - --- inherit dmd -inherit("dmd") - --- init it -function init(program, kind) - - -- init super - _super.init(program or "ldc", kind) - - -- init shflags - _super._g.shflags = { "-shared" } - - -- init cxflags for the kind: shared - _super._g.shared = {} -end - - - diff --git a/xmake/tools/lib.lua b/xmake/tools/lib.lua deleted file mode 100644 index a59f7d713..000000000 --- a/xmake/tools/lib.lua +++ /dev/null @@ -1,95 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @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) - - -- get it - return _g[name] -end - --- extract the static library to object directory -function extract(libraryfile, objectdir) - - -- make the object directory first - os.mkdir(objectdir) - - -- list object files - local objectfiles = os.iorun("%s -nologo -list %s", _g.program, libraryfile) - - -- extrace all object files - for _, objectfile in ipairs(objectfiles:split('\n')) do - - -- is object file? - if objectfile:find("%.obj") then - - -- make the outputfile - local outputfile = path.translate(format("%s\\%s", objectdir, path.filename(objectfile))) - - -- repeat? rename it - if os.isfile(outputfile) then - for i = 0, 10 do - outputfile = path.translate(format("%s\\%d_%s", objectdir, i, path.filename(objectfile))) - if not os.isfile(outputfile) then - break - end - end - end - - -- extract it - os.run("%s -nologo -extract:%s -out:%s %s", _g.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/tools/link.lua deleted file mode 100644 index c79d67a2a..000000000 --- a/xmake/tools/link.lua +++ /dev/null @@ -1,164 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file link.lua --- - --- imports -import("core.project.config") - --- init it -function init(program, kind) - - -- save the shell name - _g.program = program or "link.exe" - - -- save the tool kind - _g.kind = kind - - -- the architecture - local arch = config.get("arch") - - -- init flags for architecture - local flags_arch = "" - if arch == "x86" then - flags_arch = "-machine:x86" - elseif arch == "x64" then - flags_arch = "-machine:x64" - end - - -- init ldflags - _g.ldflags = { "-nologo", "-dynamicbase", "-nxcompat", flags_arch} - - -- init arflags - _g.arflags = {"-nologo", flags_arch} - - -- init shflags - _g.shflags = {"-nologo", flags_arch} - - -- init flags map - _g.mapflags = - { - -- strip - ["-s"] = "" - , ["-S"] = "" - - -- others - , ["-ftrapv"] = "" - , ["-fsanitize=address"] = "" - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the symbol flag -function nf_symbol(level, target) - - -- debug? generate *.pdb file - local flags = "" - if level == "debug" then - if target and target.symbolfile then - flags = "-debug -pdb:" .. target:symbolfile() - else - flags = "-debug" - end - end - - -- none - return flags -end - --- make the link flag -function nf_link(lib) - - -- make it - return lib .. ".lib" -end - --- make the linkdir flag -function nf_linkdir(dir) - - -- make it - return "-libpath:" .. dir -end - --- make the link command -function linkcmd(objectfiles, targetkind, targetfile, flags) - - -- make it - local cmd = format("%s %s -out:%s %s", _g.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) - end - - -- ok? - return cmd -end - --- link the target file -function link(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) -end - diff --git a/xmake/tools/ml.lua b/xmake/tools/ml.lua deleted file mode 100644 index 709f81d58..000000000 --- a/xmake/tools/ml.lua +++ /dev/null @@ -1,164 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file ml.lua --- - --- init it -function init(program, kind) - - -- save name - _g.program = program or "ml.exe" - - -- save kind - _g.kind = kind - - -- init asflags - if _g.program:find("64") then - _g.asflags = { "-nologo"} - else - _g.asflags = { "-nologo", "-Gd"} - end - - -- init flags map - _g.mapflags = - { - -- symbols - ["-g"] = "-Z7" - , ["-fvisibility=.*"] = "" - - -- warnings - , ["-Wall"] = "-W3" -- = "-Wall" will enable too more warnings - , ["-W1"] = "-W1" - , ["-W2"] = "-W2" - , ["-W3"] = "-W3" - , ["-Werror"] = "-WX" - , ["%-Wno%-error=.*"] = "" - - -- others - , ["-ftrapv"] = "" - , ["-fsanitize=address"] = "" - } - - -- init features - _g.features = - { - ["object:sources"] = false - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the warning flag -function nf_warning(level) - - -- the maps - local maps = - { - none = "-w" - , less = "-W1" - , more = "-W3" - , all = "-W3" - , error = "-WX" - } - - -- make it - return maps[level] or "" -end - --- make the define flag -function nf_define(macro) - - -- make it - return "-D" .. macro:gsub("\"", "\\\"") -end - --- make the undefine flag -function nf_undefine(macro) - - -- make it - return "-U" .. macro -end - --- make the includedir flag -function nf_includedir(dir) - - -- make it - 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) -end - --- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) - - -- ensure the object directory - os.mkdir(path.directory(objectfile)) - - -- compile it - os.run(_compcmd1(sourcefile, objectfile, flags)) -end - --- make the complie command -function compcmd(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) -end - --- complie the source file -function compile(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) -end - diff --git a/xmake/tools/ml64.lua b/xmake/tools/ml64.lua deleted file mode 100644 index f21e5466e..000000000 --- a/xmake/tools/ml64.lua +++ /dev/null @@ -1,32 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file ml64.lua --- - --- 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/tools/rc.lua deleted file mode 100644 index f64651d8c..000000000 --- a/xmake/tools/rc.lua +++ /dev/null @@ -1,149 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file rc.lua --- - --- imports -import("core.base.option") -import("core.project.project") - --- init it -function init(program, kind) - - -- save the shell name - _g.program = program or "rc.exe" - - -- save kind - _g.kind = kind - - -- init features - _g.features = - { - ["object:sources"] = false - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the define flag -function nf_define(macro) - - -- make it - return "-d" .. macro:gsub("\"", "\\\"") -end - --- make the undefine flag -function nf_undefine(macro) - - -- make it - return "-u" .. macro -end - --- make the includedir flag -function nf_includedir(dir) - - -- make it - 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) -end - --- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) - - -- ensure the object directory - os.mkdir(path.directory(objectfile)) - - -- compile it - try - { - function () - local outdata, errdata = os.iorun(_compcmd1(sourcefile, objectfile, flags)) - return (outdata or "") .. (errdata or "") - end, - catch - { - function (errors) - - -- compiling errors - os.raise(errors) - end - }, - finally - { - function (ok, warnings) - - -- print some warnings - if warnings and #warnings > 0 and option.get("verbose") then - cprint("${yellow}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) - end - end - } - } -end - --- make the complie command -function compcmd(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) -end - --- complie the source file -function compile(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() .. ".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/tools/rustc.lua deleted file mode 100644 index df261545a..000000000 --- a/xmake/tools/rustc.lua +++ /dev/null @@ -1,158 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file rustc.lua --- - --- imports -import("core.base.option") -import("core.project.config") -import("core.project.project") - --- init it -function init(program, kind) - - -- save the shell name - _g.program = program or "rustc" - - -- save the kind - _g.kind = kind - - -- init arflags - _g.arflags = { "--crate-type=lib" } - - -- init shflags - _g.shflags = { "--crate-type=dylib" } - - -- init ldflags - _g.ldflags = { "--crate-type=bin" } - - -- init the file formats - _g.formats = {} - _g.formats.static = {"lib", ".rlib"} - - -- init features - _g.features = - { - ["object:sources"] = false -- compile multiple source filess to the single object - , ["binary:sources"] = true -- build multiple source files to the binary target file - , ["static:sources"] = true -- build multiple source files to the static target file - , ["shared:sources"] = true -- build multiple source files to the shared target file - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the optimize flag -function nf_optimize(level) - - -- the maps - local maps = - { - none = "-C opt-level=0" - , fast = "-C opt-level=1" - , faster = "-C opt-level=2" - , fastest = "-C opt-level=3" - , smallest = "-C opt-level=s" - , aggressive = "-C opt-level=z" - } - - -- make it - return maps[level] or "" -end - --- make the symbol flag -function nf_symbol(level) - - -- the maps - local maps = - { - debug = "-C debuginfo=2" - , hidden = "" - } - - -- make it - return maps[level] or "" -end - --- make the linkdir flag -function nf_linkdir(dir) - - -- make it - 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, " ")) -end - --- build the target file -function build(sourcefiles, targetkind, targetfile, flags) - - -- ensure the target directory - os.mkdir(path.directory(targetfile)) - - -- build it - os.run(buildcmd(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), " ")) -end - --- complie the source file -function compile(sourcefiles, objectfile, incdepfile, flags) - - -- ensure the object directory - os.mkdir(path.directory(objectfile)) - - -- compile it - os.run(compcmd(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/tools/swiftc.lua deleted file mode 100644 index b740a49a9..000000000 --- a/xmake/tools/swiftc.lua +++ /dev/null @@ -1,274 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- 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 --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file swiftc.lua --- - --- imports -import("core.project.config") -import("detect.tools.find_ccache") - --- init it -function init(program, kind) - - -- save the shell name - _g.program = program or "swiftc" - - -- init kind - _g.kind = kind - - -- init flags map - _g.mapflags = - { - -- symbols - ["-fvisibility=hidden"] = "" - - -- warnings - , ["-w"] = "" - , ["-W.*"] = "" - - -- optimize - , ["-O0"] = "-Onone" - , ["-Ofast"] = "-Ounchecked" - , ["-O.*"] = "-O" - - -- vectorexts - , ["-m.*"] = "" - - -- strip - , ["-s"] = "" - , ["-S"] = "" - - -- others - , ["-ftrapv"] = "" - , ["-fsanitize=address"] = "" - } - - -- init features - _g.features = - { - ["object:sources"] = false - } -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - --- make the strip flag -function nf_strip(level) - - -- the maps - local maps = - { - debug = "-Xlinker -S" - , all = "-Xlinker -s" - } - - -- make it - return maps[level] or "" -end - --- make the symbol flag -function nf_symbol(level) - - -- the maps - local maps = - { - debug = "-g" - } - - -- make it - return maps[level] or "" -end - --- make the warning flag -function nf_warning(level) - - -- the maps - local maps = - { - none = "-w" - , less = "-W1" - , more = "-W3" - , all = "-Wall" - , error = "-Werror" - } - - -- make it - return maps[level] or "" -end - --- make the optimize flag -function nf_optimize(level) - - -- the maps - local maps = - { - none = "-Onone" - , fast = "-O" - , faster = "-O" - , fastest = "-O" - , smallest = "-O" - , aggressive = "-Ounchecked" - } - - -- make it - return maps[level] or "" -end - --- make the vector extension flag -function nf_vectorext(extension) - - -- the maps - local maps = - { - mmx = "-mmmx" - , sse = "-msse" - , sse2 = "-msse2" - , sse3 = "-msse3" - , ssse3 = "-mssse3" - , avx = "-mavx" - , avx2 = "-mavx2" - , neon = "-mfpu=neon" - } - - -- make it - return maps[extension] or "" -end - --- make the includedir flag -function nf_includedir(dir) - - -- make it - return "-Xcc -I" .. dir -end - --- make the define flag -function nf_define(macro) - - -- make it - return "-Xcc -D" .. macro:gsub("\"", "\\\"") -end - --- make the undefine flag -function nf_undefine(macro) - - -- make it - return "-Xcc -U" .. macro -end - --- make the framework flag -function nf_framework(framework) - - -- make it - return "-framework" .. framework -end - --- make the link flag -function nf_link(lib) - - -- make it - return "-l" .. lib -end - --- make the linkdir flag -function nf_linkdir(dir) - - -- make it - 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) -end - --- link the target file -function link(objectfiles, targetkind, targetfile, flags) - - -- ensure the target directory - os.mkdir(path.directory(targetfile)) - - -- link it - os.run(linkcmd(objectfiles, targetkind, targetfile, flags)) -end - --- make the compile command -function _compcmd1(sourcefile, objectfile, flags) - - -- get ccache - local ccache = nil - if config.get("ccache") then - ccache = find_ccache() - end - - -- make it - local command = format("%s -c %s -o %s %s", _g.program, flags, objectfile, sourcefile) - if ccache then - command = ccache:append(command, " ") - end - - -- ok - return command -end - --- complie the source file -function _compile1(sourcefile, objectfile, incdepfile, flags) - - -- ensure the object directory - os.mkdir(path.directory(objectfile)) - - -- compile it - os.run(_compcmd1(sourcefile, objectfile, flags)) -end - --- make the complie command -function compcmd(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) -end - --- complie the source file -function compile(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) - - -- check it - os.run("%s -h", _g.program) -end -- cgit v1.3.1