diff options
| author | ruki <[email protected]> | 2017-06-21 18:53:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-21 18:53:20 +0800 |
| commit | e7fd0a5c178956eb4801de3780f2bc3c0e7a3e1e (patch) | |
| tree | c1691a33309a18cf9b5c54dda592f33a8a7abd66 /xmake/modules/core | |
| parent | 45a54659f7449ead7ed073f9c0cbbe1da9fcdc06 (diff) | |
move tools dir to core.tools and improve tool module
Diffstat (limited to 'xmake/modules/core')
| -rw-r--r-- | xmake/modules/core/tools/ar.lua | 107 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 293 | ||||
| -rw-r--r-- | xmake/modules/core/tools/clang.lua | 59 | ||||
| -rw-r--r-- | xmake/modules/core/tools/clangxx.lua | 28 | ||||
| -rw-r--r-- | xmake/modules/core/tools/dmd.lua | 184 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 361 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gccgo.lua | 28 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gdc.lua | 29 | ||||
| -rw-r--r-- | xmake/modules/core/tools/go.lua | 148 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gxx.lua | 28 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ldc.lua | 42 | ||||
| -rw-r--r-- | xmake/modules/core/tools/lib.lua | 66 | ||||
| -rw-r--r-- | xmake/modules/core/tools/link.lua | 122 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ml.lua | 133 | ||||
| -rw-r--r-- | xmake/modules/core/tools/ml64.lua | 28 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rc.lua | 118 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rustc.lua | 127 | ||||
| -rw-r--r-- | xmake/modules/core/tools/swiftc.lua | 246 |
18 files changed, 2147 insertions, 0 deletions
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 + |
