From a9b7c8719e4dfe92456d41917cfb7a1cec1f40c0 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 20 Nov 2022 23:17:56 +0800 Subject: improve pic for autoconf --- xmake/modules/package/tools/autoconf.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index fe0901ad1..24ddc8183 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -71,6 +71,20 @@ function _is_cross_compilation(package) return false end +-- has `--with-pic`? +function _has_with_pic() + local has_with_pic = _g.has_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 + _g.has_with_pic = has_with_pic + end + return has_with_pic +end + -- get configs function _get_configs(package, configs) @@ -125,6 +139,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() then + table.insert(configs, "--with-pic") + end return configs end @@ -247,7 +265,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() then table.insert(cflags, "-fPIC") table.insert(cxxflags, "-fPIC") end @@ -386,9 +405,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 +416,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 -- cgit v1.3.1 From ed1083eba5008fc9fab83dfec7c2aaee1cd684bf Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 21 Nov 2022 22:47:20 +0800 Subject: improve with pic cache --- xmake/modules/package/tools/autoconf.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index 24ddc8183..2f35ec6f0 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,16 +72,21 @@ function _is_cross_compilation(package) return false end +-- get memcache +function _memcache() + return memcache("package.tools.autoconf") +end + -- has `--with-pic`? -function _has_with_pic() - local has_with_pic = _g.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 - _g.has_with_pic = has_with_pic + _memcache():set2(tostring(package), "with_pic", has_with_pic) end return has_with_pic end @@ -140,7 +146,7 @@ function _get_configs(package, configs) end end if package:is_plat("linux", "bsd") and - package:config("pic") ~= false and _has_with_pic() then + package:config("pic") ~= false and _has_with_pic(package) then table.insert(configs, "--with-pic") end return configs @@ -266,7 +272,7 @@ function buildenvs(package, opt) envs.RANLIB = package:build_getenv("ranlib") end if package:is_plat("linux", "bsd") and - package:config("pic") ~= false and not _has_with_pic() then + package:config("pic") ~= false and not _has_with_pic(package) then table.insert(cflags, "-fPIC") table.insert(cxxflags, "-fPIC") end -- cgit v1.3.1 From 2f28634cc1b339affb4720d7f6164704fc2f0711 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 21 Nov 2022 23:02:42 +0800 Subject: fix memcache --- xmake/modules/package/tools/autoconf.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index 2f35ec6f0..29a2dd49f 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -74,7 +74,7 @@ end -- get memcache function _memcache() - return memcache("package.tools.autoconf") + return memcache.cache("package.tools.autoconf") end -- has `--with-pic`? -- cgit v1.3.1