summaryrefslogtreecommitdiff
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
parentb40bc697d9ce4e20836b60941daabfeaae080b28 (diff)
add cross platform and custom platform name
-rw-r--r--CHANGELOG.md4
-rw-r--r--docs/README.md16
-rw-r--r--docs/zh/README.md16
-rw-r--r--docs/zh/manual.md9
-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
9 files changed, 247 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5cae66486..3720d8777 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@
* Add `includes` api instead of `add_subdirs` and `add_subfiles`
* [#133](https://github.com/tboox/xmake/issues/133): Improve the project plugin to generate `compile_commands.json` by run `xmake project -k compile_commands`
* Add `set_precompiled_header` to support the precompiled header, support gcc, clang, msvc
+* Add `xmake f -p cross` platform and support the custom platform
### Changes
@@ -36,7 +37,7 @@
* Improve the option detection (cache and multi-jobs) and increase 70% speed
* [#129](https://github.com/tboox/xmake/issues/129): Check link deps and cache the target file
* Support `*.asm` source files for vs201x project plugin
-* Mark `add_bindings` and `add_rbindings` as deprecated
+* Mark `add_bindings` and `add_rbi€7€7€7€7€7€7€7ndings` as deprecated
* Optimize `xmake rebuild` speed on windows
* Move `core.project.task` to `core.base.task`
* Move `echo` and `app2ipa` plugins to [xmake-plugins](https://github.com/tboox/xmake-plugins) repo.
@@ -336,6 +337,7 @@
* 添加`includes`接口替换`add_subdirs`和`add_subfiles`
* [#133](https://github.com/tboox/xmake/issues/133): 改进工程插件,通过运行`xmake project -k compile_commands`来导出`compile_commands.json`
* 添加`set_precompiled_header`去支持跨编译器预编译头文件,支持`gcc`, `clang`和`msvc`
+* 添加`xmake f -p cross`平台用于交叉编译,并且支持自定义平台名
### 改进
diff --git a/docs/README.md b/docs/README.md
index 44790f541..b29f8d708 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -293,11 +293,27 @@ $ xmake
##### Cross Compilation
+For linux platform:
+
```bash
$ xmake f -p linux --sdk=/usr/local/arm-linux-gcc/ [--toolchains=/sdk/bin] [--cross=arm-linux-]
$ xmake
```
+Fro other cross platform:
+
+```bash
+$ xmake f -p cross --sdk=/usr/local/arm-xxx-gcc/ [--toolchains=/sdk/bin] [--cross=arm-linux-]
+$ xmake
+```
+
+For custem cross platform (`is_plat("myplat")`):
+
+```bash
+$ xmake f -p myplat --sdk=/usr/local/arm-xxx-gcc/ [--toolchains=/sdk/bin] [--cross=arm-linux-]
+$ xmake
+```
+
| Configuration Option | Description |
| ---------------------------- | -------------------------------------------- |
| [--sdk](#-sdk) | Set the sdk root directory of toolchains |
diff --git a/docs/zh/README.md b/docs/zh/README.md
index beb9eaf09..003356c58 100644
--- a/docs/zh/README.md
+++ b/docs/zh/README.md
@@ -317,11 +317,27 @@ $ xmake
##### 交叉编译
+linux平台的交叉编译:
+
```bash
$ xmake f -p linux --sdk=/usr/local/arm-linux-gcc/ [--toolchains=/sdk/bin] [--cross=arm-linux-]
$ xmake
```
+其他平台的交叉编译:
+
+```bash
+$ xmake f -p cross --sdk=/usr/local/arm-xxx-gcc/ [--toolchains=/sdk/bin] [--cross=arm-linux-]
+$ xmake
+```
+
+如果不关心实际的平台名,只想交叉编译,可以直接用上面的命令,如果需要通过`is_plat("myplat")`判断自己的平台逻辑,则:
+
+```bash
+$ xmake f -p myplat --sdk=/usr/local/arm-xxx-gcc/ [--toolchains=/sdk/bin] [--cross=arm-linux-]
+$ xmake
+```
+
其中:
| 参数名 | 描述 |
diff --git a/docs/zh/manual.md b/docs/zh/manual.md
index c1737aa62..6ab26dfd0 100644
--- a/docs/zh/manual.md
+++ b/docs/zh/manual.md
@@ -108,13 +108,20 @@ end
目前支持的平台有:
* windows
+* cross
* linux
* macosx
* android
* iphoneos
* watchos
-当然你也可以自己扩展添加自己的平台。。。
+当然你也可以自己扩展添加自己的平台,甚至直接指定自己的平台名:
+
+```bash
+$ xmake f -p other --sdk=...
+```
+
+如果指定的平台名不存在,就会自动切到`cross`平台进行交叉编译,但是缺可以通过`is_plat("other")`来判断自己的平台逻辑。
##### is_host
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")
+
+
+