diff options
| author | ruki <[email protected]> | 2018-11-15 00:49:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-11-14 22:56:32 +0800 |
| commit | b0cabeb7b3e21380073df6521cc9027b5ac3f1ca (patch) | |
| tree | 0f939b5ff941ea68af717804035328d60000315c | |
| parent | 1feb7be8eca85f724b52fa875951179c52f9d018 (diff) | |
improve to build for android ndk
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_program.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_ndk.lua | 15 | ||||
| -rw-r--r-- | xmake/platforms/android/check.lua | 17 | ||||
| -rw-r--r-- | xmake/platforms/android/load.lua | 59 | ||||
| -rw-r--r-- | xmake/platforms/android/xmake.lua | 2 |
5 files changed, 76 insertions, 30 deletions
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua index 9bab776ad..f354b5a56 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -82,11 +82,6 @@ end -- find program function sandbox_lib_detect_find_program._find(name, pathes, opt) - -- attempt to check it directly in current environment - if sandbox_lib_detect_find_program._check(name, opt) then - return name - end - -- attempt to check it from the given directories if not path.is_absolute(name) then for _, _path in ipairs(table.wrap(pathes)) do @@ -150,6 +145,14 @@ function sandbox_lib_detect_find_program._find(name, pathes, opt) end end end + + -- attempt to check it directly in current environment + -- + -- @note must be detected at the end, because full path is more accurate + -- + if sandbox_lib_detect_find_program._check(name, opt) then + return name + end end -- find program diff --git a/xmake/modules/detect/sdks/find_ndk.lua b/xmake/modules/detect/sdks/find_ndk.lua index 9c9f727c3..130ad220a 100644 --- a/xmake/modules/detect/sdks/find_ndk.lua +++ b/xmake/modules/detect/sdks/find_ndk.lua @@ -91,7 +91,10 @@ function _find_ndk(sdkdir, arch, ndk_sdkver, ndk_toolchains_ver) local cross = arm64 and "aarch64-linux-android-" or "arm-linux-androideabi-" -- find the binary directory - local bindir = find_directory("bin", path.join(sdkdir, "toolchains", cross .. "*", "prebuilt", "*")) + local bindir = find_directory("bin", path.join(sdkdir, "toolchains", "llvm", "prebuilt", "*")) -- larger than ndk r16 + if not bindir then + bindir = find_directory("bin", path.join(sdkdir, "toolchains", cross .. "*", "prebuilt", "*")) + end if not bindir then return {} end @@ -102,14 +105,20 @@ function _find_ndk(sdkdir, arch, ndk_sdkver, ndk_toolchains_ver) return {} end + -- find the gcc toolchain + local gcc_toolchain = find_directory("bin", path.join(sdkdir, "toolchains", cross .. "*", "prebuilt", "*")) + if gcc_toolchain then + gcc_toolchain = path.directory(gcc_toolchain) + end + -- find the toolchains version - local toolchains_ver = ndk_toolchains_ver or _find_ndk_toolchains_ver(bindir) + local toolchains_ver = ndk_toolchains_ver or _find_ndk_toolchains_ver(gcc_toolchain or bindir) if not toolchains_ver then return {} end -- ok? - return {sdkdir = sdkdir, bindir = bindir, cross = cross, sdkver = sdkver, toolchains_ver = toolchains_ver} + return {sdkdir = sdkdir, bindir = bindir, cross = cross, sdkver = sdkver, gcc_toolchain = gcc_toolchain, toolchains_ver = toolchains_ver} end -- find ndk toolchains diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua index 7c1fa50b4..d2eafb583 100644 --- a/xmake/platforms/android/check.lua +++ b/xmake/platforms/android/check.lua @@ -33,6 +33,7 @@ function _check_ndk(config) config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global config.set("bin", ndk.bindir, {force = true, readonly = true}) config.set("cross", ndk.cross, {force = true, readonly = true}) + config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) else -- failed cprint("${bright red}please run:") @@ -69,15 +70,13 @@ function _toolchains(config) 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") - if is_host("windows") then - checker.toolchain_insert(toolchains, "cc", cross, "gcc.cmd", "the c compiler") - checker.toolchain_insert(toolchains, "cxx", cross, "g++.cmd", "the c++ compiler") - checker.toolchain_insert(toolchains, "as", cross, "gcc.cmd", "the assember") - checker.toolchain_insert(toolchains, "ld", cross, "g++.cmd", "the linker") - checker.toolchain_insert(toolchains, "ld", cross, "gcc.cmd", "the linker") - checker.toolchain_insert(toolchains, "sh", cross, "g++.cmd", "the shared library linker") - checker.toolchain_insert(toolchains, "sh", cross, "gcc.cmd", "the shared library linker") - end + checker.toolchain_insert(toolchains, "cc", "", "clang", "the c compiler") + checker.toolchain_insert(toolchains, "cxx", "", "clang++", "the c++ compiler") + checker.toolchain_insert(toolchains, "as", "", "clang", "the assember") + checker.toolchain_insert(toolchains, "ld", "", "clang++", "the linker") + checker.toolchain_insert(toolchains, "ld", "", "clang", "the linker") + checker.toolchain_insert(toolchains, "sh", "", "clang++", "the shared library linker") + checker.toolchain_insert(toolchains, "sh", "", "clang", "the shared library linker") -- insert rust tools to toolchains checker.toolchain_insert(toolchains, "rc", "", "rustc", "the rust compiler") diff --git a/xmake/platforms/android/load.lua b/xmake/platforms/android/load.lua index bd2a5f759..3fc815265 100644 --- a/xmake/platforms/android/load.lua +++ b/xmake/platforms/android/load.lua @@ -34,10 +34,51 @@ function main(platform) platform:add("ldflags", "-llog") platform:add("shflags", "-llog") else - platform:add("cxflags", "-march=" .. arch, "-mthumb") - platform:add("asflags", "-march=" .. arch, "-mthumb") - platform:add("ldflags", "-march=" .. arch, "-llog", "-mthumb") - platform:add("shflags", "-march=" .. arch, "-llog", "-mthumb") + platform:add("cxflags", "-mthumb") + platform:add("asflags", "-mthumb") + platform:add("ldflags", "-llog", "-mthumb") + platform:add("shflags", "-llog", "-mthumb") + end + + -- use llvm directory? e.g. android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin + local isllvm = false + local bindir = config.get("bin") + if bindir and bindir:find("llvm", 1, true) then + isllvm = true + end + + -- init architecture + if isllvm then + + -- add target + local targets = + { + ["armv5te"] = "armv5te-none-linux-androideabi" + , ["armv7-a"] = "armv7-none-linux-androideabi" + , ["arm64-v8a"] = "aarch64-none-linux-android" + , ["i386"] = "i686-none-linux-android" + , ["x86_64"] = "x86_64-none-linux-android" + , ["mips"] = "mipsel-none-linux-android" + } + platform:add("cxflags", "-target " .. targets[arch]) + platform:add("asflags", "-target " .. targets[arch]) + platform:add("ldflags", "-target " .. targets[arch]) + platform:add("shflags", "-target " .. targets[arch]) + + -- add gcc toolchain + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + platform:add("cxflags", "-gcc-toolchain " .. gcc_toolchain) + platform:add("asflags", "-gcc-toolchain " .. gcc_toolchain) + platform:add("ldflags", "-gcc-toolchain " .. gcc_toolchain) + platform:add("shflags", "-gcc-toolchain " .. gcc_toolchain) + end + else + -- old version ndk + platform:add("cxflags", "-march=" .. arch) + platform:add("asflags", "-march=" .. arch) + platform:add("ldflags", "-march=" .. arch) + platform:add("shflags", "-march=" .. arch) end -- init cxflags for the target kind: binary @@ -72,9 +113,7 @@ function main(platform) local triples = { ["armv5te"] = "arm-linux-androideabi" - , ["armv6"] = "arm-linux-androideabi" , ["armv7-a"] = "arm-linux-androideabi" - , ["armv8-a"] = "arm-linux-androideabi" , ["arm64-v8a"] = "aarch64-linux-android" , ["i386"] = "i686-linux-android" , ["x86_64"] = "x86_64-linux-android" @@ -107,8 +146,8 @@ function main(platform) platform:add("ldflags", "-pie") -- get c++ stl sdk directory - local cxxstl_sdkdir = path.translate(format("%s/sources/cxx-stl/llvm-libc++", ndk)) - if not os.isdir(cxxstl_sdkdir) and config.get("ndk_toolchains_ver") then -- <= ndk r16 + local cxxstl_sdkdir = isllvm and path.translate(format("%s/sources/cxx-stl/llvm-libc++", ndk)) or nil + if (cxxstl_sdkdir == nil or not os.isdir(cxxstl_sdkdir)) and config.get("ndk_toolchains_ver") then -- <= ndk r16 cxxstl_sdkdir = path.translate(format("%s/sources/cxx-stl/gnu-libstdc++/%s", ndk, config.get("ndk_toolchains_ver"))) end @@ -119,9 +158,7 @@ function main(platform) local toolchains_archs = { ["armv5te"] = "armeabi" - , ["armv6"] = "armeabi" , ["armv7-a"] = "armeabi-v7a" - , ["armv8-a"] = "armeabi-v7a" , ["arm64-v8a"] = "arm64-v8a" } @@ -146,9 +183,7 @@ function main(platform) local targets = { ["armv5te"] = "arm-linux-androideabi" - , ["armv6"] = "arm-linux-androideabi" , ["armv7-a"] = "arm-linux-androideabi" - , ["armv8-a"] = "arm-linux-androideabi" , ["arm64-v8a"] = "aarch64-linux-android" } diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 46b67f26b..be1c06a24 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -32,7 +32,7 @@ platform("android") set_hosts("macosx", "linux", "windows") -- set archs - set_archs("armv5te", "armv6", "armv7-a", "armv8-a", "arm64-v8a") + set_archs("armv5te", "armv7-a", "arm64-v8a", "mips") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} |
