diff options
| author | ruki <[email protected]> | 2015-06-12 10:45:14 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-12 10:45:14 +0800 |
| commit | 1678ef146c122b8a38a4485262f43b816230aa0f (patch) | |
| tree | ad6ff2cef9e9f50726f04dc1cafe135aaa26a26d /xmake/scripts/platform | |
| parent | c2e614548b92821c8396e2a2e9f06afeb97cc7bd (diff) | |
probe and compile for android
Diffstat (limited to 'xmake/scripts/platform')
| -rw-r--r-- | xmake/scripts/platform/android/android.lua | 29 | ||||
| -rw-r--r-- | xmake/scripts/platform/android/prober.lua | 114 |
2 files changed, 133 insertions, 10 deletions
diff --git a/xmake/scripts/platform/android/android.lua b/xmake/scripts/platform/android/android.lua index fe1c14cb7..629f07886 100644 --- a/xmake/scripts/platform/android/android.lua +++ b/xmake/scripts/platform/android/android.lua @@ -45,13 +45,28 @@ function android.make(configs) configs.tools = {} configs.tools.make = "make" configs.tools.ccache = config.get("__ccache") - configs.tools.cc = config.get("cc") or "arm-linux-androideabi-gcc" - configs.tools.cxx = config.get("cxx") or "arm-linux-androideabi-g++" - configs.tools.mm = config.get("mm") or configs.tools.cc - configs.tools.mxx = config.get("mxx") or configs.tools.cxx - configs.tools.ld = config.get("ld") or "arm-linux-androideabi-g++" - configs.tools.ar = config.get("ar") or "arm-linux-androideabi-ar" - configs.tools.sh = config.get("sh") or "arm-linux-androideabi-g++" + configs.tools.cc = config.get("cc") + configs.tools.cxx = config.get("cxx") + configs.tools.as = config.get("as") + configs.tools.ld = config.get("ld") + configs.tools.ar = config.get("ar") + configs.tools.sh = config.get("sh") + + -- init flags + configs.cxflags = { "-march=" .. config.get("arch") } + configs.asflags = { "-march=" .. config.get("arch") } + configs.ldflags = { "-march=" .. config.get("arch"), "-llog" } + configs.shflags = { "-march=" .. config.get("arch"), "-llog" } + + -- add flags for the sdk directory of ndk + local ndk_sdkdir = config.get("__ndk_sdkdir") + if ndk_sdkdir then + ndk_sdkdir = path.translate(ndk_sdkdir) + table.insert(configs.cxflags, string.format("--sysroot=%s/arch-arm", ndk_sdkdir)) + table.insert(configs.asflags, string.format("--sysroot=%s/arch-arm", ndk_sdkdir)) + table.insert(configs.ldflags, string.format("--sysroot=%s/arch-arm", ndk_sdkdir)) + table.insert(configs.shflags, string.format("--sysroot=%s/arch-arm", ndk_sdkdir)) + end end diff --git a/xmake/scripts/platform/android/prober.lua b/xmake/scripts/platform/android/prober.lua index 5ecf1731b..37cd18877 100644 --- a/xmake/scripts/platform/android/prober.lua +++ b/xmake/scripts/platform/android/prober.lua @@ -45,7 +45,51 @@ function prober._probe_arch(configs) configs.set("arch", "armv7-a") -- trace - utils.verbose("checking the architecture ... %s", configs.get("arch")) + utils.verbose("checking for the architecture ... %s", configs.get("arch")) + + -- ok + return true +end + +-- probe the sdk version for ndk +function prober._probe_ndk_sdkver(configs) + + -- ok? + local ndk_sdkver = config.get("ndk_sdkver") + if ndk_sdkver then return true end + + -- get the ndk + local ndk = config.get("ndk") + if ndk then + + -- match all sdk directories + local sdkdirs = os.match(ndk .. "/platforms/android-*", true) + if sdkdirs then + + -- get the max version + local version_maxn = 0 + for _, sdkdir in ipairs(sdkdirs) do + local filename = path.filename(sdkdir) + local version, count = filename:gsub("android%-", "") + if count > 0 then + 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 + end + + -- probe ok? update it + if ndk_sdkver > 0 then + configs.set("ndk_sdkver", ndk_sdkver) + configs.set("__ndk_sdkdir", string.format("%s/platforms/android-%d", ndk, ndk_sdkver)) + end + + -- trace + utils.verbose("checking for the SDK version of NDK ... %s", string.format("android-%d", ndk_sdkver)) -- ok return true @@ -82,12 +126,75 @@ function prober._probe_ccache(configs) return true end +-- probe the toolchains +function prober._probe_toolpath(configs, kind, cross, name, description) + + -- check + assert(kind) + + -- get the cross + cross = config.get("cross") or cross + + -- attempt to get it from the given cross toolchains + local toolpath = nil + local toolchains = config.get("toolchains") + if toolchains then + toolpath = tools.probe(cross .. (config.get(kind) or name), toolchains) + end + + -- attempt to get it directly from the configure + if not toolpath then + toolpath = config.get(kind) + end + + -- attempt to get it from the ndk + if not toolpath then + local ndk = config.get("ndk") + if ndk then + + -- match all toolchains + toolchains = os.match(string.format("%s/toolchains/arm-linux-androideabi-**/prebuilt/*/bin/%s%s", ndk, cross, name)) + if toolchains then + for _, filepath in ipairs(toolchains) do + -- probe the tool path + toolpath = tools.probe(cross .. name, path.directory(filepath)) + if toolpath then break end + end + end + end + end + + -- probe ok? update it + if toolpath then configs.set(kind, toolpath) end + + -- trace + utils.verbose("checking for %s (%s) ... %s", description, kind, utils.ifelse(toolpath, path.filename(toolpath), "no")) + + -- ok + return true +end + +-- probe the compiler +function prober._probe_toolchains(configs) + + -- done + if not prober._probe_toolpath(configs, "cc", "arm-linux-androideabi-", "gcc", "the c compiler") then return false end + if not prober._probe_toolpath(configs, "cxx", "arm-linux-androideabi-", "g++", "the c++ compiler") then return false end + if not prober._probe_toolpath(configs, "as", "arm-linux-androideabi-", "gcc", "the assember") then return false end + if not prober._probe_toolpath(configs, "ld", "arm-linux-androideabi-", "g++", "the linker") then return false end + if not prober._probe_toolpath(configs, "ar", "arm-linux-androideabi-", "ar", "the static library linker") then return false end + if not prober._probe_toolpath(configs, "sh", "arm-linux-androideabi-", "g++", "the shared library linker") then return false end + return true +end + -- probe the project configure function prober.config() -- call all probe functions utils.call( { prober._probe_arch - , prober._probe_ccache} + , prober._probe_ccache + , prober._probe_ndk_sdkver + , prober._probe_toolchains} , nil , config) @@ -97,7 +204,8 @@ end function prober.global() -- call all probe functions - utils.call( prober._probe_ccache + utils.call( { prober._probe_ccache + , prober._probe_ndk_sdkver} , nil , global) end |
