summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2019-04-24 22:44:45 +0800
committerruki <[email protected]>2019-04-24 10:28:33 +0800
commit2898840b2fee9a838ca84e1c0df129b00d81aa45 (patch)
treefa89c51532de1ff5ff23e0a58258f856a5566566 /xmake/modules
parenta4b4fff7cb09c6a8359bad4ee204559eb0e41c35 (diff)
improve cross compile for android
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/detect/tools/find_ranlib.lua54
-rw-r--r--xmake/modules/package/tools/autoconf.lua33
-rw-r--r--xmake/modules/private/platform/check_toolchain.lua6
3 files changed, 83 insertions, 10 deletions
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