summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-11-01 10:21:49 +0800
committerruki <[email protected]>2020-11-01 10:21:49 +0800
commitb98867b498830320ff183bc4dff426599fee1219 (patch)
tree8066d9a81750844c4b3f76b1b5208902e01bcbe3
parente2e1045005affdac1c9bae2e66feeaed280022f9 (diff)
improve cross toolchain
-rw-r--r--xmake/core/package/package.lua7
-rw-r--r--xmake/modules/private/detect/find_cross_toolchain.lua (renamed from xmake/toolchains/cross/check.lua)5
-rw-r--r--xmake/platforms/cross/xmake.lua44
-rw-r--r--xmake/toolchains/cross/xmake.lua2
-rw-r--r--xmake/toolchains/gnu-rm/check.lua46
-rw-r--r--xmake/toolchains/gnu-rm/xmake.lua2
-rw-r--r--xmake/toolchains/musl/check.lua46
-rw-r--r--xmake/toolchains/musl/xmake.lua21
8 files changed, 59 insertions, 114 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 459b1e573..e6f9738a2 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -582,14 +582,9 @@ end
-- get versions
function _instance:versions()
-
- -- make versions
if self._VERSIONS == nil then
-
- -- get versions
local versions = {}
for version, _ in pairs(table.wrap(self:get("versions"))) do
-
-- remove the url alias prefix if exists
local pos = version:find(':', 1, true)
if pos then
@@ -597,8 +592,6 @@ function _instance:versions()
end
table.insert(versions, version)
end
-
- -- remove repeat
self._VERSIONS = table.unique(versions)
end
return self._VERSIONS
diff --git a/xmake/toolchains/cross/check.lua b/xmake/modules/private/detect/find_cross_toolchain.lua
index 80ba3c536..0f18eede7 100644
--- a/xmake/toolchains/cross/check.lua
+++ b/xmake/modules/private/detect/find_cross_toolchain.lua
@@ -15,7 +15,7 @@
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
--
-- @author ruki
--- @file check.lua
+-- @file find_cross_toolchain.lua
--
-- imports
@@ -38,9 +38,10 @@ function main(toolchain)
if cross_toolchain then
config.set("cross", cross_toolchain.cross, {readonly = true, force = true})
config.set("bin", cross_toolchain.bindir, {readonly = true, force = true})
- config.set("sdkdir", cross_toolchain.sdkdir, {readonly = true, force = true})
+ config.set("sdkdir", cross_toolchain.sdkdir, {readonly = true, force = true}) -- only for toolchain
else
raise("cross toolchain not found!")
end
return cross_toolchain
end
+
diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua
index cc3a6b65d..25a963aa1 100644
--- a/xmake/platforms/cross/xmake.lua
+++ b/xmake/platforms/cross/xmake.lua
@@ -25,7 +25,7 @@ platform("cross")
set_hosts("macosx", "linux", "windows")
-- set archs
- set_archs("i386", "x86_64", "armv7", "armv7s", "arm64-v8a", "mips", "mips64")
+ set_archs("i386", "x86_64", "arm", "arm64", "mips", "mips64", "riscv", "riscv64", "s390x", "ppc", "ppc64", "sh4")
-- set formats
set_formats("static", "lib$(name).a")
@@ -36,10 +36,48 @@ platform("cross")
-- on check
on_check(function (platform)
import("core.project.config")
+ import("detect.sdks.find_cross_toolchain")
+
+ -- detect arch
local arch = config.get("arch")
if not arch then
- config.set("arch", "none")
- cprint("checking for architecture ... ${color.success}%s", config.get("arch"))
+ local cross = config.get("cross")
+ if not cross then
+ local cross_toolchain = find_cross_toolchain(config.get("sdk"), {bindir = config.get("bin")})
+ if cross_toolchain then
+ cross = cross_toolchain.cross
+ end
+ end
+ arch = "none"
+ if cross then
+ if cross:find("aarch64", 1, true) then
+ arch = "arm64"
+ elseif cross:find("arm", 1, true) then
+ arch = "arm"
+ elseif cross:find("mips64", 1, true) then
+ arch = "mips64"
+ elseif cross:find("mips", 1, true) then
+ arch = "mips"
+ elseif cross:find("riscv64", 1, true) then
+ arch = "riscv64"
+ elseif cross:find("riscv", 1, true) then
+ arch = "riscv"
+ elseif cross:find("s390x", 1, true) then
+ arch = "s390x"
+ elseif cross:find("powerpc64", 1, true) then
+ arch = "ppc64"
+ elseif cross:find("powerpc", 1, true) then
+ arch = "ppc"
+ elseif cross:find("sh4", 1, true) then
+ arch = "sh4"
+ elseif cross:find("x86_64", 1, true) then
+ arch = "x86_64"
+ elseif cross:find("i386", 1, true) or cross:find("i686", 1, true) then
+ arch = "i386"
+ end
+ end
+ config.set("arch", arch)
+ cprint("checking for architecture ... ${color.success}%s", arch)
end
end)
diff --git a/xmake/toolchains/cross/xmake.lua b/xmake/toolchains/cross/xmake.lua
index 2acc119a0..ea7bef5d5 100644
--- a/xmake/toolchains/cross/xmake.lua
+++ b/xmake/toolchains/cross/xmake.lua
@@ -28,7 +28,7 @@ toolchain("cross")
set_kind("standalone")
-- check toolchain
- on_check("check")
+ on_check("private.detect.find_cross_toolchain")
-- on load
on_load(function (toolchain)
diff --git a/xmake/toolchains/gnu-rm/check.lua b/xmake/toolchains/gnu-rm/check.lua
deleted file mode 100644
index 80ba3c536..000000000
--- a/xmake/toolchains/gnu-rm/check.lua
+++ /dev/null
@@ -1,46 +0,0 @@
---!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})
- config.set("sdkdir", cross_toolchain.sdkdir, {readonly = true, force = true})
- else
- raise("cross toolchain not found!")
- end
- return cross_toolchain
-end
diff --git a/xmake/toolchains/gnu-rm/xmake.lua b/xmake/toolchains/gnu-rm/xmake.lua
index cb32d218a..8299aea64 100644
--- a/xmake/toolchains/gnu-rm/xmake.lua
+++ b/xmake/toolchains/gnu-rm/xmake.lua
@@ -29,7 +29,7 @@ toolchain("gnu-rm")
set_kind("standalone")
-- check toolchain
- on_check("check")
+ on_check("private.detect.find_cross_toolchain")
-- on load
on_load(function (toolchain)
diff --git a/xmake/toolchains/musl/check.lua b/xmake/toolchains/musl/check.lua
deleted file mode 100644
index 80ba3c536..000000000
--- a/xmake/toolchains/musl/check.lua
+++ /dev/null
@@ -1,46 +0,0 @@
---!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})
- config.set("sdkdir", cross_toolchain.sdkdir, {readonly = true, force = true})
- else
- raise("cross toolchain not found!")
- end
- return cross_toolchain
-end
diff --git a/xmake/toolchains/musl/xmake.lua b/xmake/toolchains/musl/xmake.lua
index a8ddfdc90..24309180d 100644
--- a/xmake/toolchains/musl/xmake.lua
+++ b/xmake/toolchains/musl/xmake.lua
@@ -29,7 +29,7 @@ toolchain("musl")
set_kind("standalone")
-- check toolchain
- on_check("check")
+ on_check("private.detect.find_cross_toolchain")
-- on load
on_load(function (toolchain)
@@ -41,12 +41,12 @@ toolchain("musl")
local cross = config.get("cross") or ""
-- set toolset
- toolchain:set("toolset", "cc", cross .. "gcc", cross .. "clang")
- toolchain:set("toolset", "cxx", cross .. "gcc", cross .. "clang", cross .. "g++", cross .. "clang++")
- toolchain:set("toolset", "cpp", cross .. "gcc -E", cross .. "clang -E")
- toolchain:set("toolset", "as", cross .. "gcc", cross .. "clang")
- toolchain:set("toolset", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang")
- toolchain:set("toolset", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang")
+ toolchain:set("toolset", "cc", cross .. "gcc")
+ toolchain:set("toolset", "cxx", cross .. "gcc")
+ toolchain:set("toolset", "cpp", cross .. "gcc -E")
+ toolchain:set("toolset", "as", cross .. "gcc")
+ toolchain:set("toolset", "ld", cross .. "g++", cross .. "gcc")
+ toolchain:set("toolset", "sh", cross .. "g++", cross .. "gcc")
toolchain:set("toolset", "ar", cross .. "ar")
toolchain:set("toolset", "ex", cross .. "ar")
toolchain:set("toolset", "ranlib", cross .. "ranlib")
@@ -72,5 +72,10 @@ toolchain("musl")
end
-- add flags for arch
- -- TODO
+ if toolchain:is_arch("arm") then
+ toolchain:add("cxflags", "-march=armv7-a", "-msoft-float", {force = true})
+ toolchain:add("ldflags", "-march=armv7-a", "-msoft-float", {force = true})
+ end
+ toolchain:add("ldflags", "--static", {force = true})
+ toolchain:add("syslinks", "gcc", "c")
end)