summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2017-08-03 11:15:46 +0800
committerruki <[email protected]>2017-08-03 11:15:46 +0800
commitbcb21e7b854ee16baf2c0b992ded6b4e7cefb76c (patch)
treef1276b9715ff5e363bfac14bd848f15c761e0367 /xmake
parentb40bc697d9ce4e20836b60941daabfeaae080b28 (diff)
add cross platform and custom platform name
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/platform/platform.lua16
-rw-r--r--xmake/core/project/project.lua4
-rw-r--r--xmake/platforms/cross/check.lua107
-rw-r--r--xmake/platforms/cross/load.lua41
-rw-r--r--xmake/platforms/cross/xmake.lua41
5 files changed, 204 insertions, 5 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 9e66824d0..c7448f559 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -181,12 +181,19 @@ function platform.load(plat)
for _, dir in ipairs(platform._directories()) do
-- find this directory
- scriptpath = path.join(path.join(dir, plat), "xmake.lua")
+ scriptpath = path.join(dir, plat, "xmake.lua")
if os.isfile(scriptpath) then
break
end
end
+ -- unknown platform? switch to cross compilation platform
+ local cross = false
+ if not scriptpath or not os.isfile(scriptpath) then
+ scriptpath = path.join(os.programdir(), "platforms", "cross", "xmake.lua")
+ cross = true
+ end
+
-- not exists?
if not scriptpath or not os.isfile(scriptpath) then
return nil, string.format("the platform %s not found!", plat)
@@ -198,13 +205,16 @@ function platform.load(plat)
return nil, errors
end
+ -- get result
+ local result = utils.ifelse(cross, results["cross"], results[plat])
+
-- check the platform name
- if not results[plat] then
+ if not result then
return nil, string.format("the platform %s not found!", plat)
end
-- new an instance
- local instance, errors = _instance.new(plat, results[plat], platform._interpreter():rootdir())
+ local instance, errors = _instance.new(plat, result, platform._interpreter():rootdir())
if not instance then
return nil, errors
end
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index fb0999e60..6c844e4f0 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -84,7 +84,7 @@ function project._api_is_plat(interp, ...)
-- exists this platform? and escape '-'
for _, p in ipairs(table.join(...)) do
- if p and type(p) == "string" and plat:find(p:gsub("%-", "%%-")) then
+ if p and type(p) == "string" and plat:find("^" .. p:gsub("%-", "%%-") .. "$") then
return true
end
end
@@ -99,7 +99,7 @@ function project._api_is_arch(interp, ...)
-- exists this architecture? and escape '-'
for _, a in ipairs(table.join(...)) do
- if a and type(a) == "string" and arch:find(a:gsub("%-", "%%-")) then
+ if a and type(a) == "string" and arch:find("^" .. a:gsub("%-", "%%-") .. "$") then
return true
end
end
diff --git a/xmake/platforms/cross/check.lua b/xmake/platforms/cross/check.lua
new file mode 100644
index 000000000..bd9046145
--- /dev/null
+++ b/xmake/platforms/cross/check.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 check.lua
+--
+
+-- imports
+import("detect.sdks.find_cross_toolchains")
+import(".checker")
+
+-- check the architecture
+function __check_arch(config)
+
+ -- get the architecture
+ local arch = config.get("arch")
+ if not arch then
+ config.set("arch", "none")
+ end
+end
+
+-- get toolchains
+function _toolchains(config)
+
+ -- attempt to get it from cache first
+ if _g.TOOLCHAINS then
+ return _g.TOOLCHAINS
+ end
+
+ -- find cross toolchains
+ local cross = ""
+ for _, toolchain in ipairs(find_cross_toolchains(config.get("sdk") or config.get("toolchains"), {bin = config.get("toolchains"), cross = config.get("cross")})) do
+ if toolchain.bin and toolchain.cross then
+ config.set("cross", toolchain.cross)
+ config.set("toolchains", toolchain.bin)
+ cross = toolchain.cross
+ break
+ end
+ end
+
+ -- init toolchains
+ local toolchains = {}
+
+ -- insert c/c++ tools to toolchains
+ checker.toolchain_insert(toolchains, "cc", cross, "gcc", "the c compiler")
+ checker.toolchain_insert(toolchains, "cc", cross, "clang", "the c compiler")
+ checker.toolchain_insert(toolchains, "cxx", cross, "gcc", "the c++ compiler")
+ checker.toolchain_insert(toolchains, "cxx", cross, "clang", "the c++ compiler")
+ checker.toolchain_insert(toolchains, "cxx", cross, "g++", "the c++ compiler")
+ checker.toolchain_insert(toolchains, "cxx", cross, "clang++", "the c++ compiler")
+ checker.toolchain_insert(toolchains, "ld", cross, "g++", "the linker")
+ checker.toolchain_insert(toolchains, "ld", cross, "gcc", "the linker")
+ checker.toolchain_insert(toolchains, "ld", cross, "clang++", "the linker")
+ checker.toolchain_insert(toolchains, "ld", cross, "clang", "the linker")
+ checker.toolchain_insert(toolchains, "ar", cross, "ar", "the static library archiver")
+ checker.toolchain_insert(toolchains, "ex", cross, "ar", "the static library extractor")
+ checker.toolchain_insert(toolchains, "sh", cross, "g++", "the shared library linker")
+ checker.toolchain_insert(toolchains, "sh", cross, "gcc", "the shared library linker")
+ checker.toolchain_insert(toolchains, "sh", cross, "clang++", "the shared library linker")
+ checker.toolchain_insert(toolchains, "sh", cross, "clang", "the shared library linker")
+
+ -- insert asm tools to toolchains
+ checker.toolchain_insert(toolchains, "as", cross, "clang", "the assember")
+ checker.toolchain_insert(toolchains, "as", cross, "gcc", "the assember")
+
+ -- save toolchains
+ _g.TOOLCHAINS = toolchains
+
+ -- ok
+ return toolchains
+end
+
+-- check it
+function main(kind, toolkind)
+
+ -- only check the given tool?
+ if toolkind then
+ return checker.toolchain_check(kind, toolkind, _toolchains)
+ end
+
+ -- init the check list of config
+ _g.config =
+ {
+ __check_arch
+ }
+
+ -- check it
+ checker.check(kind, _g)
+end
+
diff --git a/xmake/platforms/cross/load.lua b/xmake/platforms/cross/load.lua
new file mode 100644
index 000000000..a820a26e7
--- /dev/null
+++ b/xmake/platforms/cross/load.lua
@@ -0,0 +1,41 @@
+--!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 load.lua
+--
+
+-- imports
+import("core.project.config")
+
+-- load it
+function main()
+
+ -- init linkdirs and includedirs
+ local sdkdir = config.get("sdk")
+ if sdkdir then
+ _g.includedirs = {path.join(sdkdir, "include")}
+ _g.linkdirs = {path.join(sdkdir, "lib")}
+ end
+
+ -- ok
+ return _g
+end
+
diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua
new file mode 100644
index 000000000..4330be48d
--- /dev/null
+++ b/xmake/platforms/cross/xmake.lua
@@ -0,0 +1,41 @@
+--!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 xmake.lua
+--
+
+-- define platform
+platform("cross")
+
+ -- set hosts
+ set_hosts("macosx", "linux", "windows")
+
+ -- set formats
+ set_formats {static = {"lib", ".a"}, object = {"", ".o"}, shared = {"lib", ".so"}, symbol = {"", ".sym"}}
+
+ -- on check
+ on_check("check")
+
+ -- on load
+ on_load("load")
+
+
+