summaryrefslogtreecommitdiff
path: root/xmake/modules/private/action/require/impl/actions/install.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/modules/private/action/require/impl/actions/install.lua')
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua38
1 files changed, 28 insertions, 10 deletions
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 5e0c2c542..4d0bada1f 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -41,17 +41,33 @@ function _patch_pkgconfig(package)
return
end
+ local installdir = path.unix(path.normalize(package:installdir()))
+
-- get lib/pkgconfig/*.pc or share/pkgconfig/*.pc file
local libpkgconfigdir = path.join(package:installdir(), "lib", "pkgconfig")
local sharepkgconfigdir = path.join(package:installdir(), "share", "pkgconfig")
- local pcfile = (os.isdir(libpkgconfigdir) and find_file("*.pc", libpkgconfigdir))
- or (os.isdir(sharepkgconfigdir) and find_file("*.pc", sharepkgconfigdir)) or nil
- if pcfile then
+ local pcfiles = {}
+ table.join2(pcfiles, os.isdir(libpkgconfigdir) and os.files(path.join(libpkgconfigdir, "*.pc")) or {})
+ table.join2(pcfiles, os.isdir(sharepkgconfigdir) and os.files(path.join(sharepkgconfigdir, "*.pc")) or {})
+ if #pcfiles > 0 then
+ for _, pcfile in ipairs(pcfiles) do
+ local pcfile_content = io.readfile(pcfile)
+ if pcfile_content then
+ local pcfile_content, count = pcfile_content:replace(installdir, "${installdir}", {plain = true})
+ if count > 0 then
+ local line_ending = pcfile_content:find("\r\n") and "\r\n" or "\n"
+ pcfile_content = "# Modified by Xmake: Using relative paths to make package relocatable" .. line_ending
+ .. "installdir=${pcfiledir}/" .. path.unix(path.relative(installdir, path.directory(pcfile))) .. line_ending
+ .. pcfile_content
+ io.writefile(pcfile, pcfile_content)
+ end
+ end
+ end
return
end
-- trace
- pcfile = path.join(libpkgconfigdir, package:name() .. ".pc")
+ local pcfile = path.join(libpkgconfigdir, package:name() .. ".pc")
vprint("patching %s ..", pcfile)
-- fetch package
@@ -62,10 +78,10 @@ function _patch_pkgconfig(package)
-- get libs
local libs = ""
- local installdir = package:installdir()
+ local base_libdir = path.join(installdir, "lib")
for _, linkdir in ipairs(fetchinfo.linkdirs) do
- if linkdir ~= path.join(installdir, "lib") then
- libs = libs .. " -L" .. (linkdir:gsub("\\", "/"))
+ if linkdir ~= base_libdir then
+ libs = libs .. " -L" .. "${libdir}/" .. path.unix(path.relative(linkdir, base_libdir))
end
end
libs = libs .. " -L${libdir}"
@@ -78,9 +94,10 @@ function _patch_pkgconfig(package)
-- cflags
local cflags = ""
+ local base_includedir = path.join(installdir, "include")
for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
- if includedir ~= path.join(installdir, "include") then
- cflags = cflags .. " -I" .. (includedir:gsub("\\", "/"))
+ if includedir ~= base_includedir then
+ cflags = cflags .. " -I" .. "${includedir}/" .. path.unix(path.relative(includedir, base_includedir))
end
end
cflags = cflags .. " -I${includedir}"
@@ -91,7 +108,8 @@ function _patch_pkgconfig(package)
-- patch a *.pc file
local file = io.open(pcfile, 'w')
if file then
- file:print("prefix=%s", installdir:gsub("\\", "/"))
+ file:print("# Generated by Xmake")
+ file:print("prefix=%s", "${pcfiledir}/" .. path.unix(path.relative(installdir, path.directory(pcfile))))
file:print("exec_prefix=${prefix}")
file:print("libdir=${exec_prefix}/lib")
file:print("includedir=${prefix}/include")