summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-11-21 16:00:32 +0800
committerGitHub <[email protected]>2022-11-21 16:00:32 +0800
commit5ef00879d693c73e63a89a1748efee8cb24fef00 (patch)
tree0f59e5816f84c737e0ef5dd3bceac84f4cafd572
parent1eb3b2594f65b2bac9403f611fc0b322da182f69 (diff)
parent2f28634cc1b339affb4720d7f6164704fc2f0711 (diff)
Merge pull request #3086 from xmake-io/pic
improve pic for autoconf
-rw-r--r--xmake/modules/package/tools/autoconf.lua33
1 files changed, 29 insertions, 4 deletions
diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua
index fe0901ad1..29a2dd49f 100644
--- a/xmake/modules/package/tools/autoconf.lua
+++ b/xmake/modules/package/tools/autoconf.lua
@@ -23,6 +23,7 @@ import("core.base.option")
import("core.project.config")
import("core.tool.linker")
import("core.tool.compiler")
+import("core.cache.memcache")
import("lib.detect.find_tool")
-- translate paths
@@ -71,6 +72,25 @@ function _is_cross_compilation(package)
return false
end
+-- get memcache
+function _memcache()
+ return memcache.cache("package.tools.autoconf")
+end
+
+-- has `--with-pic`?
+function _has_with_pic(package)
+ local has_with_pic = _memcache():get2(tostring(package), "with_pic")
+ if has_with_pic == nil then
+ local result = try {function() return os.iorunv("./configure", {"--help"}, {shell = true}) end}
+ if result and result:find("--with-pic", 1, true) then
+ has_with_pic = true
+ end
+ has_with_pic = has_with_pic or false
+ _memcache():set2(tostring(package), "with_pic", has_with_pic)
+ end
+ return has_with_pic
+end
+
-- get configs
function _get_configs(package, configs)
@@ -125,6 +145,10 @@ function _get_configs(package, configs)
table.insert(configs, "--host=" .. host)
end
end
+ if package:is_plat("linux", "bsd") and
+ package:config("pic") ~= false and _has_with_pic(package) then
+ table.insert(configs, "--with-pic")
+ end
return configs
end
@@ -247,7 +271,8 @@ function buildenvs(package, opt)
envs.CPP = package:build_getenv("cpp")
envs.RANLIB = package:build_getenv("ranlib")
end
- if package:is_plat("linux") and package:config("pic") ~= false then
+ if package:is_plat("linux", "bsd") and
+ package:config("pic") ~= false and not _has_with_pic(package) then
table.insert(cflags, "-fPIC")
table.insert(cxxflags, "-fPIC")
end
@@ -386,9 +411,6 @@ function configure(package, configs, opt)
-- init options
opt = opt or {}
- -- get envs
- local envs = opt.envs or buildenvs(package, opt)
-
-- generate configure file
if not os.isfile("configure") then
if os.isfile("autogen.sh") then
@@ -400,6 +422,9 @@ function configure(package, configs, opt)
end
end
+ -- get envs
+ local envs = opt.envs or buildenvs(package, opt)
+
-- pass configurations
local argv = {}
for name, value in pairs(_get_configs(package, configs)) do