@@ -46,14 +46,28 @@ function _patch_pkgconfig(package)
4646 -- get lib/pkgconfig/*.pc or share/pkgconfig/*.pc file
4747 local libpkgconfigdir = path .join (package :installdir (), " lib" , " pkgconfig" )
4848 local sharepkgconfigdir = path .join (package :installdir (), " share" , " pkgconfig" )
49- local pcfile = (os .isdir (libpkgconfigdir ) and find_file (" *.pc" , libpkgconfigdir ))
50- or (os .isdir (sharepkgconfigdir ) and find_file (" *.pc" , sharepkgconfigdir )) or nil
51- if pcfile then
49+ local pcfiles = {}
50+ table .join2 (pcfiles , os .isdir (libpkgconfigdir ) and os .files (path .join (libpkgconfigdir , " *.pc" )) or {})
51+ table .join2 (pcfiles , os .isdir (sharepkgconfigdir ) and os .files (path .join (sharepkgconfigdir , " *.pc" )) or {})
52+ if # pcfiles > 0 then
53+ for _ , pcfile in ipairs (pcfiles ) do
54+ local pcfile_content = io .readfile (pcfile )
55+ if pcfile_content then
56+ local pcfile_content , count = pcfile_content :replace (installdir , " ${installdir}" , {plain = true })
57+ if count > 0 then
58+ local line_ending = pcfile_content :find (" \r\n " ) and " \r\n " or " \n "
59+ pcfile_content = " # Modified by Xmake: Using relative paths to make package relocatable" .. line_ending
60+ .. " installdir=${pcfiledir}/" .. path .unix (path .relative (installdir , path .directory (pcfile ))) .. line_ending
61+ .. pcfile_content
62+ io .writefile (pcfile , pcfile_content )
63+ end
64+ end
65+ end
5266 return
5367 end
5468
5569 -- trace
56- pcfile = path .join (libpkgconfigdir , package :name () .. " .pc" )
70+ local pcfile = path .join (libpkgconfigdir , package :name () .. " .pc" )
5771 vprint (" patching %s .." , pcfile )
5872
5973 -- fetch package
0 commit comments