diff options
| author | ruki <[email protected]> | 2019-04-24 22:44:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-04-24 10:28:33 +0800 |
| commit | 2898840b2fee9a838ca84e1c0df129b00d81aa45 (patch) | |
| tree | fa89c51532de1ff5ff23e0a58258f856a5566566 | |
| parent | a4b4fff7cb09c6a8359bad4ee204559eb0e41c35 (diff) | |
improve cross compile for android
| -rw-r--r-- | xmake/languages/c++/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_ranlib.lua | 54 | ||||
| -rw-r--r-- | xmake/modules/package/tools/autoconf.lua | 33 | ||||
| -rw-r--r-- | xmake/modules/private/platform/check_toolchain.lua | 6 | ||||
| -rw-r--r-- | xmake/platforms/android/config.lua | 11 |
5 files changed, 94 insertions, 11 deletions
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index 73c438adb..6ea974ba4 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -163,6 +163,7 @@ language("c++") , {nil, "ld", "kv", nil, "The Linker" } , {nil, "ar", "kv", nil, "The Static Library Linker" } , {nil, "sh", "kv", nil, "The Shared Library Linker" } + , {nil, "ranlib", "kv", nil, "The Static Library Index Generator" } , {category = "Cross Complation Configuration/Compiler Flags Configuration" } , {nil, "cflags", "kv", nil, "The C Compiler Flags" } diff --git a/xmake/modules/detect/tools/find_ranlib.lua b/xmake/modules/detect/tools/find_ranlib.lua new file mode 100644 index 000000000..c20b14bf1 --- /dev/null +++ b/xmake/modules/detect/tools/find_ranlib.lua @@ -0,0 +1,54 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_ranlib.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find ranlib +-- +-- @param opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local ranlib = find_ranlib() +-- local ranlib, version = find_ranlib({program = "xcrun -sdk macosx ranlib", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "ranlib", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index d44adea5e..42096eff1 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -18,6 +18,9 @@ -- @file autoconf.lua -- +-- imports +import("core.project.config") + -- get configs function _get_configs(package, configs) local configs = configs or {} @@ -43,6 +46,9 @@ function _get_configs(package, configs) , mips64 = "mips64-linux-android" } table.insert(configs, "--host=" .. (triples[package:arch()] or "armv7a-linux-androideabi")) + elseif package:is_plat("cross") then + else + raise("autoconf: unknown platform(%s)!", package:plat()) end return configs end @@ -65,6 +71,7 @@ function _enter_envs(package) envs.LDFLAGS = os.getenv("LDFLAGS") envs.ARFLAGS = os.getenv("ARFLAGS") envs.SHFLAGS = os.getenv("SHFLAGS") + envs.TOOLCHAIN = os.getenv("TOOLCHAIN") envs.ACLOCAL_PATH = os.getenv("ACLOCAL_PATH") envs.PKG_CONFIG_PATH = os.getenv("PKG_CONFIG_PATH") @@ -76,13 +83,13 @@ function _enter_envs(package) os.addenvp("CXXFLAGS", package:config("cxxflags"), ' ') os.addenvp("ASFLAGS", package:config("asflags"), ' ') else - os.setenv("RANLIB", "") - os.setenvp("CC", package:build_getenv("cc"), ' ') - os.setenvp("AS", package:build_getenv("as"), ' ') - os.setenvp("AR", package:build_getenv("ar"), ' ') - os.setenvp("LD", package:build_getenv("ld"), ' ') - os.setenvp("LDSHARED", package:build_getenv("sh"), ' ') - os.setenvp("CPP", package:build_getenv("cpp"), ' ') + os.setenvp("CC", package:build_getenv("cc")) + os.setenvp("AS", package:build_getenv("as")) + os.setenvp("AR", package:build_getenv("ar")) + os.setenvp("LD", package:build_getenv("ld")) + os.setenvp("LDSHARED", package:build_getenv("sh")) + os.setenvp("CPP", package:build_getenv("cpp")) + os.setenvp("RANLIB", package:build_getenv("ranlib")) os.addenvp("CFLAGS", package:build_getenv("cflags"), ' ') os.addenvp("CFLAGS", package:build_getenv("cxflags"), ' ') os.addenvp("CXXFLAGS", package:build_getenv("cxflags"), ' ') @@ -91,6 +98,18 @@ function _enter_envs(package) os.addenvp("ARFLAGS", package:build_getenv("arflags"), ' ') os.addenvp("LDFLAGS", package:build_getenv("ldflags"), ' ') os.addenvp("SHFLAGS", package:build_getenv("shflags"), ' ') + if package:is_plat("android") then + local gcc_toolchain = config.get("gcc_toolchain") + if not gcc_toolchain then + local bindir = config.get("bindir") + if bindir then + gcc_toolchain = path.directory(bindir) + end + end + if gcc_toolchain and os.isdir(gcc_toolchain) then + os.setenv("TOOLCHAIN", gcc_toolchain) + end + end end for _, dep in ipairs(package:orderdeps()) do local pkgconfig = path.join(dep:installdir(), "lib", "pkgconfig") diff --git a/xmake/modules/private/platform/check_toolchain.lua b/xmake/modules/private/platform/check_toolchain.lua index 49aafad90..c0f3c9345 100644 --- a/xmake/modules/private/platform/check_toolchain.lua +++ b/xmake/modules/private/platform/check_toolchain.lua @@ -23,7 +23,7 @@ import("core.base.option") import("lib.detect.find_tool") -- check the given tool -function _check_tool(config, toolkind, description, name, cross, check) +function _check_tool(config, toolkind, description, name, cross, pathes, check) -- get the program local program = config.get(toolkind) @@ -38,7 +38,7 @@ function _check_tool(config, toolkind, description, name, cross, check) -- attempt to check it local toolname = nil if not program then - local tool = find_tool(name, {program = (cross or "") .. name, pathes = config.get("bin"), check = check}) + local tool = find_tool(name, {program = (cross or "") .. name, pathes = pathes or config.get("bin"), check = check}) if tool then program = tool.program toolname = tool.name @@ -74,7 +74,7 @@ function main(config, name, toolchain) break end else - if _check_tool(config, name, toolchain.description, toolinfo.name, toolinfo.cross, toolinfo.check) then + if _check_tool(config, name, toolchain.description, toolinfo.name, toolinfo.cross, toolinfo.pathes, toolinfo.check) then break end end diff --git a/xmake/platforms/android/config.lua b/xmake/platforms/android/config.lua index fbc6ce7a7..92fa49d4c 100644 --- a/xmake/platforms/android/config.lua +++ b/xmake/platforms/android/config.lua @@ -56,12 +56,13 @@ function _toolchains() local sh = toolchain("the shared library linker") local ar = toolchain("the static library archiver") local ex = toolchain("the static library extractor") + local ranlib = toolchain("the static library index generator") local as = toolchain("the assember") local rc = toolchain("the rust compiler") local rc_ld = toolchain("the rust linker") local rc_sh = toolchain("the rust shared library linker") local rc_ar = toolchain("the rust static library archiver") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar} -- init the c compiler @@ -89,6 +90,14 @@ function _toolchains() -- init the static library extractor ex:add({name = "ar", cross = cross}, "llvm-ar") + -- init the static library index generator + local gcc_toolchain_bin = nil + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + gcc_toolchain_bin = path.join(gcc_toolchain, "bin") + end + ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib") + -- init the rust compiler and linker rc:add("$(env RC)", "rustc") rc_ld:add("$(env RC)", "rustc") |
