diff options
| author | ruki <[email protected]> | 2020-05-24 21:10:49 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-05-24 21:10:49 +0800 |
| commit | fb2ba113ca1534249b0872002af0f133becd7e51 (patch) | |
| tree | d5bc9fb1553f622842712b18a7959a0c08a92d63 /xmake/toolchains | |
| parent | dd09a2264181f82a0b6aefb38dce5c92fb3af8fe (diff) | |
| parent | 5ad2eaee8cd65987359dbdfc5149bdd61b9260fc (diff) | |
Merge pull request #792 from xmake-io/toolchain
Improve to detect cross-compilation toolchains
Diffstat (limited to 'xmake/toolchains')
29 files changed, 1840 insertions, 0 deletions
diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua new file mode 100644 index 000000000..944a6bc22 --- /dev/null +++ b/xmake/toolchains/clang/xmake.lua @@ -0,0 +1,72 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("clang") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "clang") + set_toolsets("cxx", "clang", "clang++") + set_toolsets("ld", "clang++", "clang") + set_toolsets("sh", "clang++", "clang") + set_toolsets("ar", "ar") + set_toolsets("ex", "ar") + set_toolsets("strip", "strip") + set_toolsets("mm", "clang") + set_toolsets("mxx", "clang", "clang++") + set_toolsets("as", "clang") + + -- check toolchain + on_check(function (toolchain) + return import("lib.detect.find_tool")("clang") + end) + + -- on load + on_load(function (toolchain) + + -- get march + local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + + -- init flags for c/c++ + toolchain:add("cxflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + if not is_plat("windows") and os.isdir("/usr") then + for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + end + for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + end + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", march) + + -- init flags for asm + toolchain:add("asflags", march) + end) diff --git a/xmake/toolchains/cross/check.lua b/xmake/toolchains/cross/check.lua new file mode 100644 index 000000000..34b62ccc0 --- /dev/null +++ b/xmake/toolchains/cross/check.lua @@ -0,0 +1,45 @@ +--!A cross-toolchain 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 check.lua +-- + +-- imports +import("core.project.config") +import("detect.sdks.find_cross_toolchain") + +-- check the cross toolchain +function main(toolchain) + + -- is cross? + local sdkdir = config.get("sdk") + local bindir = config.get("bin") + local cross = config.get("cross") + if not sdkdir and not bindir and not cross then + return + end + + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + else + raise("cross toolchain not found!") + end + return cross_toolchain +end diff --git a/xmake/toolchains/cross/xmake.lua b/xmake/toolchains/cross/xmake.lua new file mode 100644 index 000000000..1cf211646 --- /dev/null +++ b/xmake/toolchains/cross/xmake.lua @@ -0,0 +1,69 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("cross") + + -- mark as standalone toolchain + set_kind("standalone") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- imports + import("core.project.config") + + -- get cross prefix + local cross = config.get("cross") or "" + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "gcc", cross .. "clang") + toolchain:set("toolsets", "cxx", cross .. "gcc", cross .. "clang", cross .. "g++", cross .. "clang++") + toolchain:set("toolsets", "cpp", cross .. "gcc -E", cross .. "clang -E") + toolchain:set("toolsets", "as", cross .. "gcc", cross .. "clang") + toolchain:set("toolsets", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "ranlib", cross .. "ranlib") + toolchain:set("toolsets", "strip", cross .. "strip") + + -- init linkdirs and includedirs + local sdkdir = toolchain:sdkdir() + if sdkdir then + local includedir = path.join(sdkdir, "include") + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + local linkdir = path.join(sdkdir, "lib") + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + + -- add bin search library for loading some dependent .dll files windows + local bindir = toolchain:bindir() + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + end) diff --git a/xmake/toolchains/cuda/xmake.lua b/xmake/toolchains/cuda/xmake.lua new file mode 100644 index 000000000..884851581 --- /dev/null +++ b/xmake/toolchains/cuda/xmake.lua @@ -0,0 +1,28 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("cuda") + + -- set toolsets + set_toolsets("cu", "nvcc", "clang") + set_toolsets("culd", "nvcc") + set_toolsets("cu-ccbin", "$(env CXX)", "$(env CC)", "clang", "gcc") + diff --git a/xmake/toolchains/dlang/xmake.lua b/xmake/toolchains/dlang/xmake.lua new file mode 100644 index 000000000..783530b90 --- /dev/null +++ b/xmake/toolchains/dlang/xmake.lua @@ -0,0 +1,36 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("dlang") + + -- set toolsets + set_toolsets("dc", "$(env DC)", "dmd", "ldc2", "gdc") + set_toolsets("dcld", "$(env DC)", "dmd", "ldc2", "gdc") + set_toolsets("dcsh", "$(env DC)", "dmd", "ldc2", "gdc") + set_toolsets("dcar", "$(env DC)", "dmd", "ldc2", "gdc") + + -- on load + on_load(function (toolchain) + local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + toolchain:add("dcflags", march) + toolchain:add("dcshflags", march) + toolchain:add("dcldflags", march) + end) diff --git a/xmake/toolchains/envs/xmake.lua b/xmake/toolchains/envs/xmake.lua new file mode 100644 index 000000000..f5dda488b --- /dev/null +++ b/xmake/toolchains/envs/xmake.lua @@ -0,0 +1,37 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("envs") + + -- set toolsets + set_toolsets("cc", "$(env CC)") + set_toolsets("cxx", "$(env CXX)") + set_toolsets("ld", "$(env LD)", "$(env CXX)") + set_toolsets("sh", "$(env SH)", "$(env LD)", "$(env CXX)") + set_toolsets("ar", "$(env AR)") + set_toolsets("ex", "$(env EX)", "$(env AR)") + set_toolsets("strip", "$(env STRIP)") + set_toolsets("ranlib","$(env RANLIB)") + set_toolsets("mm", "$(env MM)") + set_toolsets("mxx", "$(env MXX)") + set_toolsets("as", "$(env AS)") + set_toolsets("sc", "$(env SC)") + diff --git a/xmake/toolchains/fasm/xmake.lua b/xmake/toolchains/fasm/xmake.lua new file mode 100644 index 000000000..cf61cc2ab --- /dev/null +++ b/xmake/toolchains/fasm/xmake.lua @@ -0,0 +1,31 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("fasm") + + -- set toolsets + set_toolsets("as", "fasm") + + -- on load + on_load(function (toolchain) + -- reset asflags for fasm + toolchain:add("fasm.asflags", "") + end) diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua new file mode 100644 index 000000000..17270aedb --- /dev/null +++ b/xmake/toolchains/gcc/xmake.lua @@ -0,0 +1,72 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("gcc") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "gcc") + set_toolsets("cxx", "gcc", "g++") + set_toolsets("ld", "g++", "gcc") + set_toolsets("sh", "g++", "gcc") + set_toolsets("ar", "ar") + set_toolsets("ex", "ar") + set_toolsets("strip", "strip") + set_toolsets("mm", "gcc") + set_toolsets("mxx", "gcc", "g++") + set_toolsets("as", "gcc") + + -- check toolchain + on_check(function (toolchain) + return import("lib.detect.find_tool")("gcc") + end) + + -- on load + on_load(function (toolchain) + + -- get march + local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + + -- init flags for c/c++ + toolchain:add("cxflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + if not is_plat("windows") and os.isdir("/usr") then + for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + end + for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + end + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", march) + + -- init flags for asm + toolchain:add("asflags", march) + end) diff --git a/xmake/toolchains/go/xmake.lua b/xmake/toolchains/go/xmake.lua new file mode 100644 index 000000000..402e5cc04 --- /dev/null +++ b/xmake/toolchains/go/xmake.lua @@ -0,0 +1,33 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("go") + + -- set toolsets + set_toolsets("gc", "$(env GC)", "go", "gccgo") + set_toolsets("gcld", "$(env GC)", "go", "gccgo") + set_toolsets("gcar", "$(env GC)", "go", "gccgo") + + -- on load + on_load(function (toolchain) + toolchain:set("gcldflags", "") + end) + diff --git a/xmake/toolchains/llvm/check.lua b/xmake/toolchains/llvm/check.lua new file mode 100644 index 000000000..04d4d6dec --- /dev/null +++ b/xmake/toolchains/llvm/check.lua @@ -0,0 +1,46 @@ +--!A cross-toolchain 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 check.lua +-- + +-- imports +import("core.project.config") +import("detect.sdks.find_cross_toolchain") + +-- check the cross toolchain +function main(toolchain) + + -- get sdk directory + local sdkdir = config.get("sdk") + local bindir = config.get("bin") + if not sdkdir and not bindir then + if is_plat("linux") and os.isfile("/usr/bin/llvm-ar") then + sdkdir = "/usr" + end + end + + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + else + raise("llvm toolchain not found!") + end + return cross_toolchain +end diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua new file mode 100644 index 000000000..53132de83 --- /dev/null +++ b/xmake/toolchains/llvm/xmake.lua @@ -0,0 +1,63 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("llvm") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "clang") + set_toolsets("cxx", "clang", "clang++") + set_toolsets("cpp", "clang -E") + set_toolsets("as", "clang") + set_toolsets("ld", "clang++", "clang") + set_toolsets("sh", "clang++", "clang") + set_toolsets("ar", "llvm-ar") + set_toolsets("ex", "llvm-ar") + set_toolsets("ranlib", "llvm-ranlib") + set_toolsets("strip", "llvm-strip") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- init linkdirs and includedirs + local sdkdir = toolchain:sdkdir() + if sdkdir then + local includedir = path.join(sdkdir, "include") + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + local linkdir = path.join(sdkdir, "lib") + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + + -- add bin search library for loading some dependent .dll files windows + local bindir = toolchain:bindir() + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + end) diff --git a/xmake/toolchains/mingw/check.lua b/xmake/toolchains/mingw/check.lua new file mode 100644 index 000000000..0bf65a0ce --- /dev/null +++ b/xmake/toolchains/mingw/check.lua @@ -0,0 +1,40 @@ +--!A cross-toolchain 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 check.lua +-- + +-- imports +import("core.project.config") +import("detect.sdks.find_mingw") + +-- check the mingw toolchain +function main(toolchain) + local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) + if mingw then + config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) + config.set("cross", mingw.cross, {readonly = true, force = true}) + config.set("bin", mingw.bindir, {readonly = true, force = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --mingw=xxx") + cprint("or - xmake global --mingw=xxx") + raise() + end + return true +end diff --git a/xmake/toolchains/mingw/xmake.lua b/xmake/toolchains/mingw/xmake.lua new file mode 100644 index 000000000..10a9b2ffa --- /dev/null +++ b/xmake/toolchains/mingw/xmake.lua @@ -0,0 +1,70 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("mingw") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- imports + import("core.project.config") + + -- get cross + local cross = config.get("cross") or "" + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + local bindir = toolchain:bindir() + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "gcc") + toolchain:set("toolsets", "cxx", cross .. "gcc", cross .. "g++") + toolchain:set("toolsets", "cpp", cross .. "gcc -E") + toolchain:set("toolsets", "as", cross .. "gcc") + toolchain:set("toolsets", "ld", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "sh", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "ranlib", cross .. "ranlib") + toolchain:set("toolsets", "mrc", cross .. "windres") + + -- init flags for architecture + local archflags = nil + local arch = config.get("arch") + if arch then + if arch == "x86_64" then archflags = "-m64" + elseif arch == "i386" then archflags = "-m32" + else archflags = "-arch " .. arch + end + end + if archflags then + toolchain:add("cxflags", archflags) + toolchain:add("asflags", archflags) + toolchain:add("ldflags", archflags) + toolchain:add("shflags", archflags) + end + end) diff --git a/xmake/toolchains/nasm/xmake.lua b/xmake/toolchains/nasm/xmake.lua new file mode 100644 index 000000000..fe9beb8b6 --- /dev/null +++ b/xmake/toolchains/nasm/xmake.lua @@ -0,0 +1,36 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("nasm") + + -- set toolsets + set_toolsets("as", "nasm") + + -- on load + on_load(function (toolchain) + if is_plat("macosx") then + toolchain:add("nasm.asflags", "-f", is_arch("x86_64") and "macho64" or "macho32") + elseif is_plat("linux", "bsd") then + toolchain:add("nasm.asflags", "-f", is_arch("x86_64") and "elf64" or "elf32") + elseif is_plat("windows", "mingw", "msys", "cygwin") then + toolchain:add("nasm.asflags", "-f", is_arch("x64") and "win64" or "win32") + end + end) diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua new file mode 100644 index 000000000..4cd4eea11 --- /dev/null +++ b/xmake/toolchains/ndk/check.lua @@ -0,0 +1,56 @@ +--!A cross-toolchain 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 check.lua +-- + +-- imports +import("core.project.config") +import("detect.sdks.find_ndk") +import("detect.sdks.find_android_sdk") + +-- check the ndk toolchain +function _check_ndk() + local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) + if ndk then + config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) + config.set("bin", ndk.bindir, {force = true, readonly = true}) + config.set("cross", ndk.cross, {force = true, readonly = true}) + config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --ndk=xxx") + cprint("or - xmake global --ndk=xxx") + raise() + end +end + +-- check the android sdk +function _check_android_sdk() + local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) + if sdk then + config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) + end +end + +-- main entry +function main(toolchain) + _check_android_sdk() + _check_ndk() + return true +end diff --git a/xmake/toolchains/ndk/load.lua b/xmake/toolchains/ndk/load.lua new file mode 100644 index 000000000..b2b0ae95f --- /dev/null +++ b/xmake/toolchains/ndk/load.lua @@ -0,0 +1,340 @@ +--!A cross-toolchain 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 load.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- get cross + local cross = config.get("cross") or "" + + -- get gcc toolchain bin directory + local gcc_toolchain_bin = nil + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + gcc_toolchain_bin = path.join(gcc_toolchain, "bin") + end + + -- set toolsets + toolchain:set("toolsets", "cc", "clang", cross .. "gcc") + toolchain:set("toolsets", "cxx", "clang++", cross .. "g++") + toolchain:set("toolsets", "cpp", "clang -E", cross .. "gcc -E") + toolchain:set("toolsets", "as", "clang", cross .. "gcc") + toolchain:set("toolsets", "ld", "clang++", "clang", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "sh", "clang++", "clang", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "ar", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ar") or (cross .. "ar"), "llvm-ar") + toolchain:set("toolsets", "ex", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ar") or (cross .. "ar"), "llvm-ar") + toolchain:set("toolsets", "ranlib", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ranlib") or (cross .. "ranlib")) + toolchain:set("toolsets", "strip", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "strip") or (cross .. "strip")) + + -- init flags + local arm32 = false + local arch = config.get("arch") + toolchain:add("ldflags", "-llog") + toolchain:add("shflags", "-llog") + if arch and (arch == "armeabi" or arch == "armeabi-v7a" or arch == "armv5te" or arch == "armv7-a") then -- armv5te/armv7-a are deprecated + arm32 = true + toolchain:add("cxflags", "-mthumb") + toolchain:add("asflags", "-mthumb") + toolchain:add("ldflags", "-mthumb") + toolchain:add("shflags", "-mthumb") + end + + -- use llvm directory? e.g. android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin + local isllvm = false + local bindir = config.get("bin") + if bindir and bindir:find("llvm", 1, true) then + isllvm = true + end + + -- init architecture + if isllvm then + + -- add target + local targets = + { + ["armv5te"] = "armv5te-none-linux-androideabi" -- deprecated + , ["armeabi"] = "armv5te-none-linux-androideabi" -- removed in ndk r17 + , ["armv7-a"] = "armv7-none-linux-androideabi" -- deprecated + , ["armeabi-v7a"] = "armv7-none-linux-androideabi" + , ["arm64-v8a"] = "aarch64-none-linux-android" + , ["i386"] = "i686-none-linux-android" -- deprecated + , ["x86"] = "i686-none-linux-android" + , ["x86_64"] = "x86_64-none-linux-android" + , ["mips"] = "mipsel-none-linux-android" -- removed in ndk r17 + , ["mips64"] = "mips64el-none-linux-android" -- removed in ndk r17 + } + assert(targets[arch], "unknown arch(%s) for android!", arch) + toolchain:add("cxflags", "-target " .. targets[arch]) + toolchain:add("asflags", "-target " .. targets[arch]) + toolchain:add("ldflags", "-target " .. targets[arch]) + toolchain:add("shflags", "-target " .. targets[arch]) + + -- add gcc toolchain + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + toolchain:add("cxflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("asflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("ldflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("shflags", "-gcc-toolchain " .. gcc_toolchain) + end + else + local march = arch + if arch == "arm64-v8a" then + march = "armv8-a" + else + march = "armv5te" + end + -- old version ndk + toolchain:add("cxflags", "-march=" .. march) + toolchain:add("asflags", "-march=" .. march) + toolchain:add("ldflags", "-march=" .. march) + toolchain:add("shflags", "-march=" .. march) + end + + -- init cxflags for the target kind: binary + toolchain:add("binary.cxflags", "-fPIE", "-pie") + + -- add flags for the sdk directory of ndk + local ndk = config.get("ndk") + local ndkver = config.get("ndkver") + local ndk_sdkver = config.get("ndk_sdkver") + if ndk and ndk_sdkver then + + -- the sysroot archs + local sysroot_archs = + { + ["armv5te"] = "arch-arm" -- deprecated + , ["armv7-a"] = "arch-arm" -- deprecated + , ["armeabi"] = "arch-arm" -- removed in ndk r17 + , ["armeabi-v7a"] = "arch-arm" + , ["arm64-v8a"] = "arch-arm64" + , i386 = "arch-x86" -- deprecated + , x86 = "arch-x86" + , x86_64 = "arch-x86_64" + , mips = "arch-mips" -- removed in ndk r17 + , mips64 = "arch-mips64" -- removed in ndk r17 + } + local sysroot_arch = sysroot_archs[arch] + + -- add sysroot + -- + -- @see https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md + -- + -- Before NDK r14, we had a set of libc headers for each API version. + -- In many cases these headers were incorrect. Many exposed APIs that didn‘t exist, and others didn’t expose APIs that did. + -- + -- In NDK r14 (as an opt in feature) we unified these into a single set of headers, called unified headers. + -- This single header path is used for every platform level. API level guards are handled with #ifdef. + -- These headers can be found in prebuilts/ndk/headers. + -- + -- Unified headers are built directly from the Android platform, so they are up to date and correct (or at the very least, + -- any bugs in the NDK headers will also be a bug in the platform headers, which means we're much more likely to find them). + -- + -- In r15 unified headers are used by default. In r16, the old headers have been removed. + -- + local ndk_sdkdir = path.translate(format("%s/platforms/android-%d", ndk, ndk_sdkver)) + local ndk_sysroot_be_r14 = path.join(ndk, "sysroot") + if os.isdir(ndk_sysroot_be_r14) then + + -- the triples + local triples = + { + ["armv5te"] = "arm-linux-androideabi" -- deprecated + , ["armv7-a"] = "arm-linux-androideabi" -- deprecated + , ["armeabi"] = "arm-linux-androideabi" -- removed in ndk r17 + , ["armeabi-v7a"] = "arm-linux-androideabi" + , ["arm64-v8a"] = "aarch64-linux-android" + , i386 = "i686-linux-android" -- deprecated + , x86 = "i686-linux-android" + , x86_64 = "x86_64-linux-android" + , mips = "mips-linux-android" -- removed in ndk r17 + , mips64 = "mips64-linux-android" -- removed in ndk r17 + } + toolchain:add("cxflags", "-D__ANDROID_API__=" .. ndk_sdkver) + toolchain:add("asflags", "-D__ANDROID_API__=" .. ndk_sdkver) + toolchain:add("cflags", "--sysroot=" .. ndk_sysroot_be_r14) + toolchain:add("cxxflags","--sysroot=" .. ndk_sysroot_be_r14) + toolchain:add("asflags", "--sysroot=" .. ndk_sysroot_be_r14) + toolchain:add("cflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) + toolchain:add("cxxflags","-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) + toolchain:add("asflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) + else + if sysroot_arch then + toolchain:add("cflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("cxxflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("asflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + end + end + if sysroot_arch then + toolchain:add("ldflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("shflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + end + + -- add "-fPIE -pie" to ldflags + toolchain:add("ldflags", "-fPIE") + toolchain:add("ldflags", "-pie") + + -- get llvm c++ stl sdk directory + local cxxstl_sdkdir_llvmstl = path.translate(format("%s/sources/cxx-stl/llvm-libc++", ndk)) + + -- get gnu c++ stl sdk directory + local cxxstl_sdkdir_gnustl = nil + if config.get("ndk_toolchains_ver") then + cxxstl_sdkdir_gnustl = path.translate(format("%s/sources/cxx-stl/gnu-libstdc++/%s", ndk, config.get("ndk_toolchains_ver"))) + end + + -- get stlport c++ sdk directory + local cxxstl_sdkdir_stlport = path.translate(format("%s/sources/cxx-stl/stlport", ndk)) + + -- get c++ stl sdk directory + local cxxstl_sdkdir = nil + local ndk_cxxstl = config.get("ndk_cxxstl") + if ndk_cxxstl then + -- we uses c++_static/c++_shared instead of llvmstl_static/llvmstl_shared + if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then + cxxstl_sdkdir = cxxstl_sdkdir_llvmstl + elseif ndk_cxxstl:startswith("gnustl") then + cxxstl_sdkdir = cxxstl_sdkdir_gnustl + elseif ndk_cxxstl:startswith("stlport") then + cxxstl_sdkdir = cxxstl_sdkdir_stlport + end + else + if isllvm then + ndk_cxxstl = "c++_static" + cxxstl_sdkdir = cxxstl_sdkdir_llvmstl + end + if (cxxstl_sdkdir == nil or not os.isdir(cxxstl_sdkdir)) and cxxstl_sdkdir_gnustl then -- <= ndk r16 + ndk_cxxstl = "gnustl_static" + cxxstl_sdkdir = cxxstl_sdkdir_gnustl + end + end + + -- only for c++ stl + if config.get("ndk_stdcxx") and cxxstl_sdkdir and os.isdir(cxxstl_sdkdir) then + + -- the toolchains archs + local toolchains_archs = + { + ["armv5te"] = "armeabi" -- deprecated + , ["armv7-a"] = "armeabi-v7a" -- deprecated + , ["armeabi"] = "armeabi" -- removed in ndk r17 + , ["armeabi-v7a"] = "armeabi-v7a" + , ["arm64-v8a"] = "arm64-v8a" + , i386 = "x86" -- deprecated + , x86 = "x86" + , x86_64 = "x86_64" + , mips = "mips" -- removed in ndk r17 + , mips64 = "mips64" -- removed in ndk r17 + } + local toolchains_arch = toolchains_archs[arch] + + -- add c++ stl include and link directories + if toolchains_arch then + toolchain:add("ldflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) + toolchain:add("shflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) + end + if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then + toolchain:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) + if toolchains_arch then + toolchain:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) + end + local abi_path = path.join(ndk, "sources", "cxx-stl", "llvm-libc++abi") + local before_r13 = path.join(abi_path, "libcxxabi") + local after_r13 = path.join(abi_path, "include") + if os.isdir(before_r13) then + toolchain:add("cxxflags", "-I" .. before_r13) + elseif os.isdir(after_r13) then + toolchain:add("cxxflags", "-I" .. after_r13) + end + elseif ndk_cxxstl:startswith("gnustl") then + toolchain:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) + if toolchains_arch then + toolchain:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) + end + elseif ndk_cxxstl:startswith("stlport") then + toolchain:add("cxxflags", format("-I%s/stlport", cxxstl_sdkdir)) + end + + -- add c++ stl links + if ndk_cxxstl == "c++_static" or ndk_cxxstl == "llvmstl_static" then + toolchain:add("ldflags", "-lc++_static", "-lc++abi") + toolchain:add("shflags", "-lc++_static", "-lc++abi") + if arm32 then + toolchain:add("ldflags", "-lunwind", "-latomic") + toolchain:add("shflags", "-lunwind", "-latomic") + end + elseif ndk_cxxstl == "c++_shared" or ndk_cxxstl == "llvmstl_shared" then + toolchain:add("ldflags", "-lc++_shared", "-lc++abi") + toolchain:add("shflags", "-lc++_shared", "-lc++abi") + if arm32 then + toolchain:add("ldflags", "-lunwind", "-latomic") + toolchain:add("shflags", "-lunwind", "-latomic") + end + elseif ndk_cxxstl == "gnustl_static" then + toolchain:add("ldflags", "-lgnustl_static") + toolchain:add("shflags", "-lgnustl_static") + elseif ndk_cxxstl == "gnustl_shared" then + toolchain:add("ldflags", "-lgnustl_shared") + toolchain:add("shflags", "-lgnustl_shared") + elseif ndk_cxxstl == "stlport_static" then + toolchain:add("ldflags", "-lstlport_static") + toolchain:add("shflags", "-lstlport_static") + elseif ndk_cxxstl == "stlport_shared" then + toolchain:add("ldflags", "-lstlport_shared") + toolchain:add("shflags", "-lstlport_shared") + end + + -- fix 'ld: error: cannot find -lc++' for clang++.exe on r20/windows + -- @see https://github.com/xmake-io/xmake/issues/684 + if ndkver and ndkver >= 20 and (ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl")) then + toolchain:add("ldflags", "-nostdlib++") + toolchain:add("shflags", "-nostdlib++") + end + end + end + + -- init targets for rust + local targets_rust = + { + ["armv5te"] = "arm-linux-androideabi" -- deprecated + , ["armv7-a"] = "arm-linux-androideabi" -- deprecated + , ["armeabi"] = "arm-linux-androideabi" -- removed in ndk r17 + , ["armeabi-v7a"] = "arm-linux-androideabi" + , ["arm64-v8a"] = "aarch64-linux-android" + } + + -- init flags for rust + if targets_rust[arch] then + toolchain:add("rcflags", "--target=" .. targets_rust[arch]) + end + toolchain:add("rcshflags", "-C link-args=\"" .. (table.concat(toolchain:get("shflags"), " "):gsub("%-march=.-%s", "") .. "\"")) + toolchain:add("rcldflags", "-C link-args=\"" .. (table.concat(toolchain:get("ldflags"), " "):gsub("%-march=.-%s", "") .. "\"")) + local sh = toolchain:tool("sh") -- @note we cannot use `config.get("sh")`, because we need check sh first + if sh then + toolchain:add("rcshflags", "-C linker=" .. sh) + end + local ld = toolchain:tool("ld") + if ld then + toolchain:add("rcldflags", "-C linker=" .. ld) + end +end diff --git a/xmake/toolchains/ndk/xmake.lua b/xmake/toolchains/ndk/xmake.lua new file mode 100644 index 000000000..931df3753 --- /dev/null +++ b/xmake/toolchains/ndk/xmake.lua @@ -0,0 +1,28 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("ndk") + + -- check toolchain + on_check("check") + + -- load toolchain + on_load("load") diff --git a/xmake/toolchains/rust/xmake.lua b/xmake/toolchains/rust/xmake.lua new file mode 100644 index 000000000..43684a5bb --- /dev/null +++ b/xmake/toolchains/rust/xmake.lua @@ -0,0 +1,34 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("rust") + + -- set toolsets + set_toolsets("rc", "$(env RC)", "rustc") + set_toolsets("rcld", "$(env RC)", "rustc") + set_toolsets("rcsh", "$(env RC)", "rustc") + set_toolsets("rcar", "$(env RC)", "rustc") + + -- on load + on_load(function (toolchain) + toolchain:set("rcshflags", "") + toolchain:set("rcldflags", "") + end) diff --git a/xmake/toolchains/sdcc/check.lua b/xmake/toolchains/sdcc/check.lua new file mode 100644 index 000000000..a55f99a76 --- /dev/null +++ b/xmake/toolchains/sdcc/check.lua @@ -0,0 +1,37 @@ +--!A cross-toolchain 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 check.lua +-- + +-- imports +import("core.project.config") +import("detect.sdks.find_cross_toolchain") + +-- check the cross toolchain +function main(toolchain) + local sdkdir = config.get("sdk") + local bindir = config.get("bin") + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + else + raise("sdcc toolchain not found!") + end + return cross_toolchain +end diff --git a/xmake/toolchains/sdcc/xmake.lua b/xmake/toolchains/sdcc/xmake.lua new file mode 100644 index 000000000..859f0b6d9 --- /dev/null +++ b/xmake/toolchains/sdcc/xmake.lua @@ -0,0 +1,71 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("sdcc") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "sdcc") + set_toolsets("cxx", "sdcc") + set_toolsets("cpp", "sdcpp") + set_toolsets("as", "sdcc") + set_toolsets("ld", "sdcc") + set_toolsets("sh", "sdcc") + set_toolsets("ar", "sdar") + set_toolsets("ex", "sdar") + + -- set archs + set_archs("stm8", "mcs51", "z80", "z180", "r2k", "r3ka", "s08", "hc08") + + -- set formats + set_formats("static", "$(name).lib") + set_formats("object", "$(name).rel") + set_formats("binary", "$(name).bin") + set_formats("symbol", "$(name).sym") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- init linkdirs and includedirs + local sdkdir = toolchain:sdkdir() + if sdkdir then + local includedir = path.join(sdkdir, "include") + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + local linkdir = path.join(sdkdir, "lib") + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + + -- add port flags for arch + local arch = get_config("arch") + if arch then + toolchain:add("cxflags", "-m" .. arch) + toolchain:add("ldflags", "-m" .. arch) + end + end) diff --git a/xmake/toolchains/vs/check.lua b/xmake/toolchains/vs/check.lua new file mode 100644 index 000000000..12fac2aa0 --- /dev/null +++ b/xmake/toolchains/vs/check.lua @@ -0,0 +1,113 @@ +--!A cross-toolchain 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 check.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("detect.sdks.find_vstudio") +import("lib.detect.find_tool") + +-- attempt to check vs environment +function _check_vsenv() + + -- have been checked? + local vs = config.get("vs") + if vs and config.get("__vcvarsall") then + return vs + end + + -- find vstudio + local vstudio = find_vstudio({vcvars_ver = config.get("vs_toolset"), sdkver = config.get("vs_sdkver")}) + if vstudio then + + -- make order vsver + local vsvers = {} + for vsver, _ in pairs(vstudio) do + if not vs or vs ~= vsver then + table.insert(vsvers, vsver) + end + end + table.sort(vsvers, function (a, b) return tonumber(a) > tonumber(b) end) + if vs then + table.insert(vsvers, 1, vs) + end + + -- get vcvarsall + for _, vsver in ipairs(vsvers) do + local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {} + local vsenv = vcvarsall[config.get("arch") or ""] + if vsenv and vsenv.path and vsenv.include and vsenv.lib then + + -- save vsenv + config.set("__vcvarsall", vcvarsall) + + -- check compiler + local oldenvs = {} + oldenvs.PATH = os.getenv("PATH") + oldenvs.LIB = os.getenv("LIB") + os.setenv("PATH", vsenv.path .. ';' .. (oldenvs.PATH or "")) + os.setenv("LIB", vsenv.lib .. ';' .. (oldenvs.LIB or "")) + local program = nil + local tool = find_tool("cl.exe", {force = true}) + if tool then + program = tool.program + end + for name, values in pairs(oldenvs) do + os.setenv(name, values) + end + + -- ok? + if program then + return vsver + end + end + end + end +end + +-- check the visual studio +function _check_vstudio() + local vs = _check_vsenv() + if vs then + config.set("vs", vs, {readonly = true, force = true}) + cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.success}%s", config.get("arch"), vs) + else + cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", config.get("arch")) + if not (opt and opt.try) then + print("please run:") + print(" - xmake config --vs=xxx [--vs_toolset=xxx]") + print("or - xmake global --vs=xxx") + raise() + end + end + return vs +end + +-- main entry +function main() + -- @see https://github.com/xmake-io/xmake/pull/679 + local cc = path.basename(config.get("cc") or "cl"):lower() + local cxx = path.basename(config.get("cxx") or "cl"):lower() + local mrc = path.basename(config.get("mrc") or "rc"):lower() + if cc == "cl" or cxx == "cl" or mrc == "rc" then + return _check_vstudio(config) + end +end + diff --git a/xmake/toolchains/vs/load.lua b/xmake/toolchains/vs/load.lua new file mode 100644 index 000000000..855869a0b --- /dev/null +++ b/xmake/toolchains/vs/load.lua @@ -0,0 +1,90 @@ +--!A cross-toolchain 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 load.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("detect.sdks.find_vstudio") + +-- add the given vs environment +function _add_vsenv(toolchain, name) + + -- get vcvarsall + local vcvarsall = config.get("__vcvarsall") + if not vcvarsall then + return + end + + -- get arch + local arch = config.get("arch") or "" + + -- get vs environment for the current arch + local vsenv = vcvarsall[arch] or {} + + -- switch vstudio environment if vs_sdkver has been changed + local switch_vsenv = false + local vs = config.get("vs") + local vs_sdkver = config.get("vs_sdkver") + if vs and vs_sdkver and vsenv.WindowsSDKVersion and vs_sdkver ~= vsenv.WindowsSDKVersion then + switch_vsenv = true + end + if switch_vsenv then + -- find vstudio + local vstudio = find_vstudio({vcvars_ver = config.get("vs_toolset"), sdkver = vs_sdkver}) + if vstudio then + vcvarsall = (vstudio[vs] or {}).vcvarsall or {} + vsenv = vcvarsall[arch] or {} + if vsenv and vsenv.path and vsenv.include and vsenv.lib then + config.set("__vcvarsall", vcvarsall) + end + end + end + + -- get the pathes for the vs environment + local new = vsenv[name] + if new then + toolchain:add("runenvs", name:upper(), path.splitenv(new)) + end +end + +-- main entry +function main(toolchain) + + -- set toolsets + toolchain:set("toolsets", "cc", "cl.exe") + toolchain:set("toolsets", "cxx", "cl.exe") + toolchain:set("toolsets", "mrc", "rc.exe") + if is_arch("x64") then + toolchain:set("toolsets", "as", "ml64.exe") + else + toolchain:set("toolsets", "as", "ml.exe") + end + toolchain:set("toolsets", "ld", "link.exe") + toolchain:set("toolsets", "sh", "link.exe -dll") + toolchain:set("toolsets", "ar", "link.exe -lib") + toolchain:set("toolsets", "ex", "lib.exe") + + -- add vs environments + _add_vsenv(toolchain, "path") + _add_vsenv(toolchain, "lib") + _add_vsenv(toolchain, "include") + _add_vsenv(toolchain, "libpath") +end + diff --git a/xmake/toolchains/vs/xmake.lua b/xmake/toolchains/vs/xmake.lua new file mode 100644 index 000000000..cc717de9f --- /dev/null +++ b/xmake/toolchains/vs/xmake.lua @@ -0,0 +1,31 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("vs") + + -- mark as standalone toolchain + set_kind("standalone") + + -- check toolchain + on_check("check") + + -- load toolchain + on_load("load") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua new file mode 100644 index 000000000..925db3870 --- /dev/null +++ b/xmake/toolchains/xcode/check.lua @@ -0,0 +1,51 @@ +--!A cross-toolchain 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 check.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("detect.sdks.find_xcode") + +-- main entry +function main(toolchain) + + -- find xcode + local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = config.get("plat"), arch = config.get("arch")}) + if xcode then + config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) + else + return false + end + + -- save target minver + local xcode_sdkver = config.get("xcode_sdkver") + local target_minver = config.get("target_minver") + if xcode_sdkver and not target_minver then + target_minver = xcode_sdkver + if is_plat("macosx") then + local macos_ver = macos.version() + if macos_ver then + target_minver = macos_ver:major() .. "." .. macos_ver:minor() + end + end + config.set("target_minver", target_minver) + end + return true +end diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua new file mode 100644 index 000000000..3aeb78672 --- /dev/null +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -0,0 +1,62 @@ +--!A cross-toolchain 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 load_iphoneos.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init architecture + local arch = config.get("arch") or "arm64" + local simulator = (arch == "i386" or arch == "x86_64") + + -- init platform name + local platname = simulator and "iPhoneSimulator" or "iPhoneOS" + + -- init target minimal version + local target_minver = config.get("target_minver") + if target_minver and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "i386") then + target_minver = "10" -- iOS 10 is the maximum deployment target for 32-bit targets + end + local target_minver_flags = (simulator and "-mios-simulator-version-min=" or "-miphoneos-version-min=") .. target_minver + + -- init the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for objc/c++ + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) + toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) +end + diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua new file mode 100644 index 000000000..5cebd96bb --- /dev/null +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -0,0 +1,78 @@ +--!A cross-toolchain 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 load_macosx.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init flags for architecture + local arch = config.get("arch") or os.arch() + local target_minver = config.get("target_minver") + + -- init flags for the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = nil + if xcode_dir and xcode_sdkver then + xcode_sdkdir = xcode_dir .. "/Contents/Developer/platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + end + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch) + toolchain:add("ldflags", "-arch " .. arch) + if target_minver then + toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) + end + if xcode_sdkdir then + toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + else + toolchain:add("cxflags", "-I/usr/local/include") + toolchain:add("cxflags", "-I/usr/include") + toolchain:add("ldflags", "-L/usr/local/lib") + toolchain:add("ldflags", "-L/usr/lib") + end + toolchain:add("ldflags", "-stdlib=libc++") + toolchain:add("ldflags", "-lz") + toolchain:add("shflags", toolchain:get("ldflags")) + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for swift + if target_minver and xcode_sdkdir then + toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + end +end diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua new file mode 100644 index 000000000..5048f4bb7 --- /dev/null +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -0,0 +1,59 @@ +--!A cross-toolchain 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 load_watchos.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init architecture + local arch = config.get("arch") + local simulator = arch == "i386" + + -- init platform name + local platname = simulator and "WatchSimulator" or "WatchOS" + + -- init target minimal version + local target_minver = config.get("target_minver") + local target_minver_flags = (simulator and "-mwatchos-simulator-version-min=" or "-mwatchos-version-min=") .. target_minver + + -- init the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for objc/c++ + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) + toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) +end + diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua new file mode 100644 index 000000000..74462908c --- /dev/null +++ b/xmake/toolchains/xcode/xmake.lua @@ -0,0 +1,76 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("xcode") + + -- mark as standalone toolchain + set_kind("standalone") + + -- check toolchain + on_check("check") + + -- load toolchain + on_load(function (toolchain) + + -- get cross + local cross, arch, simulator + if is_plat("macosx") then + cross = "xcrun -sdk macosx " + elseif is_plat("iphoneos") then + arch = get_config("arch") or os.arch() + simulator = (arch == "i386" or arch == "x86_64") + cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + elseif is_plat("watchos") then + arch = get_config("arch") or os.arch() + simulator = (arch == "i386") + cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " + else + raise("unknown platform for xcode!") + end + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "clang") + toolchain:set("toolsets", "cxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "ld", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "sh", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "strip", cross .. "strip") + toolchain:set("toolsets", "dsymutil", cross .. "dsymutil", "dsymutil") + toolchain:set("toolsets", "mm", cross .. "clang") + toolchain:set("toolsets", "mxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "sc", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scld", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scsh", cross .. "swiftc", "swiftc") + if arch then + toolchain:set("toolsets", "cpp", cross .. "clang -arch " .. arch .. " -E") + end + if is_plat("macosx") then + toolchain:set("toolsets", "as", cross .. "clang") + elseif simulator then + toolchain:set("toolsets", "as", cross .. "clang") + else + toolchain:set("toolsets", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross) .. "clang") + end + + -- load configurations + import("load_" .. get_config("plat"))(toolchain) + end) diff --git a/xmake/toolchains/yasm/xmake.lua b/xmake/toolchains/yasm/xmake.lua new file mode 100644 index 000000000..a99a15cc6 --- /dev/null +++ b/xmake/toolchains/yasm/xmake.lua @@ -0,0 +1,36 @@ +--!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 xmake.lua +-- + +-- define toolchain +toolchain("yasm") + + -- set toolsets + set_toolsets("as", "yasm") + + -- on load + on_load(function (toolchain) + if is_plat("macosx") then + toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "macho64" or "macho32") + elseif is_plat("linux", "bsd") then + toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "elf64" or "elf32") + elseif is_plat("windows", "mingw", "msys", "cygwin") then + toolchain:add("yasm.asflags", "-f", is_arch("x64") and "win64" or "win32") + end + end) |
