summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-24 11:05:01 +0800
committerruki <[email protected]>2017-05-24 11:05:01 +0800
commit0041140dbfebce83293bcd3991760c8651f7a7ee (patch)
tree0dbdb04598df12c820df7b003f9d8cdb6a380834
parent59d3a4a90038971d8a7f875bd640bd76b9525dea (diff)
add find ndk and toolchains
-rw-r--r--xmake/modules/detect/sdk/find_ndk_sdkvers.lua62
-rw-r--r--xmake/modules/detect/sdk/find_ndk_toolchains.lua73
-rw-r--r--xmake/modules/detect/sdk/find_xcode_sdkvers.lua (renamed from xmake/modules/detect/sdk/find_xcode_sdkver.lua)8
-rw-r--r--xmake/platforms/android/check.lua108
-rw-r--r--xmake/platforms/checker.lua4
-rw-r--r--xmake/platforms/macosx/check.lua3
6 files changed, 178 insertions, 80 deletions
diff --git a/xmake/modules/detect/sdk/find_ndk_sdkvers.lua b/xmake/modules/detect/sdk/find_ndk_sdkvers.lua
new file mode 100644
index 000000000..16ad5eca7
--- /dev/null
+++ b/xmake/modules/detect/sdk/find_ndk_sdkvers.lua
@@ -0,0 +1,62 @@
+--!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 find_ndk_sdkvers.lua
+--
+
+-- find ndk sdk versions
+--
+-- @param ndk_dir the ndk directory
+--
+-- @return the ndk sdk version array
+--
+-- @code
+--
+-- local ndk_sdkvers = find_ndk_sdkvers("/xxx/android-ndk-r10e")
+--
+-- @endcode
+--
+function main(ndk_dir)
+
+ -- get ndk directory
+ if not ndk_dir or not os.isdir(ndk_dir) then
+ return {}
+ end
+
+ -- find all sdk directories
+ local ndk_sdkvers = {}
+ for _, sdkdir in ipairs(os.dirs(path.join(ndk_dir, "platforms/android-*"))) do
+
+ -- get version
+ local filename = path.filename(sdkdir)
+ local version, count = filename:gsub("android%-", "")
+ if count > 0 then
+
+ -- get the max version
+ if tonumber(version) > 0 then
+ table.insert(ndk_sdkvers, version)
+ end
+ end
+ end
+
+ -- ok?
+ return ndk_sdkvers
+end
diff --git a/xmake/modules/detect/sdk/find_ndk_toolchains.lua b/xmake/modules/detect/sdk/find_ndk_toolchains.lua
new file mode 100644
index 000000000..f7d5b7430
--- /dev/null
+++ b/xmake/modules/detect/sdk/find_ndk_toolchains.lua
@@ -0,0 +1,73 @@
+--!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 find_ndk_toolchains.lua
+--
+
+-- imports
+import("core.project.config")
+
+-- find ndk toolchains
+--
+-- @param ndk_dir the ndk directory
+-- @param opt the argument options
+-- .e.g {arch = "[armv5te|armv6|armv7-a|armv8-a|arm64-v8a]"}
+--
+-- @return the toolchains array. .e.g {{bin = .., cross = ..}, .. }
+--
+-- @code
+--
+-- local ndk_toolchains = find_ndk_toolchains("/xxx/android-ndk-r10e")
+-- local ndk_toolchains = find_ndk_toolchains("/xxx/android-ndk-r10e", {arch = "arm64-v8a"})
+--
+-- @endcode
+--
+function main(ndk_dir, opt)
+
+ -- init arguments
+ opt = opt or {}
+
+ -- get ndk directory
+ if not ndk_dir or not os.isdir(ndk_dir) then
+ return {}
+ end
+
+ -- get arch
+ local arch = opt.arch or config.get("arch") or "armv7-a"
+
+ -- is arm64?
+ local arm64 = arch and arch:startswith("arm64")
+
+ -- the cross
+ local cross = ifelse(arm64, "aarch64-linux-android-", "arm-linux-androideabi-")
+
+ -- save the toolchains directory
+ local ndk_toolchains = {}
+ for _, bindir in ipairs(os.dirs(path.join(ndk_dir, "toolchains", cross .. "**", "prebuilt/*/bin"))) do
+ local binfiles = os.files(path.join(bindir, cross .. "*"))
+ if binfiles and #binfiles > 0 then
+ table.insert(ndk_toolchains, {bin = bindir, cross = cross})
+ end
+ end
+
+ -- ok?
+ return ndk_toolchains
+end
diff --git a/xmake/modules/detect/sdk/find_xcode_sdkver.lua b/xmake/modules/detect/sdk/find_xcode_sdkvers.lua
index 075379eaf..fb479208c 100644
--- a/xmake/modules/detect/sdk/find_xcode_sdkver.lua
+++ b/xmake/modules/detect/sdk/find_xcode_sdkvers.lua
@@ -19,7 +19,7 @@
-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
--
-- @author ruki
--- @file find_xcode_sdkver.lua
+-- @file find_xcode_sdkvers.lua
--
-- imports
@@ -35,9 +35,9 @@ import("detect.sdk.find_xcode_dir")
--
-- @code
--
--- local xcode_sdkvers = find_xcode_sdkver()
--- local xcode_sdkvers = find_xcode_sdkver({xcode_dir = ""})
--- local xcode_sdkvers = find_xcode_sdkver({xcode_dir = "", plat = "iphoneos", arch = "arm64"})
+-- local xcode_sdkvers = find_xcode_sdkvers()
+-- local xcode_sdkvers = find_xcode_sdkvers({xcode_dir = ""})
+-- local xcode_sdkvers = find_xcode_sdkvers({xcode_dir = "", plat = "iphoneos", arch = "arm64"})
--
-- @endcode
--
diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua
index 51bac4dcd..cb8b15e21 100644
--- a/xmake/platforms/android/check.lua
+++ b/xmake/platforms/android/check.lua
@@ -23,8 +23,9 @@
--
-- imports
-import("core.tool.tool")
-import("platforms.checker", {rootdir = os.programdir()})
+import(".checker")
+import("detect.sdk.find_ndk_sdkvers")
+import("detect.sdk.find_ndk_toolchains")
-- check the sdk version for ndk
function _check_ndk_sdkver(config)
@@ -33,31 +34,20 @@ function _check_ndk_sdkver(config)
local ndk_sdkver = config.get("ndk_sdkver")
if not ndk_sdkver then
- -- get the ndk
- local ndk = config.get("ndk")
- if ndk then
+ -- find the max version
+ local sdkver_max = 0
+ for _, sdkver in ipairs(find_ndk_sdkvers(config.get("ndk"))) do
- -- match all sdk directories
- local version_maxn = 0
- for _, sdkdir in ipairs(os.match(ndk .. "/platforms/android-*", true)) do
-
- -- get version
- local filename = path.filename(sdkdir)
- local version, count = filename:gsub("android%-", "")
- if count > 0 then
-
- -- get the max version
- version = tonumber(version)
- if version > version_maxn then
- version_maxn = version
- end
- end
+ -- get the max version
+ sdkver = tonumber(sdkver)
+ if sdkver > sdkver_max then
+ sdkver_max = sdkver
end
-
- -- save the version
- if version_maxn > 0 then ndk_sdkver = version_maxn end
end
+ -- save the version
+ if sdkver_max > 0 then ndk_sdkver = sdkver_max end
+
-- probe ok? update it
if ndk_sdkver ~= nil and ndk_sdkver > 0 then
@@ -74,58 +64,36 @@ function _check_ndk_sdkver(config)
end
end
--- check toolchains directory
-function _check_toolchains_dir(config)
+-- check toolchains
+function _check_toolchains(config)
-- get toolchains directory
- local toolchains_dir = config.get("toolchains")
- if not toolchains_dir then
-
- -- get architecture
- local arch = config.get("arch")
+ local toolchains = config.get("toolchains")
+ if not toolchains then
- -- get ndk
- local ndk = config.get("ndk")
- if ndk then
-
- -- match all toolchains
- if arch and arch:startswith("arm64") then
- toolchains_dir = os.match("%s/toolchains/aarch64-linux-android-**/prebuilt/*/bin/aarch64-linux-android-*", false, ndk)
- else
- toolchains_dir = os.match("%s/toolchains/arm-linux-androideabi-**/prebuilt/*/bin/arm-linux-androideabi-*", false, ndk)
- end
-
- -- save the toolchains directory
- for _, filepath in ipairs(toolchains_dir) do
- config.set("toolchains", path.directory(filepath))
- break
- end
+ -- find first toolchains
+ for _, toolchains in ipairs(find_ndk_toolchains(config.get("ndk"), config.get("arch"))) do
+ config.set("toolchains", toolchains.bin)
+ config.set("cross", toolchains.cross)
+ break
end
end
-end
-
--- check toolchains version
-function _check_toolchains_ver(config)
+ toolchains = config.get("toolchains")
-- get toolchains version
local toolchains_ver = config.get("toolchains_ver")
- if not toolchains_ver then
+ if not toolchains_ver and toolchains then
+ local toolchains_ver = toolchains:match("%-(%d*%.%d*)[/\\]")
+ if toolchains_ver then
- -- get toolchains directory
- local toolchains_dir = config.get("toolchains")
- if toolchains_dir then
- local pos, _, toolchains_ver = toolchains_dir:find("%-(%d*%.%d*)[/\\]")
- if pos and toolchains_ver then
-
- -- save the toolchains version
- config.set("toolchains_ver", toolchains_ver)
-
- -- trace
- cprint("checking for the version of toolchains ... ${green}%s", toolchains_ver)
- else
- -- trace
- cprint("checking for the version of toolchains ... ${red}no")
- end
+ -- save the toolchains version
+ config.set("toolchains_ver", toolchains_ver)
+
+ -- trace
+ cprint("checking for the version of toolchains ... ${green}%s", toolchains_ver)
+ else
+ -- trace
+ cprint("checking for the version of toolchains ... ${red}no")
end
end
end
@@ -142,10 +110,7 @@ function _toolchains(config)
local arch = config.get("arch")
-- get cross
- local cross = "arm-linux-androideabi-"
- if arch and arch:startswith("arm64") then
- cross = "aarch64-linux-android-"
- end
+ local cross = config.get("cross")
-- init toolchains
local toolchains = {}
@@ -187,8 +152,7 @@ function main(kind, toolkind)
{
{ checker.check_arch, "armv7-a" }
, _check_ndk_sdkver
- , _check_toolchains_dir
- , _check_toolchains_ver
+ , _check_toolchains
, { checker.toolchain_check, "sh", _toolchains }
, { checker.toolchain_check, "ld", _toolchains }
}
diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua
index 20465276e..870b51053 100644
--- a/xmake/platforms/checker.lua
+++ b/xmake/platforms/checker.lua
@@ -26,7 +26,7 @@
import("core.tool.tool")
import("core.base.option")
import("detect.sdk.find_xcode_dir")
-import("detect.sdk.find_xcode_sdkver")
+import("detect.sdk.find_xcode_sdkvers")
-- find the given tool
function _toolchain_check(config, toolkind, toolinfo)
@@ -187,7 +187,7 @@ function check_xcode_sdkver(config)
if not xcode_sdkver then
-- check ok? update it
- xcode_sdkver = find_xcode_sdkver({xcode_dir = config.get("xcode_dir"), plat = config.get("plat"), arch = config.get("arch")})[1]
+ xcode_sdkver = find_xcode_sdkvers({xcode_dir = config.get("xcode_dir"), plat = config.get("plat"), arch = config.get("arch")})[1]
if xcode_sdkver then
-- save it
diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua
index 6aec3fa2d..e09776969 100644
--- a/xmake/platforms/macosx/check.lua
+++ b/xmake/platforms/macosx/check.lua
@@ -23,8 +23,7 @@
--
-- imports
-import("core.tool.tool")
-import("platforms.checker", {rootdir = os.programdir()})
+import(".checker")
-- get toolchains
function _toolchains(config)