From c548ab42140686edaa93b9b952e8f64241bf364c Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 15 Mar 2019 23:40:59 +0800 Subject: pass configs to autoconf --- xmake/modules/package/tools/autoconf.lua | 74 ++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 18 deletions(-) (limited to 'xmake/modules/package/tools/autoconf.lua') diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index 29e147636..c4858fa01 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -22,6 +22,56 @@ -- @file autoconf.lua -- +-- get configs +function _get_configs(package, configs) + local configs = configs or {} + table.insert(configs, "--prefix=" .. package:installdir()) + return configs +end + +-- enter environments +function _enter_envs(package) + + -- get old environments + local envs = {} + envs.CFLAGS = os.getenv("CFLAGS") + envs.CXXFLAGS = os.getenv("CXXFLAGS") + envs.ASFLAGS = os.getenv("ASFLAGS") + + -- set new environments + local cflags = package:config("cflags") + local cxflags = package:config("cxflags") + local cxxflags = package:config("cxxflags") + local asflags = package:config("asflags") + if package:plat() == "windows" then + local vs_runtime = package:config("vs_runtime") + if vs_runtime then + cxflags = (cxflags or "") .. " /" .. vs_runtime .. (package:debug() and "d" or "") + end + end + if cflags then + os.addenv("CFLAGS", cflags) + end + if cxflags then + os.addenv("CFLAGS", cxflags) + os.addenv("CXXFLAGS", cxflags) + end + if cxxflags then + os.addenv("CXXFLAGS", cxxflags) + end + if asflags then + os.addenv("ASFLAGS", asflags) + end + return envs +end + +-- leave environments +function _leave_envs(package, envs) + for k, v in pairs(envs) do + os.setenv(k, v) + end +end + -- install package function install(package, configs) @@ -34,12 +84,9 @@ function install(package, configs) end end - -- inherit require and option configs + -- pass configurations local argv = {} - if not configs or not configs.prefix then - table.insert(argv, "--prefix=" .. package:installdir()) - end - for name, value in pairs(configs) do + for name, value in pairs(_get_configs(package, configs)) do value = tostring(value):trim() if type(name) == "number" then if value ~= "" then @@ -50,15 +97,8 @@ function install(package, configs) end end - -- inherit flags from configs - local flags_prev = {} - for _, name in ipairs({"cflags", "cxxflags", "ldflags"}) do - local flags = package:config(name) or (configs and configs[name] or nil) - if flags then - flags_prev[name] = os.getenv(name:upper()) - os.addenv(name:upper(), flags) - end - end + -- enter environments + local envs = _enter_envs(package) -- do configure os.vrunv("./configure", argv) @@ -67,9 +107,7 @@ function install(package, configs) os.vrun("make -j4") os.vrun("make install") - -- restore flags - for name, flags in pairs(flags_prev) do - os.setenv(name:upper(), flags) - end + -- leave environments + _leave_envs(package, envs) end -- cgit v1.3.1 From 8bb6ddf5c40f15fe6570f73dc5c4e5295ce95180 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 Mar 2019 23:17:58 +0800 Subject: patch pkgconfig for package --- xmake/actions/require/impl/action/install.lua | 69 +++++++++++++++++++++++++-- xmake/modules/package/tools/autoconf.lua | 20 ++++++-- 2 files changed, 81 insertions(+), 8 deletions(-) (limited to 'xmake/modules/package/tools/autoconf.lua') diff --git a/xmake/actions/require/impl/action/install.lua b/xmake/actions/require/impl/action/install.lua index 75e07d033..6bb9d85ca 100644 --- a/xmake/actions/require/impl/action/install.lua +++ b/xmake/actions/require/impl/action/install.lua @@ -28,6 +28,62 @@ import("core.project.target") import("test") import(".utils.filter") +-- patch pkgconfig if not exists +function _patch_pkgconfig(package) + + -- get lib/pkgconfig/*.pc file + local pcfile = path.join(package:installdir(), "lib", "pkgconfig", package:name() .. ".pc") + if os.isfile(pcfile) then + return + end + + -- trace + vprint("patching %s ..", pcfile) + + -- fetch package + local fetchinfo = package:fetchdeps() + if not fetchinfo then + return + end + + -- get libs + local libs = "" + for _, linkdir in ipairs(fetchinfo.linkdirs) do + libs = libs .. "-L" .. linkdir + end + libs = libs .. " -L${libdir}" + for _, link in ipairs(fetchinfo.links) do + libs = libs .. " -l" .. link + end + for _, link in ipairs(fetchinfo.syslinks) do + libs = libs .. " -l" .. link + end + + -- cflags + local cflags = "" + for _, includedir in ipairs(fetchinfo.includedirs) do + cflags = cflags .. "-I" .. includedir + end + cflags = cflags .. " -I${includedir}" + + -- patch a *.pc file + local file = io.open(pcfile, 'w') + if file then + file:print("prefix=%s", package:installdir()) + file:print("exec_prefix=${prefix}") + file:print("libdir=${exec_prefix}/lib") + file:print("includedir=${prefix}/include") + file:print("") + file:print("Name: %s", package:name()) + file:print("Description: %s", package:description()) + file:print("Version: %s", package:version_str()) + file:print("Libs: %s", libs) + file:print("Libs.private: ") + file:print("Cflags: %s", cflags) + file:close() + end +end + -- install the given package function main(package) @@ -79,7 +135,7 @@ function main(package) local installtask = function () -- install the third-party package directly, e.g. brew::pcre2/libpcre2-8, conan::OpenSSL/1.0.2n@conan/stable - local need_test = false + local installed_now = false if package:is3rd() then local script = package:script("install") if script ~= nil then @@ -113,7 +169,7 @@ function main(package) -- save the package info to the manifest file package:manifest_save() - need_test = true + installed_now = true end end @@ -127,8 +183,13 @@ function main(package) end assert(fetchinfo, "fetch %s failed!", tipname) - -- test it - if need_test then + -- this package is installed now + if installed_now then + + -- patch pkg-config files for package + _patch_pkgconfig(package) + + -- test it test(package) end diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index c4858fa01..32186a080 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -33,10 +33,12 @@ end function _enter_envs(package) -- get old environments - local envs = {} - envs.CFLAGS = os.getenv("CFLAGS") - envs.CXXFLAGS = os.getenv("CXXFLAGS") - envs.ASFLAGS = os.getenv("ASFLAGS") + local envs = {} + envs.CFLAGS = os.getenv("CFLAGS") + envs.CXXFLAGS = os.getenv("CXXFLAGS") + envs.ASFLAGS = os.getenv("ASFLAGS") + envs.ACLOCAL_PATH = os.getenv("ACLOCAL_PATH") + envs.PKG_CONFIG_PATH = os.getenv("PKG_CONFIG_PATH") -- set new environments local cflags = package:config("cflags") @@ -62,6 +64,16 @@ function _enter_envs(package) if asflags then os.addenv("ASFLAGS", asflags) end + for _, dep in ipairs(package:orderdeps()) do + local pkgconfig = path.join(dep:installdir(), "lib", "pkgconfig") + if os.isdir(pkgconfig) then + os.addenv("PKG_CONFIG_PATH", pkgconfig) + end + local aclocal = path.join(dep:installdir(), "share", "aclocal") + if os.isdir(aclocal) then + os.addenv("ACLOCAL_PATH", aclocal) + end + end return envs end -- cgit v1.3.1