From 1c9411e8147751592dae6e67834772151a90b383 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 23:09:15 +0800 Subject: add nasm toolchain --- xmake/modules/detect/tools/find_nasm.lua | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 xmake/modules/detect/tools/find_nasm.lua (limited to 'xmake/modules/detect/tools/find_nasm.lua') diff --git a/xmake/modules/detect/tools/find_nasm.lua b/xmake/modules/detect/tools/find_nasm.lua new file mode 100644 index 000000000..40b710d2e --- /dev/null +++ b/xmake/modules/detect/tools/find_nasm.lua @@ -0,0 +1,54 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_nasm.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find nasm +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local nasm = find_nasm() +-- local nasm, version = find_nasm({program = "nasm", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "nasm", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end -- cgit v1.3.1 From a5a4b0ac5b9674ac00049cc1f4ff8f11d5268f6b Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 22:44:16 +0800 Subject: set standalone toolchain --- tests/projects/asm/nasm/src/main.S | 1 - xmake/actions/config/xmake.lua | 2 +- xmake/core/platform/platform.lua | 25 +++++++++++++++++-------- xmake/core/tool/toolchain.lua | 13 ++++++++++++- xmake/modules/detect/tools/find_fasm.lua | 1 + xmake/modules/detect/tools/find_nasm.lua | 1 + xmake/platforms/bsd/check.lua | 16 +++++----------- xmake/platforms/linux/check.lua | 16 +++++----------- xmake/platforms/macosx/check.lua | 16 +++++----------- xmake/toolchains/clang/xmake.lua | 3 +++ xmake/toolchains/cross/xmake.lua | 3 +++ xmake/toolchains/gcc/xmake.lua | 3 +++ xmake/toolchains/llvm/xmake.lua | 3 +++ xmake/toolchains/xcode/xmake.lua | 3 +++ 14 files changed, 62 insertions(+), 44 deletions(-) (limited to 'xmake/modules/detect/tools/find_nasm.lua') diff --git a/tests/projects/asm/nasm/src/main.S b/tests/projects/asm/nasm/src/main.S index 5b3a93699..e96a8d2c9 100644 --- a/tests/projects/asm/nasm/src/main.S +++ b/tests/projects/asm/nasm/src/main.S @@ -1,6 +1,5 @@ global _main - section .text _main: diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 4953fc718..3b02846d1 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -156,7 +156,7 @@ task("config") , " - sdk/bin" , " - sdk/lib" , " - sdk/include" } - , {nil, "toolchain", "kv", nil, "The Cross Toolchain Name" + , {nil, "toolchain", "kv", nil, "The Toolchain Name" , "e.g." , " - llvm" } diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 1ca688636..328bcce75 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -107,19 +107,28 @@ end function _instance:toolchains() local toolchains = self._TOOLCHAINS if not toolchains then - local names = {} - if config.get("toolchain") then - table.insert(names, config.get("toolchain")) - elseif self._INFO:get("toolchains") then - table.join2(names, self._INFO:get("toolchains")) - end + + -- get the given toolchain toolchains = {} - for _, name in ipairs(names) do - local toolchain_inst, errors = toolchain.load(name, self:name()) + local toolchain_given = config.get("toolchain") + if toolchain_given then + local toolchain_inst, errors = toolchain.load(toolchain_given, self:name()) if not toolchain_inst then os.raise(errors) end table.insert(toolchains, toolchain_inst) + toolchain_given = toolchain_inst + end + + -- get the platform toolchains + if (not toolchain_given or not toolchain_given:standalone()) and self._INFO:get("toolchains") then + for _, name in ipairs(self._INFO:get("toolchains")) do + local toolchain_inst, errors = toolchain.load(name, self:name()) + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + end end self._TOOLCHAINS = toolchains end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 78da9ea7f..f5d6ada4f 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -77,6 +77,16 @@ function _instance:get(name) return self._INFO:get(name) end +-- get toolchain kind +function _instance:kind() + return self._INFO:get("kind") +end + +-- is standalone toolchain? +function _instance:standalone() + return self:kind() == "standalone" +end + -- get the program and name of the given tool kind function _instance:tool(toolkind) local toolpathes = self:get("toolsets." .. toolkind) @@ -271,7 +281,8 @@ function toolchain._apis() { values = { - "toolchain.set_bindir" + "toolchain.set_kind" + , "toolchain.set_bindir" , "toolchain.set_sdkdir" } , keyvalues = diff --git a/xmake/modules/detect/tools/find_fasm.lua b/xmake/modules/detect/tools/find_fasm.lua index 5ebf9e699..0b555a406 100644 --- a/xmake/modules/detect/tools/find_fasm.lua +++ b/xmake/modules/detect/tools/find_fasm.lua @@ -39,6 +39,7 @@ function main(opt) -- init options opt = opt or {} + opt.norun = true -- find program local program = find_program(opt.program or "fasm", opt) diff --git a/xmake/modules/detect/tools/find_nasm.lua b/xmake/modules/detect/tools/find_nasm.lua index 40b710d2e..68936502e 100644 --- a/xmake/modules/detect/tools/find_nasm.lua +++ b/xmake/modules/detect/tools/find_nasm.lua @@ -39,6 +39,7 @@ function main(opt) -- init options opt = opt or {} + opt.check = "-v" -- find program local program = find_program(opt.program or "nasm", opt) diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua index 3cd6b8980..71d2e555c 100644 --- a/xmake/platforms/bsd/check.lua +++ b/xmake/platforms/bsd/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then table.remove(toolchains, idx) num = num - 1 else - if _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua index a851256e5..71d2e555c 100644 --- a/xmake/platforms/linux/check.lua +++ b/xmake/platforms/linux/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "cross" or name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then table.remove(toolchains, idx) num = num - 1 else - if _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 08e04d7d6..b4eb3b73b 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "xcode" or name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then table.remove(toolchains, idx) num = num - 1 else - if _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index 5d495fff5..ca84a94be 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("clang") + + -- mark as standalone toolchain + set_kind("standalone") -- set toolsets set_toolsets("cc", "clang") diff --git a/xmake/toolchains/cross/xmake.lua b/xmake/toolchains/cross/xmake.lua index 78be10f98..1cf211646 100644 --- a/xmake/toolchains/cross/xmake.lua +++ b/xmake/toolchains/cross/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("cross") + + -- mark as standalone toolchain + set_kind("standalone") -- check toolchain on_check("check") diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index ba1ef6989..77f2ef228 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("gcc") + + -- mark as standalone toolchain + set_kind("standalone") -- set toolsets set_toolsets("cc", "gcc") diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index d04234809..4c6c4748b 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("llvm") + + -- mark as standalone toolchain + set_kind("standalone") -- check toolchain on_check("check") diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index aed4a44e9..74462908c 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,6 +21,9 @@ -- define toolchain toolchain("xcode") + -- mark as standalone toolchain + set_kind("standalone") + -- check toolchain on_check("check") -- cgit v1.3.1