summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-04-26 13:03:49 +0800
committerruki <[email protected]>2016-04-26 13:03:49 +0800
commitc172d1cda21f5ece12301bbc22d2eacf67c068d5 (patch)
tree601ecc4b9d99ec0ad80170cbf9b66e77aef90cbc
parentb01a6861eb85ac9b15d03749b9e95e298556aa72 (diff)
add android platform
-rw-r--r--xmake/core/platform/checker.lua25
-rw-r--r--xmake/core/sandbox/modules/os.lua4
-rw-r--r--xmake/platforms/android/checker.lua148
-rwxr-xr-xxmake/platforms/android/xmake.lua114
-rw-r--r--xmake/platforms/iphoneos/checker.lua1
-rw-r--r--xmake/platforms/iphonesimulator/checker.lua1
-rw-r--r--xmake/platforms/macosx/checker.lua1
-rw-r--r--xmake/platforms/watchos/checker.lua1
-rw-r--r--xmake/platforms/watchsimulator/checker.lua1
9 files changed, 284 insertions, 12 deletions
diff --git a/xmake/core/platform/checker.lua b/xmake/core/platform/checker.lua
index 4cbb70243..2278faf97 100644
--- a/xmake/core/platform/checker.lua
+++ b/xmake/core/platform/checker.lua
@@ -111,18 +111,23 @@ function checker.check(name)
end
-- belong to the current host?
- if instance:host() == xmake._HOST then
+ for _, host in ipairs(table.wrap(instance:hosts())) do
+ if host == xmake._HOST then
- -- get the checker module
- local module, errors = instance:checker()
- if not module then
- return false, errors
- end
+ -- get the checker module
+ local module, errors = instance:checker()
+ if not module then
+ return false, errors
+ end
+
+ -- check it
+ local ok, errors = checker._check(module.get("global"), global)
+ if not ok then
+ return false, errors
+ end
- -- check it
- local ok, errors = checker._check(module.get("global"), global)
- if not ok then
- return false, errors
+ -- ok
+ break
end
end
end
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 98dca8bc7..e6447541e 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -204,13 +204,13 @@ function sandbox_os.execute(cmd, ...)
end
-- match files or directories
-function sandbox_os.match(pattern, findir)
+function sandbox_os.match(pattern, findir, ...)
-- check
assert(pattern)
-- format it first
- pattern = vformat(pattern)
+ pattern = vformat(pattern, ...)
-- match it
return os.match(pattern, findir)
diff --git a/xmake/platforms/android/checker.lua b/xmake/platforms/android/checker.lua
new file mode 100644
index 000000000..7aec1a852
--- /dev/null
+++ b/xmake/platforms/android/checker.lua
@@ -0,0 +1,148 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file checker.lua
+--
+
+-- imports
+import("core.tool.tool")
+import("platforms.checker", {rootdir = os.programdir()})
+
+-- check the sdk version for ndk
+function _check_ndk_sdkver(config)
+
+ -- get ndk sdk version
+ local ndk_sdkver = config.get("ndk_sdkver")
+ if not ndk_sdkver then
+
+ -- get the ndk
+ local ndk = config.get("ndk")
+ if ndk then
+
+ -- 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
+ end
+
+ -- save the version
+ if version_maxn > 0 then ndk_sdkver = version_maxn end
+ end
+
+ -- probe ok? update it
+ if ndk_sdkver ~= nil and ndk_sdkver > 0 then
+
+ -- save it
+ config.set("ndk_sdkver", ndk_sdkver)
+
+ -- trace
+ print("checking for the SDK version of NDK ... android-%d", ndk_sdkver)
+ else
+
+ -- trace
+ print("checking for the SDK version of NDK ... no")
+ end
+ end
+end
+
+-- check the toolchains
+function _check_toolchains(config)
+
+ -- get architecture
+ local arch = config.get("arch")
+
+ -- get toolchains
+ 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 = os.match("%s/toolchains/aarch64-linux-android-**/prebuilt/*/bin/aarch64-linux-android-*", false, ndk)
+ else
+ toolchains = os.match("%s/toolchains/arm-linux-androideabi-**/prebuilt/*/bin/arm-linux-androideabi-*", false, ndk)
+ end
+
+ -- save the toolchains directory
+ for _, filepath in ipairs(toolchains) do
+ config.set("toolchains", path.directory(filepath))
+ break
+ end
+ end
+ end
+
+ -- get cross
+ local cross = "arm-linux-androideabi-"
+ if arch and arch:startswith("arm64") then
+ cross = "aarch64-linux-android-"
+ end
+
+ -- done
+ checker.check_toolchain(config, "cc", cross, "gcc", "the c compiler")
+ checker.check_toolchain(config, "cxx", cross, "g++", "the c++ compiler")
+ checker.check_toolchain(config, "as", cross, "gcc", "the assember")
+ checker.check_toolchain(config, "ld", cross, "g++", "the linker")
+ checker.check_toolchain(config, "ar", cross, "ar", "the static library linker")
+ checker.check_toolchain(config, "sh", cross, "g++", "the shared library linker")
+end
+
+-- init it
+function init()
+
+ -- init the check list of config
+ _g.config =
+ {
+ { checker.check_arch, "armv7-a" }
+ , checker.check_make
+ , checker.check_ccache
+ , _check_ndk_sdkver
+ , _check_toolchains
+ }
+
+ -- init the check list of global
+ _g.global =
+ {
+ checker.check_make
+ , checker.check_ccache
+ , _check_ndk_sdkver
+ }
+
+end
+
+-- get the property
+function get(name)
+
+ -- get it
+ return _g[name]
+end
+
diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua
new file mode 100755
index 000000000..8bc316e72
--- /dev/null
+++ b/xmake/platforms/android/xmake.lua
@@ -0,0 +1,114 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define platform
+platform("android")
+
+ -- set os
+ set_platform_os("android")
+
+ -- set hosts
+ set_platform_hosts("macosx", "linux", "windows")
+
+ -- set archs
+ set_platform_archs("armv5te", "armv6", "armv7-a", "armv8-a", "arm64-v8a")
+
+ -- set checker
+ set_platform_checker("checker")
+
+ -- on load
+ on_platform_load(function ()
+
+ -- imports
+ import("core.project.config")
+
+ -- init the file formats
+ _g.formats = {}
+ _g.formats.static = {"lib", ".a"}
+ _g.formats.object = {"", ".o"}
+ _g.formats.shared = {"lib", ".so"}
+
+ -- init the toolchains
+ _g.tools = {}
+ _g.tools.make = config.get("make")
+ _g.tools.ccache = config.get("__ccache")
+ _g.tools.cc = config.get("cc")
+ _g.tools.cxx = config.get("cxx")
+ _g.tools.as = config.get("as")
+ _g.tools.ld = config.get("ld")
+ _g.tools.ar = config.get("ar")
+ _g.tools.sh = config.get("sh")
+ _g.tools.ex = config.get("ar")
+ _g.tools.sc = config.get("sc")
+
+ -- init flags
+ local arch = config.get("arch")
+ if arch:startswith("arm64") then
+ _g.cxflags = {}
+ _g.asflags = {}
+ _g.ldflags = {"-llog"}
+ _g.shflags = {"-llog"}
+ else
+ _g.cxflags = { "-march=" .. arch, "-mthumb"}
+ _g.asflags = { "-march=" .. arch, "-mthumb"}
+ _g.ldflags = { "-march=" .. arch, "-llog", "-mthumb"}
+ _g.shflags = { "-march=" .. arch, "-llog", "-mthumb"}
+ end
+
+ -- add flags for the sdk directory of ndk
+ local ndk = config.get("ndk")
+ local ndk_sdkver = config.get("ndk_sdkver")
+ if ndk and ndk_sdkver then
+ local ndk_sdkdir = path.translate(format("%s/platforms/android-%d", ndk, ndk_sdkver))
+ if arch:startswith("arm64") then
+ insert(_g.cxflags, format("--sysroot=%s/arch-arm64", ndk_sdkdir))
+ insert(_g.asflags, format("--sysroot=%s/arch-arm64", ndk_sdkdir))
+ insert(_g.ldflags, format("--sysroot=%s/arch-arm64", ndk_sdkdir))
+ insert(_g.shflags, format("--sysroot=%s/arch-arm64", ndk_sdkdir))
+ else
+ insert(_g.cxflags, format("--sysroot=%s/arch-arm", ndk_sdkdir))
+ insert(_g.asflags, format("--sysroot=%s/arch-arm", ndk_sdkdir))
+ insert(_g.ldflags, format("--sysroot=%s/arch-arm", ndk_sdkdir))
+ insert(_g.shflags, format("--sysroot=%s/arch-arm", ndk_sdkdir))
+ end
+ end
+ end)
+
+ -- set menu
+ set_platform_menu({
+ config =
+ {
+ {}
+ , {nil, "ndk", "kv", nil, "The NDK Directory" }
+ , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" }
+ }
+
+ , global =
+ {
+ {}
+ , {nil, "ndk", "kv", nil, "The NDK Directory" }
+ , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" }
+ }
+ })
+
+
+
diff --git a/xmake/platforms/iphoneos/checker.lua b/xmake/platforms/iphoneos/checker.lua
index b497b0d30..a8fcd1937 100644
--- a/xmake/platforms/iphoneos/checker.lua
+++ b/xmake/platforms/iphoneos/checker.lua
@@ -77,6 +77,7 @@ function init()
_g.global =
{
checker.check_xcode
+ , checker.check_make
, checker.check_ccache
}
diff --git a/xmake/platforms/iphonesimulator/checker.lua b/xmake/platforms/iphonesimulator/checker.lua
index a0f269ab3..55c54b338 100644
--- a/xmake/platforms/iphonesimulator/checker.lua
+++ b/xmake/platforms/iphonesimulator/checker.lua
@@ -63,6 +63,7 @@ function init()
_g.global =
{
checker.check_xcode
+ , checker.check_make
, checker.check_ccache
}
diff --git a/xmake/platforms/macosx/checker.lua b/xmake/platforms/macosx/checker.lua
index f39b28ff5..af89e001f 100644
--- a/xmake/platforms/macosx/checker.lua
+++ b/xmake/platforms/macosx/checker.lua
@@ -63,6 +63,7 @@ function init()
_g.global =
{
checker.check_xcode
+ , checker.check_make
, checker.check_ccache
}
diff --git a/xmake/platforms/watchos/checker.lua b/xmake/platforms/watchos/checker.lua
index 59e580dba..694cee36d 100644
--- a/xmake/platforms/watchos/checker.lua
+++ b/xmake/platforms/watchos/checker.lua
@@ -77,6 +77,7 @@ function init()
_g.global =
{
checker.check_xcode
+ , checker.check_make
, checker.check_ccache
}
diff --git a/xmake/platforms/watchsimulator/checker.lua b/xmake/platforms/watchsimulator/checker.lua
index ad39fa36c..57f28f888 100644
--- a/xmake/platforms/watchsimulator/checker.lua
+++ b/xmake/platforms/watchsimulator/checker.lua
@@ -63,6 +63,7 @@ function init()
_g.global =
{
checker.check_xcode
+ , checker.check_make
, checker.check_ccache
}