summaryrefslogtreecommitdiff
path: root/xmake/modules/private/action/require/impl/actions/install.lua
diff options
context:
space:
mode:
authorChan Lee <[email protected]>2025-05-14 19:13:47 +0800
committerChan Lee <[email protected]>2025-05-14 19:28:44 +0800
commit0682d7c5b2e19d1759fe41688ff9897d123e1f04 (patch)
tree1117315a0da491e734f068ccaa67269ac7e55f2e /xmake/modules/private/action/require/impl/actions/install.lua
parente2dafa09e52622995afe22ed32206ecf38c9a9d0 (diff)
package(install): use relative paths in generated .pc files to improve relocatability
Diffstat (limited to 'xmake/modules/private/action/require/impl/actions/install.lua')
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua15
1 files changed, 9 insertions, 6 deletions
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index d30c9364f..0dbbe6a48 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -41,6 +41,8 @@ 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")
@@ -62,10 +64,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 +80,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}"
@@ -92,7 +95,7 @@ function _patch_pkgconfig(package)
local file = io.open(pcfile, 'w')
if file then
file:print("# Generated by Xmake")
- file:print("prefix=%s", installdir:gsub("\\", "/"))
+ 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")