summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-03-20 23:17:58 +0800
committerruki <[email protected]>2019-03-20 13:47:53 +0800
commit8bb6ddf5c40f15fe6570f73dc5c4e5295ce95180 (patch)
treeec8d64fe7232ee25d692a9c32f3c6dcd1443b9b4
parent150774e55f09435550cf842128dd1cc8a258a707 (diff)
patch pkgconfig for package
-rw-r--r--xmake/actions/require/impl/action/install.lua69
-rw-r--r--xmake/modules/package/tools/autoconf.lua20
2 files changed, 81 insertions, 8 deletions
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